wannabeuk Posted December 1, 2018 Posted December 1, 2018 (edited) Hi all, I'm trying to create a block that is 2x1 (like a door) which has only three sides, allowing the player to walk inside it (like a booth). But I simply can't get my head around how to do the collisions. I've found a good example from a old mod (1.7) but i can't seem to work out how you would do this in 1.12. Does anyone know any uptodate examples or is willing to give me some pointers? Thanks. Edited December 2, 2018 by wannabeuk spelling Quote
Animefan8888 Posted December 1, 2018 Posted December 1, 2018 On 12/1/2018 at 1:38 PM, wannabeuk said: I'm trying to create a block that is 2x1 (like a door) Expand A door is actually too blocks(states). Also we cant help you if you dont post your code, preferably on git or some other code sharing site. Quote 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.
wannabeuk Posted December 2, 2018 Author Posted December 2, 2018 Thanks for the reply, I was aware it was two blocks it's just so much has changed since I last started modding that i was completely lost. I've managed to get my block to place correctly so it's two high. Now i'm trying to work on collisions. This is what i have : static double AXIS_MIN_MIN = 0, AXIS_MIN_MAX = 0.1, AXIS_MAX_MIN = 0.9, AXIS_MAX_MAX = 1, AXIS_FLOOR_MIN = -0.01, AXIS_FLOOR_MAX = 0; @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) { if(entityIn == null) { return; } List<AxisAlignedBB> axis = new ArrayList<AxisAlignedBB>(); EnumFacing facing = worldIn.getBlockState(pos).getValue(FACING); int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); //TODO : Work out how to do upper / lower block if(facing == EnumFacing.NORTH) { axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MAX_MIN, y, z), new BlockPos(x + AXIS_MAX_MAX, y + 1, z + 1))); // east axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MIN_MIN, y, z), new BlockPos(x + AXIS_MIN_MAX, y + 1, z + 1))); // west } else if (facing == EnumFacing.SOUTH) { axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MIN_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MIN_MAX))); // north axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MAX_MIN, y, z), new BlockPos(x + AXIS_MAX_MAX, y + 1, z + 1))); // east axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MIN_MIN, y, z), new BlockPos(x + AXIS_MIN_MAX, y + 1, z + 1))); // west } else if (facing == EnumFacing.EAST) { axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MIN_MIN, y, z), new BlockPos(x + AXIS_MIN_MAX, y + 1, z + 1))); // west axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MIN_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MIN_MAX))); // north axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south } else if (facing == EnumFacing.WEST) { axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MAX_MIN, y, z), new BlockPos(x + AXIS_MAX_MAX, y + 1, z + 1))); // east axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MIN_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MIN_MAX))); // north axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south } for(AxisAlignedBB a : axis) { if(a != null && entityBox.intersects(a)) { collidingBoxes.add(a); } } } it seems to have no effect on the collisions so i'm not sure if my code is just wrong. or if i'm missing something Quote
V0idWa1k3r Posted December 2, 2018 Posted December 2, 2018 On 12/2/2018 at 10:23 AM, wannabeuk said: axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south Expand Don't offset the boxes by the blockpos provided to you, the game will do that for you later. Apart from that your code should work, but here is an example of mine. Quote
wannabeuk Posted December 2, 2018 Author Posted December 2, 2018 Thanks voidwalker that worked perfectly. Quote
Recommended Posts
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.