Search in sources :

Example 91 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityProgrammer method tryProgramDrone.

private void tryProgramDrone(EntityPlayer player) {
    if (inventory[PROGRAM_SLOT] != null) {
        if (player == null || !player.capabilities.isCreativeMode) {
            List<ItemStack> requiredStacks = getRequiredPuzzleStacks();
            for (ItemStack stack : requiredStacks) {
                if (!hasEnoughPuzzleStacks(player, stack))
                    return;
            }
            for (ItemStack stack : requiredStacks) {
                int left = stack.stackSize;
                if (player != null) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (PneumaticCraftUtils.areStacksEqual(stack, player.inventory.getStackInSlot(i), true, true, false, false)) {
                            left -= player.inventory.decrStackSize(i, left).stackSize;
                            if (left <= 0)
                                break;
                        }
                    }
                }
                if (left > 0) {
                    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                        IInventory neighbor = IOHelper.getInventoryForTE(getWorldObj().getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ));
                        for (int slot : IOHelper.getAccessibleSlotsForInventory(neighbor, d.getOpposite())) {
                            if (IOHelper.canExtractItemFromInventory(neighbor, stack, slot, d.getOpposite().ordinal())) {
                                ItemStack neighborStack = neighbor.getStackInSlot(slot);
                                if (PneumaticCraftUtils.areStacksEqual(neighborStack, stack, true, true, false, false)) {
                                    left -= neighbor.decrStackSize(slot, left).stackSize;
                                    if (left <= 0)
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            List<ItemStack> returnedStacks = getReturnedPuzzleStacks();
            for (ItemStack stack : returnedStacks) {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    IInventory neighbor = IOHelper.getInventoryForTE(getWorldObj().getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ));
                    stack = IOHelper.insert(neighbor, stack, d.getOpposite().ordinal(), false);
                    if (stack == null)
                        break;
                }
                if (player != null && stack != null) {
                    if (!player.inventory.addItemStackToInventory(stack)) {
                        player.dropPlayerItemWithRandomChoice(stack.copy(), false);
                        stack = null;
                    }
                }
                if (stack != null) {
                    worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack));
                }
            }
        }
        NBTTagCompound tag = inventory[PROGRAM_SLOT].getTagCompound();
        if (tag == null) {
            tag = new NBTTagCompound();
            inventory[PROGRAM_SLOT].setTagCompound(tag);
        }
        writeProgWidgetsToNBT(tag);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 92 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection 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 93 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityPressureTube method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    for (TubeModule module : modules) {
        if (module != null) {
            module.shouldDrop = true;
            module.update();
        }
    }
    List<Pair<ForgeDirection, IAirHandler>> teList = getConnectedPneumatics();
    boolean hasModules = false;
    for (TubeModule module : modules) {
        if (module != null) {
            hasModules = true;
            break;
        }
    }
    if (!hasModules && teList.size() - specialConnectedHandlers.size() == 1 && !worldObj.isRemote) {
        for (Pair<ForgeDirection, IAirHandler> entry : teList) {
            if (entry.getKey() != ForgeDirection.UNKNOWN && modules[entry.getKey().getOpposite().ordinal()] == null && isConnectedTo(entry.getKey().getOpposite()))
                airLeak(entry.getKey().getOpposite());
        }
    }
}
Also used : IAirHandler(pneumaticCraft.api.tileentity.IAirHandler) TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Pair(org.apache.commons.lang3.tuple.Pair)

Example 94 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityPressureTube method printManometerMessage.

@Override
public void printManometerMessage(EntityPlayer player, List<String> text) {
    super.printManometerMessage(player, text);
    MovingObjectPosition mop = PneumaticCraftUtils.getEntityLookedObject(player);
    if (mop != null && mop.hitInfo instanceof ForgeDirection) {
        ForgeDirection dir = (ForgeDirection) mop.hitInfo;
        if (dir != ForgeDirection.UNKNOWN && modules[dir.ordinal()] != null) {
            modules[dir.ordinal()].addInfo(text);
        }
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 95 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection 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)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8