Some general changes to the handling of blocks

This commit is contained in:
IronApollo 2019-01-14 05:49:05 -05:00
parent f74381b93f
commit 62e6e9de96
6 changed files with 42 additions and 17 deletions

View File

@ -1,3 +1,6 @@
apply plugin: 'eclipse'
apply plugin: 'maven'
repositories { repositories {
maven {url "https://ci.athion.net/job/FAWE-WorldGuard-1.13/lastSuccessfulBuild/artifact/mvn"} maven {url "https://ci.athion.net/job/FAWE-WorldGuard-1.13/lastSuccessfulBuild/artifact/mvn"}
} }

View File

@ -83,9 +83,15 @@ public class BaseBlock extends BlockState {
public BaseBlock(BlockType blockType) { public BaseBlock(BlockType blockType) {
this(blockType.getDefaultState()); this(blockType.getDefaultState());
} }
/**
* Construct a block with a state.
*
* @param blockState The blockstate
*/
public BaseBlock(BlockState 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 * @param nbtData NBT data, which must be provided
*/ */
public BaseBlock(BlockState state, CompoundTag nbtData) { public BaseBlock(BlockState state, CompoundTag nbtData) {
super(state.getBlockType()); // super(state.getBlockType());
checkNotNull(nbtData); checkNotNull(nbtData);
this.blockState = state; this.blockState = state;
this.nbtData = nbtData; this.nbtData = nbtData;
@ -200,7 +206,7 @@ public class BaseBlock extends BlockState {
@Override @Override
public BlockTypes getBlockType() { public BlockTypes getBlockType() {
return blockState.getBlockType(); return blockState.getBlockType();
} }
@Override @Override

View File

@ -85,14 +85,17 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
public static BlockState get(@Nullable BlockType type, String state) throws InputParseException { public static BlockState get(@Nullable BlockType type, String state) throws InputParseException {
return get(type, state, null); return get(type, state, null);
} }
private BaseBlock emptyBaseBlock; // private BlockTypes blockType;
// private BaseBlock emptyBaseBlock;
// Neighbouring state table. // Neighbouring state table.
private Table<Property<?>, Object, BlockState> states; private Table<Property<?>, Object, BlockState> states;
protected BlockState(BlockType blockType) { // protected BlockState(BlockTypes blockType) {
this.emptyBaseBlock = new BaseBlock(this); //// protected BlockState() {
} // this.blockType = blockType;
// this.emptyBaseBlock = new BaseBlock(this);
// }
/** /**
* Returns a temporary BlockState for a given type and string * Returns a temporary BlockState for a given type and string
@ -306,13 +309,13 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
return (Map<Property<?>, Object>) map; return (Map<Property<?>, Object>) map;
} }
@Override // @Override
public BaseBlock toBaseBlock() { // public BaseBlock toBaseBlock() {
// if (this.fuzzy) { //// if (this.fuzzy) {
// throw new IllegalArgumentException("Can't create a BaseBlock from a fuzzy BlockState!"); //// throw new IllegalArgumentException("Can't create a BaseBlock from a fuzzy BlockState!");
// } //// }
return this.emptyBaseBlock; // return this.emptyBaseBlock;
} // }
@Override @Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) { public BaseBlock toBaseBlock(CompoundTag compoundTag) {
@ -321,6 +324,11 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
} }
return new BaseBlock(this, compoundTag); return new BaseBlock(this, compoundTag);
} }
// @Override
// public BlockTypes getBlockType() {
// return this.blockType;
// }
/** /**
* Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense * Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense

View File

@ -9,12 +9,14 @@ public class BlockStateImpl extends BlockState {
private final int ordinal; private final int ordinal;
private final BlockTypes type; private final BlockTypes type;
private BlockMaterial material; private BlockMaterial material;
private BaseBlock baseBlock;
protected BlockStateImpl(BlockTypes type, int internalId, int ordinal) { protected BlockStateImpl(BlockTypes type, int internalId, int ordinal) {
super(type); // super(type);
this.type = type; this.type = type;
this.internalId = internalId; this.internalId = internalId;
this.ordinal = ordinal; this.ordinal = ordinal;
this.baseBlock = new BaseBlock(this);
} }
public BlockMaterial getMaterial() { public BlockMaterial getMaterial() {
@ -45,4 +47,9 @@ public class BlockStateImpl extends BlockState {
public final BlockTypes getBlockType() { public final BlockTypes getBlockType() {
return type; return type;
} }
@Override
public BaseBlock toBaseBlock() {
return this.baseBlock;
}
} }

View File

@ -774,7 +774,7 @@ public enum BlockTypes implements BlockType {
String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase(); String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase();
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("id"), this, name); 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); ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, settings);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -95,6 +95,7 @@ public class LegacyMapper {
for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) { for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) {
try { try {
BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue()); BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue());
// BlockState blockState = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState();
BlockTypes type = blockState.getBlockType(); BlockTypes type = blockState.getBlockType();
if (type.hasProperty(PropertyKey.WATERLOGGED)) { if (type.hasProperty(PropertyKey.WATERLOGGED)) {
blockState = blockState.with(PropertyKey.WATERLOGGED, false); blockState = blockState.with(PropertyKey.WATERLOGGED, false);