@Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); Utils.writeStacksToNBT(nbttagcompound, "Items", items); if (box.isInitialized()) { NBTTagCompound boxStore = new NBTTagCompound(); box.writeToNBT(boxStore); nbttagcompound.setTag("box", boxStore); } if (path != null) { NBTTagList list = new NBTTagList(); for (BlockIndex i : path) { NBTTagCompound c = new NBTTagCompound(); i.writeTo(c); list.appendTag(c); } nbttagcompound.setTag("path", list); } nbttagcompound.setBoolean("done", done); }
private void craftItem() { ItemStack recipeOutput = getRecipeOutput(); craftSlot.onPickupFromSlot(internalPlayer, recipeOutput); ItemStack[] tempStorage = internalInventoryCrafting.tempStacks; for (int i = 0; i < tempStorage.length; i++) { if (tempStorage[i] != null && tempStorage[i].stackSize <= 0) { tempStorage[i] = null; } inv.getItemStacks()[i] = tempStorage[i]; } subtractEnergy(getRequiredEnergy()); List<ItemStack> outputs = Lists.newArrayList(recipeOutput.copy()); for (int i = 0; i < internalPlayer.inventory.mainInventory.length; i++) { if (internalPlayer.inventory.mainInventory[i] != null) { outputs.add(internalPlayer.inventory.mainInventory[i]); internalPlayer.inventory.mainInventory[i] = null; } } for (ItemStack output : outputs) { output.stackSize -= Transactor.getTransactorFor(invOutput).add(output, ForgeDirection.UP, true).stackSize; if (output.stackSize > 0) { output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output); } if (output.stackSize > 0) { InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord); } } }
@Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); Utils.readStacksFromNBT(nbttagcompound, "items", items); energyStored = nbttagcompound.getFloat("energyStored"); NBTTagList list = nbttagcompound.getTagList("planned"); for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound cpt = (NBTTagCompound) list.tagAt(i); ItemStack stack = ItemStack.loadItemStackFromNBT(cpt); for (AssemblyRecipe r : AssemblyRecipe.assemblyRecipes) { if (r.output.itemID == stack.itemID && r.output.getItemDamage() == stack.getItemDamage()) { plannedOutput.add(r); } } } if (nbttagcompound.hasKey("recipe")) { ItemStack stack = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("recipe")); for (AssemblyRecipe r : plannedOutput) { if (r.output.itemID == stack.itemID && r.output.getItemDamage() == stack.getItemDamage()) { setCurrentRecipe(r); break; } } } }
@Override public void onBlockPlacedBy( World world, int i, int j, int k, EntityLiving entityliving, ItemStack stack) { ForgeDirection orientation = Utils.get2dOrientation( new Position(entityliving.posX, entityliving.posY, entityliving.posZ), new Position(i, j, k)); world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1); }
private void updateTiles() { for (int i = 0; i < 6; ++i) { TileEntity tile = container.getTile(ForgeDirection.VALID_DIRECTIONS[i]); if (Utils.checkPipesConnections(tile, container)) { tiles[i] = tile; } else { tiles[i] = null; } } }
public int isPoweringTo(int l) { if (!broadcastRedstone) return 0; ForgeDirection o = ForgeDirection.values()[l].getOpposite(); TileEntity tile = container.getTile(o); if (tile instanceof TileGenericPipe && Utils.checkPipesConnections(this.container, tile)) return 0; return 15; }
public ItemStack checkExtract(IInventory inventory, boolean doRemove, ForgeDirection from) { IInventory inv = Utils.getInventory(inventory); int first = 0; int last = inv.getSizeInventory() - 1; if (inventory instanceof ISidedInventory) { ISidedInventory sidedInv = (ISidedInventory) inventory; int[] accessibleSlots = sidedInv.getAccessibleSlotsFromSide(from.ordinal()); ItemStack result = checkExtractGeneric(inv, doRemove, from, accessibleSlots); return result; } ItemStack result = checkExtractGeneric(inv, doRemove, from, first, last); return result; }
public void onBlockRemoval() { if (wireSet[IPipe.WireColor.Red.ordinal()]) { Utils.dropItems( worldObj, new ItemStack(BuildCraftTransport.redPipeWire), xCoord, yCoord, zCoord); } if (wireSet[IPipe.WireColor.Blue.ordinal()]) { Utils.dropItems( worldObj, new ItemStack(BuildCraftTransport.bluePipeWire), xCoord, yCoord, zCoord); } if (wireSet[IPipe.WireColor.Green.ordinal()]) { Utils.dropItems( worldObj, new ItemStack(BuildCraftTransport.greenPipeWire), xCoord, yCoord, zCoord); } if (wireSet[IPipe.WireColor.Yellow.ordinal()]) { Utils.dropItems( worldObj, new ItemStack(BuildCraftTransport.yellowPipeWire), xCoord, yCoord, zCoord); } if (hasGate()) { gate.dropGate(worldObj, xCoord, yCoord, zCoord); } for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (container.hasFacade(direction)) { container.dropFacade(direction); } if (container.hasPlug(direction)) { container.removeAndDropPlug(direction); } } if (broadcastRedstone) { updateNeighbors(false); // self will update due to block id changing } }
@Override public boolean isWireConnectedTo(TileEntity tile, WireColor color) { if (!(tile instanceof TileGenericPipe)) return false; TileGenericPipe tilePipe = (TileGenericPipe) tile; if (!BlockGenericPipe.isFullyDefined(tilePipe.pipe)) return false; if (!tilePipe.pipe.wireSet[color.ordinal()]) return false; return (tilePipe.pipe.transport instanceof PipeTransportStructure || transport instanceof PipeTransportStructure || Utils.checkPipesConnections(container, tile)); }
private void switchSignals() { if (signals != null) { for (EntityBlock b : signals) { if (b != null) { CoreProxy.proxy.removeEntity(b); } } signals = null; } if (showSignals) { signals = new EntityBlock[6]; if (!origin.isSet() || !origin.vect[0].isSet()) { signals[0] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord + maxSize - 1, yCoord, zCoord), LaserKind.Blue); signals[1] = Utils.createLaser( worldObj, new Position(xCoord - maxSize + 1, yCoord, zCoord), new Position(xCoord, yCoord, zCoord), LaserKind.Blue); } if (!origin.isSet() || !origin.vect[1].isSet()) { signals[2] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord, yCoord + maxSize - 1, zCoord), LaserKind.Blue); signals[3] = Utils.createLaser( worldObj, new Position(xCoord, yCoord - maxSize + 1, zCoord), new Position(xCoord, yCoord, zCoord), LaserKind.Blue); } if (!origin.isSet() || !origin.vect[2].isSet()) { signals[4] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord, yCoord, zCoord + maxSize - 1), LaserKind.Blue); signals[5] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord - maxSize + 1), new Position(xCoord, yCoord, zCoord), LaserKind.Blue); } } }
private void createLasers() { if (lasers != null) { for (EntityBlock entity : lasers) { if (entity != null) { CoreProxy.proxy.removeEntity(entity); } } } lasers = new EntityBlock[12]; Origin o = origin; if (!origin.vect[0].isSet()) { o.xMin = origin.vectO.x; o.xMax = origin.vectO.x; } else if (origin.vect[0].x < xCoord) { o.xMin = origin.vect[0].x; o.xMax = xCoord; } else { o.xMin = xCoord; o.xMax = origin.vect[0].x; } if (!origin.vect[1].isSet()) { o.yMin = origin.vectO.y; o.yMax = origin.vectO.y; } else if (origin.vect[1].y < yCoord) { o.yMin = origin.vect[1].y; o.yMax = yCoord; } else { o.yMin = yCoord; o.yMax = origin.vect[1].y; } if (!origin.vect[2].isSet()) { o.zMin = origin.vectO.z; o.zMax = origin.vectO.z; } else if (origin.vect[2].z < zCoord) { o.zMin = origin.vect[2].z; o.zMax = zCoord; } else { o.zMin = zCoord; o.zMax = origin.vect[2].z; } lasers = Utils.createLaserBox( worldObj, o.xMin, o.yMin, o.zMin, o.xMax, o.yMax, o.zMax, LaserKind.Red); }
@Override public boolean outputOpen(ForgeDirection to) { if (!super.outputOpen(to)) return false; FluidTankInfo[] tanks = transport.getTankInfo(ForgeDirection.UNKNOWN); // center tank if (tanks == null || tanks[0] == null || tanks[0].fluid == null || tanks[0].fluid.amount == 0) return true; Fluid fluidInTank = tanks[0].fluid.getFluid(); boolean[] validDirections = new boolean[ForgeDirection.values().length]; boolean[] filteredDirections = new boolean[ForgeDirection.values().length]; boolean filterForLiquid = false; // check every direction // perhaps we should/can cache this? for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { validDirections[dir.ordinal()] = false; filteredDirections[dir.ordinal()] = false; if (Utils.checkPipesConnections(container.getTile(dir), container)) { for (int slot = 0; slot < 9; ++slot) { Fluid fluid = fluids[dir.ordinal() * 9 + slot]; if (fluid != null) { filteredDirections[dir.ordinal()] = true; if (fluidInTank.getID() == fluid.getID()) { validDirections[dir.ordinal()] = true; filterForLiquid = true; } } } } } // the direction is filtered and liquids match if (filteredDirections[to.ordinal()] && validDirections[to.ordinal()]) return true; // we havent found a filter for this liquid and the direction is free if (!filterForLiquid && !filteredDirections[to.ordinal()]) return true; // we have a filter for the liquid, but not a valid Direction :/ return false; }
public void dropFacade(ForgeDirection direction) { if (this.worldObj.isRemote) return; if (!hasFacade(direction)) return; Utils.dropItems( worldObj, new ItemStack( BuildCraftTransport.facadeItem, 1, ItemFacade.encode( this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()])), this.xCoord, this.yCoord, this.zCoord); this.facadeBlocks[direction.ordinal()] = 0; this.facadeMeta[direction.ordinal()] = 0; scheduleRenderUpdate(); }
/* LEGACY PIPE RENDERING */ private void legacyPipeRender( RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l) { float minSize = Utils.pipeMinPos; float maxSize = Utils.pipeMaxPos; block.setBlockBounds(minSize, minSize, minSize, maxSize, maxSize, maxSize); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i - 1, j, k)) { block.setBlockBounds(0.0F, minSize, minSize, minSize, maxSize, maxSize); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); } if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i + 1, j, k)) { block.setBlockBounds(maxSize, minSize, minSize, 1.0F, maxSize, maxSize); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); } if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j - 1, k)) { block.setBlockBounds(minSize, 0.0F, minSize, maxSize, minSize, maxSize); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); } if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j + 1, k)) { block.setBlockBounds(minSize, maxSize, minSize, maxSize, 1.0F, maxSize); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); } if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j, k - 1)) { block.setBlockBounds(minSize, minSize, 0.0F, maxSize, maxSize, minSize); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); } if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j, k + 1)) { block.setBlockBounds(minSize, minSize, maxSize, maxSize, maxSize, 1.0F); renderblocks.func_83018_a(block); renderblocks.renderStandardBlock(block, i, j, k); } block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); }
/** If this pipe is open on one side, return it. */ public ForgeDirection getOpenOrientation() { int Connections_num = 0; ForgeDirection target_orientation = ForgeDirection.UNKNOWN; for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) if (Utils.checkPipesConnections(container.getTile(o), container)) { Connections_num++; if (Connections_num == 1) { target_orientation = o; } } if (Connections_num > 1 || Connections_num == 0) return ForgeDirection.UNKNOWN; return target_orientation.getOpposite(); }
@Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); Utils.readStacksFromNBT(nbttagcompound, "Items", items); if (nbttagcompound.hasKey("box")) { box.initialize(nbttagcompound.getCompoundTag("box")); } if (nbttagcompound.hasKey("path")) { path = new LinkedList<BlockIndex>(); NBTTagList list = nbttagcompound.getTagList("path"); for (int i = 0; i < list.tagCount(); ++i) { path.add(new BlockIndex((NBTTagCompound) list.tagAt(i))); } } done = nbttagcompound.getBoolean("done"); }
@Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); Utils.writeStacksToNBT(nbttagcompound, "items", items); nbttagcompound.setFloat("energyStored", energyStored); NBTTagList list = new NBTTagList(); for (AssemblyRecipe recipe : plannedOutput) { NBTTagCompound cpt = new NBTTagCompound(); recipe.output.writeToNBT(cpt); list.appendTag(cpt); } nbttagcompound.setTag("planned", list); if (currentRecipe != null) { NBTTagCompound recipe = new NBTTagCompound(); currentRecipe.output.writeToNBT(recipe); nbttagcompound.setTag("recipe", recipe); } }
@Override public void breakBlock(World world, int x, int y, int z, int par5, int par6) { Utils.preDestroyBlock(world, x, y, z); super.breakBlock(world, x, y, z, par5, par6); }
public class TileAdvancedCraftingTable extends TileLaserTableBase implements IInventory, ILaserTarget, IMachine, IActionReceptor, ISidedInventory { private final class InternalInventoryCraftingContainer extends Container { @Override public boolean canInteractWith(EntityPlayer var1) { return false; } } private final class CraftingGrid extends SimpleInventory { public int[] oreIDs = new int[9]; public CraftingGrid() { super(9, "CraftingSlots", 1); Arrays.fill(oreIDs, -1); } @Override public void setInventorySlotContents(int slotId, ItemStack itemstack) { super.setInventorySlotContents(slotId, itemstack); if (TileAdvancedCraftingTable.this.getWorldObj() == null || !TileAdvancedCraftingTable.this.getWorldObj().isRemote) oreIDs[slotId] = itemstack == null ? -1 : OreDictionary.getOreID(itemstack); } } private final class InternalInventoryCrafting extends InventoryCrafting { int[] bindings = new int[9]; ItemStack[] tempStacks; public int[] hitCount; private boolean useRecipeStack; private InternalInventoryCrafting() { super(new InternalInventoryCraftingContainer(), 3, 3); } @Override public ItemStack getStackInSlot(int slot) { if (slot >= 0 && slot < 9) { if (useRecipeStack || tempStacks == null) { return craftingSlots.getStackInSlot(slot); } else { if (bindings[slot] >= 0) { return tempStacks[bindings[slot]]; } } } // vanilla returns null for out of bound stacks in InventoryCrafting as well return null; } @Override public void setInventorySlotContents(int slot, ItemStack par2ItemStack) { if (tempStacks != null && slot >= 0 && slot < 9 && bindings[slot] >= 0) { tempStacks[bindings[slot]] = par2ItemStack; } } @Override public ItemStack decrStackSize(int slot, int amount) { if (tempStacks != null && slot >= 0 && slot < 9 && bindings[slot] >= 0) { if (tempStacks[bindings[slot]].stackSize <= amount) { ItemStack result = tempStacks[bindings[slot]]; tempStacks[bindings[slot]] = null; return result; } else { ItemStack result = tempStacks[bindings[slot]].splitStack(amount); if (tempStacks[bindings[slot]].stackSize <= 0) { tempStacks[bindings[slot]] = null; } return result; } } else { return null; } } public void recipeUpdate(boolean flag) { useRecipeStack = flag; } } private final class InternalPlayer extends EntityPlayer { public InternalPlayer() { super(TileAdvancedCraftingTable.this.getWorldObj(), new GameProfile(null, "[BuildCraft]")); posX = TileAdvancedCraftingTable.this.xCoord; posY = TileAdvancedCraftingTable.this.yCoord + 1; posZ = TileAdvancedCraftingTable.this.zCoord; } @Override public void addChatMessage(IChatComponent var1) {} @Override public boolean canCommandSenderUseCommand(int var1, String var2) { return false; } @Override public ChunkCoordinates getPlayerCoordinates() { return null; } } public InventoryCraftResult craftResult; private InternalInventoryCrafting internalInventoryCrafting; public TileAdvancedCraftingTable() { craftingSlots = new CraftingGrid(); inv.addListener(this); invInput = new InventoryMapper(inv, 0, 15); invOutput = new InventoryMapper(inv, 15, 9); craftResult = new InventoryCraftResult(); } private static final int[] SLOTS = Utils.createSlotArray(0, 24); private static final EnumSet<ForgeDirection> SEARCH_SIDES = EnumSet.of(DOWN, NORTH, SOUTH, EAST, WEST); private static final float REQUIRED_POWER = 500F; private final CraftingGrid craftingSlots; private final InventoryMapper invInput; private final InventoryMapper invOutput; private SlotCrafting craftSlot; private boolean craftable; private boolean justCrafted; private InternalPlayer internalPlayer; private IRecipe currentRecipe; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; private TileBuffer[] cache; @Override public void writeToNBT(NBTTagCompound data) { super.writeToNBT(data); craftingSlots.writeToNBT(data, "craftingSlots"); } @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); if (data.hasKey("StorageSlots")) inv.readFromNBT(data, "StorageSlots"); if (data.hasKey("items")) craftingSlots.readFromNBT(data); else craftingSlots.readFromNBT(data, "craftingSlots"); } @Override public int getSizeInventory() { return 24; } @Override public String getInventoryName() { return StringUtils.localize("tile.assemblyWorkbenchBlock.name"); } @Override public void markDirty() { super.markDirty(); craftable = craftResult.getStackInSlot(0) != null; } @Override public double getRequiredEnergy() { return craftResult.getStackInSlot(0) != null ? REQUIRED_POWER : 0f; } public int getProgressScaled(int i) { return (int) ((getEnergy() * i) / REQUIRED_POWER); } @Override public void invalidate() { super.invalidate(); cache = null; } @Override public void updateEntity() { if (internalPlayer == null) { internalInventoryCrafting = new InternalInventoryCrafting(); internalPlayer = new InternalPlayer(); craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0); updateRecipe(); } if (!!worldObj.isRemote) return; if (lastMode == ActionMachineControl.Mode.Off) return; updateRecipe(); searchNeighborsForIngredients(); locateAndBindIngredients(); updateRecipeOutputDisplay(); justCrafted = false; if (canCraftAndOutput()) { if (getEnergy() >= getRequiredEnergy()) { craftItem(); justCrafted = true; } } else { craftable = false; internalInventoryCrafting.tempStacks = null; internalInventoryCrafting.hitCount = null; setEnergy(0); } } private boolean canCraftAndOutput() { if (!hasIngredients()) return false; ItemStack output = getRecipeOutput(); if (output == null) return false; return InvUtils.isRoomForStack(output, ForgeDirection.UP, invOutput); } private void locateAndBindIngredients() { internalInventoryCrafting.tempStacks = new InventoryCopy(inv).getItemStacks(); internalInventoryCrafting.hitCount = new int[internalInventoryCrafting.tempStacks.length]; ItemStack[] inputSlots = internalInventoryCrafting.tempStacks; for (int gridSlot = 0; gridSlot < craftingSlots.getSizeInventory(); gridSlot++) { internalInventoryCrafting.bindings[gridSlot] = -1; if (craftingSlots.getStackInSlot(gridSlot) == null) continue; boolean foundMatch = false; for (int inputSlot = 0; inputSlot < inputSlots.length; inputSlot++) { if (!isMatchingIngredient(gridSlot, inputSlot)) continue; if (internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].stackSize && internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].getMaxStackSize()) { internalInventoryCrafting.bindings[gridSlot] = inputSlot; internalInventoryCrafting.hitCount[inputSlot]++; foundMatch = true; break; } } if (!foundMatch) return; } } private boolean isMatchingIngredient(int gridSlot, int inputSlot) { ItemStack inputStack = internalInventoryCrafting.tempStacks[inputSlot]; if (inputStack == null) return false; if (StackHelper.instance() .isMatchingItem(craftingSlots.getStackInSlot(gridSlot), inputStack, true, false)) return true; if (StackHelper.instance().isCraftingEquivalent(craftingSlots.oreIDs[gridSlot], inputStack)) return true; return false; } private boolean hasIngredients() { return currentRecipe != null && currentRecipe.matches(internalInventoryCrafting, worldObj); } private void craftItem() { ItemStack recipeOutput = getRecipeOutput(); craftSlot.onPickupFromSlot(internalPlayer, recipeOutput); ItemStack[] tempStorage = internalInventoryCrafting.tempStacks; for (int i = 0; i < tempStorage.length; i++) { if (tempStorage[i] != null && tempStorage[i].stackSize <= 0) { tempStorage[i] = null; } inv.getItemStacks()[i] = tempStorage[i]; } subtractEnergy(getRequiredEnergy()); List<ItemStack> outputs = Lists.newArrayList(recipeOutput.copy()); for (int i = 0; i < internalPlayer.inventory.mainInventory.length; i++) { if (internalPlayer.inventory.mainInventory[i] != null) { outputs.add(internalPlayer.inventory.mainInventory[i]); internalPlayer.inventory.mainInventory[i] = null; } } for (ItemStack output : outputs) { output.stackSize -= Transactor.getTransactorFor(invOutput).add(output, ForgeDirection.UP, true).stackSize; if (output.stackSize > 0) { output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output); } if (output.stackSize > 0) { InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord); } } } private void searchNeighborsForIngredients() { if (cache == null) { cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false); } for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, ForgeDirection.UP)) { ItemStack ingred = slot.getStackInSlot(); if (ingred == null) continue; IStackFilter filter = new CraftingFilter(ingred); if (InvUtils.countItems(invInput, ForgeDirection.UP, filter) < InvUtils.countItems(craftingSlots, ForgeDirection.UP, filter)) { for (ForgeDirection side : SEARCH_SIDES) { TileEntity tile = cache[side.ordinal()].getTile(); if (tile instanceof IInventory) { IInventory inv = InvUtils.getInventory(((IInventory) tile)); ItemStack result = InvUtils.moveOneItem(inv, side.getOpposite(), invInput, side, filter); if (result != null) { return; } } } } } } public void updateCraftingMatrix(int slot, ItemStack stack) { craftingSlots.setInventorySlotContents(slot, stack); updateRecipe(); if (worldObj.isRemote) { PacketSlotChange packet = new PacketSlotChange( PacketIds.ADVANCED_WORKBENCH_SETSLOT, xCoord, yCoord, zCoord, slot, stack); BuildCraftSilicon.instance.sendToServer(packet); } } private void updateRecipe() { if (internalInventoryCrafting == null) { return; } internalInventoryCrafting.recipeUpdate(true); if (this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj)) { currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj); } internalInventoryCrafting.recipeUpdate(false); markDirty(); } private void updateRecipeOutputDisplay() { if (internalInventoryCrafting == null || currentRecipe == null) { craftResult.setInventorySlotContents(0, null); return; } ItemStack resultStack = getRecipeOutput(); if (resultStack == null) { internalInventoryCrafting.recipeUpdate(true); resultStack = getRecipeOutput(); internalInventoryCrafting.recipeUpdate(false); } craftResult.setInventorySlotContents(0, resultStack); markDirty(); } private ItemStack getRecipeOutput() { if (internalInventoryCrafting == null || currentRecipe == null) { return null; } return currentRecipe.getCraftingResult(internalInventoryCrafting); } public IInventory getCraftingSlots() { return craftingSlots; } public IInventory getOutputSlot() { return craftResult; } @Override public boolean canCraft() { return craftable && !justCrafted && lastMode != ActionMachineControl.Mode.Off; } @Override public boolean isActive() { return requiresLaserEnergy(); } @Override public boolean manageFluids() { return false; } @Override public boolean manageSolids() { return false; } @Override public boolean allowAction(IAction action) { return action == BuildCraftCore.actionOn || action == BuildCraftCore.actionOff; } @Override public int[] getAccessibleSlotsFromSide(int side) { return SLOTS; } @Override public boolean canInsertItem(int slot, ItemStack stack, int side) { return isItemValidForSlot(slot, stack); } @Override public boolean canExtractItem(int slot, ItemStack stack, int side) { return slot >= 15; } @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { return slot < 15; } @Override public void actionActivated(IAction action) { if (action == BuildCraftCore.actionOn) { lastMode = ActionMachineControl.Mode.On; } else if (action == BuildCraftCore.actionOff) { lastMode = ActionMachineControl.Mode.Off; } } @Override public boolean hasCustomInventoryName() { return false; } }
@Override public boolean onBlockActivated( World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) { // Drop through if the player is sneaking if (entityplayer.isSneaking()) return false; Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null; if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) { int meta = world.getBlockMetadata(i, j, k); switch (ForgeDirection.values()[meta]) { case WEST: world.setBlockMetadata(i, j, k, ForgeDirection.SOUTH.ordinal()); break; case EAST: world.setBlockMetadata(i, j, k, ForgeDirection.NORTH.ordinal()); break; case NORTH: world.setBlockMetadata(i, j, k, ForgeDirection.WEST.ordinal()); break; case SOUTH: default: world.setBlockMetadata(i, j, k, ForgeDirection.EAST.ordinal()); break; } ((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k); world.markBlockNeedsUpdate(i, j, k); return true; } else { LiquidStack liquid = LiquidManager.getLiquidForFilledItem(entityplayer.getCurrentEquippedItem()); if (liquid != null) { int qty = ((TileRefinery) world.getBlockTileEntity(i, j, k)) .fill(ForgeDirection.UNKNOWN, liquid, true); if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) { entityplayer.inventory.setInventorySlotContents( entityplayer.inventory.currentItem, Utils.consumeItem(entityplayer.inventory.getCurrentItem())); } return true; } } if (!CoreProxy.proxy.isRenderWorld(world)) entityplayer.openGui(BuildCraftFactory.instance, GuiIds.REFINERY, world, i, j, k); return true; }
@Override public void updateEntity() { tick++; tick = tick % recentEnergy.length; recentEnergy[tick] = 0.0f; if (currentRecipe == null) return; if (!currentRecipe.canBeDone(items)) { setNextCurrentRecipe(); if (currentRecipe == null) return; } if (energyStored >= currentRecipe.energy) { energyStored = 0; if (currentRecipe.canBeDone(items)) { for (ItemStack in : currentRecipe.input) { if (in == null) { continue; // Optimisation, reduces calculation for a null ingredient } int found = 0; // Amount of ingredient found in inventory for (int i = 0; i < items.length; ++i) { if (items[i] == null) { continue; // Broken out of large if statement, increases clarity } if (items[i].isItemEqual(in)) { int supply = items[i].stackSize; int toBeFound = in.stackSize - found; if (supply >= toBeFound) { found += decrStackSize(i, toBeFound) .stackSize; // Adds the amount of ingredient taken (in this case the total // still needed) } else { found += decrStackSize(i, supply) .stackSize; // Adds the amount of ingredient taken (in this case the total // in that slot) } if (found >= in.stackSize) { break; // Breaks out of the for loop when the required amount of ingredient has been // taken } } } } ItemStack remaining = currentRecipe.output.copy(); ItemStack added = Utils.addToRandomInventory( remaining, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN); remaining.stackSize -= added.stackSize; if (remaining.stackSize > 0) { Utils.addToRandomPipeEntry(this, ForgeDirection.UNKNOWN, remaining); } if (remaining.stackSize > 0) { EntityItem entityitem = new EntityItem( worldObj, xCoord + 0.5, yCoord + 0.7, zCoord + 0.5, currentRecipe.output.copy()); worldObj.spawnEntityInWorld(entityitem); } setNextCurrentRecipe(); } } }
public InventoryWrapperSimple(IInventory inventory) { super(inventory); slots = Utils.createSlotArray(0, inventory.getSizeInventory()); }
@Override public void createLaserData() { lasersData = Utils.createLaserDataBox(xMin, yMin, zMin, xMax, yMax, zMax); }
@SideOnly(Side.CLIENT) public void activateLasers() { deactivateLasers(); EntityClientPlayerMP player = FMLClientHandler.instance().getClient().thePlayer; int playerY = (int) player.posY - 1; for (ChunkCoordIntPair coords : persistentChunks) { int xCoord = coords.chunkXPos * 16; int zCoord = coords.chunkZPos * 16; addLasersToList( Utils.createLaserBox( player.worldObj, xCoord, playerY, zCoord, xCoord + 16, playerY, zCoord + 16, buildcraft.core.LaserKind.Blue)); addLasersToList( Utils.createLaserBox( player.worldObj, xCoord, playerY - 20, zCoord, xCoord + 16, playerY - 20, zCoord + 16, buildcraft.core.LaserKind.Blue)); addLasersToList( Utils.createLaserBox( player.worldObj, xCoord, playerY + 20, zCoord, xCoord + 16, playerY + 20, zCoord + 16, buildcraft.core.LaserKind.Blue)); addLasersToList( Utils.createLaserBox( player.worldObj, xCoord + 7, playerY, zCoord + 7, xCoord + 9, playerY, zCoord + 9, buildcraft.core.LaserKind.Blue)); addLasersToList( Utils.createLaserBox( player.worldObj, xCoord + 7, playerY - 20, zCoord + 7, xCoord + 9, playerY - 20, zCoord + 9, buildcraft.core.LaserKind.Blue)); addLasersToList( Utils.createLaserBox( player.worldObj, xCoord + 7, playerY + 20, zCoord + 7, xCoord + 9, playerY + 20, zCoord + 9, buildcraft.core.LaserKind.Blue)); } active = true; }
@Override public boolean doDrop() { Utils.preDestroyBlock(getWorld(), container.xCoord, container.yCoord, container.zCoord); return true; }