Get it to a point where it works minimally on 1.13 Spigot.

This commit is contained in:
Matthew Miller
2018-07-16 00:21:32 +10:00
parent 59ca29577c
commit 3e1d438565
16 changed files with 2751 additions and 70 deletions

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import java.io.File;
@ -148,4 +149,23 @@ public abstract class LocalConfiguration {
return new File(".");
}
public String convertLegacyItem(String legacy) {
String item = legacy;
try {
String[] splitter = item.split(":", 2);
int id = 0;
byte data = 0;
if (splitter.length == 1) {
id = Integer.parseInt(item);
} else {
id = Integer.parseInt(splitter[0]);
data = Byte.parseByte(splitter[1]);
}
item = LegacyMapper.getInstance().getItemFromLegacy(id, data).getId();
} catch (Throwable e) {
}
return item;
}
}

View File

@ -56,11 +56,7 @@ public class YAMLConfiguration extends LocalConfiguration {
}
profile = config.getBoolean("debug", profile);
wandItem = config.getString("wand-item", wandItem);
try {
wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId();
} catch (Throwable e) {
}
wandItem = convertLegacyItem(config.getString("wand-item", wandItem));
defaultChangeLimit = Math.max(-1, config.getInt(
"limits.max-blocks-changed.default", defaultChangeLimit));
@ -104,11 +100,7 @@ public class YAMLConfiguration extends LocalConfiguration {
useInventoryCreativeOverride = config.getBoolean("use-inventory.creative-mode-overrides",
useInventoryCreativeOverride);
navigationWand = config.getString("navigation-wand.item", navigationWand);
try {
navigationWand = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(navigationWand)).getId();
} catch (Throwable e) {
}
navigationWand = convertLegacyItem(config.getString("navigation-wand.item", navigationWand));
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
navigationUseGlass = config.getBoolean("navigation.use-glass", navigationUseGlass);

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.registry.state.Property;
import java.util.Map;
import java.util.stream.Collectors;
public interface BlockStateHolder<T extends BlockStateHolder> {
@ -70,4 +71,13 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
* @return A BlockState
*/
BlockState toImmutableState();
default String getAsString() {
if (getStates().isEmpty()) {
return this.getBlockType().getId();
} else {
String properties = getStates().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining(","));
return this.getBlockType().getId() + "[" + properties + "]";
}
}
}

View File

@ -63,7 +63,7 @@ public class BundledBlockData {
private BundledBlockData() {
try {
loadFromResource();
} catch (IOException e) {
} catch (Throwable e) {
log.log(Level.WARNING, "Failed to load the built-in block registry", e);
}
}

View File

@ -44,7 +44,7 @@ public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override
public BlockMaterial getMaterial(String id) {
return BundledBlockData.getInstance().getMaterialById(id);
return new PassthroughBlockMaterial(BundledBlockData.getInstance().getMaterialById(id));
}
@Nullable

View File

@ -61,7 +61,7 @@ public class BundledItemData {
private BundledItemData() {
try {
loadFromResource();
} catch (IOException e) {
} catch (Throwable e) {
log.log(Level.WARNING, "Failed to load the built-in item registry", e);
}
}

View File

@ -57,7 +57,7 @@ public class LegacyMapper {
private LegacyMapper() {
try {
loadFromResource();
} catch (IOException e) {
} catch (Throwable e) {
log.log(Level.WARNING, "Failed to load the built-in legacy id registry", e);
}
}

View File

@ -0,0 +1,249 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BlockMaterial;
import javax.annotation.Nullable;
public class PassthroughBlockMaterial implements BlockMaterial {
@Nullable private final BlockMaterial blockMaterial;
public PassthroughBlockMaterial(@Nullable BlockMaterial material) {
this.blockMaterial = material;
}
@Override
public boolean isRenderedAsNormalBlock() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isRenderedAsNormalBlock();
}
}
@Override
public boolean isFullCube() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isFullCube();
}
}
@Override
public boolean isOpaque() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isOpaque();
}
}
@Override
public boolean isPowerSource() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isPowerSource();
}
}
@Override
public boolean isLiquid() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isLiquid();
}
}
@Override
public boolean isSolid() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isSolid();
}
}
@Override
public float getHardness() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getHardness();
}
}
@Override
public float getResistance() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getResistance();
}
}
@Override
public float getSlipperiness() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getSlipperiness();
}
}
@Override
public boolean isGrassBlocking() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isGrassBlocking();
}
}
@Override
public float getAmbientOcclusionLightValue() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getAmbientOcclusionLightValue();
}
}
@Override
public int getLightOpacity() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightOpacity();
}
}
@Override
public int getLightValue() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightValue();
}
}
@Override
public boolean isFragileWhenPushed() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isFragileWhenPushed();
}
}
@Override
public boolean isUnpushable() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isUnpushable();
}
}
@Override
public boolean isAdventureModeExempt() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isAdventureModeExempt();
}
}
@Override
public boolean isTicksRandomly() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isTicksRandomly();
}
}
@Override
public boolean isUsingNeighborLight() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isUsingNeighborLight();
}
}
@Override
public boolean isMovementBlocker() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isMovementBlocker();
}
}
@Override
public boolean isBurnable() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isOpaque();
}
}
@Override
public boolean isToolRequired() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isToolRequired();
}
}
@Override
public boolean isReplacedDuringPlacement() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isReplacedDuringPlacement();
}
}
@Override
public boolean isTranslucent() {
if (blockMaterial == null) {
return !isOpaque();
} else {
return blockMaterial.isTranslucent();
}
}
@Override
public boolean hasContainer() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.hasContainer();
}
}
}

File diff suppressed because it is too large Load Diff