From 62e6e9de968b45b4a1aaee211d34058d18696d76 Mon Sep 17 00:00:00 2001 From: IronApollo Date: Mon, 14 Jan 2019 05:49:05 -0500 Subject: [PATCH] Some general changes to the handling of blocks --- favs/build.gradle | 3 ++ .../worldedit/world/block/BaseBlock.java | 12 +++++-- .../worldedit/world/block/BlockState.java | 32 ++++++++++++------- .../worldedit/world/block/BlockStateImpl.java | 9 +++++- .../worldedit/world/block/BlockTypes.java | 2 +- .../world/registry/LegacyMapper.java | 1 + 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/favs/build.gradle b/favs/build.gradle index 778e6aee2..7aded4c06 100644 --- a/favs/build.gradle +++ b/favs/build.gradle @@ -1,3 +1,6 @@ +apply plugin: 'eclipse' +apply plugin: 'maven' + repositories { maven {url "https://ci.athion.net/job/FAWE-WorldGuard-1.13/lastSuccessfulBuild/artifact/mvn"} } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 986b4de88..2db95dab0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -83,9 +83,15 @@ public class BaseBlock extends BlockState { public BaseBlock(BlockType blockType) { this(blockType.getDefaultState()); } + /** + * Construct a block with a state. + * + * @param blockState The blockstate + */ public BaseBlock(BlockState blockState) { - this(blockState, blockState.getNbtData()); +// this(blockState, blockState.getNbtData()); + this.blockState = blockState; } /** @@ -95,7 +101,7 @@ public class BaseBlock extends BlockState { * @param nbtData NBT data, which must be provided */ public BaseBlock(BlockState state, CompoundTag nbtData) { - super(state.getBlockType()); +// super(state.getBlockType()); checkNotNull(nbtData); this.blockState = state; this.nbtData = nbtData; @@ -200,7 +206,7 @@ public class BaseBlock extends BlockState { @Override public BlockTypes getBlockType() { - return blockState.getBlockType(); + return blockState.getBlockType(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 6a960eaed..5b87172ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -85,14 +85,17 @@ public abstract class BlockState implements BlockStateHolder { public static BlockState get(@Nullable BlockType type, String state) throws InputParseException { return get(type, state, null); } - private BaseBlock emptyBaseBlock; +// private BlockTypes blockType; +// private BaseBlock emptyBaseBlock; // Neighbouring state table. private Table, Object, BlockState> states; - - protected BlockState(BlockType blockType) { - this.emptyBaseBlock = new BaseBlock(this); - } + +// protected BlockState(BlockTypes blockType) { +//// protected BlockState() { +// this.blockType = blockType; +// this.emptyBaseBlock = new BaseBlock(this); +// } /** * Returns a temporary BlockState for a given type and string @@ -306,13 +309,13 @@ public abstract class BlockState implements BlockStateHolder { return (Map, Object>) map; } - @Override - public BaseBlock toBaseBlock() { -// if (this.fuzzy) { -// throw new IllegalArgumentException("Can't create a BaseBlock from a fuzzy BlockState!"); -// } - return this.emptyBaseBlock; - } +// @Override +// public BaseBlock toBaseBlock() { +//// if (this.fuzzy) { +//// throw new IllegalArgumentException("Can't create a BaseBlock from a fuzzy BlockState!"); +//// } +// return this.emptyBaseBlock; +// } @Override public BaseBlock toBaseBlock(CompoundTag compoundTag) { @@ -321,6 +324,11 @@ public abstract class BlockState implements BlockStateHolder { } return new BaseBlock(this, compoundTag); } + +// @Override +// public BlockTypes getBlockType() { +// return this.blockType; +// } /** * Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateImpl.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateImpl.java index ffce42d65..44d330401 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateImpl.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateImpl.java @@ -9,12 +9,14 @@ public class BlockStateImpl extends BlockState { private final int ordinal; private final BlockTypes type; private BlockMaterial material; + private BaseBlock baseBlock; protected BlockStateImpl(BlockTypes type, int internalId, int ordinal) { - super(type); +// super(type); this.type = type; this.internalId = internalId; this.ordinal = ordinal; + this.baseBlock = new BaseBlock(this); } public BlockMaterial getMaterial() { @@ -45,4 +47,9 @@ public class BlockStateImpl extends BlockState { public final BlockTypes getBlockType() { return type; } + + @Override + public BaseBlock toBaseBlock() { + return this.baseBlock; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index 541753639..0afa1720c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -774,7 +774,7 @@ public enum BlockTypes implements BlockType { String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase(); ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("id"), this, name); } - Settings settings = new Settings((this.getTypeEnum() == BlockTypes.__RESERVED__ ? BlockTypes.AIR : this), id, internalId, states); + Settings settings = new Settings(this, id, internalId, states); ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, settings); } catch (Throwable e) { e.printStackTrace(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index 8bf2a99cc..640271d0f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -95,6 +95,7 @@ public class LegacyMapper { for (Map.Entry blockEntry : dataFile.blocks.entrySet()) { try { BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue()); +// BlockState blockState = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState(); BlockTypes type = blockState.getBlockType(); if (type.hasProperty(PropertyKey.WATERLOGGED)) { blockState = blockState.with(PropertyKey.WATERLOGGED, false);