Posted November 19, 20186 yr Hi, I took some classes/code from Mr.Crayfish to create his sittable chairs (the EntitySittableBlock & SittableUtil) but when I add the code for onBlockActivated, I get stuck to the chair but the mob gets removed. Please could someone help with this issue? Here is my code for my chair class.. please can someone tell me what is wrong or what to add to resolve this issue? Spoiler package com.billyplayz.billysdecosmod.blocks; import java.util.List; import com.billyplayz.billysdecosmod.entity.EntitySittableBlock; import com.billyplayz.billysdecosmod.util.CollisionHelper; import com.billyplayz.billysdecosmod.util.SittableUtil; import com.google.common.collect.Lists; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class ChairBlock extends BlockBase{ private boolean red = false; public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.125, 0.0, 0.125, 0.875, 1.125, 0.875); public static final AxisAlignedBB CHAIR_SEAT = new AxisAlignedBB(0.125, 0.0, 0.125, 0.875, 0.5, 0.875); public static final AxisAlignedBB CHAIR_BACKREST_NORTH = CollisionHelper.getBlockBounds(EnumFacing.NORTH, 0.0, 0.5, 0.125, 0.125, 1.125, 0.875); public static final AxisAlignedBB CHAIR_BACKREST_EAST = CollisionHelper.getBlockBounds(EnumFacing.EAST, 0.0, 0.5, 0.125, 0.125, 1.125, 0.875); public static final AxisAlignedBB CHAIR_BACKREST_SOUTH = CollisionHelper.getBlockBounds(EnumFacing.SOUTH, 0.0, 0.5, 0.125, 0.125, 1.125, 0.875); public static final AxisAlignedBB CHAIR_BACKREST_WEST = CollisionHelper.getBlockBounds(EnumFacing.WEST, 0.0, 0.5, 0.125, 0.125, 1.125, 0.875); public ChairBlock(String name, Material material) { super(name, material.WOOD); setSoundType(SoundType.WOOD); } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return BOUNDING_BOX; } @Override public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { return SittableUtil.isSomeoneSitting(worldIn, pos.getX(), pos.getY(), pos.getZ()) ? 1 : 0; } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) { if(!(entityIn instanceof EntitySittableBlock)) { List<AxisAlignedBB> list = getCollisionBoxList(this.getActualState(state, worldIn, pos)); for(AxisAlignedBB box : list) { addCollisionBoxToList(pos, entityBox, collidingBoxes, box); } } } private List<AxisAlignedBB> getCollisionBoxList(IBlockState state) { List<AxisAlignedBB> list = Lists.newArrayList(); EnumFacing facing = state.getValue(FACING); switch(facing) { case NORTH: list.add(CHAIR_BACKREST_NORTH); break; case SOUTH: list.add(CHAIR_BACKREST_SOUTH); break; case WEST: list.add(CHAIR_BACKREST_WEST); break; default: list.add(CHAIR_BACKREST_EAST); break; } list.add(CHAIR_SEAT); return list; } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(!playerIn.isSneaking()) { if(SittableUtil.sitOnBlock(worldIn, pos.getX(), pos.getY(), pos.getZ(), playerIn, 6 * 0.0625)) { worldIn.updateComparatorOutputLevel(pos, this); return true; } } return false; } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing facing = EnumFacing.getFront(meta); if(facing.getAxis()==EnumFacing.Axis.Y) { facing=EnumFacing.NORTH; } return getDefaultState().withProperty(FACING, facing); } @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getIndex(); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[]{FACING}); } @Override public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } } Thank you to anyone who can help me.
November 19, 20186 yr 1 hour ago, Billy Playz said: Hi, I took some classes/code from Mr.Crayfish to create his sittable chairs Don't just copy-pasta code, read it, understand it, and use it. Assuming that his code is under a license that allows you to copy and distribute his code. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
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.