From 5bd8bc1686a0d38d84e0aff0f3f4c1e75e0633fd Mon Sep 17 00:00:00 2001 From: Raoul Van den Berge Date: Sat, 6 Aug 2016 20:43:12 +0200 Subject: [PATCH] Better constructor / destructor collision --- .../java/refinedstorage/block/BlockCable.java | 17 ++++++- .../block/BlockConstructor.java | 51 +++++++++++++++++++ .../refinedstorage/block/BlockDestructor.java | 8 +++ .../refinedstorage/proxy/ClientProxy.java | 33 +++++++----- 4 files changed, 93 insertions(+), 16 deletions(-) diff --git a/src/main/java/refinedstorage/block/BlockCable.java b/src/main/java/refinedstorage/block/BlockCable.java index f8f9ec63f..70d111caa 100755 --- a/src/main/java/refinedstorage/block/BlockCable.java +++ b/src/main/java/refinedstorage/block/BlockCable.java @@ -32,10 +32,11 @@ import refinedstorage.tile.TileMultipartNode; import refinedstorage.tile.TileNode; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class BlockCable extends BlockCoverable { - private static final PropertyDirection DIRECTION = PropertyDirection.create("direction"); + protected static final PropertyDirection DIRECTION = PropertyDirection.create("direction"); protected static AxisAlignedBB createAABB(int fromX, int fromY, int fromZ, int toX, int toY, int toZ) { return new AxisAlignedBB((float) fromX / 16F, (float) fromY / 16F, (float) fromZ / 16F, (float) toX / 16F, (float) toY / 16F, (float) toZ / 16F); @@ -142,7 +143,7 @@ public class BlockCable extends BlockCoverable { return false; } - public static List getCollisionBoxes(IBlockState state) { + public List getUnionizedCollisionBoxes(IBlockState state) { List boxes = new ArrayList<>(); boxes.add(CORE_AABB); @@ -174,6 +175,18 @@ public class BlockCable extends BlockCoverable { return boxes; } + public List getNonUnionizedCollisionBoxes(IBlockState state) { + return Collections.emptyList(); + } + + public List getCollisionBoxes(IBlockState state) { + List boxes = new ArrayList<>(); + + boxes.addAll(getUnionizedCollisionBoxes(state)); + boxes.addAll(getNonUnionizedCollisionBoxes(state)); + + return boxes; + } @Override public void addCollisionBoxToListDefault(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List collidingBoxes, Entity entityIn) { diff --git a/src/main/java/refinedstorage/block/BlockConstructor.java b/src/main/java/refinedstorage/block/BlockConstructor.java index 83e612259..f2820d624 100755 --- a/src/main/java/refinedstorage/block/BlockConstructor.java +++ b/src/main/java/refinedstorage/block/BlockConstructor.java @@ -6,17 +6,68 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; 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.World; import refinedstorage.RefinedStorage; import refinedstorage.RefinedStorageGui; import refinedstorage.tile.TileConstructor; +import java.util.ArrayList; +import java.util.List; + public class BlockConstructor extends BlockCable { + public static final AxisAlignedBB HOLDER_NORTH_AABB = createAABB(7, 7, 2, 9, 9, 6); + public static final AxisAlignedBB HOLDER_EAST_AABB = createAABB(10, 7, 7, 14, 9, 9); + public static final AxisAlignedBB HOLDER_SOUTH_AABB = createAABB(7, 7, 10, 9, 9, 14); + public static final AxisAlignedBB HOLDER_WEST_AABB = createAABB(2, 7, 7, 6, 9, 9); + public static final AxisAlignedBB HOLDER_DOWN_AABB = createAABB(7, 2, 7, 9, 6, 9); + public static final AxisAlignedBB HOLDER_UP_AABB = createAABB(7, 10, 7, 9, 14, 9); + + public static final AxisAlignedBB HEAD_NORTH_AABB = createAABB(0, 0, 0, 16, 16, 2); + public static final AxisAlignedBB HEAD_EAST_AABB = createAABB(14, 0, 0, 16, 16, 16); + public static final AxisAlignedBB HEAD_SOUTH_AABB = createAABB(0, 0, 14, 16, 16, 16); + public static final AxisAlignedBB HEAD_WEST_AABB = createAABB(0, 0, 0, 2, 16, 16); + public static final AxisAlignedBB HEAD_DOWN_AABB = createAABB(0, 0, 0, 16, 2, 16); + public static final AxisAlignedBB HEAD_UP_AABB = createAABB(0, 14, 0, 16, 16, 16); + public BlockConstructor() { super("constructor"); } + public List getNonUnionizedCollisionBoxes(IBlockState state) { + List boxes = new ArrayList<>(); + + switch (state.getValue(DIRECTION)) { + case NORTH: + boxes.add(HOLDER_NORTH_AABB); + boxes.add(HEAD_NORTH_AABB); + break; + case EAST: + boxes.add(HOLDER_EAST_AABB); + boxes.add(HEAD_EAST_AABB); + break; + case SOUTH: + boxes.add(HOLDER_SOUTH_AABB); + boxes.add(HEAD_SOUTH_AABB); + break; + case WEST: + boxes.add(HOLDER_WEST_AABB); + boxes.add(HEAD_WEST_AABB); + break; + case UP: + boxes.add(HOLDER_UP_AABB); + boxes.add(HEAD_UP_AABB); + break; + case DOWN: + boxes.add(HOLDER_DOWN_AABB); + boxes.add(HEAD_DOWN_AABB); + break; + } + + return boxes; + } + @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileConstructor(); diff --git a/src/main/java/refinedstorage/block/BlockDestructor.java b/src/main/java/refinedstorage/block/BlockDestructor.java index 8eefd2eb3..040d665ba 100755 --- a/src/main/java/refinedstorage/block/BlockDestructor.java +++ b/src/main/java/refinedstorage/block/BlockDestructor.java @@ -6,12 +6,16 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; 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.World; import refinedstorage.RefinedStorage; +import refinedstorage.RefinedStorageBlocks; import refinedstorage.RefinedStorageGui; import refinedstorage.tile.TileDestructor; +import java.util.List; + public class BlockDestructor extends BlockCable { public BlockDestructor() { super("destructor"); @@ -22,6 +26,10 @@ public class BlockDestructor extends BlockCable { return new TileDestructor(); } + public List getNonUnionizedCollisionBoxes(IBlockState state) { + return RefinedStorageBlocks.CONSTRUCTOR.getNonUnionizedCollisionBoxes(state); + } + @Override public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { diff --git a/src/main/java/refinedstorage/proxy/ClientProxy.java b/src/main/java/refinedstorage/proxy/ClientProxy.java index b9bb8d83a..cb69a01b3 100755 --- a/src/main/java/refinedstorage/proxy/ClientProxy.java +++ b/src/main/java/refinedstorage/proxy/ClientProxy.java @@ -50,22 +50,23 @@ public class ClientProxy extends CommonProxy { return; } + EntityPlayer player = e.getPlayer(); + BlockPos pos = e.getTarget().getBlockPos(); - IBlockState state = e.getPlayer().getEntityWorld().getBlockState(pos); + IBlockState state = player.worldObj.getBlockState(pos); if (!(state.getBlock() instanceof BlockCable)) { return; } + state = ((BlockCable) state.getBlock()).getActualState(state, player.worldObj, pos); + + List unionized = ((BlockCable) state.getBlock()).getUnionizedCollisionBoxes(state); + List nonUnionized = ((BlockCable) state.getBlock()).getNonUnionizedCollisionBoxes(state); + e.setCanceled(true); - state = ((BlockCable) state.getBlock()).getActualState(state, e.getPlayer().worldObj, pos); - - drawSelectionBox(e.getPlayer(), BlockCable.getCollisionBoxes(state), e.getPartialTicks(), pos); - } - - private void drawSelectionBox(EntityPlayer player, List boxes, float partialTicks, BlockPos pos) { GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F); @@ -73,17 +74,21 @@ public class ClientProxy extends CommonProxy { GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) e.getPartialTicks(); + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) e.getPartialTicks(); + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) e.getPartialTicks(); - AxisAlignedBB aabb = boxes.get(0); + AxisAlignedBB unionizedAabb = unionized.get(0); - for (int i = 1; i < boxes.size(); ++i) { - aabb = aabb.union(boxes.get(i)); + for (int i = 1; i < unionized.size(); ++i) { + unionizedAabb = unionizedAabb.union(unionized.get(i)); } - drawSelectionBoundingBox(aabb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2).offset(pos.getX(), pos.getY(), pos.getZ())); + drawSelectionBoundingBox(unionizedAabb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2).offset(pos.getX(), pos.getY(), pos.getZ())); + + for (AxisAlignedBB aabb : nonUnionized) { + drawSelectionBoundingBox(aabb.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2).offset(pos.getX(), pos.getY(), pos.getZ())); + } GlStateManager.depthMask(true); GlStateManager.enableTexture2D();