Better constructor / destructor collision
This commit is contained in:
@@ -32,10 +32,11 @@ import refinedstorage.tile.TileMultipartNode;
|
|||||||
import refinedstorage.tile.TileNode;
|
import refinedstorage.tile.TileNode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockCable extends BlockCoverable {
|
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) {
|
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);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<AxisAlignedBB> getCollisionBoxes(IBlockState state) {
|
public List<AxisAlignedBB> getUnionizedCollisionBoxes(IBlockState state) {
|
||||||
List<AxisAlignedBB> boxes = new ArrayList<>();
|
List<AxisAlignedBB> boxes = new ArrayList<>();
|
||||||
|
|
||||||
boxes.add(CORE_AABB);
|
boxes.add(CORE_AABB);
|
||||||
@@ -174,6 +175,18 @@ public class BlockCable extends BlockCoverable {
|
|||||||
return boxes;
|
return boxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AxisAlignedBB> getCollisionBoxes(IBlockState state) {
|
||||||
|
List<AxisAlignedBB> boxes = new ArrayList<>();
|
||||||
|
|
||||||
|
boxes.addAll(getUnionizedCollisionBoxes(state));
|
||||||
|
boxes.addAll(getNonUnionizedCollisionBoxes(state));
|
||||||
|
|
||||||
|
return boxes;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCollisionBoxToListDefault(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
|
public void addCollisionBoxToListDefault(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
|
||||||
|
|||||||
@@ -6,17 +6,68 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.RefinedStorageGui;
|
import refinedstorage.RefinedStorageGui;
|
||||||
import refinedstorage.tile.TileConstructor;
|
import refinedstorage.tile.TileConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockConstructor extends BlockCable {
|
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() {
|
public BlockConstructor() {
|
||||||
super("constructor");
|
super("constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
|
||||||
|
List<AxisAlignedBB> 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
|
@Override
|
||||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||||
return new TileConstructor();
|
return new TileConstructor();
|
||||||
|
|||||||
@@ -6,12 +6,16 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageGui;
|
import refinedstorage.RefinedStorageGui;
|
||||||
import refinedstorage.tile.TileDestructor;
|
import refinedstorage.tile.TileDestructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockDestructor extends BlockCable {
|
public class BlockDestructor extends BlockCable {
|
||||||
public BlockDestructor() {
|
public BlockDestructor() {
|
||||||
super("destructor");
|
super("destructor");
|
||||||
@@ -22,6 +26,10 @@ public class BlockDestructor extends BlockCable {
|
|||||||
return new TileDestructor();
|
return new TileDestructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
|
||||||
|
return RefinedStorageBlocks.CONSTRUCTOR.getNonUnionizedCollisionBoxes(state);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
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) {
|
if (!world.isRemote) {
|
||||||
|
|||||||
@@ -50,22 +50,23 @@ public class ClientProxy extends CommonProxy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityPlayer player = e.getPlayer();
|
||||||
|
|
||||||
BlockPos pos = e.getTarget().getBlockPos();
|
BlockPos pos = e.getTarget().getBlockPos();
|
||||||
|
|
||||||
IBlockState state = e.getPlayer().getEntityWorld().getBlockState(pos);
|
IBlockState state = player.worldObj.getBlockState(pos);
|
||||||
|
|
||||||
if (!(state.getBlock() instanceof BlockCable)) {
|
if (!(state.getBlock() instanceof BlockCable)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state = ((BlockCable) state.getBlock()).getActualState(state, player.worldObj, pos);
|
||||||
|
|
||||||
|
List<AxisAlignedBB> unionized = ((BlockCable) state.getBlock()).getUnionizedCollisionBoxes(state);
|
||||||
|
List<AxisAlignedBB> nonUnionized = ((BlockCable) state.getBlock()).getNonUnionizedCollisionBoxes(state);
|
||||||
|
|
||||||
e.setCanceled(true);
|
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<AxisAlignedBB> boxes, float partialTicks, BlockPos pos) {
|
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||||
GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
|
GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
|
||||||
@@ -73,17 +74,21 @@ public class ClientProxy extends CommonProxy {
|
|||||||
GlStateManager.disableTexture2D();
|
GlStateManager.disableTexture2D();
|
||||||
GlStateManager.depthMask(false);
|
GlStateManager.depthMask(false);
|
||||||
|
|
||||||
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks;
|
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) e.getPartialTicks();
|
||||||
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks;
|
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) e.getPartialTicks();
|
||||||
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks;
|
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) {
|
for (int i = 1; i < unionized.size(); ++i) {
|
||||||
aabb = aabb.union(boxes.get(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.depthMask(true);
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture2D();
|
||||||
|
|||||||
Reference in New Issue
Block a user