use of com.bergerkiller.generated.net.minecraft.world.level.block.state.properties.IBlockStateHandle in project BKCommonLib by bergerhealer.
the class BlockDataImpl method getRenderOptions.
@Override
public BlockRenderOptions getRenderOptions(World world, int x, int y, int z) {
if (!this.hasRenderOptions) {
return new BlockRenderOptions(this, "");
}
CommonListener.BLOCK_PHYSICS_FIRED = false;
Object stateData;
if (world == null || BLOCK_UPDATE_STATE_BLACKLIST.contains(this.getType())) {
// TODO: We should call updateState() with an IBlockAccess that returns all Air.
// Right now, it will return the options of the last-modified block
stateData = this.data.getRaw();
} else {
// This refreshes the state (cached) to reflect a particular Block
stateData = BlockHandle.T.updateState.raw.invoke(this.block.getRaw(), this.data.getRaw(), HandleConversion.toWorldHandle(world), BlockPositionHandle.T.constr_x_y_z.raw.newInstance(x, y, z));
}
BlockRenderOptions options;
if (stateData == null) {
// Not sure if this can happen; but we handle it!
options = new BlockRenderOptions(this, new HashMap<String, String>(0));
} else {
// Serialize all tokens into String key-value pairs
Map<IBlockStateHandle, Comparable<?>> states = IBlockDataHandle.T.getStates.invoke(stateData);
Map<String, String> statesStr = new HashMap<String, String>(states.size());
for (Map.Entry<IBlockStateHandle, Comparable<?>> state : states.entrySet()) {
String key = state.getKey().getKeyToken();
String value = state.getKey().getValueToken(state.getValue());
statesStr.put(key, value);
}
options = new BlockRenderOptions(this, statesStr);
}
// Add additional options not provided by the server
// This handles the display parameters for blocks like Water and Lava
BlockRenderProvider renderProvider = BlockRenderProvider.get(this);
if (renderProvider != null) {
renderProvider.addOptions(options, world, x, y, z);
}
// This offers performance benefits
if (options.isEmpty()) {
this.hasRenderOptions = false;
}
// Block physics events ruin things, if they occur, disable the type and log it
if (CommonListener.BLOCK_PHYSICS_FIRED) {
CommonListener.BLOCK_PHYSICS_FIRED = false;
BLOCK_UPDATE_STATE_BLACKLIST.add(this.getType());
Logging.LOGGER.warning("[BlockData] Block physics are occurring when reading state of " + CommonLegacyMaterials.getMaterialName(this.getType()) + " data=" + this.toString() + " options=" + options);
}
return options;
}
Aggregations