blueDude-owo Posted October 11, 2021 Share Posted October 11, 2021 i need help with changing the blockstate of my block when a certain block is near it here's the code: package net.blub.blub_mod.block; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorldReader; public class BluestoneWire extends Block { public static final BooleanProperty NORTH = BooleanProperty.create("north"); public static final BooleanProperty SOUTH = BooleanProperty.create("south"); public static final BooleanProperty EAST = BooleanProperty.create("east"); public static final BooleanProperty WEST = BooleanProperty.create("west"); public BluestoneWire(Properties properties) { super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(NORTH, false).setValue(SOUTH, false).setValue(EAST, false).setValue(WEST, false)); } @Override public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) { int x = pos.getX(); int nx = pos.getX()-1; int y = pos.getY(); int ny = pos.getY()-1; int z = pos.getZ(); int nz = pos.getZ()-1; BlockPos posnz = new BlockPos(x, y, nz); if ((world.getBlockState(posnz).getBlock()) == Blocks.ANDESITE) { state.setValue(NORTH, true); } else { state.setValue(NORTH, false); } super.onNeighborChange(state, world, pos, neighbor); } protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> stateContainer) { stateContainer.add(NORTH, SOUTH, EAST, WEST); } } Quote Link to comment Share on other sites More sharing options...
blueDude-owo Posted October 12, 2021 Author Share Posted October 12, 2021 so what should i do ? Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted October 12, 2021 Share Posted October 12, 2021 you need to place the new state at the position via World#setBlockState Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.