Hey guys, I want to change a block's texture when a player click on it.
My goal is to create an altar with the possiblity to place the item on it.
There is my code:
@SubscribeEvent
public void event(PlayerInteractEvent e) {
BlockPos bp = e.getPos();
BlockState bs = e.getWorld().getBlockState(bp);
Block b = bs.getBlock();
PlayerEntity p = e.getPlayer();
if((b == BlockList.altar) && (p.getHeldItemMainhand().getItem() == ItemList.amulet)) {
Dimensions.getLogger().info("Trigger On");
Block.replaceBlock(BlockList.altar.getDefaultState(), BlockList.altar_2.getDefaultState(), e.getWorld(), bp, 0);
p.setHeldItem(e.getHand(), new ItemStack(Items.AIR, 1));
}
else if((b == BlockList.altar_2) && (p.getHeldItemMainhand().getItem() == Items.AIR)) {
Dimensions.getLogger().info("Trigger Off");
Block.replaceBlock(BlockList.altar_2.getDefaultState(), BlockList.altar.getDefaultState(), e.getWorld(), bp, 0);
p.addItemStackToInventory(new ItemStack(ItemList.amulet, 1));
}
}
I have the debug message in the console and our inventory is modifying correctly but the block does not replace.
Do someone know how to do that ?
Thank you.