Create default TileEntity data where required.

Fixes #1093
Fixes #1042
This commit is contained in:
dordsor21
2021-06-10 13:39:36 +01:00
parent 71130025e8
commit 7ef8b2f95e
13 changed files with 134 additions and 9 deletions

View File

@ -69,7 +69,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
*/
public BaseBlock(BlockState blockState) {
this.blockState = blockState;
nbtData = null;
this.nbtData = null;
}
/**

View File

@ -62,12 +62,12 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
private final BaseBlock emptyBaseBlock;
private CompoundInput compoundInput = CompoundInput.NULL;
protected BlockState(BlockType blockType, int internalId, int ordinal) {
protected BlockState(BlockType blockType, int internalId, int ordinal, CompoundTag tile) {
this.blockType = blockType;
this.internalId = internalId;
this.ordinal = ordinal;
this.ordinalChar = (char) ordinal;
this.emptyBaseBlock = new ImmutableBaseBlock(this);
this.emptyBaseBlock = new ImmutableBaseBlock(this, tile);
}
/**

View File

@ -186,7 +186,7 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
*/
@Nullable
default CompoundTag getNbtData() {
return null;
return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
}
/**

View File

@ -98,7 +98,7 @@ public class BlockTypesCache {
int ordinal = this.stateOrdinals[propId];
if (ordinal != -1) {
int stateId = internalId + (propId << BIT_OFFSET);
BlockState state = new BlockState(type, stateId, ordinal);
BlockState state = new BlockState(type, stateId, ordinal, blockMaterial.getDefaultTile());
states.add(state);
}
}
@ -106,7 +106,7 @@ public class BlockTypesCache {
this.defaultState = states.get(this.stateOrdinals[defaultPropId]);
} else {
this.defaultState = new BlockState(type, internalId, states.size());
this.defaultState = new BlockState(type, internalId, states.size(), blockMaterial.getDefaultTile());
states.add(this.defaultState);
}
}

View File

@ -48,7 +48,7 @@ public class FuzzyBlockState extends BlockState {
}
private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) {
super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
super(state.getBlockType(), state.getInternalId(), state.getOrdinal(), null);
if (values == null || values.isEmpty()) {
props = Collections.emptyMap();
this.values = Collections.emptyMap();

View File

@ -13,16 +13,19 @@ public final class ImmutableBaseBlock extends BaseBlock {
public ImmutableBaseBlock(BlockState blockState) {
super(blockState);
}
public ImmutableBaseBlock(BlockState blockState, CompoundTag tile) {
super(blockState, tile);
}
@Nullable
@Override
public CompoundTag getNbtData() {
return null;
return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
}
@Override
public boolean hasNbtData() {
return false;
return getBlockType().getMaterial().isTile();
}
@Override