Search in sources :

Example 6 with LogisticsCraftingTableTileEntity

use of logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity in project LogisticsPipes by RS485.

the class LogisticsSolidBlock method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World world, int posX, int posY, int posZ, EntityLivingBase entity, ItemStack itemStack) {
    super.onBlockPlacedBy(world, posX, posY, posZ, entity, itemStack);
    TileEntity tile = world.getTileEntity(posX, posY, posZ);
    if (tile instanceof LogisticsCraftingTableTileEntity) {
        ((LogisticsCraftingTableTileEntity) tile).placedBy(entity);
    }
    if (tile instanceof IRotationProvider) {
        double x = tile.xCoord + 0.5 - entity.posX;
        double z = tile.zCoord + 0.5 - entity.posZ;
        double w = Math.atan2(x, z);
        double halfPI = Math.PI / 2;
        double halfhalfPI = halfPI / 2;
        w -= halfhalfPI;
        if (w < 0) {
            w += 2 * Math.PI;
        }
        if (0 < w && w <= halfPI) {
            ((IRotationProvider) tile).setRotation(1);
        } else if (halfPI < w && w <= 2 * halfPI) {
            ((IRotationProvider) tile).setRotation(2);
        } else if (2 * halfPI < w && w <= 3 * halfPI) {
            ((IRotationProvider) tile).setRotation(0);
        } else if (3 * halfPI < w && w <= 4 * halfPI) {
            ((IRotationProvider) tile).setRotation(3);
        }
    }
}
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) IRotationProvider(logisticspipes.interfaces.IRotationProvider) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)

Example 7 with LogisticsCraftingTableTileEntity

use of logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity in project LogisticsPipes by RS485.

the class FindMostLikelyRecipeComponents method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    TileEntity tile = this.getTile(player.getEntityWorld(), TileEntity.class);
    CoreRoutedPipe pipe = null;
    if (tile instanceof LogisticsCraftingTableTileEntity) {
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            TileEntity conn = CoordinateUtils.add(((LogisticsCraftingTableTileEntity) tile).getLPPosition(), dir).getTileEntity(player.getEntityWorld());
            if (conn instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) conn).pipe instanceof PipeItemsCraftingLogistics) {
                    pipe = (CoreRoutedPipe) ((LogisticsTileGenericPipe) conn).pipe;
                    break;
                }
            }
        }
    } else if (tile instanceof LogisticsTileGenericPipe) {
        if (((LogisticsTileGenericPipe) tile).pipe instanceof PipeBlockRequestTable) {
            pipe = (CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe;
        }
    }
    List<Integer> list = new ArrayList<Integer>(content.size());
    while (list.size() < content.size()) {
        list.add(-1);
    }
    if (pipe == null)
        return;
    LinkedList<ItemIdentifier> craftable = null;
    for (int j = 0; j < content.size(); j++) {
        GuiRecipeImport.Canidates canidates = content.get(j);
        int maxItemPos = -1;
        int max = 0;
        for (int i = 0; i < canidates.order.size(); i++) {
            ItemIdentifier ident = canidates.order.get(i).getItem();
            int newAmount = SimpleServiceLocator.logisticsManager.getAmountFor(ident, pipe.getRouter().getIRoutersByCost());
            if (newAmount > max) {
                max = newAmount;
                maxItemPos = i;
            }
        }
        if (max < 64) {
            if (craftable == null) {
                craftable = SimpleServiceLocator.logisticsManager.getCraftableItems(pipe.getRouter().getIRoutersByCost());
            }
            for (ItemIdentifier craft : craftable) {
                for (int i = 0; i < canidates.order.size(); i++) {
                    ItemIdentifier ident = canidates.order.get(i).getItem();
                    if (craft == ident) {
                        maxItemPos = i;
                        break;
                    }
                }
            }
        }
        list.set(j, maxItemPos);
    }
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(MostLikelyRecipeComponentsResponse.class).setResponse(list), player);
}
Also used : GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) PipeItemsCraftingLogistics(logisticspipes.pipes.PipeItemsCraftingLogistics) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) TileEntity(net.minecraft.tileentity.TileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)

Example 8 with LogisticsCraftingTableTileEntity

use of logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity in project LogisticsPipes by RS485.

the class LogisticsCraftingTable method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
        return false;
    }
    LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
    ItemIdentifierStack result = bench.resultInv.getIDStackInSlot(0);
    if (result == null) {
        return false;
    }
    inventory.setInventorySlotContents(9, result);
    // Import
    for (int i = 0; i < bench.matrix.getSizeInventory(); i++) {
        if (i >= inventory.getSizeInventory() - 2) {
            break;
        }
        final ItemStack newStack = bench.matrix.getStackInSlot(i) == null ? null : bench.matrix.getStackInSlot(i).copy();
        if (newStack != null && newStack.stackSize > 1) {
            newStack.stackSize = 1;
        }
        inventory.setInventorySlotContents(i, newStack);
    }
    if (!bench.isFuzzy()) {
        inventory.compact_first(9);
    }
    return true;
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)

Aggregations

LogisticsCraftingTableTileEntity (logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)8 TileEntity (net.minecraft.tileentity.TileEntity)4 LogisticsIC2PowerProviderTileEntity (logisticspipes.blocks.powertile.LogisticsIC2PowerProviderTileEntity)2 LogisticsPowerJunctionTileEntity (logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity)2 LogisticsRFPowerProviderTileEntity (logisticspipes.blocks.powertile.LogisticsRFPowerProviderTileEntity)2 LogisticsStatisticsTileEntity (logisticspipes.blocks.stats.LogisticsStatisticsTileEntity)2 IGuiTileEntity (logisticspipes.interfaces.IGuiTileEntity)2 PipeBlockRequestTable (logisticspipes.pipes.PipeBlockRequestTable)2 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)2 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 GuiLogisticsCraftingTable (logisticspipes.gui.GuiLogisticsCraftingTable)1 GuiRecipeImport (logisticspipes.gui.popup.GuiRecipeImport)1 IRotationProvider (logisticspipes.interfaces.IRotationProvider)1 PipeItemsCraftingLogistics (logisticspipes.pipes.PipeItemsCraftingLogistics)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1 DummyContainer (logisticspipes.utils.gui.DummyContainer)1 ItemStack (net.minecraft.item.ItemStack)1