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 {
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) {
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

View File

@ -85,14 +85,17 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
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<Property<?>, 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<BlockState> {
return (Map<Property<?>, 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<BlockState> {
}
return new BaseBlock(this, compoundTag);
}
// @Override
// public BlockTypes getBlockType() {
// return this.blockType;
// }
/**
* 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 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;
}
}

View File

@ -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();

View File

@ -95,6 +95,7 @@ public class LegacyMapper {
for (Map.Entry<String, String> 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);