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.

[solved] How do i add horizontal facing to a custom pressure plate?

Featured Replies

Posted

Hello

I´m creating custom pressure plates from alot of stone-Types.

One set is made out of the 16 glzed terracottas.

Now i want to have them rotateable to fit with the different rotations of this block.

But they are stuck in pressed state.

My PressurePlateBlock-class:

Spoiler

package drachenbauer32.coloredbuttonspressureplatesmod.blocks;

import java.util.List;

import net.minecraft.block.AbstractPressurePlateBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

public class PressurePlateBlock extends AbstractPressurePlateBlock
{
    public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
    
    public PressurePlateBlock(Block.Properties propertiesIn)
    {
        super(propertiesIn);
        this.setDefaultState(this.stateContainer.getBaseState().with(POWERED, Boolean.valueOf(false)));
    }
    
    protected int getRedstoneStrength(BlockState state)
    {
        return state.get(POWERED) ? 15 : 0;
    }
    
    protected BlockState setRedstoneStrength(BlockState state, int strength)
    {
        return state.with(POWERED, Boolean.valueOf(strength > 0));
    }
    
    protected void playClickOnSound(IWorld worldIn, BlockPos pos)
    {
        worldIn.playSound((PlayerEntity)null, pos, SoundEvents.BLOCK_STONE_PRESSURE_PLATE_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F);
    }
    
    protected void playClickOffSound(IWorld worldIn, BlockPos pos)
    {
        worldIn.playSound((PlayerEntity)null, pos, SoundEvents.BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF, SoundCategory.BLOCKS, 0.3F, 0.5F);
    }
    
    protected int computeRedstoneStrength(World worldIn, BlockPos pos)
    {
        AxisAlignedBB axisalignedbb = PRESSURE_AABB.offset(pos);
        List<? extends Entity> list = worldIn.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb);
           
        if (!list.isEmpty())
        {
            for(Entity entity : list)
            {
                if (!entity.doesEntityNotTriggerPressurePlate())
                {
                    return 15;
                }
            }
        }
        
        return 0;
   }

   protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder)
   {
      builder.add(POWERED);
   }
}

I needed to create it, because the constructor of the existing one is protected, so i cannot instantiate it for my custom pressureplates.

 

And here is the class for the rotateable ones:

Spoiler

package drachenbauer32.coloredbuttonspressureplatesmod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction;
import net.minecraft.util.Rotation;

public class RotateablePressurePlateBlock extends PressurePlateBlock
{
    public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
    
    public RotateablePressurePlateBlock(Properties propertiesIn)
    {
        super(propertiesIn);
        this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH));
    }
    
    @Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder)
    {
        super.fillStateContainer(builder);
        builder.add(FACING);
    }
    
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context)
    {
        return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
    }
    
    @Override
    public BlockState rotate(BlockState state, Rotation rot)
    {
        return state.with(FACING, rot.rotate(state.get(FACING)));
    }
}

What must i change here to make it work right?

 

Edit:

i had to put the facing and the powered state (set to false) into the setDefaultState-line in the consturctor ff the modifyed-class, not only the facing.

After i rompved and replaced theese presureplates in my test-world, now they work correct.

Edited by Drachenbauer

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.