Search in sources :

Example 96 with TileEntity

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList)

Example 97 with TileEntity

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();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity)

Example 98 with TileEntity

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity)

Example 99 with TileEntity

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;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISidedPneumaticMachine(pneumaticCraft.api.tileentity.ISidedPneumaticMachine)

Example 100 with TileEntity

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)822 ItemStack (net.minecraft.item.ItemStack)149 BlockPos (net.minecraft.util.math.BlockPos)130 Block (net.minecraft.block.Block)83 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)76 EnumFacing (net.minecraft.util.EnumFacing)62 ArrayList (java.util.ArrayList)61 IBlockState (net.minecraft.block.state.IBlockState)61 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 IInventory (net.minecraft.inventory.IInventory)49 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)44 World (net.minecraft.world.World)43 EntityItem (net.minecraft.entity.item.EntityItem)39 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)35 FluidStack (net.minecraftforge.fluids.FluidStack)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 HashMap (java.util.HashMap)25 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)23 AMVector3 (am2.api.math.AMVector3)21 Entity (net.minecraft.entity.Entity)21