use of mekanism.common.block.attribute.Attribute in project Mekanism by mekanism.
the class BlockStateHelper method copyStateData.
public static BlockState copyStateData(BlockState oldState, BlockState newState) {
Block oldBlock = oldState.getBlock();
Block newBlock = newState.getBlock();
for (Attribute attr : Attribute.getAll(oldBlock)) {
if (attr instanceof AttributeState) {
newState = ((AttributeState) attr).copyStateData(oldState, newState);
}
}
if (oldBlock instanceof IStateStorage && newBlock instanceof IStateStorage) {
newState = newState.setValue(storageProperty, oldState.getValue(storageProperty));
}
if (oldBlock instanceof IStateFluidLoggable && newBlock instanceof IStateFluidLoggable) {
IStateFluidLoggable oldFluidLoggable = (IStateFluidLoggable) oldBlock;
IStateFluidLoggable newFluidLoggable = (IStateFluidLoggable) newBlock;
if (oldFluidLoggable.getSupportedFluids().length == newFluidLoggable.getSupportedFluids().length) {
// Basic check if the number of supported fluids is the same copy it over
// TODO: Eventually maybe we want a better check? In theory they should always match but just in case
newState = newState.setValue(newFluidLoggable.getFluidLoggedProperty(), oldState.getValue(oldFluidLoggable.getFluidLoggedProperty()));
}
}
return newState;
}
use of mekanism.common.block.attribute.Attribute in project Mekanism by mekanism.
the class BlockStateHelper method getStateForPlacement.
@Contract("_, null, _, _, _, _ -> null")
public static BlockState getStateForPlacement(Block block, @Nullable BlockState state, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nullable PlayerEntity player, @Nonnull Direction face) {
if (state == null) {
return null;
}
for (Attribute attr : Attribute.getAll(block)) {
if (attr instanceof AttributeState) {
state = ((AttributeState) attr).getStateForPlacement(block, state, world, pos, player, face);
}
}
if (block instanceof IStateFluidLoggable) {
IStateFluidLoggable fluidLoggable = (IStateFluidLoggable) block;
FluidState fluidState = world.getFluidState(pos);
state = state.setValue(fluidLoggable.getFluidLoggedProperty(), fluidLoggable.getSupportedFluidPropertyIndex(fluidState.getType()));
}
return state;
}
Aggregations