Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Should I have a TileEntity and Entity for a sittable block with a dynamic texture?

Featured Replies

Posted

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 by The_Biggest_Noob

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.