Posted August 4, 20214 yr I have a Wrench Item and when you shift-right click a block with it, it checks if it is a stair, then replaces it with a sittable stair. I haven't actually implemented the sitting functionality yet because I have read on the forums that to make a sittable block you create an entity and when the sittable stair is clicked make the player mount the entity, but I also would like to implement a dynamic texture (not sure if that is the right term) using tile entities so when the stair changes into a sittable stair its texture doesn't change. I am not sure if this is the most practical way to do this, and I would like to know if it would affect performance having a tile entity and entity for each sittable stair. Also would I be able to have just a tile entity or entity to accomplish this? Also I'm kind-of new to modding and my code isn't very good. Wrench class: public class WrenchItem extends Item { public WrenchItem(Properties properties) { super(properties); } @Override public ActionResultType onItemUse(ItemUseContext context) { // Useful variables World world = context.getWorld(); BlockPos blockpos = context.getPos(); BlockState blockstate = world.getBlockState(blockpos); PlayerEntity player = context.getPlayer(); boolean flag = false; // On use if (player.isSneaking()) { // Shift right click // Tile entity for dynamic tex // Entity for sitting // Add custom use sound if (StairsBlock.isBlockStairs(blockstate) && !world.isRemote) { world.setBlockState(blockpos, BlockInit.SITTABLE_STAIRS.get().getDefaultState() .with(SittableStairsBlock.FACING, blockstate.get((StairsBlock.FACING))) .with(SittableStairsBlock.HALF, blockstate.get((StairsBlock.HALF))) .with(SittableStairsBlock.WATERLOGGED, blockstate.get((StairsBlock.WATERLOGGED))) .with(SittableStairsBlock.SHAPE, blockstate.get((StairsBlock.SHAPE))) , 1); flag = true; } } else { // Right click if (blockstate.getBlock() == Blocks.GRASS_BLOCK && !world.isRemote) { world.setBlockState(blockpos, Blocks.DIRT.getDefaultState(), 1); flag = true; } } // Damages wrench when used, updates changed blocks, and plays use sound if (flag) { context.getItem().damageItem(1, player, (Consumer) -> {player.sendBreakAnimation(context.getHand());}); this.playUseSound(world, blockpos); world.notifyNeighborsOfStateChange(blockpos, blockstate.getBlock()); return ActionResultType.SUCCESS; } else { return ActionResultType.PASS; } } private void playUseSound(World worldIn, BlockPos pos) { worldIn.playSound((PlayerEntity)null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F); } } Edited August 4, 20214 yr by The_Biggest_Noob
August 4, 20214 yr Author 10 hours ago, diesieben07 said: all you need to do is spawn an entity and make the player mount that Thanks, this is a way simpler method for making sittable blocks. How would I handle killing the entity when the block is broken so you can't sit in air?
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.