More efficient bounds checking
This commit is contained in:
parent
51e2bef632
commit
139cdbf660
3 changed files with 70 additions and 33 deletions
|
@ -27,6 +27,13 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
|
|||
return BlockRenderingHandler.INSTANCE.getRenderId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
TileEntityEMContractor tileEntity = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
|
||||
tileEntity.updateBounds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,8 @@ package resonantinduction.contractor;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -11,7 +12,9 @@ public class TileEntityEMContractor extends TileEntity
|
|||
{
|
||||
public static int MAX_REACH = 40;
|
||||
|
||||
public ForgeDirection facing = ForgeDirection.UP;
|
||||
private ForgeDirection facing = ForgeDirection.UP;
|
||||
|
||||
public AxisAlignedBB operationBounds;
|
||||
|
||||
/**
|
||||
* true = suck, false = push
|
||||
|
@ -21,46 +24,73 @@ public class TileEntityEMContractor extends TileEntity
|
|||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
AxisAlignedBB box = null;
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
switch(facing)
|
||||
if(operationBounds != null)
|
||||
{
|
||||
case DOWN:
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord, Math.max(yCoord-MAX_REACH, 1), zCoord, xCoord+1, yCoord, zCoord+1);
|
||||
break;
|
||||
case UP:
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, Math.min(yCoord+MAX_REACH, 255), zCoord+1);
|
||||
break;
|
||||
case NORTH:
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+MAX_REACH, yCoord+1, zCoord+1);
|
||||
break;
|
||||
case SOUTH:
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord-MAX_REACH, yCoord, zCoord, xCoord, yCoord+1, zCoord+1);
|
||||
break;
|
||||
case WEST:
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+MAX_REACH);
|
||||
break;
|
||||
case EAST:
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord-MAX_REACH, xCoord+1, yCoord+1, zCoord);
|
||||
break;
|
||||
}
|
||||
|
||||
List list = worldObj.getEntitiesWithinAABB(EntityPlayer.class, box);
|
||||
|
||||
System.out.println(facing.ordinal());
|
||||
|
||||
if(!list.isEmpty())
|
||||
{
|
||||
System.out.println("Good!");
|
||||
List list = worldObj.getEntitiesWithinAABB(Entity.class, operationBounds);
|
||||
|
||||
if(!list.isEmpty())
|
||||
{
|
||||
System.out.println("Good!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBounds()
|
||||
{
|
||||
switch(facing)
|
||||
{
|
||||
case DOWN:
|
||||
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, Math.max(yCoord-MAX_REACH, 1), zCoord, xCoord+1, yCoord, zCoord+1);
|
||||
break;
|
||||
case UP:
|
||||
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, Math.min(yCoord+MAX_REACH, 255), zCoord+1);
|
||||
break;
|
||||
case NORTH:
|
||||
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+MAX_REACH, yCoord+1, zCoord+1);
|
||||
break;
|
||||
case SOUTH:
|
||||
operationBounds = AxisAlignedBB.getBoundingBox(xCoord-MAX_REACH, yCoord, zCoord, xCoord, yCoord+1, zCoord+1);
|
||||
break;
|
||||
case WEST:
|
||||
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+MAX_REACH);
|
||||
break;
|
||||
case EAST:
|
||||
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord-MAX_REACH, xCoord+1, yCoord+1, zCoord);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementFacing()
|
||||
{
|
||||
int newOrdinal = facing.ordinal() < 5 ? facing.ordinal()+1 : 0;
|
||||
facing = ForgeDirection.getOrientation(newOrdinal);
|
||||
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
public ForgeDirection getFacing()
|
||||
{
|
||||
return facing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.readFromNBT(nbtTags);
|
||||
|
||||
facing = ForgeDirection.getOrientation(nbtTags.getInteger("facing"));
|
||||
suck = nbtTags.getBoolean("suck");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.writeToNBT(nbtTags);
|
||||
|
||||
nbtTags.setInteger("facing", facing.ordinal());
|
||||
nbtTags.setBoolean("suck", suck);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
|
|||
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
|
||||
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
||||
|
||||
switch(((TileEntityEMContractor)t).facing)
|
||||
switch(((TileEntityEMContractor)t).getFacing())
|
||||
{
|
||||
case DOWN:
|
||||
GL11.glRotatef(180, 0, 0, 1);
|
||||
|
|
Loading…
Add table
Reference in a new issue