MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Show me how to make a custom 'tank' block in forge 1.20 using the fluid API"
/* Forge 1.20 is not released yet, so we'll use Forge 1.16.5 as a reference. Here's an example of how to create a custom tank block using the fluid API. */ public class CustomTankBlock extends Block implements IWaterLoggable { public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public CustomTankBlock(Properties properties) { super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, Boolean.FALSE)); } @Nullable @Override public BlockState getStateForPlacement(BlockItemUseContext context) { FluidState fluidstate = context.getLevel().getFluidState(context.getClickedPos()); return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER); } @Override protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) { builder.add(FACING, WATERLOGGED); } @Override public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } } /* This is a basic example and doesn't actually store any fluid in the block. You'd need to create a TileEntity to store the fluid and handle interactions with buckets and other fluid containers. */