Jump to content

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


Drachenbauer

Recommended Posts

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