use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberValve method checkForCubeOfSize.
private static boolean checkForCubeOfSize(int size, World world, int baseX, int baseY, int baseZ) {
boolean validValveFound = false;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
for (int z = 0; z < size; z++) {
if (x != 0 && x != size - 1 && y != 0 && y != size - 1 && z != 0 && z != size - 1)
continue;
if (world.getBlock(x + baseX, y + baseY, z + baseZ) != Blockss.pressureChamberWall && world.getBlock(x + baseX, y + baseY, z + baseZ) != Blockss.pressureChamberValve && world.getBlock(x + baseX, y + baseY, z + baseZ) != Blockss.pressureChamberInterface) {
return false;
} else if (world.getBlock(x + baseX, y + baseY, z + baseZ) == Blockss.pressureChamberValve) {
boolean xMid = x != 0 && x != size - 1;
boolean yMid = y != 0 && y != size - 1;
boolean zMid = z != 0 && z != size - 1;
ForgeDirection facing = ForgeDirection.getOrientation(world.getBlockMetadata(x + baseX, y + baseY, z + baseZ));
if (xMid && yMid && (facing == ForgeDirection.NORTH || facing == ForgeDirection.SOUTH) || xMid && zMid && (facing == ForgeDirection.UP || facing == ForgeDirection.DOWN) || yMid && zMid && (facing == ForgeDirection.EAST || facing == ForgeDirection.WEST)) {
validValveFound = true;
} else {
return false;
}
} else {
// when blockID == wall/interface
TileEntity te = world.getTileEntity(x + baseX, y + baseY, z + baseZ);
if (te instanceof TileEntityPressureChamberWall && ((TileEntityPressureChamberWall) te).getCore() != null) {
return false;
}
}
}
}
}
// depends on whether there is a valid valve in the structure now.
if (!validValveFound)
return false;
TileEntityPressureChamberValve teValve = null;
List<TileEntityPressureChamberValve> valveList = new ArrayList<TileEntityPressureChamberValve>();
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
for (int z = 0; z < size; z++) {
TileEntity te = world.getTileEntity(x + baseX, y + baseY, z + baseZ);
if (te instanceof TileEntityPressureChamberValve) {
boolean xMid = x != 0 && x != size - 1;
boolean yMid = y != 0 && y != size - 1;
boolean zMid = z != 0 && z != size - 1;
ForgeDirection facing = ForgeDirection.getOrientation(world.getBlockMetadata(x + baseX, y + baseY, z + baseZ));
if (xMid && yMid && (facing == ForgeDirection.NORTH || facing == ForgeDirection.SOUTH) || xMid && zMid && (facing == ForgeDirection.UP || facing == ForgeDirection.DOWN) || yMid && zMid && (facing == ForgeDirection.EAST || facing == ForgeDirection.WEST)) {
teValve = (TileEntityPressureChamberValve) te;
valveList.add(teValve);
}
}
}
}
}
// this line shouldn't be triggered
if (teValve == null)
return false;
// TE's.
for (TileEntityPressureChamberValve valve : valveList) {
valve.accessoryValves = new ArrayList<TileEntityPressureChamberValve>(valveList);
valve.sendDescriptionPacket();
}
// the valve.
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
for (int z = 0; z < size; z++) {
TileEntity te = world.getTileEntity(x + baseX, y + baseY, z + baseZ);
if (te instanceof TileEntityPressureChamberWall) {
TileEntityPressureChamberWall teWall = (TileEntityPressureChamberWall) te;
// set base TE to the valve
teWall.setCore(teValve);
// found.
}
}
}
}
// set the multi-block coords in the valve TE
teValve.setMultiBlockCoords(size, baseX, baseY, baseZ);
teValve.sendDescriptionPacket();
return true;
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberValve method invalidateMultiBlock.
private void invalidateMultiBlock() {
for (int x = 0; x < multiBlockSize; x++) {
for (int y = 0; y < multiBlockSize; y++) {
for (int z = 0; z < multiBlockSize; z++) {
TileEntity te = worldObj.getTileEntity(x + multiBlockX, y + multiBlockY, z + multiBlockZ);
if (te instanceof TileEntityPressureChamberWall) {
TileEntityPressureChamberWall teWall = (TileEntityPressureChamberWall) te;
// Clear the base TE's, so that
teWall.setCore(null);
// the walls can be used in a new
// MultiBlock
}
}
}
}
if (accessoryValves != null) {
for (TileEntityPressureChamberValve valve : accessoryValves) {
valve.setMultiBlockCoords(0, 0, 0, 0);
if (valve != this) {
valve.accessoryValves.clear();
valve.sendDescriptionPacket();
}
}
accessoryValves.clear();
}
sendDescriptionPacket();
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberWall method getCore.
public TileEntityPressureChamberValve getCore() {
if (teValve == null && (valveX != 0 || valveY != 0 || valveZ != 0)) {
// when the saved TE equals null, check if we can
// retrieve the TE from the NBT saved coords.
TileEntity te = worldObj.getTileEntity(valveX, valveY, valveZ);
setCore(te instanceof TileEntityPressureChamberValve ? (TileEntityPressureChamberValve) te : null);
}
return teValve;
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class TileEntityPressureTube method updateConnections.
public void updateConnections(World world, int x, int y, int z) {
sidesConnected = new boolean[6];
boolean hasModule = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = getTileCache()[direction.ordinal()].getTileEntity();
IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
if (machine != null) {
sidesConnected[direction.ordinal()] = isConnectedTo(direction) && machine.isConnectedTo(direction.getOpposite());
} else if (te instanceof ISidedPneumaticMachine) {
sidesConnected[direction.ordinal()] = ((ISidedPneumaticMachine) te).getAirHandler(direction.getOpposite()) != null;
}
if (modules[direction.ordinal()] != null) {
hasModule = true;
}
}
int sidesCount = 0;
for (boolean bool : sidesConnected) {
if (bool)
sidesCount++;
}
if (sidesCount == 1 && !hasModule) {
for (int i = 0; i < 6; i++) {
if (sidesConnected[i]) {
if (isConnectedTo(ForgeDirection.getOrientation(i).getOpposite()))
sidesConnected[i ^ 1] = true;
break;
}
}
}
for (int i = 0; i < 6; i++) {
if (modules[i] != null && modules[i].isInline())
sidesConnected[i] = false;
}
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class TileEntityLiquidHopper method exportItem.
@Override
protected boolean exportItem(int maxItems) {
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
if (tank.getFluid() != null) {
TileEntity neighbor = IOHelper.getNeighbor(this, dir);
if (neighbor instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) neighbor;
if (fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
FluidStack fluid = tank.getFluid().copy();
fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
if (fluid.amount > 0) {
tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
if (tank.getFluidAmount() <= 0)
tank.setFluid(null);
return true;
}
}
}
}
if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
for (EntityItem entity : getNeighborItems(this, dir)) {
if (!entity.isDead) {
List<ItemStack> returnedItems = new ArrayList<ItemStack>();
if (FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
if (entity.getEntityItem().stackSize <= 0)
entity.setDead();
for (ItemStack stack : returnedItems) {
EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
item.motionX = entity.motionX;
item.motionY = entity.motionY;
item.motionZ = entity.motionZ;
worldObj.spawnEntityInWorld(item);
}
return true;
}
}
}
}
if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
if (extractedFluid != null && extractedFluid.amount == 1000) {
Block fluidBlock = extractedFluid.getFluid().getBlock();
if (fluidBlock != null) {
drain(ForgeDirection.UNKNOWN, 1000, true);
worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
}
}
}
}
return false;
}
Aggregations