diff --git a/src/main/java/forestry/core/network/PacketId.java b/src/main/java/forestry/core/network/PacketId.java index c11781d17..f7e9657f3 100644 --- a/src/main/java/forestry/core/network/PacketId.java +++ b/src/main/java/forestry/core/network/PacketId.java @@ -20,6 +20,7 @@ public enum PacketId { FX_SIGNAL, WORKTABLE_MEMORY_UPDATE, + WORKTABLE_NEI_SELECT, HABITAT_BIOME_POINTER, CANDLE, diff --git a/src/main/java/forestry/core/recipes/nei/CustomOverlayHandler.java b/src/main/java/forestry/core/recipes/nei/CustomOverlayHandler.java new file mode 100644 index 000000000..f752e3781 --- /dev/null +++ b/src/main/java/forestry/core/recipes/nei/CustomOverlayHandler.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.recipes.nei; + +import java.util.List; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +import forestry.core.network.PacketId; +import forestry.core.network.PacketNBT; +import forestry.core.proxy.Proxies; + +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; + +/** + * @author bdew + */ +public class CustomOverlayHandler implements IOverlayHandler { + private final int xOffs; + private final int yOffs; + private final boolean forceShift; + + public CustomOverlayHandler(int xOffs, int yOffs, boolean forceShift) { + this.xOffs = xOffs; + this.yOffs = yOffs; + this.forceShift = forceShift; + } + + @Override + public void overlayRecipe(GuiContainer cont, IRecipeHandler recipe, int recipeIndex, boolean shift) { + List ingr = recipe.getIngredientStacks(recipeIndex); + + if (shift || forceShift) { + NBTTagList stacksnbt = new NBTTagList(); + + for (PositionedStack pstack : ingr) { + if (pstack != null) { + // This is back-asswards but i don't see a better way :( + int x = (pstack.relx - 25) / 18; + int y = (pstack.rely - 6) / 18; + + ItemStack stack = pstack.item; + NBTTagCompound stacknbt = stack.writeToNBT(new NBTTagCompound()); + stacknbt.setInteger("slot", y * 3 + x); + stacksnbt.appendTag(stacknbt); + } + + ItemStack stack = recipe.getResultStack(recipeIndex).items[0]; + NBTTagCompound stacknbt = stack.writeToNBT(new NBTTagCompound()); + stacknbt.setInteger("slot", 9); + stacksnbt.appendTag(stacknbt); + } + + NBTTagCompound data = new NBTTagCompound(); + data.setTag("stacks", stacksnbt); + + Proxies.net.sendToServer(new PacketNBT(PacketId.WORKTABLE_NEI_SELECT, data)); + } else { + IStackPositioner positioner = new OffsetPositioner(xOffs, yOffs); + LayoutManager.overlayRenderer = new DefaultOverlayRenderer(ingr, positioner); + } + } +} diff --git a/src/main/java/forestry/core/recipes/nei/ItemFilterForestry.java b/src/main/java/forestry/core/recipes/nei/ItemFilterForestry.java new file mode 100644 index 000000000..123eb0096 --- /dev/null +++ b/src/main/java/forestry/core/recipes/nei/ItemFilterForestry.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.recipes.nei; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +import forestry.core.config.Constants; + +import codechicken.nei.api.ItemFilter; + +/** + * @author bdew + */ +public class ItemFilterForestry implements ItemFilter { + private final boolean items; + + public ItemFilterForestry(Boolean items) { + this.items = items; + } + + @Override + public boolean matches(ItemStack item) { + if (item == null || item.getItem() == null) { + return false; + } + + if (item.getItem() instanceof ItemBlock && items) { + return false; + } + + if (!(item.getItem() instanceof ItemBlock) && !items) { + return false; + } + + String itemName = Item.itemRegistry.getNameForObject(item.getItem()); + if (itemName == null) { + return false; + } + + String[] s = itemName.split(":"); + if (s.length <= 1) { + return false; + } + + return s[0].equals(Constants.MOD); + } +} diff --git a/src/main/java/forestry/core/recipes/nei/ItemFilterGenetic.java b/src/main/java/forestry/core/recipes/nei/ItemFilterGenetic.java new file mode 100644 index 000000000..0d3610be2 --- /dev/null +++ b/src/main/java/forestry/core/recipes/nei/ItemFilterGenetic.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.recipes.nei; + +import net.minecraft.item.ItemStack; + +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; + +import codechicken.nei.api.ItemFilter; + +/** + * @author bdew + */ +public class ItemFilterGenetic implements ItemFilter { + private final ISpeciesRoot root; + private final int type; + private final boolean analyzedOnly; + + public ItemFilterGenetic(ISpeciesRoot root, int type, boolean analyzedOnly) { + this.root = root; + this.type = type; + this.analyzedOnly = analyzedOnly; + } + + private boolean isMember(ItemStack item) { + if (type >= 0) { + return root.isMember(item, type); + } else { + return root.isMember(item); + } + } + + @Override + public boolean matches(ItemStack item) { + if (analyzedOnly) { + if (!isMember(item)) { + return false; + } + IIndividual individual = root.getMember(item); + return individual.isAnalyzed() || !individual.isSecret(); + } else { + return isMember(item); + } + } +} diff --git a/src/main/java/forestry/core/recipes/nei/ItemFilterOther.java b/src/main/java/forestry/core/recipes/nei/ItemFilterOther.java new file mode 100644 index 000000000..6e93b261f --- /dev/null +++ b/src/main/java/forestry/core/recipes/nei/ItemFilterOther.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.recipes.nei; + +import net.minecraft.item.ItemStack; + +import forestry.api.genetics.AlleleManager; + +/** + * @author bdew + */ +public class ItemFilterOther extends ItemFilterForestry { + + public ItemFilterOther(Boolean items) { + super(items); + } + + @Override + public boolean matches(ItemStack item) { + return super.matches(item) && !AlleleManager.alleleRegistry.isIndividual(item); + } +} diff --git a/src/main/java/forestry/core/recipes/nei/NEIIntegrationConfig.java b/src/main/java/forestry/core/recipes/nei/NEIIntegrationConfig.java index dbcbdd1c5..c670810fc 100644 --- a/src/main/java/forestry/core/recipes/nei/NEIIntegrationConfig.java +++ b/src/main/java/forestry/core/recipes/nei/NEIIntegrationConfig.java @@ -10,7 +10,15 @@ ******************************************************************************/ package forestry.core.recipes.nei; +import net.minecraftforge.oredict.OreDictionary; + +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.EnumBeeType; +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.TreeManager; +import forestry.api.lepidopterology.EnumFlutterType; import forestry.core.utils.Log; +import forestry.factory.gui.GuiWorktable; import forestry.factory.recipes.nei.NEIHandlerBottler; import forestry.factory.recipes.nei.NEIHandlerCarpenter; import forestry.factory.recipes.nei.NEIHandlerCentrifuge; @@ -19,6 +27,7 @@ import forestry.factory.recipes.nei.NEIHandlerFermenter; import forestry.factory.recipes.nei.NEIHandlerMoistener; import forestry.factory.recipes.nei.NEIHandlerSqueezer; import forestry.factory.recipes.nei.NEIHandlerStill; +import forestry.plugins.PluginLepidopterology; import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; @@ -39,6 +48,24 @@ public class NEIIntegrationConfig implements IConfigureNEI { registerHandler(new NEIHandlerMoistener()); registerHandler(new NEIHandlerSqueezer()); registerHandler(new NEIHandlerStill()); + + CustomOverlayHandler handler = new CustomOverlayHandler(-14, 14, true); + API.registerGuiOverlayHandler(GuiWorktable.class, handler, "crafting"); + + API.addSubset("Forestry.Bees.Princesses", new ItemFilterGenetic(BeeManager.beeRoot, EnumBeeType.PRINCESS.ordinal(), true)); + API.addSubset("Forestry.Bees.Drones", new ItemFilterGenetic(BeeManager.beeRoot, EnumBeeType.DRONE.ordinal(), true)); + API.addSubset("Forestry.Bees.Larvae", new ItemFilterGenetic(BeeManager.beeRoot, EnumBeeType.LARVAE.ordinal(), true)); + + API.addSubset("Forestry.Trees.Saplings", new ItemFilterGenetic(TreeManager.treeRoot, EnumGermlingType.SAPLING.ordinal(), true)); + API.addSubset("Forestry.Trees.Pollen", new ItemFilterGenetic(TreeManager.treeRoot, EnumGermlingType.POLLEN.ordinal(), true)); + + API.addSubset("Forestry.Butterflies.Butterflies", new ItemFilterGenetic(PluginLepidopterology.butterflyInterface, EnumFlutterType.BUTTERFLY.ordinal(), true)); + API.addSubset("Forestry.Butterflies.Caterpillars", new ItemFilterGenetic(PluginLepidopterology.butterflyInterface, EnumFlutterType.CATERPILLAR.ordinal(), true)); + API.addSubset("Forestry.Butterflies.Serum", new ItemFilterGenetic(PluginLepidopterology.butterflyInterface, EnumFlutterType.SERUM.ordinal(), true)); + + API.addSubset("Forestry.Bees.Combs", OreDictionary.getOres("beeComb")); + API.addSubset("Forestry.Blocks", new ItemFilterOther(false)); + API.addSubset("Forestry.Items", new ItemFilterOther(true)); } protected static void registerHandler(IRecipeHandlerBase handler) { @@ -54,7 +81,7 @@ public class NEIIntegrationConfig implements IConfigureNEI { @Override public String getVersion() { - return "1.0.0"; + return "1.1.0"; } } diff --git a/src/main/java/forestry/core/recipes/nei/SetRecipeCommandHandler.java b/src/main/java/forestry/core/recipes/nei/SetRecipeCommandHandler.java new file mode 100644 index 000000000..5003ed96f --- /dev/null +++ b/src/main/java/forestry/core/recipes/nei/SetRecipeCommandHandler.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.recipes.nei; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +/** + * @author bdew + */ +public class SetRecipeCommandHandler { + private final Class containerClass; + private final Class slotClass; + + public SetRecipeCommandHandler(Class containerClass, Class slotClass) { + this.containerClass = containerClass; + this.slotClass = slotClass; + } + + public void handle(NBTTagCompound data, EntityPlayerMP player) { + NBTTagList stacks = data.getTagList("stacks", 10); + Container cont = player.openContainer; + if (!containerClass.isInstance(cont)) { + return; + } + + Map stmap = new HashMap(); + for (int i = 0; i < stacks.tagCount(); i++) { + NBTTagCompound itemdata = stacks.getCompoundTagAt(i); + stmap.put(itemdata.getInteger("slot"), ItemStack.loadItemStackFromNBT(itemdata)); + } + for (Object slotobj : cont.inventorySlots) { + if (!slotClass.isInstance(slotobj)) { + continue; + } + + Slot slot = (Slot) slotobj; + if (stmap.containsKey(slot.getSlotIndex())) { + slot.putStack(stmap.get(slot.getSlotIndex())); + } else { + slot.putStack(null); + } + } + } +} diff --git a/src/main/java/forestry/factory/network/PacketHandlerFactory.java b/src/main/java/forestry/factory/network/PacketHandlerFactory.java index 47e04fb0d..d33f8031e 100644 --- a/src/main/java/forestry/factory/network/PacketHandlerFactory.java +++ b/src/main/java/forestry/factory/network/PacketHandlerFactory.java @@ -13,13 +13,20 @@ package forestry.factory.network; import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import forestry.core.gui.slots.SlotCraftMatrix; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.IPacketHandler; import forestry.core.network.PacketId; +import forestry.core.network.PacketNBT; +import forestry.core.recipes.nei.SetRecipeCommandHandler; +import forestry.factory.gui.ContainerWorktable; public class PacketHandlerFactory implements IPacketHandler { + private static final SetRecipeCommandHandler worktableNEISelectHandler = new SetRecipeCommandHandler(ContainerWorktable.class, SlotCraftMatrix.class); + @Override public boolean onPacketData(PacketId packetID, DataInputStreamForestry data, EntityPlayer player) throws IOException { @@ -28,6 +35,11 @@ public class PacketHandlerFactory implements IPacketHandler { PacketWorktableMemoryUpdate.onPacketData(data); return true; } + case WORKTABLE_NEI_SELECT: { + PacketNBT packet = new PacketNBT(data); + worktableNEISelectHandler.handle(packet.getTagCompound(), (EntityPlayerMP) player); + return true; + } } return false;