mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 05:02:25 +00:00
add NEI support for the crafting grid
This commit is contained in:
1 parent
e7e2efdec1
commit
5549bdd679
9 files changed
+419
-19
No files matched your search
@@ -37,7 +37,6 @@ import crazypants.render.RenderUtil;
|
||||
import crazypants.util.DyeColor;
|
||||
import crazypants.util.Lang;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
public class ItemSettings extends BaseSettingsPanel {
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -21,6 +20,7 @@ public class BlockInventoryPanel extends AbstractMachineBlock<TileInventoryPanel
|
||||
PacketHandler.INSTANCE.registerMessage(PacketItemList.class, PacketItemList.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketRequestMissingItems.class, PacketRequestMissingItems.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketFetchItem.class, PacketFetchItem.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketMoveItems.class, PacketMoveItems.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
BlockInventoryPanel panel = new BlockInventoryPanel();
|
||||
panel.init();
|
||||
|
||||
@@ -58,6 +58,8 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
private final String infoTextFilter;
|
||||
private final String infoTextOffline;
|
||||
|
||||
private ICraftingHelper craftingHelper;
|
||||
|
||||
public GuiInventoryPanel(TileInventoryPanel te, Container container) {
|
||||
super(te, container);
|
||||
redstoneButton.visible = false;
|
||||
@@ -93,11 +95,15 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
addToolTip(new GuiToolTip(new Rectangle(InventoryPanelContainer.FILTER_SLOT_X, InventoryPanelContainer.FILTER_SLOT_Y, 16, 16), list) {
|
||||
@Override
|
||||
public boolean shouldDraw() {
|
||||
return !((InventoryPanelContainer) inventorySlots).getSlotFilter().getHasStack() && super.shouldDraw();
|
||||
return !getContainer().getSlotFilter().getHasStack() && super.shouldDraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setCraftingHelper(ICraftingHelper craftingHelper) {
|
||||
this.craftingHelper = craftingHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
@@ -192,8 +198,12 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
itemRender.renderItemOverlayIntoGUI(font, mc.renderEngine, stack, x, y, str);
|
||||
}
|
||||
|
||||
private InventoryDatabaseClient getDatabase() {
|
||||
return (InventoryDatabaseClient) getTileEntity().getDatabaseClient();
|
||||
public InventoryPanelContainer getContainer() {
|
||||
return (InventoryPanelContainer) inventorySlots;
|
||||
}
|
||||
|
||||
public InventoryDatabaseClient getDatabase() {
|
||||
return getTileEntity().getDatabaseClient();
|
||||
}
|
||||
|
||||
private IconEIO getSortOrderIcon() {
|
||||
@@ -373,7 +383,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
InventoryPlayer playerInv = mc.thePlayer.inventory;
|
||||
targetSlot = playerInv.getFirstEmptyStack();
|
||||
if(targetSlot >= 0) {
|
||||
targetSlot = ((InventoryPanelContainer) inventorySlots).getSlotIndex(playerInv, targetSlot);
|
||||
targetSlot = getContainer().getSlotIndex(playerInv, targetSlot);
|
||||
}
|
||||
if(targetSlot < 0) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
public interface ICraftingHelper {
|
||||
|
||||
void refill(GuiInventoryPanel gui, int amount);
|
||||
|
||||
}
|
||||
@@ -47,10 +47,8 @@ public abstract class InventoryDatabase<ItemEntry extends ItemEntryBase> {
|
||||
return hint;
|
||||
}
|
||||
|
||||
if(!create) {
|
||||
return null;
|
||||
} else if(nbt == null && itemID < SIMPLE_MAX_ITEMID && meta < SIMPLE_MAX_META) {
|
||||
return getSimpleItem(itemID, meta);
|
||||
if(nbt == null && itemID < SIMPLE_MAX_ITEMID && meta < SIMPLE_MAX_META) {
|
||||
return getSimpleItem(itemID, meta, create);
|
||||
} else {
|
||||
return getComplexItem(itemID, meta, nbt);
|
||||
}
|
||||
@@ -88,10 +86,10 @@ public abstract class InventoryDatabase<ItemEntry extends ItemEntryBase> {
|
||||
return hash;
|
||||
}
|
||||
|
||||
private ItemEntry getSimpleItem(int itemID, int meta) {
|
||||
private ItemEntry getSimpleItem(int itemID, int meta, boolean create) {
|
||||
Integer dbID = (itemID << SIMPLE_META_BITS) | meta;
|
||||
ItemEntry entry = simpleRegsitry.get(dbID);
|
||||
if(entry == null) {
|
||||
if(entry == null && create) {
|
||||
entry = createItemEntry(dbID, dbID, itemID, meta, null);
|
||||
simpleRegsitry.put(dbID, entry);
|
||||
System.out.println("New simple item: " + entry);
|
||||
@@ -102,7 +100,7 @@ public abstract class InventoryDatabase<ItemEntry extends ItemEntryBase> {
|
||||
protected ItemEntry getSimpleItem(int dbID) {
|
||||
int itemID = dbID >> SIMPLE_META_BITS;
|
||||
int meta = dbID & SIMPLE_META_MASK;
|
||||
return getSimpleItem(itemID, meta);
|
||||
return getSimpleItem(itemID, meta, true);
|
||||
}
|
||||
|
||||
public ItemEntry getItem(int dbID) {
|
||||
|
||||
@@ -46,6 +46,8 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
private int indexFilterSlot;
|
||||
private int startReturnSlot;
|
||||
private int endReturnSlot;
|
||||
private int startCraftingGrid;
|
||||
private int endCraftingGrid;
|
||||
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public InventoryPanelContainer(InventoryPlayer playerInv, TileInventoryPanel te) {
|
||||
@@ -96,11 +98,13 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
}
|
||||
});
|
||||
|
||||
startCraftingGrid = inventorySlots.size();
|
||||
for(int y=0,i=TileInventoryPanel.SLOT_CRAFTING_START ; y<3 ; y++) {
|
||||
for(int x=0 ; x<3 ; x++,i++) {
|
||||
addSlotToContainer(new Slot(tileEntity, i, CRAFTING_GRID_X+x*18, CRAFTING_GRID_Y+y*18));
|
||||
}
|
||||
}
|
||||
endCraftingGrid = inventorySlots.size();
|
||||
|
||||
indexFilterSlot = inventorySlots.size();
|
||||
slotFilter = addSlotToContainer(new Slot(tileEntity, TileInventoryPanel.SLOT_VIEW_FILTER, FILTER_SLOT_X, FILTER_SLOT_Y) {
|
||||
@@ -141,6 +145,18 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
return slotFilter;
|
||||
}
|
||||
|
||||
public List<Slot> getCraftingGridSlots() {
|
||||
return inventorySlots.subList(startCraftingGrid, endCraftingGrid);
|
||||
}
|
||||
|
||||
public List<Slot> getReturnAreaSlots() {
|
||||
return inventorySlots.subList(startReturnSlot, endReturnSlot);
|
||||
}
|
||||
|
||||
public List<Slot> getPlayerInventorySlots() {
|
||||
return inventorySlots.subList(startPlayerSlot, endPlayerSlot);
|
||||
}
|
||||
|
||||
private void removeChangeLog() {
|
||||
if(changedItems != null) {
|
||||
getInventoryPanel().getDatabaseServer().removeChangeLog(this);
|
||||
@@ -198,14 +214,13 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
|
||||
@Override
|
||||
protected List<SlotRange> getTargetSlotsForTransfer(int slotIndex, Slot slot) {
|
||||
SlotDefinition slotDef = tileEntity.getSlotDefinition();
|
||||
if(slotDef.isInputSlot(slotIndex) || slotDef.isUpgradeSlot(slotIndex)) {
|
||||
return Collections.singletonList(getPlayerInventorySlotRange(false));
|
||||
}
|
||||
if(slotDef.isOutputSlot(slotIndex) || slotIndex == indexCraftingSlot) {
|
||||
if(slotIndex == indexCraftingSlot) {
|
||||
return Collections.singletonList(getPlayerInventorySlotRange(true));
|
||||
}
|
||||
if(slotIndex >= startPlayerSlot) {
|
||||
if(slotIndex >= startReturnSlot && slotIndex < endReturnSlot) {
|
||||
return Collections.singletonList(new SlotRange(startReturnSlot, endReturnSlot, false));
|
||||
}
|
||||
if((slotIndex >= startCraftingGrid && slotIndex < endCraftingGrid) || slotIndex >= startPlayerSlot) {
|
||||
ArrayList<SlotRange> res = new ArrayList<SlotRange>();
|
||||
res.add(new SlotRange(startReturnSlot, endReturnSlot, false));
|
||||
addPlayerSlotRanges(res, slotIndex);
|
||||
@@ -304,4 +319,43 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean moveItemsToReturnArea(int fromSlot) {
|
||||
return moveItems(fromSlot, startReturnSlot, endReturnSlot, Short.MAX_VALUE);
|
||||
}
|
||||
|
||||
public boolean moveItems(int fromSlot, int toSlotStart, int toSlotEnd, int amount) {
|
||||
if(!executeMoveItems(fromSlot, toSlotStart, toSlotEnd, amount)) {
|
||||
return false;
|
||||
}
|
||||
if(getTileEntity().getWorldObj().isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketMoveItems(fromSlot, toSlotStart, toSlotEnd, amount));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean executeMoveItems(int fromSlot, int toSlotStart, int toSlotEnd, int amount) {
|
||||
if((fromSlot >= toSlotStart && fromSlot < toSlotEnd) || toSlotEnd <= toSlotStart || amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Slot srcSlot = getSlot(fromSlot);
|
||||
ItemStack src = srcSlot.getStack();
|
||||
if(src != null) {
|
||||
ItemStack toMove = src.copy();
|
||||
toMove.stackSize = Math.min(src.stackSize, amount);
|
||||
int remaining = src.stackSize - toMove.stackSize;
|
||||
if(mergeItemStack(toMove, toSlotStart, toSlotEnd, false)) {
|
||||
remaining += toMove.stackSize;
|
||||
if(remaining == 0) {
|
||||
srcSlot.putStack(null);
|
||||
} else {
|
||||
src.stackSize = remaining;
|
||||
srcSlot.onSlotChanged();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import codechicken.lib.inventory.InventoryUtils;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.OffsetPositioner;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.DefaultOverlayRenderer;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IStackPositioner;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InventoryPanelNEIOverlayHandler implements IOverlayHandler {
|
||||
|
||||
private static final int NEI_OFFSET_X = 25;
|
||||
private static final int NEI_OFFSET_Y = 6;
|
||||
|
||||
private static final int CRAFTING_GRID_OFFSET_X = InventoryPanelContainer.CRAFTING_GRID_X - NEI_OFFSET_X;
|
||||
private static final int CRAFTING_GRID_OFFSET_Y = InventoryPanelContainer.CRAFTING_GRID_Y - NEI_OFFSET_Y;
|
||||
|
||||
private final IStackPositioner positioner = new OffsetPositioner(CRAFTING_GRID_OFFSET_X, CRAFTING_GRID_OFFSET_Y);
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
GuiInventoryPanel guiInvPanel = (GuiInventoryPanel) gui;
|
||||
System.out.println("InventoryPanelNEIOverlayHandler.overlayRecipe " + recipe + " " + recipeIndex + " " + shift);
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
|
||||
for(PositionedStack stack : ingredients) {
|
||||
System.out.println("stack={x="+stack.relx+",y="+stack.rely+",item="+stack.item+"}");
|
||||
}
|
||||
|
||||
LayoutManager.overlayRenderer = new DefaultOverlayRenderer(ingredients, positioner);
|
||||
|
||||
if(shift) {
|
||||
shift = clearIngredients(guiInvPanel);
|
||||
}
|
||||
|
||||
PositionedStack[] slots = mapSlots(ingredients, guiInvPanel.getContainer());
|
||||
if(slots != null) {
|
||||
CraftingHelper helper = new CraftingHelper(slots);
|
||||
guiInvPanel.setCraftingHelper(helper);
|
||||
if(shift) {
|
||||
helper.refill(guiInvPanel, 64);
|
||||
}
|
||||
} else {
|
||||
guiInvPanel.setCraftingHelper(null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean clearIngredients(GuiInventoryPanel gui) {
|
||||
InventoryPanelContainer c = gui.getContainer();
|
||||
for(Slot slot : c.getCraftingGridSlots()) {
|
||||
if(slot.getHasStack()) {
|
||||
c.moveItemsToReturnArea(slot.slotNumber);
|
||||
if(slot.getHasStack())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private PositionedStack[] mapSlots(List<PositionedStack> ingredients, InventoryPanelContainer c) {
|
||||
PositionedStack[] slots = new PositionedStack[9];
|
||||
List<Slot> craftingGrid = c.getCraftingGridSlots();
|
||||
int found = 0;
|
||||
for(PositionedStack pstack : ingredients) {
|
||||
for(int idx = 0; idx < 9 ; idx++) {
|
||||
Slot slot = craftingGrid.get(idx);
|
||||
if(slot.xDisplayPosition == pstack.relx + CRAFTING_GRID_OFFSET_X && slot.yDisplayPosition == pstack.rely + CRAFTING_GRID_OFFSET_Y) {
|
||||
slots[idx] = pstack;
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found != ingredients.size()) {
|
||||
return null;
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
static class CraftingHelper implements ICraftingHelper {
|
||||
final PositionedStack[] ingredients;
|
||||
|
||||
public CraftingHelper(PositionedStack[] ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refill(GuiInventoryPanel gui, int amount) {
|
||||
InventoryPanelContainer container = gui.getContainer();
|
||||
List<Slot> craftingGrid = container.getCraftingGridSlots();
|
||||
int slotsToProcess = (1<<9)-1;
|
||||
boolean madeProgress;
|
||||
int maxAmount = 64;
|
||||
do {
|
||||
Candidate[] candidates = new Candidate[9];
|
||||
for(int idx = 0; idx < 9; idx++) {
|
||||
if((slotsToProcess & (1 << idx)) != 0) {
|
||||
PositionedStack pstack = ingredients[idx];
|
||||
Slot slot = craftingGrid.get(idx);
|
||||
ItemStack stack = slot.getStack();
|
||||
if(pstack == null) {
|
||||
if(stack != null) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Candidate candidate;
|
||||
if(stack != null) {
|
||||
if(!isStackCompatible(pstack, stack)) {
|
||||
return;
|
||||
}
|
||||
candidate = findCandidates(stack, gui, candidates);
|
||||
} else {
|
||||
candidate = findAllCandidates(pstack, gui, candidates);
|
||||
}
|
||||
|
||||
if(candidate == null) {
|
||||
return;
|
||||
}
|
||||
candidate.used++;
|
||||
candidates[idx] = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int targetAmount = maxAmount;
|
||||
int currentAmount = 0;
|
||||
for(int idx = 0; idx < 9; idx++) {
|
||||
Candidate candidate = candidates[idx];
|
||||
if(candidate != null) {
|
||||
Slot slot = craftingGrid.get(idx);
|
||||
int current = getSlotStackSize(slot);
|
||||
int maxStackSize = candidate.stack.getMaxStackSize();
|
||||
currentAmount = Math.max(currentAmount, current);
|
||||
if(candidate.stack.isStackable() && maxStackSize > 1) {
|
||||
targetAmount = Math.min(targetAmount, current + Math.min(maxStackSize, candidate.getAvailable()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetAmount = Math.min(targetAmount, currentAmount + amount);
|
||||
madeProgress = false;
|
||||
for(int idx = 0; idx < 9; idx++) {
|
||||
final int mask = 1 << idx;
|
||||
Candidate candidate = candidates[idx];
|
||||
if(candidate != null) {
|
||||
Slot slot = craftingGrid.get(idx);
|
||||
for(Slot srcSlot : candidate.sourceSlots) {
|
||||
int current = getSlotStackSize(slot);
|
||||
if(current >= targetAmount) {
|
||||
break;
|
||||
}
|
||||
if(container.moveItems(srcSlot.slotNumber, slot.slotNumber, slot.slotNumber+1, targetAmount - current)) {
|
||||
slotsToProcess &= ~mask;
|
||||
madeProgress = true;
|
||||
}
|
||||
}
|
||||
|
||||
int current = getSlotStackSize(slot);
|
||||
if(candidate.entry != null) {
|
||||
if(current < targetAmount) {
|
||||
int toMove = Math.min(candidate.entry.getCount(), targetAmount - current);
|
||||
System.out.println("fetching items from DB");
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketFetchItem(candidate.entry, slot.slotNumber, toMove));
|
||||
slotsToProcess &= ~mask;
|
||||
current += toMove;
|
||||
}
|
||||
}
|
||||
|
||||
if(current > 0) {
|
||||
maxAmount = Math.min(maxAmount, current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}while(madeProgress && slotsToProcess != 0);
|
||||
}
|
||||
|
||||
private static int getSlotStackSize(Slot slot) {
|
||||
ItemStack stack = slot.getStack();
|
||||
return (stack != null) ? stack.stackSize : 0;
|
||||
}
|
||||
|
||||
private static boolean isStackCompatible(PositionedStack pstack, ItemStack stack) {
|
||||
for(ItemStack istack : pstack.items) {
|
||||
if(InventoryUtils.canStack(stack, istack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Candidate findAllCandidates(PositionedStack pstack, GuiInventoryPanel gui, Candidate[] candidates) {
|
||||
Candidate bestInventory = null;
|
||||
Candidate bestNetwork = null;
|
||||
for(ItemStack istack : pstack.items) {
|
||||
Candidate candidate = findCandidates(istack, gui, candidates);
|
||||
if(candidate.available > 0) {
|
||||
if(bestInventory == null || bestInventory.available < candidate.available) {
|
||||
bestInventory = candidate;
|
||||
}
|
||||
}
|
||||
if(candidate.entry != null) {
|
||||
if(bestNetwork == null || bestNetwork.entry.getCount() < candidate.entry.getCount()) {
|
||||
bestNetwork = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(bestInventory != null) {
|
||||
return bestInventory;
|
||||
} else {
|
||||
return bestNetwork;
|
||||
}
|
||||
}
|
||||
|
||||
private Candidate findCandidates(ItemStack stack, GuiInventoryPanel gui, Candidate[] candidates) {
|
||||
for(Candidate candidate : candidates) {
|
||||
if(candidate != null && InventoryUtils.canStack(candidate.stack, stack)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
Candidate candidate = new Candidate(stack);
|
||||
InventoryPanelContainer container = gui.getContainer();
|
||||
findCandidates(candidate, stack, container.getReturnAreaSlots());
|
||||
findCandidates(candidate, stack, container.getPlayerInventorySlots());
|
||||
if(candidate.available == 0) {
|
||||
InventoryDatabaseClient db = gui.getDatabase();
|
||||
candidate.entry = db.lookupItem(stack, null, false);
|
||||
System.out.println("Looked up DB entry: stack=" + stack + " entry="+candidate.entry);
|
||||
if(candidate.entry != null && candidate.entry.getCount() <= 0) {
|
||||
candidate.entry = null;
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
private void findCandidates(Candidate candidates, ItemStack stack, Collection<Slot> slots) {
|
||||
for(Slot slot : slots) {
|
||||
ItemStack slotStack = slot.getStack();
|
||||
if(slotStack != null && InventoryUtils.canStack(slotStack, stack)) {
|
||||
candidates.sourceSlots.add(slot);
|
||||
candidates.available += slotStack.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class Candidate {
|
||||
final ItemStack stack;
|
||||
final ArrayList<Slot> sourceSlots = new ArrayList<Slot>();
|
||||
InventoryDatabaseClient.ItemEntry entry;
|
||||
int available;
|
||||
int used;
|
||||
|
||||
public Candidate(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public int getAvailable() {
|
||||
int avail = available;
|
||||
if(entry != null) {
|
||||
avail += entry.getCount();
|
||||
}
|
||||
if(avail > 0 && used > 1) {
|
||||
avail = Math.max(1, avail / used);
|
||||
}
|
||||
return avail;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class PacketMoveItems implements IMessage, IMessageHandler<PacketMoveItems, IMessage> {
|
||||
|
||||
private int fromSlot;
|
||||
private int toSlotStart;
|
||||
private int toSlotEnd;
|
||||
private int amount;
|
||||
|
||||
public PacketMoveItems(int fromSlot, int toSlotStart, int toSlotEnd, int amount) {
|
||||
this.fromSlot = fromSlot;
|
||||
this.toSlotStart = toSlotStart;
|
||||
this.toSlotEnd = toSlotEnd;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public PacketMoveItems() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf bb) {
|
||||
fromSlot = bb.readShort();
|
||||
toSlotStart = bb.readShort();
|
||||
toSlotEnd = bb.readShort();
|
||||
amount = bb.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf bb) {
|
||||
bb.writeShort(fromSlot);
|
||||
bb.writeShort(toSlotStart);
|
||||
bb.writeShort(toSlotEnd);
|
||||
bb.writeShort(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketMoveItems message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
if(player.openContainer instanceof InventoryPanelContainer) {
|
||||
InventoryPanelContainer ipc = (InventoryPanelContainer) player.openContainer;
|
||||
ipc.executeMoveItems(message.fromSlot, message.toSlotStart, message.toSlotEnd, message.amount);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import codechicken.nei.api.IConfigureNEI;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.gas.GasUtil;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.invpanel.GuiInventoryPanel;
|
||||
import crazypants.enderio.machine.invpanel.InventoryPanelNEIOverlayHandler;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
|
||||
public class NEIEnderIOConfig implements IConfigureNEI {
|
||||
@@ -31,6 +33,8 @@ public class NEIEnderIOConfig implements IConfigureNEI {
|
||||
API.registerRecipeHandler(new SoulBinderRecipeHandler());
|
||||
API.registerUsageHandler(new SoulBinderRecipeHandler());
|
||||
|
||||
API.registerGuiOverlayHandler(GuiInventoryPanel.class, new InventoryPanelNEIOverlayHandler(), "crafting");
|
||||
|
||||
API.hideItem(new ItemStack(EnderIO.blockConduitFacade));
|
||||
API.hideItem(new ItemStack(EnderIO.itemEnderface));
|
||||
API.hideItem(PainterUtil.applyDefaultPaintedState(new ItemStack(EnderIO.blockPaintedCarpet)));
|
||||
|
||||
Reference in new issue
Block a user