mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 13:10:13 +00:00
allow to store crafting recipes in the inventory panel
This commit is contained in:
1 parent
674dc78b6d
commit
dccdd478b6
13 files changed
+487
-86
No files matched your search
@@ -32,6 +32,7 @@ public class BlockInventoryPanel extends AbstractMachineBlock<TileInventoryPanel
|
||||
PacketHandler.INSTANCE.registerMessage(PacketMoveItems.class, PacketMoveItems.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketDatabaseReset.class, PacketDatabaseReset.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketGuiSettings.class, PacketGuiSettings.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketStoredCraftingRecipe.class, PacketStoredCraftingRecipe.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
BlockInventoryPanel panel = new BlockInventoryPanel();
|
||||
panel.init();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,7 +29,6 @@ import crazypants.enderio.gui.VScrollbarEIO;
|
||||
import crazypants.enderio.machine.gui.GuiMachineBase;
|
||||
import crazypants.enderio.machine.invpanel.client.CraftingHelper;
|
||||
import crazypants.enderio.machine.invpanel.client.DatabaseView;
|
||||
import crazypants.enderio.machine.invpanel.client.ICraftingHelper;
|
||||
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
|
||||
import crazypants.enderio.machine.invpanel.client.ItemEntry;
|
||||
import crazypants.enderio.machine.invpanel.client.SortOrder;
|
||||
@@ -41,14 +39,13 @@ import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Lang;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
private static final Rectangle inventoryArea = new Rectangle(107, 27, 108, 90);
|
||||
private static final Rectangle inventoryArea = new Rectangle(24+107, 27, 108, 90);
|
||||
|
||||
private static final Rectangle btnRefill = new Rectangle(85, 32, 20, 20);
|
||||
private static final Rectangle btnRefill = new Rectangle(24+85, 32, 20, 20);
|
||||
|
||||
private static final int ID_SORT = 9876;
|
||||
private static final int ID_CLEAR = 9877;
|
||||
@@ -73,7 +70,9 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
private final String infoTextFilter;
|
||||
private final String infoTextOffline;
|
||||
|
||||
private ICraftingHelper craftingHelper;
|
||||
private CraftingHelper craftingHelper;
|
||||
|
||||
private final Rectangle btnAddStoredRecipe = new Rectangle();
|
||||
|
||||
public GuiInventoryPanel(TileInventoryPanel te, Container container) {
|
||||
super(te, container);
|
||||
@@ -82,10 +81,14 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
for (int y = 0; y < GHOST_ROWS; y++) {
|
||||
for (int x = 0; x < GHOST_COLUMNS; x++) {
|
||||
ghostSlots.add(new InvSlot(108 + x * 18, 28 + y * 18));
|
||||
ghostSlots.add(new InvSlot(24 + 108 + x * 18, 28 + y * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < TileInventoryPanel.MAX_STORED_CRAFTING_RECIPES; i++) {
|
||||
ghostSlots.add(new RecipeSlot(i, 7, 7 + i * 20));
|
||||
}
|
||||
|
||||
this.view = new DatabaseView();
|
||||
|
||||
int sortMode = te.getGuiSortMode();
|
||||
@@ -97,10 +100,10 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
tfFilter = new TextFieldEIO(fr, 108, 11, 106, 10);
|
||||
tfFilter = new TextFieldEIO(fr, 24+108, 11, 106, 10);
|
||||
tfFilter.setEnableBackgroundDrawing(false);
|
||||
tfFilter.setText(te.getGuiFilterString());
|
||||
btnSort = new IconButtonEIO(this, ID_SORT, 233, 27, getSortOrderIcon()) {
|
||||
btnSort = new IconButtonEIO(this, ID_SORT, 24+233, 27, getSortOrderIcon()) {
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int x, int y) {
|
||||
return mousePressedButton(mc, x, y, 0);
|
||||
@@ -115,8 +118,8 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
scrollbar = new VScrollbarEIO(this, 215, 27, 90);
|
||||
btnClear = new MultiIconButtonEIO(this, ID_CLEAR, 65, 60, IconEIO.X_BUT, IconEIO.X_BUT_PRESSED, IconEIO.X_BUT_HOVER);
|
||||
scrollbar = new VScrollbarEIO(this, 24+215, 27, 90);
|
||||
btnClear = new MultiIconButtonEIO(this, ID_CLEAR, 24+65, 60, IconEIO.X_BUT, IconEIO.X_BUT_PRESSED, IconEIO.X_BUT_HOVER);
|
||||
|
||||
textFields.add(tfFilter);
|
||||
|
||||
@@ -128,7 +131,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.return.line");
|
||||
addToolTip(new GuiToolTip(new Rectangle(6, 72, 5 * 18, 8), list));
|
||||
addToolTip(new GuiToolTip(new Rectangle(24+6, 72, 5 * 18, 8), list));
|
||||
|
||||
list.clear();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.filterslot.line");
|
||||
@@ -159,7 +162,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.clear.line");
|
||||
btnClear.setToolTip(list.toArray(new String[list.size()]));
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(12, 132, 15, 47), "") {
|
||||
addToolTip(new GuiToolTip(new Rectangle(24+12, 132, 15, 47), "") {
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
@@ -167,6 +170,10 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
text.add(Fluids.toCapactityString(getTileEntity().fuelTank));
|
||||
}
|
||||
});
|
||||
|
||||
list.clear();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.addrecipe.line");
|
||||
addToolTip(new GuiToolTip(btnAddStoredRecipe, list));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,10 +186,28 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
public void setCraftingHelper(ICraftingHelper craftingHelper) {
|
||||
public void setCraftingHelper(CraftingHelper craftingHelper) {
|
||||
if(this.craftingHelper != null) {
|
||||
this.craftingHelper.remove();
|
||||
}
|
||||
this.craftingHelper = craftingHelper;
|
||||
ttRefill.setVisible(craftingHelper != null);
|
||||
ttSetReceipe.setVisible(craftingHelper == null);
|
||||
if(craftingHelper != null) {
|
||||
craftingHelper.install();
|
||||
}
|
||||
}
|
||||
|
||||
public void fillFromStoredRecipe(int index, boolean shift) {
|
||||
StoredCraftingRecipe recipe = getTileEntity().getStoredCraftingRecipe(index);
|
||||
if(recipe == null) {
|
||||
return;
|
||||
}
|
||||
if(getContainer().clearCraftingGrid()) {
|
||||
CraftingHelper helper = CraftingHelper.createFromRecipe(recipe);
|
||||
setCraftingHelper(helper);
|
||||
helper.refill(this, shift ? 64 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,20 +219,12 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
addScrollbar(scrollbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fixupGuiPosition() {
|
||||
guiLeft = (width - 232) / 2; // account for the tabs
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
if(b.id == ID_CLEAR) {
|
||||
if(getContainer().clearCraftingGrid()) {
|
||||
if(craftingHelper != null) {
|
||||
craftingHelper.remove();
|
||||
setCraftingHelper(null);
|
||||
}
|
||||
setCraftingHelper(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +236,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
int sx = guiLeft;
|
||||
int sy = guiTop;
|
||||
|
||||
drawTexturedModalRect(sx, sy, 0, 0, xSize, ySize);
|
||||
drawTexturedModalRect(sx+24, sy, 0, 0, 256, ySize);
|
||||
|
||||
if(craftingHelper != null) {
|
||||
boolean hover = btnRefill.contains(mouseX - sx, mouseY - sy);
|
||||
@@ -231,16 +248,42 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
drawTexturedModalRect(sx + btnRefill.x - 2, sy + btnRefill.y - 2, iconX, 232, 24, 24);
|
||||
}
|
||||
|
||||
TileInventoryPanel te = getTileEntity();
|
||||
|
||||
int y = sy;
|
||||
int numStoredRecipes = te.getStoredCraftingRecipes();
|
||||
if(numStoredRecipes == 1) {
|
||||
drawTexturedModalRect(sx, y, 227, 225, 28, 30); y += 30;
|
||||
} else if(numStoredRecipes > 1) {
|
||||
drawTexturedModalRect(sx, y, 227, 225, 28, 24); y += 24;
|
||||
for(int i = 1; i < numStoredRecipes - 1; i++) {
|
||||
drawTexturedModalRect(sx, y, 198, 229, 28, 20); y += 20;
|
||||
}
|
||||
drawTexturedModalRect(sx, y, 198, 229, 28, 26); y += 26;
|
||||
}
|
||||
|
||||
if(numStoredRecipes < TileInventoryPanel.MAX_STORED_CRAFTING_RECIPES && getContainer().hasNewCraftingRecipe()) {
|
||||
y += 2;
|
||||
btnAddStoredRecipe.x = 13;
|
||||
btnAddStoredRecipe.y = y - sy;
|
||||
btnAddStoredRecipe.width = 12;
|
||||
btnAddStoredRecipe.height = 14;
|
||||
boolean hover = btnAddStoredRecipe.contains(mouseX - sx, mouseY - sy);
|
||||
drawTexturedModalRect(sx + 13, y, 182, hover ? 241 : 225, 15, 14);
|
||||
} else {
|
||||
btnAddStoredRecipe.width = 0;
|
||||
btnAddStoredRecipe.height = 0;
|
||||
}
|
||||
|
||||
int headerColor = 0x404040;
|
||||
FontRenderer fr = getFontRenderer();
|
||||
fr.drawString(headerCrafting, sx + 7, sy + 6, headerColor);
|
||||
fr.drawString(headerReturn, sx + 7, sy + 72, headerColor);
|
||||
fr.drawString(headerInventory, sx + 38, sy + 120, headerColor);
|
||||
fr.drawString(headerCrafting, sx + 24 + 7, sy + 6, headerColor);
|
||||
fr.drawString(headerReturn, sx + 24 + 7, sy + 72, headerColor);
|
||||
fr.drawString(headerInventory, sx + 24 + 38, sy + 120, headerColor);
|
||||
|
||||
TileInventoryPanel te = getTileEntity();
|
||||
SmartTank fuelTank = te.fuelTank;
|
||||
if(fuelTank.getFluidAmount() > 0) {
|
||||
RenderUtil.renderGuiTank(fuelTank.getFluid(), fuelTank.getCapacity(), fuelTank.getFluidAmount(), sx + 12, sy + 132, zLevel, 16, 47);
|
||||
RenderUtil.renderGuiTank(fuelTank.getFluid(), fuelTank.getCapacity(), fuelTank.getFluidAmount(), sx + 24 + 12, sy + 132, zLevel, 16, 47);
|
||||
}
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(par1, mouseX, mouseY);
|
||||
@@ -282,9 +325,23 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
unit = "m";
|
||||
}
|
||||
str = value + unit;
|
||||
} else if(stack.stackSize > 1) {
|
||||
str = Integer.toString(stack.stackSize);
|
||||
}
|
||||
itemRender.renderItemAndEffectIntoGUI(font, mc.renderEngine, stack, x, y);
|
||||
itemRender.renderItemOverlayIntoGUI(font, mc.renderEngine, stack, x, y, str);
|
||||
if(str != null) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x + 16, y + 16, 0);
|
||||
GL11.glScalef(0.8f, 0.8f, 1.0f);
|
||||
font.drawStringWithShadow(str, 1 - font.getStringWidth(str), -8, 0xFFFFFF);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
}
|
||||
itemRender.renderItemOverlayIntoGUI(font, mc.renderEngine, stack, x, y, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -380,7 +437,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
@Override
|
||||
public int getXSize() {
|
||||
return 256;
|
||||
return 280;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -388,19 +445,6 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
return 212;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public boolean hideItemPanelSlot(GuiContainer gc, int x, int y, int w, int h) {
|
||||
// NEI seems to have an issue with the shifted GUI position - so let's work around it
|
||||
if(x+w >= guiLeft && x < guiLeft+xSize && y+h >= guiTop && y < guiTop+49) {
|
||||
return true;
|
||||
}
|
||||
if(x+w >= guiLeft && x < guiLeft+232 && x+h >= guiTop+49 && y < guiTop+ySize) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
@@ -417,6 +461,17 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
setCraftingHelper(CraftingHelper.createFromSlots(getContainer().getCraftingGridSlots()));
|
||||
}
|
||||
}
|
||||
|
||||
if(btnAddStoredRecipe.contains(x, y)) {
|
||||
TileInventoryPanel te = getTileEntity();
|
||||
if(te.getStoredCraftingRecipes() < TileInventoryPanel.MAX_STORED_CRAFTING_RECIPES && getContainer().hasNewCraftingRecipe()) {
|
||||
StoredCraftingRecipe recipe = new StoredCraftingRecipe();
|
||||
if(recipe.loadFromCraftingGrid(getContainer().getCraftingGridSlots())) {
|
||||
playClickSound();
|
||||
te.addStoredCraftingRecipe(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void playClickSound() {
|
||||
@@ -485,6 +540,15 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketFetchItem(db.getGeneration(), invSlot.entry, targetSlot, count));
|
||||
}
|
||||
} else if(slot instanceof RecipeSlot) {
|
||||
RecipeSlot recipeSlot = (RecipeSlot) slot;
|
||||
if(recipeSlot.isVisible()) {
|
||||
if(button == 0) {
|
||||
fillFromStoredRecipe(recipeSlot.index, isShiftKeyDown());
|
||||
} else if(button == 1) {
|
||||
getTileEntity().removeStoredCraftingRecipe(recipeSlot.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,4 +560,26 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
class RecipeSlot extends GhostSlot {
|
||||
final int index;
|
||||
|
||||
RecipeSlot(int index, int x, int y) {
|
||||
this.index = index;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
TileInventoryPanel te = getTileEntity();
|
||||
StoredCraftingRecipe recipe = te.getStoredCraftingRecipe(index);
|
||||
return recipe != null ? recipe.getResult(te) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return index < getTileEntity().getStoredCraftingRecipes();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,13 @@ import crazypants.util.ItemUtil;
|
||||
|
||||
public class InventoryPanelContainer extends AbstractMachineContainer implements ChangeLog {
|
||||
|
||||
public static final int CRAFTING_GRID_X = 7;
|
||||
public static final int CRAFTING_GRID_X = 24+7;
|
||||
public static final int CRAFTING_GRID_Y = 16;
|
||||
|
||||
public static final int RETURN_INV_X = 7;
|
||||
public static final int RETURN_INV_X = 24+7;
|
||||
public static final int RETURN_INV_Y = 82;
|
||||
|
||||
public static final int FILTER_SLOT_X = 233;
|
||||
public static final int FILTER_SLOT_X = 24+233;
|
||||
public static final int FILTER_SLOT_Y = 7;
|
||||
|
||||
private final HashSet<ItemEntry> changedItems;
|
||||
@@ -53,6 +53,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
private int endSlotCraftingGrid;
|
||||
|
||||
private boolean updateReturnAreaSlots;
|
||||
private boolean storedRecipeExists;
|
||||
|
||||
public InventoryPanelContainer(InventoryPlayer playerInv, TileInventoryPanel te) {
|
||||
super(playerInv, te);
|
||||
@@ -128,7 +129,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
|
||||
@Override
|
||||
public Point getPlayerInventoryOffset() {
|
||||
return new Point(39, 130);
|
||||
return new Point(24+39, 130);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +141,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
removeChangeLog();
|
||||
}
|
||||
|
||||
private TileInventoryPanel getInventoryPanel() {
|
||||
public TileInventoryPanel getInventoryPanel() {
|
||||
return (TileInventoryPanel) tileEntity;
|
||||
}
|
||||
|
||||
@@ -220,6 +221,22 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
}
|
||||
|
||||
tileEntity.setInventorySlotContents(9, CraftingManager.getInstance().findMatchingRecipe(tmp, tileEntity.getWorldObj()));
|
||||
|
||||
checkCraftingRecipes();
|
||||
}
|
||||
|
||||
public void checkCraftingRecipes() {
|
||||
storedRecipeExists = false;
|
||||
int storedCraftingRecipes = getInventoryPanel().getStoredCraftingRecipes();
|
||||
if(hasCraftingRecipe() && storedCraftingRecipes > 0) {
|
||||
List<Slot> craftingGrid = getCraftingGridSlots();
|
||||
for(int idx = 0; idx < storedCraftingRecipes; idx++) {
|
||||
if(getInventoryPanel().getStoredCraftingRecipe(idx).isEqual(craftingGrid)) {
|
||||
storedRecipeExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,6 +261,10 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
return getSlot(slotCraftResult).getHasStack();
|
||||
}
|
||||
|
||||
public boolean hasNewCraftingRecipe() {
|
||||
return hasCraftingRecipe() && !storedRecipeExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SlotRange> getTargetSlotsForTransfer(int slotIndex, Slot slot) {
|
||||
if((slotIndex == slotCraftResult) || (slotIndex >= firstSlotReturn && slotIndex < endSlotReturn)) {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
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 crazypants.enderio.network.NetworkUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PacketStoredCraftingRecipe implements IMessage, IMessageHandler<PacketStoredCraftingRecipe, IMessage> {
|
||||
|
||||
public static final int ACTION_ADD = 0;
|
||||
public static final int ACTION_DELETE = 1;
|
||||
|
||||
private int action;
|
||||
private int index;
|
||||
private StoredCraftingRecipe recipe;
|
||||
|
||||
public PacketStoredCraftingRecipe() {
|
||||
}
|
||||
|
||||
public PacketStoredCraftingRecipe(int action, int index, StoredCraftingRecipe recipe) {
|
||||
this.action = action;
|
||||
this.index = index;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
action = buf.readUnsignedByte();
|
||||
index = buf.readUnsignedByte();
|
||||
NBTTagCompound nbt = NetworkUtil.readNBTTagCompound(buf);
|
||||
if(nbt != null) {
|
||||
recipe = new StoredCraftingRecipe();
|
||||
if(!recipe.readFromNBT(nbt)) {
|
||||
recipe = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(action);
|
||||
buf.writeByte(index);
|
||||
NBTTagCompound nbt = null;
|
||||
if(recipe != null) {
|
||||
nbt = new NBTTagCompound();
|
||||
recipe.writeToNBT(nbt);
|
||||
}
|
||||
NetworkUtil.writeNBTTagCompound(nbt, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketStoredCraftingRecipe message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
if(player.openContainer instanceof InventoryPanelContainer) {
|
||||
InventoryPanelContainer ipc = (InventoryPanelContainer) player.openContainer;
|
||||
switch (message.action) {
|
||||
case ACTION_ADD:
|
||||
if(message.recipe != null) {
|
||||
ipc.getInventoryPanel().addStoredCraftingRecipe(message.recipe);
|
||||
}
|
||||
break;
|
||||
case ACTION_DELETE:
|
||||
ipc.getInventoryPanel().removeStoredCraftingRecipe(message.index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import crazypants.util.ItemUtil;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class StoredCraftingRecipe {
|
||||
|
||||
private final ItemStack[] slots;
|
||||
|
||||
private boolean updateResult;
|
||||
private ItemStack result;
|
||||
|
||||
public StoredCraftingRecipe() {
|
||||
slots = new ItemStack[9];
|
||||
}
|
||||
|
||||
public boolean loadFromCraftingGrid(List<Slot> craftingGrid) {
|
||||
if (craftingGrid.size() != 9) {
|
||||
return false;
|
||||
}
|
||||
int count = 0;
|
||||
for(int slotIdx = 0; slotIdx < 9 && slotIdx < craftingGrid.size(); slotIdx++) {
|
||||
Slot slot = craftingGrid.get(slotIdx);
|
||||
ItemStack stack = slot.getStack();
|
||||
if(stack != null) {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
slots[slotIdx] = stack;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
public ItemStack get(int index) {
|
||||
return slots[index];
|
||||
}
|
||||
|
||||
public boolean isEqual(List<Slot> craftingGrid) {
|
||||
for(int slotIdx = 0; slotIdx < 9; slotIdx++) {
|
||||
ItemStack a = slots[slotIdx];
|
||||
ItemStack b = craftingGrid.get(slotIdx).getStack();
|
||||
if((a != null || b != null) && !ItemUtil.areStacksEqual(a, b)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
for(int slotIdx = 0; slotIdx < 9; slotIdx++) {
|
||||
ItemStack itemStack = slots[slotIdx];
|
||||
if(itemStack != null) {
|
||||
NBTTagCompound itemStackNBT = new NBTTagCompound();
|
||||
itemStack.writeToNBT(itemStackNBT);
|
||||
nbtRoot.setTag(Integer.toString(slotIdx), itemStackNBT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean readFromNBT(NBTTagCompound nbtRoot) {
|
||||
boolean hasSlots = false;
|
||||
for(int slotIdx = 0; slotIdx < 9; slotIdx++) {
|
||||
NBTTagCompound itemStackNBT = (NBTTagCompound) nbtRoot.getTag(Integer.toString(slotIdx));
|
||||
if(itemStackNBT != null) {
|
||||
slots[slotIdx] = ItemStack.loadItemStackFromNBT(itemStackNBT);
|
||||
hasSlots = true;
|
||||
} else {
|
||||
slots[slotIdx] = null;
|
||||
}
|
||||
}
|
||||
updateResult = true;
|
||||
result = null;
|
||||
return hasSlots;
|
||||
}
|
||||
|
||||
public ItemStack getResult(TileInventoryPanel te) {
|
||||
if(updateResult) {
|
||||
findCraftingResult(te);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void findCraftingResult(TileInventoryPanel te) {
|
||||
InventoryCrafting tmp = new InventoryCrafting(new Container() {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer ep) {
|
||||
return false;
|
||||
}
|
||||
}, 3, 3);
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
tmp.setInventorySlotContents(i, slots[i]);
|
||||
}
|
||||
|
||||
result = CraftingManager.getInstance().findMatchingRecipe(tmp, te.getWorldObj());
|
||||
if(result != null) {
|
||||
result = result.copy();
|
||||
result.stackSize = 1;
|
||||
}
|
||||
updateResult = false;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import net.minecraft.inventory.Container;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
@@ -36,6 +37,8 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
public static final int SLOT_VIEW_FILTER = 10;
|
||||
public static final int SLOT_RETURN_START = 11;
|
||||
|
||||
public static final int MAX_STORED_CRAFTING_RECIPES = 6;
|
||||
|
||||
protected final SmartTank fuelTank;
|
||||
protected boolean tanksDirty;
|
||||
|
||||
@@ -44,15 +47,18 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
|
||||
private boolean active;
|
||||
|
||||
public Container eventHandler;
|
||||
public InventoryPanelContainer eventHandler;
|
||||
private IItemFilter itemFilter;
|
||||
|
||||
private int guiSortMode;
|
||||
private String guiFilterString = "";
|
||||
|
||||
private final ArrayList<StoredCraftingRecipe> storedCraftingRecipes;
|
||||
|
||||
public TileInventoryPanel() {
|
||||
super(new SlotDefinition(0, 8, 11, 20, 21, 20));
|
||||
this.fuelTank = new SmartTank(EnderIO.fluidNutrientDistillation, 2000);
|
||||
this.storedCraftingRecipes = new ArrayList<StoredCraftingRecipe>();
|
||||
}
|
||||
|
||||
public InventoryDatabaseServer getDatabaseServer() {
|
||||
@@ -222,12 +228,53 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
}
|
||||
}
|
||||
|
||||
public int getStoredCraftingRecipes() {
|
||||
return storedCraftingRecipes.size();
|
||||
}
|
||||
|
||||
public StoredCraftingRecipe getStoredCraftingRecipe(int index) {
|
||||
if(index < 0 || index >= storedCraftingRecipes.size()) {
|
||||
return null;
|
||||
}
|
||||
return storedCraftingRecipes.get(index);
|
||||
}
|
||||
|
||||
public void addStoredCraftingRecipe(StoredCraftingRecipe recipe) {
|
||||
if(worldObj != null && worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketStoredCraftingRecipe(PacketStoredCraftingRecipe.ACTION_ADD, 0, recipe));
|
||||
} else {
|
||||
storedCraftingRecipes.add(recipe);
|
||||
markDirty();
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeStoredCraftingRecipe(int index) {
|
||||
if(worldObj != null && worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketStoredCraftingRecipe(PacketStoredCraftingRecipe.ACTION_DELETE, index, null));
|
||||
} else if(index >= 0 && index < storedCraftingRecipes.size()) {
|
||||
storedCraftingRecipes.remove(index);
|
||||
markDirty();
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
fuelTank.writeCommon("fuelTank", nbtRoot);
|
||||
nbtRoot.setInteger("guiSortMode", guiSortMode);
|
||||
nbtRoot.setString("guiFilterString", guiFilterString);
|
||||
|
||||
if(!storedCraftingRecipes.isEmpty()) {
|
||||
NBTTagList recipesNBT = new NBTTagList();
|
||||
for(StoredCraftingRecipe recipe : storedCraftingRecipes) {
|
||||
NBTTagCompound recipeNBT = new NBTTagCompound();
|
||||
recipe.writeToNBT(recipeNBT);
|
||||
recipesNBT.appendTag(recipeNBT);
|
||||
}
|
||||
nbtRoot.setTag("craftingRecipes", recipesNBT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,6 +283,22 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
fuelTank.readCommon("fuelTank", nbtRoot);
|
||||
guiSortMode = nbtRoot.getInteger("guiSortMode");
|
||||
guiFilterString = nbtRoot.getString("guiFilterString");
|
||||
|
||||
storedCraftingRecipes.clear();
|
||||
NBTTagList recipesNBT = (NBTTagList) nbtRoot.getTag("craftingRecipes");
|
||||
if(recipesNBT != null) {
|
||||
for (int idx = 0; idx < recipesNBT.tagCount() && storedCraftingRecipes.size() < MAX_STORED_CRAFTING_RECIPES; idx++) {
|
||||
NBTTagCompound recipeNBT = recipesNBT.getCompoundTagAt(idx);
|
||||
StoredCraftingRecipe recipe = new StoredCraftingRecipe();
|
||||
if(recipe.readFromNBT(recipeNBT)) {
|
||||
storedCraftingRecipes.add(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(eventHandler != null) {
|
||||
eventHandler.checkCraftingRecipes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package crazypants.enderio.machine.invpanel.client;
|
||||
import crazypants.enderio.machine.invpanel.GuiInventoryPanel;
|
||||
import crazypants.enderio.machine.invpanel.InventoryPanelContainer;
|
||||
import crazypants.enderio.machine.invpanel.PacketFetchItem;
|
||||
import crazypants.enderio.machine.invpanel.StoredCraftingRecipe;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.util.ItemUtil;
|
||||
import java.util.ArrayList;
|
||||
@@ -11,14 +12,25 @@ import java.util.List;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class CraftingHelper implements ICraftingHelper {
|
||||
public class CraftingHelper {
|
||||
final ItemStack[][] ingredients;
|
||||
|
||||
public CraftingHelper(ItemStack[][] ingredients) {
|
||||
protected CraftingHelper(ItemStack[][] ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
public static ICraftingHelper createFromSlots(List<Slot> slots) {
|
||||
public static CraftingHelper createFromRecipe(StoredCraftingRecipe recipe) {
|
||||
ItemStack[][] ingredients = new ItemStack[9][];
|
||||
for (int idx = 0; idx < 9; idx++) {
|
||||
ItemStack stack = recipe.get(idx);
|
||||
if(stack != null) {
|
||||
ingredients[idx] = new ItemStack[] { stack };
|
||||
}
|
||||
}
|
||||
return new CraftingHelperNEI(ingredients);
|
||||
}
|
||||
|
||||
public static CraftingHelper createFromSlots(List<Slot> slots) {
|
||||
if (slots.size() != 9) {
|
||||
return null;
|
||||
}
|
||||
@@ -35,16 +47,17 @@ public class CraftingHelper implements ICraftingHelper {
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
return new CraftingHelper(ingredients);
|
||||
return new CraftingHelperNEI(ingredients);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install() {
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refill(GuiInventoryPanel gui, int amount) {
|
||||
InventoryPanelContainer container = gui.getContainer();
|
||||
InventoryDatabaseClient db = gui.getDatabase();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.DefaultOverlayRenderer;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import crazypants.enderio.machine.invpanel.InventoryPanelContainer;
|
||||
|
||||
public class CraftingHelperNEI extends CraftingHelper {
|
||||
|
||||
public Object overlayRenderer;
|
||||
|
||||
public CraftingHelperNEI(ItemStack[][] ingredients) {
|
||||
super(ingredients);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public void install() {
|
||||
super.install();
|
||||
if(overlayRenderer != null) {
|
||||
LayoutManager.overlayRenderer = (IRecipeOverlayRenderer) overlayRenderer;
|
||||
} else {
|
||||
List<PositionedStack> list = new ArrayList<PositionedStack>();
|
||||
for(int y = 0; y < 3; y++) {
|
||||
for(int x = 0; x < 3; x++) {
|
||||
ItemStack[] ingredient = ingredients[y*3+x];
|
||||
if(ingredient != null) {
|
||||
list.add(new PositionedStack(ingredient,
|
||||
InventoryPanelNEIOverlayHandler.NEI_OFFSET_X + x*18,
|
||||
InventoryPanelNEIOverlayHandler.NEI_OFFSET_Y + y*18));
|
||||
}
|
||||
}
|
||||
}
|
||||
LayoutManager.overlayRenderer = new DefaultOverlayRenderer(list, InventoryPanelNEIOverlayHandler.positioner);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public void remove() {
|
||||
super.remove();
|
||||
LayoutManager.overlayRenderer = null;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import crazypants.enderio.machine.invpanel.GuiInventoryPanel;
|
||||
|
||||
public interface ICraftingHelper {
|
||||
|
||||
void remove();
|
||||
|
||||
void refill(GuiInventoryPanel gui, int amount);
|
||||
|
||||
}
|
||||
+5
-13
@@ -1,6 +1,5 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.OffsetPositioner;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.DefaultOverlayRenderer;
|
||||
@@ -16,34 +15,27 @@ 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;
|
||||
public static final int NEI_OFFSET_X = 25;
|
||||
public 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);
|
||||
public static 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;
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
|
||||
LayoutManager.overlayRenderer = new DefaultOverlayRenderer(ingredients, positioner);
|
||||
|
||||
if(shift) {
|
||||
shift = guiInvPanel.getContainer().clearCraftingGrid();
|
||||
}
|
||||
|
||||
ItemStack[][] slots = mapSlots(ingredients, guiInvPanel.getContainer());
|
||||
if(slots != null) {
|
||||
CraftingHelper helper = new CraftingHelper(slots) {
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
LayoutManager.overlayRenderer = null;
|
||||
}
|
||||
};
|
||||
CraftingHelperNEI helper = new CraftingHelperNEI(slots);
|
||||
helper.overlayRenderer = new DefaultOverlayRenderer(ingredients, positioner);
|
||||
guiInvPanel.setCraftingHelper(helper);
|
||||
if(shift) {
|
||||
helper.refill(guiInvPanel, 64);
|
||||
|
||||
@@ -54,7 +54,6 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
fixupGuiPosition();
|
||||
for (IGuiOverlay overlay : overlays) {
|
||||
overlay.init(this);
|
||||
}
|
||||
@@ -63,9 +62,6 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
}
|
||||
|
||||
protected void fixupGuiPosition() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int key) {
|
||||
GuiTextField focused = null;
|
||||
|
||||
Reference in new issue
Block a user