@Override public int fill(ForgeDirection direction, FluidStack resource, boolean doFill) { SocketModule m = getSide(direction); SideConfig c = configs[direction.ordinal()]; if (m.isFluidInterface() && m.canInsertFluid()) return m.fluidFill(resource, doFill, c, this, direction); return 0; }
@Override public void onInventoryChanged() { for (int i = 0; i < 6; i++) { for (int j = 0; j < 3; j++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onInventoryChange(configs[i], j, this, ForgeDirection.getOrientation(i), false); } } }
@Override public FluidStack drain(ForgeDirection direction, int maxDrain, boolean doDrain) { SocketModule m = getSide(direction); SideConfig c = configs[direction.ordinal()]; if (m.isFluidInterface() && m.canExtractFluid()) return m.fluidExtract(maxDrain, doDrain, c, this); return null; }
@Override public int addItem(ItemStack stack, boolean doAdd, ForgeDirection direction) { if (direction.ordinal() >= 0 && direction.ordinal() < 6) { SocketModule m = getSide(direction); SideConfig c = configs[direction.ordinal()]; if (m.isItemInterface() && m.canInsertItems()) return m.itemFill(stack, doAdd, c, this, direction); } return 0; }
@Override public void modifyLatch(int cell, boolean on) { if (rsLatch[cell] != on) { rsLatch[cell] = on; for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onRSLatchChange(configs[i], cell, this, ForgeDirection.getOrientation(i), on); } } }
public void modifyRS(int cell, boolean on) { if (rsControl[cell] != on) { rsControl[cell] = on; for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onRSInterfaceChange(configs[i], cell, this, ForgeDirection.getOrientation(i), on); if (dead) return; } } }
@Override public boolean canExtractItem(int slot, ItemStack is, int side) { SocketModule m = getSide(ForgeDirection.getOrientation(side)); if (m != null && m.canDirectlyExtractItems(configs[side], this)) { int[] slots = getAccessibleSlotsFromSide(side); if (slots.length > 0) { if (slots[0] == slot) return true; } } return false; }
@Override public ItemStack[] extractItem(boolean doRemove, ForgeDirection direction, int maxItemCount) { if (direction.ordinal() > 0 && direction.ordinal() < 6) { SocketModule m = getSide(direction); SideConfig c = configs[direction.ordinal()]; if (m.isItemInterface() && m.canExtractItems()) { ItemStack temp = m.itemExtract(maxItemCount, doRemove, c, this); if (temp != null) return new ItemStack[] {temp}; } } return new ItemStack[] {}; }
public FluidStack drainInternal(int tank, int maxDrain, boolean doDrain) { if (tank >= 0 && tank < 3) { FluidStack result = tanks[tank].drain(maxDrain, doDrain); if (result != null && doDrain) { for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onTankChange(configs[i], tank, this, ForgeDirection.getOrientation(i), false); } } return result; } return null; }
public int fillInternal(int tank, FluidStack resource, boolean doFill) { if (tank >= 0 && tank < 3) { int result = tanks[tank].fill(resource, doFill); if (result > 0 && doFill) { for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onTankChange(configs[i], tank, this, ForgeDirection.getOrientation(i), true); } } return result; } return 0; }
public void checkSideForChange(int side) { ForgeDirection d = ForgeDirection.getOrientation(side); SocketModule m = getSide(d); int xo = xCoord + d.offsetX; int yo = yCoord + d.offsetY; int zo = zCoord + d.offsetZ; boolean result = false; int id = worldObj.getBlockId(xo, yo, zo); int meta = worldObj.getBlockMetadata(xo, yo, zo); if ((id != sideID[side] && sideID[side] != 1) || (meta != sideMeta[side] && sideMeta[side] != -1)) { m.onAdjChangeSide(this, configs[side], d); } sideID[side] = id; sideMeta[side] = meta; }
@Override public int[] getAccessibleSlotsFromSide(int side) { int[] result = new int[1]; SocketModule m = getSide(ForgeDirection.getOrientation(side)); if (m != null && (m.canDirectlyExtractItems(configs[side], this) || m.canDirectlyInsertItems(configs[side], this))) { SideConfig config = configs[side]; if (config.inventory >= 0 && config.inventory <= 2) { result[0] = config.inventory; } else { result = new int[] {}; } } else { result = new int[] {}; } return result; }
public int addItemInternal(ItemStack stack, boolean doAdd, int inv) { int amntAdded; int temp; if (inv > -1 && inv < 3) { ItemStack currStack = inventory.getStackInSlot(inv); if (currStack == null) { if (doAdd) { inventory.setInventorySlotContents(inv, stack.copy()); for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onInventoryChange(configs[i], inv, this, ForgeDirection.getOrientation(i), true); } } return stack.stackSize; } else if (currStack.isItemEqual(stack)) { temp = Math.min( currStack.stackSize + stack.stackSize, currStack.getItem().getItemStackLimit()); if (temp == (currStack.stackSize + stack.stackSize)) { amntAdded = stack.stackSize; } else { amntAdded = currStack.getItem().getItemStackLimit() - currStack.stackSize; } if (doAdd && amntAdded > 0) { currStack.stackSize += amntAdded; for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onInventoryChange(configs[i], inv, this, ForgeDirection.getOrientation(i), true); } } return amntAdded; } } return 0; }
public ItemStack extractItemInternal(boolean doRemove, int inv, int maxItemCount) { ItemStack newStack; if (inv > -1 && inv < 3) { ItemStack currStack = inventory.getStackInSlot(inv); if (currStack != null) { newStack = currStack.copy(); newStack.stackSize = Math.min(currStack.stackSize, maxItemCount); if (doRemove) { currStack.stackSize -= newStack.stackSize; if (currStack.stackSize <= 0) inventory.setInventorySlotContents(inv, null); for (int i = 0; i < 6; i++) { SocketModule m = getSide(ForgeDirection.getOrientation(i)); m.onInventoryChange(configs[i], inv, this, ForgeDirection.getOrientation(i), false); } } return newStack; } } return null; }
public void updateEntity() { if (worldObj.isRemote) { updateCoolDown++; if (updateCoolDown == 600) { this.validate(); updateCoolDown = 0; } } if (!worldObj.isRemote) { ForgeDirection d; SocketModule m; SideConfig c; for (int i = 0; i < 6; i++) { d = ForgeDirection.getOrientation(i); m = getSide(d); c = configs[i]; /*if(m.pullsFromHopper()) { int xo = xCoord + d.offsetX; int yo = yCoord + d.offsetY; int zo = zCoord + d.offsetZ; TileEntity t = worldObj.getBlockTileEntity(xo, yo, zo); if(t != null && t instanceof TileEntityHopper) { TileEntityHopper th = (TileEntityHopper)t; for (int j = 0; j < th.getSizeInventory(); ++j) { if (th.getStackInSlot(j) != null) { ItemStack itemstack = th.getStackInSlot(j).copy(); itemstack.stackSize = 1; int added = addItem(itemstack, true, d); itemstack.stackSize = th.getStackInSlot(j).stackSize - added; if(itemstack.stackSize <= 0) itemstack = null; th.setInventorySlotContents(j, itemstack); break; } } } }*/ m.updateSide(c, this, d); } } if (!initialized && worldObj != null) { if (!worldObj.isRemote) { /*EnergyTileLoadEvent loadEvent = new EnergyTileLoadEvent(this); MinecraftForge.EVENT_BUS.post(loadEvent); this.addedToEnergyNet = true;*/ sideID = new int[6]; sideMeta = new int[6]; for (int i = 0; i < 6; i++) { sideID[i] = -1; sideMeta[i] = -1; checkSideForChange(i); } } initialized = true; } }
@Override public boolean canInterface(ForgeDirection from) { if (from == ForgeDirection.UNKNOWN) return false; SocketModule m = getSide(from); return m.isEnergyInterface(configs[from.ordinal()]); }
@Override public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { if (from == ForgeDirection.UNKNOWN) return 0; SocketModule m = getSide(from); return m.extractEnergy(maxExtract, simulate, configs[from.ordinal()], this); }