Jump to content

Help with changing blockstate when a certain block is near it.


blueDude-owo

Recommended Posts

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);
	}

}

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.