Improved bounding box for lasers!
This commit is contained in:
parent
bcf148e90d
commit
ab0427ebd2
1 changed files with 63 additions and 1 deletions
|
@ -18,8 +18,26 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import buildcraft.core.CreativeTabBuildCraft;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import buildcraft.core.ICustomHighlight;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockLaser extends BlockContainer {
|
||||
import static net.minecraft.util.AxisAlignedBB.getBoundingBox;
|
||||
|
||||
public class BlockLaser extends BlockContainer implements ICustomHighlight {
|
||||
|
||||
private static final AxisAlignedBB[][] boxes = {
|
||||
{getBoundingBox(0.0, 0.75, 0.0, 1.0, 1.0, 1.0), getBoundingBox(0.3125, 0.1875, 0.3125, 0.6875, 0.75, 0.6875)},// -Y
|
||||
{getBoundingBox(0.0, 0.0, 0.0, 1.0, 0.25, 1.0), getBoundingBox(0.3125, 0.25, 0.3125, 0.6875, 0.8125, 0.6875)},// +Y
|
||||
{getBoundingBox(0.0, 0.0, 0.75, 1.0, 1.0, 1.0), getBoundingBox(0.3125, 0.3125, 0.1875, 0.6875, 0.6875, 0.75)},// -Z
|
||||
{getBoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 0.25), getBoundingBox(0.3125, 0.3125, 0.25, 0.6875, 0.6875, 0.8125)},// +Z
|
||||
{getBoundingBox(0.75, 0.0, 0.0, 1.0, 1.0, 1.0), getBoundingBox(0.1875, 0.3125, 0.3125, 0.75, 0.6875, 0.6875)},// -X
|
||||
{getBoundingBox(0.0, 0.0, 0.0, 0.25, 1.0, 1.0), getBoundingBox(0.25, 0.3125, 0.3125, 0.8125, 0.6875, 0.6875)} // +X
|
||||
};
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon textureTop, textureBottom, textureSide;
|
||||
|
@ -30,6 +48,50 @@ public class BlockLaser extends BlockContainer {
|
|||
setCreativeTab(CreativeTabBuildCraft.TIER_3.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB[] getBoxes(World wrd, int x, int y, int z, EntityPlayer player) {
|
||||
return boxes[wrd.getBlockMetadata(x, y, z)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getExpansion() {
|
||||
return 0.0075;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MovingObjectPosition collisionRayTrace(World wrd, int x, int y, int z, Vec3 origin, Vec3 direction) {
|
||||
AxisAlignedBB[] aabbs = boxes[wrd.getBlockMetadata(x, y, z)];
|
||||
MovingObjectPosition closest = null;
|
||||
for(AxisAlignedBB aabb : aabbs){
|
||||
MovingObjectPosition mop = aabb.getOffsetBoundingBox(x, y, z).calculateIntercept(origin, direction);
|
||||
if(mop != null){
|
||||
if (closest != null && mop.hitVec.distanceTo(origin) < closest.hitVec.distanceTo(origin)) {
|
||||
closest = mop;
|
||||
} else {
|
||||
closest = mop;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closest != null){
|
||||
closest.blockX = x;
|
||||
closest.blockY = y;
|
||||
closest.blockZ = z;
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addCollisionBoxesToList(World wrd, int x, int y, int z, AxisAlignedBB mask, List list, Entity ent) {
|
||||
AxisAlignedBB[] aabbs = boxes[wrd.getBlockMetadata(x, y, z)];
|
||||
for (AxisAlignedBB aabb : aabbs) {
|
||||
aabb = aabb.getOffsetBoundingBox(x, y, z);
|
||||
if (mask.intersectsWith(aabb)){
|
||||
list.add(aabb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return SiliconProxy.laserBlockModel;
|
||||
|
|
Loading…
Reference in a new issue