Search in sources :

Example 6 with TileEntity

use of net.minecraft.tileentity.TileEntity in project BluePower by Qmunity.

the class IOHelper method dropInventory.

public static void dropInventory(World world, int x, int y, int z) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (!(tileEntity instanceof IInventory)) {
        return;
    }
    IInventory inventory = (IInventory) tileEntity;
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        ItemStack itemStack = inventory.getStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            spawnItemInWorld(world, itemStack, x, y, z);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 7 with TileEntity

use of net.minecraft.tileentity.TileEntity in project BluePower by Qmunity.

the class PneumaticTube method updateConnections.

private void updateConnections() {
    if (getWorld() != null && !getWorld().isRemote) {
        int connectionCount = 0;
        boolean clearedCache = false;
        clearCache();
        for (int i = 0; i < 6; i++) {
            boolean oldState = connections[i];
            ForgeDirection d = ForgeDirection.getOrientation(i);
            TileEntity neighbor = getTileCache(d);
            connections[i] = IOHelper.canInterfaceWith(neighbor, d.getOpposite(), this, canConnectToInventories());
            if (!connections[i])
                connections[i] = neighbor instanceof ITubeConnection && ((ITubeConnection) neighbor).isConnectedTo(d.getOpposite());
            if (connections[i]) {
                connections[i] = isConnected(d, null);
            }
            if (connections[i])
                connectionCount++;
            if (!clearedCache && oldState != connections[i]) {
                if (Config.enableTubeCaching)
                    getLogic().clearNodeCaches();
                clearedCache = true;
            }
        }
        isCrossOver = connectionCount != 2;
        sendUpdatePacket();
    }
    initialized = true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITubeConnection(com.bluepowermod.api.tube.ITubeConnection) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 8 with TileEntity

use of net.minecraft.tileentity.TileEntity in project BluePower by Qmunity.

the class TubeLogic method retrieveStack.

public boolean retrieveStack(TileEntity target, ForgeDirection dirToRetrieveInto, ItemStack filter, TubeColor color) {
    if (tube.getWorld() == null)
        return false;
    TubeStack stack = new TubeStack(filter, null, color);
    stack.setTarget(target, dirToRetrieveInto);
    Pair<ForgeDirection, TileEntity> result = getHeadingForItem(stack, false);
    if (result == null)
        return false;
    int fuzzySetting = 0;
    if (target instanceof IFuzzyRetrieving) {
        fuzzySetting = ((IFuzzyRetrieving) target).getFuzzySetting();
    }
    ItemStack extractedItem = null;
    if (result.getValue() instanceof TileManager) {
        // Exception for managers, the result can only end up as a manager if the pulling inventory was
        // a manager.
        TileEntity managedInventory = ((TileManager) result.getValue()).getTileCache(((TileManager) result.getValue()).getFacingDirection());
        extractedItem = IOHelper.extract(managedInventory, result.getKey().getOpposite(), filter, false, false, fuzzySetting);
    } else if (filter != null) {
        extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), filter, !(target instanceof TileManager), false, fuzzySetting);
    } else {
        extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), false);
    }
    if (extractedItem == null)
        throw new IllegalArgumentException("This isn't possible!");
    stack = new TubeStack(extractedItem, result.getKey().getOpposite(), color);
    stack.setTarget(target, dirToRetrieveInto);
    PneumaticTube tube = MultipartCompatibility.getPart(this.tube.getWorld(), result.getValue().xCoord - result.getKey().offsetX, result.getValue().yCoord - result.getKey().offsetY, result.getValue().zCoord - result.getKey().offsetZ, PneumaticTube.class);
    if (tube == null)
        throw new IllegalArgumentException("wieeeeerd!");
    return tube.getLogic().injectStack(stack, result.getKey().getOpposite(), false);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPneumaticTube(com.bluepowermod.api.tube.IPneumaticTube) IFuzzyRetrieving(com.bluepowermod.tile.IFuzzyRetrieving) MessageRedirectTubeStack(com.bluepowermod.network.message.MessageRedirectTubeStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) TileManager(com.bluepowermod.tile.tier3.TileManager)

Example 9 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class LogisticsSolidBlock method onNeighborChange.

@Override
public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ) {
    super.onNeighborChange(world, x, y, z, tileX, tileY, tileZ);
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile instanceof LogisticsSolidTileEntity) {
        ((LogisticsSolidTileEntity) tile).notifyOfBlockChange();
    }
}
Also used : LogisticsRFPowerProviderTileEntity(logisticspipes.blocks.powertile.LogisticsRFPowerProviderTileEntity) LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) IGuiTileEntity(logisticspipes.interfaces.IGuiTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) LogisticsIC2PowerProviderTileEntity(logisticspipes.blocks.powertile.LogisticsIC2PowerProviderTileEntity) LogisticsStatisticsTileEntity(logisticspipes.blocks.stats.LogisticsStatisticsTileEntity)

Example 10 with TileEntity

use of net.minecraft.tileentity.TileEntity in project BluePower by Qmunity.

the class TileSortingMachine method triggerSorting.

private void triggerSorting() {
    if (isBufferEmpty()) {
        ForgeDirection dir = getOutputDirection().getOpposite();
        // might need opposite
        TileEntity inputTE = getTileCache(dir);
        if (inputTE instanceof IInventory) {
            IInventory inputInv = (IInventory) inputTE;
            int[] accessibleSlots;
            if (inputInv instanceof ISidedInventory) {
                accessibleSlots = ((ISidedInventory) inputInv).getAccessibleSlotsFromSide(dir.getOpposite().ordinal());
            } else {
                accessibleSlots = new int[inputInv.getSizeInventory()];
                for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
            }
            for (int slot : accessibleSlots) {
                ItemStack stack = inputInv.getStackInSlot(slot);
                if (stack != null && IOHelper.canExtractItemFromInventory(inputInv, stack, slot, dir.getOpposite().ordinal())) {
                    if (tryProcessItem(stack, false)) {
                        if (stack.stackSize == 0)
                            inputInv.setInventorySlotContents(slot, null);
                        return;
                    }
                }
            }
            if (sortMode == SortMode.ANYSTACK_SEQUENTIAL) {
                for (int i = curColumn; i < inventory.length; i += 8) {
                    ItemStack filterStack = inventory[i];
                    if (filterStack != null) {
                        ItemStack extractedStack = IOHelper.extract(inputTE, dir.getOpposite(), filterStack, true, false);
                        if (extractedStack != null) {
                            addItemToOutputBuffer(extractedStack.copy(), colors[curColumn]);
                            gotoNextNonEmptyColumn();
                            break;
                        }
                    }
                }
            } else if (sortMode == SortMode.ALLSTACK_SEQUENTIAL) {
                if (matchAndProcessColumn(inputInv, accessibleSlots, curColumn)) {
                    gotoNextNonEmptyColumn();
                }
            } else if (sortMode == SortMode.RANDOM_ALLSTACKS) {
                for (int i = 0; i < 8; i++) {
                    if (matchAndProcessColumn(inputInv, accessibleSlots, i)) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

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