diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index d2e2aabe9..f103e8157 100644 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -17,29 +17,39 @@ import java.util.Map; import net.minecraft.block.Block; import net.minecraft.item.Item; +import net.minecraftforge.common.MinecraftForge; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry.Type; -import forestry.api.fuels.FuelManager; -import forestry.core.ForestryCore; +import forestry.api.core.ForestryAPI; +import forestry.core.EventHandlerCore; +import forestry.core.GuiHandler; +import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; +import forestry.core.config.GameMode; import forestry.core.config.Version; +import forestry.core.errors.EnumErrorCode; +import forestry.core.errors.ErrorStateRegistry; +import forestry.core.multiblock.MultiblockEventHandler; import forestry.core.network.PacketHandler; +import forestry.core.proxy.Proxies; import forestry.core.utils.Log; import forestry.core.utils.StringUtil; -import forestry.core.utils.datastructures.FluidMap; -import forestry.core.utils.datastructures.ItemStackMap; +import forestry.core.worldgen.WorldGenerator; +import forestry.plugins.PluginManager; /** * Forestry Minecraft Mod @@ -81,56 +91,67 @@ public class Forestry { } public Forestry() { - FuelManager.fermenterFuel = new ItemStackMap<>(); - FuelManager.moistenerResource = new ItemStackMap<>(); - FuelManager.rainSubstrate = new ItemStackMap<>(); - FuelManager.bronzeEngineFuel = new FluidMap<>(); - FuelManager.copperEngineFuel = new ItemStackMap<>(); - FuelManager.generatorFuel = new FluidMap<>(); + ForestryAPI.instance = this; + ForestryAPI.forestryConstants = new Constants(); + ForestryAPI.errorStateRegistry = new ErrorStateRegistry(); + EnumErrorCode.init(); } - @SidedProxy(clientSide = "forestry.core.ForestryClient", serverSide = "forestry.core.ForestryCore") - public static ForestryCore core = new ForestryCore(); public static PacketHandler packetHandler; @EventHandler public void preInit(FMLPreInitializationEvent event) { packetHandler = new PacketHandler(); - - configFolder = new File(event.getModConfigurationDirectory(), "forestry"); - core.preInit(event.getSourceFile(), this); + // Register event handler + MinecraftForge.EVENT_BUS.register(new EventHandlerCore()); + MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler()); + + configFolder = new File(event.getModConfigurationDirectory(), "forestry"); + Config.load(); + + PluginManager.runSetup(); + + ForestryAPI.activeMode = new GameMode(Config.gameMode); + + PluginManager.runPreInit(); } @EventHandler public void init(FMLInitializationEvent event) { - core.init(this); + // Register gui handler + NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); + + PluginManager.runInit(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { - core.postInit(); + PluginManager.runPostInit(); + + // Register world generator + WorldGenerator worldGenerator = new WorldGenerator(); + GameRegistry.registerWorldGenerator(worldGenerator, 0); + + // Register tick handlers + Proxies.common.registerTickHandlers(worldGenerator); + + // Handle IMC messages. + PluginManager.processIMCMessages(FMLInterModComms.fetchRuntimeMessages(ForestryAPI.instance)); } @EventHandler public void serverStarting(FMLServerStartingEvent event) { - core.serverStarting(event.getServer()); + PluginManager.serverStarting(event.getServer()); } public File getConfigFolder() { return configFolder; } - /*@EventHandler - public void fingerprintWarning(FMLFingerprintViolationEvent event) { - Log.info("Fingerprint of the mod jar is invalid. The jar file was tampered with."); - FMLInterModComms.sendMessage("Railcraft", "securityViolation", "Fingerprint of jar file did not match."); - FMLInterModComms.sendMessage("Thaumcraft", "securityViolation", "Fingerprint of jar file did not match."); - FMLInterModComms.sendMessage("IC2", "securityViolation", "Fingerprint of jar file did not match."); - }*/ @EventHandler public void processIMCMessages(IMCEvent event) { - core.processIMCMessages(event.getMessages()); + PluginManager.processIMCMessages(event.getMessages()); } @EventHandler diff --git a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java index 2d16314fc..4647445f6 100755 --- a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java @@ -35,9 +35,9 @@ import forestry.apiculture.gui.GuiBeeHousing; import forestry.apiculture.gui.GuiBeealyzer; import forestry.apiculture.gui.GuiHabitatLocator; import forestry.apiculture.gui.GuiImprinter; -import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory; -import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; -import forestry.apiculture.items.ItemImprinter.ImprinterInventory; +import forestry.apiculture.inventory.ItemInventoryBeealyzer; +import forestry.apiculture.inventory.ItemInventoryHabitatLocator; +import forestry.apiculture.inventory.ItemInventoryImprinter; import forestry.apiculture.multiblock.TileAlvearyHygroregulator; import forestry.apiculture.multiblock.TileAlvearyPlain; import forestry.apiculture.multiblock.TileAlvearySieve; @@ -87,7 +87,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return null; } - return new GuiBeealyzer(player, new BeealyzerInventory(player, equipped)); + return new GuiBeealyzer(player, new ItemInventoryBeealyzer(player, equipped)); case BeehouseGUI: { TileBeehouse tileBeehouse = TileUtil.getTile(world, x, y, z, TileBeehouse.class); @@ -112,7 +112,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return null; } - return new GuiHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); + return new GuiHabitatLocator(player, new ItemInventoryHabitatLocator(player, equipped)); case HygroregulatorGUI: return new GuiAlvearyHygroregulator(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearyHygroregulator.class)); @@ -122,7 +122,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { if (equipped == null) { return null; } - return new GuiImprinter(player.inventory, new ImprinterInventory(player, equipped)); + return new GuiImprinter(player.inventory, new ItemInventoryImprinter(player, equipped)); default: return null; @@ -166,7 +166,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { } synchApiaristTracker(world, player); - return new ContainerAlyzer(new BeealyzerInventory(player, equipped), player); + return new ContainerAlyzer(new ItemInventoryBeealyzer(player, equipped), player); case BeehouseGUI: synchApiaristTracker(world, player); @@ -188,7 +188,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return null; } - return new ContainerHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); + return new ContainerHabitatLocator(player, new ItemInventoryHabitatLocator(player, equipped)); case HygroregulatorGUI: return new ContainerAlvearyHygroregulator(player.inventory, TileUtil.getTile(world, x, y, z, TileAlvearyHygroregulator.class)); @@ -199,7 +199,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { if (equipped == null) { return null; } - return new ContainerImprinter(player.inventory, new ImprinterInventory(player, equipped)); + return new ContainerImprinter(player.inventory, new ItemInventoryImprinter(player, equipped)); default: return null; diff --git a/src/main/java/forestry/apiculture/BeeHousingInventory.java b/src/main/java/forestry/apiculture/InventoryBeeHousing.java similarity index 92% rename from src/main/java/forestry/apiculture/BeeHousingInventory.java rename to src/main/java/forestry/apiculture/InventoryBeeHousing.java index 0ffe54fde..6eae1f8e8 100644 --- a/src/main/java/forestry/apiculture/BeeHousingInventory.java +++ b/src/main/java/forestry/apiculture/InventoryBeeHousing.java @@ -20,13 +20,13 @@ import forestry.core.inventory.InventoryAdapterRestricted; import forestry.core.utils.InventoryUtil; import forestry.core.utils.SlotUtil; -public class BeeHousingInventory extends InventoryAdapterRestricted implements IBeeHousingInventory { +public class InventoryBeeHousing extends InventoryAdapterRestricted implements IBeeHousingInventory { public static final int SLOT_QUEEN = 0; public static final int SLOT_DRONE = 1; public static final int SLOT_PRODUCT_1 = 2; public static final int SLOT_PRODUCT_COUNT = 7; - public BeeHousingInventory(int size, String name, IAccessHandler accessHandler) { + public InventoryBeeHousing(int size, String name, IAccessHandler accessHandler) { super(size, name, accessHandler); } diff --git a/src/main/java/forestry/apiculture/blocks/BlockCandle.java b/src/main/java/forestry/apiculture/blocks/BlockCandle.java index 2cb1f625e..39291afe2 100644 --- a/src/main/java/forestry/apiculture/blocks/BlockCandle.java +++ b/src/main/java/forestry/apiculture/blocks/BlockCandle.java @@ -44,7 +44,7 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.api.core.Tabs; import forestry.apiculture.tiles.TileCandle; -import forestry.core.ForestryClient; +import forestry.core.proxy.ProxyRenderClient; import forestry.core.render.TextureManager; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.StringUtil; @@ -110,7 +110,7 @@ public class BlockCandle extends BlockTorch { @Override public int getRenderType() { - return ForestryClient.candleRenderId; + return ProxyRenderClient.getCandleRenderId(); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java index 7fb1d7410..e98f232b4 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java @@ -13,6 +13,7 @@ package forestry.apiculture.entities; import com.google.common.collect.ImmutableList; import java.io.IOException; +import java.util.List; import java.util.Random; import net.minecraft.block.Block; @@ -77,31 +78,24 @@ public class EntityMinecartBeehouse extends EntityMinecartContainer implements I private static final Iterable beeModifiers = ImmutableList.of(new TileBeehouse.BeehouseBeeModifier()); private static final Iterable beeListeners = ImmutableList.of(new DefaultBeeListener()); - private final IBeekeepingLogic beeLogic; - private final IErrorLogic errorLogic; - private final BeeCartInventory beeInventory; - private final AccessHandler accessHandler; + private final IBeekeepingLogic beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); + private final IErrorLogic errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic(); + private final BeeCartInventory beeInventory = new BeeCartInventory(this); + private final AccessHandler accessHandler = new AccessHandler(this); // CLIENT private int breedingProgressPercent = 0; private boolean needsActiveUpdate = true; + @SuppressWarnings("unused") public EntityMinecartBeehouse(World world) { super(world); setHasDisplayTile(true); - this.beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); - this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic(); - this.beeInventory = new BeeCartInventory(this); - this.accessHandler = new AccessHandler(this); } public EntityMinecartBeehouse(World world, double posX, double posY, double posZ) { super(world, posX, posY, posZ); setHasDisplayTile(true); - this.beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); - this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic(); - this.beeInventory = new BeeCartInventory(this); - this.accessHandler = new AccessHandler(this); } @Override @@ -348,8 +342,8 @@ public class EntityMinecartBeehouse extends EntityMinecartContainer implements I } @Override - public String[] getHints() { - return Config.hints.get("apiary"); + public List getHints() { + return Config.hints.get("bee.house"); } private static class BeeCartInventory implements IBeeHousingInventory { diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java index 8687f0874..4292cc6dc 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java @@ -12,6 +12,7 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; +import forestry.apiculture.inventory.InventoryHygroregulator; import forestry.apiculture.multiblock.TileAlvearyHygroregulator; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; @@ -21,7 +22,7 @@ public class ContainerAlvearyHygroregulator extends ContainerLiquidTanks { public ContainerAlvearySieve(InventoryPlayer player, TileAlvearySieve tile) { super(tile, player, 8, 87); - addSlotToContainer(new SlotOutput(tile, 0, 94, 52).setCrafter(tile)); - addSlotToContainer(new SlotOutput(tile, 1, 115, 39).setCrafter(tile)); - addSlotToContainer(new SlotOutput(tile, 2, 73, 39).setCrafter(tile)); - addSlotToContainer(new SlotOutput(tile, 3, 94, 26).setCrafter(tile)); + ICrafter crafter = tile.getCrafter(); - addSlotToContainer(new SlotFiltered(tile, TileAlvearySieve.AlvearySieveInventory.SLOT_SIEVE, 43, 39).setCrafter(tile)); + addSlotToContainer(new SlotOutput(tile, 0, 94, 52).setCrafter(crafter)); + addSlotToContainer(new SlotOutput(tile, 1, 115, 39).setCrafter(crafter)); + addSlotToContainer(new SlotOutput(tile, 2, 73, 39).setCrafter(crafter)); + addSlotToContainer(new SlotOutput(tile, 3, 94, 26).setCrafter(crafter)); + + addSlotToContainer(new SlotFiltered(tile, InventoryAlvearySieve.SLOT_SIEVE, 43, 39).setCrafter(crafter)); } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java b/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java index d17f8936f..a630aee76 100644 --- a/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java +++ b/src/main/java/forestry/apiculture/gui/ContainerBeeHelper.java @@ -12,8 +12,8 @@ package forestry.apiculture.gui; import net.minecraft.inventory.IInventory; -import forestry.apiculture.BeeHousingInventory; -import forestry.apiculture.tiles.TileApiary; +import forestry.apiculture.InventoryBeeHousing; +import forestry.apiculture.inventory.InventoryApiary; import forestry.core.gui.ContainerForestry; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; @@ -22,21 +22,21 @@ import forestry.core.tiles.IFilterSlotDelegate; public abstract class ContainerBeeHelper { public static void addSlots(ContainerForestry container, T inventory, boolean hasFrames) { // Queen/Princess - container.addSlotToContainer(new SlotFiltered(inventory, BeeHousingInventory.SLOT_QUEEN, 29, 39)); + container.addSlotToContainer(new SlotFiltered(inventory, InventoryBeeHousing.SLOT_QUEEN, 29, 39)); // Drone - container.addSlotToContainer(new SlotFiltered(inventory, BeeHousingInventory.SLOT_DRONE, 29, 65)); + container.addSlotToContainer(new SlotFiltered(inventory, InventoryBeeHousing.SLOT_DRONE, 29, 65)); // Frames if (hasFrames) { - int slotFrames = TileApiary.ApiaryInventory.SLOT_FRAMES_1; + int slotFrames = InventoryApiary.SLOT_FRAMES_1; container.addSlotToContainer(new SlotFiltered(inventory, slotFrames++, 66, 23)); container.addSlotToContainer(new SlotFiltered(inventory, slotFrames++, 66, 52)); container.addSlotToContainer(new SlotFiltered(inventory, slotFrames, 66, 81)); } // Product Inventory - int slotProduct = BeeHousingInventory.SLOT_PRODUCT_1; + int slotProduct = InventoryBeeHousing.SLOT_PRODUCT_1; container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 116, 52)); container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 137, 39)); container.addSlotToContainer(new SlotOutput(inventory, slotProduct++, 137, 65)); diff --git a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java index 30279ae5b..a5a57de0a 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java @@ -12,14 +12,14 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.EntityPlayer; -import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; +import forestry.apiculture.inventory.ItemInventoryHabitatLocator; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -public class ContainerHabitatLocator extends ContainerItemInventory { +public class ContainerHabitatLocator extends ContainerItemInventory { - public ContainerHabitatLocator(EntityPlayer player, HabitatLocatorInventory inventory) { + public ContainerHabitatLocator(EntityPlayer player, ItemInventoryHabitatLocator inventory) { super(inventory, player.inventory, 8, 102); // Energy diff --git a/src/main/java/forestry/apiculture/gui/ContainerImprinter.java b/src/main/java/forestry/apiculture/gui/ContainerImprinter.java index d1cc81281..0065d001f 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerImprinter.java +++ b/src/main/java/forestry/apiculture/gui/ContainerImprinter.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import forestry.apiculture.items.ItemImprinter.ImprinterInventory; +import forestry.apiculture.inventory.ItemInventoryImprinter; import forestry.apiculture.network.PacketImprintSelectionResponse; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.IGuiSelectable; @@ -22,11 +21,10 @@ import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketGuiSelectRequest; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryUtil; -public class ContainerImprinter extends ContainerItemInventory implements IGuiSelectable { +public class ContainerImprinter extends ContainerItemInventory implements IGuiSelectable { - public ContainerImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) { + public ContainerImprinter(InventoryPlayer inventoryplayer, ItemInventoryImprinter inventory) { super(inventory, inventoryplayer, 8, 103); // Input @@ -35,15 +33,6 @@ public class ContainerImprinter extends ContainerItemInventory beeList = new ArrayList<>(); ((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false); @@ -57,8 +55,8 @@ public class GuiBeealyzer extends GuiAlyzer { IBee bee = null; EnumBeeType beeType = EnumBeeType.DRONE; - for (int k = BeealyzerInventory.SLOT_SPECIMEN; k <= BeealyzerInventory.SLOT_ANALYZE_5; k++) { - if (k == BeealyzerInventory.SLOT_ENERGY) { + for (int k = ItemInventoryBeealyzer.SLOT_SPECIMEN; k <= ItemInventoryBeealyzer.SLOT_ANALYZE_5; k++) { + if (k == ItemInventoryBeealyzer.SLOT_ENERGY) { continue; } diff --git a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java index b8b82301f..53ad4d5b3 100755 --- a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java @@ -26,7 +26,7 @@ import net.minecraftforge.common.BiomeDictionary; import org.lwjgl.opengl.GL11; -import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; +import forestry.apiculture.inventory.ItemInventoryHabitatLocator; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; import forestry.core.gui.widgets.Widget; @@ -34,7 +34,7 @@ import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.render.TextureManager; -public class GuiHabitatLocator extends GuiForestry { +public class GuiHabitatLocator extends GuiForestry { private final HabitatSlot[] habitatSlots = new HabitatSlot[]{ new HabitatSlot(0, "Ocean"), // ocean, beach @@ -54,7 +54,7 @@ public class GuiHabitatLocator extends GuiForestry { +public class GuiImprinter extends GuiForestry { private int startX; private int startY; private final Map iconStacks = new HashMap<>(); - public GuiImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) { + public GuiImprinter(InventoryPlayer inventoryplayer, ItemInventoryImprinter inventory) { super(Constants.TEXTURE_PATH_GUI + "/imprinter.png", new ContainerImprinter(inventoryplayer, inventory), inventory); xSize = 176; diff --git a/src/main/java/forestry/apiculture/inventory/InventoryAlvearySieve.java b/src/main/java/forestry/apiculture/inventory/InventoryAlvearySieve.java new file mode 100644 index 000000000..e8d9ae229 --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/InventoryAlvearySieve.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import forestry.apiculture.multiblock.TileAlvearySieve; +import forestry.core.config.ForestryItem; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.tiles.ICrafter; +import forestry.core.utils.ItemStackUtil; + +public class InventoryAlvearySieve extends InventoryAdapterTile implements ICrafter { + public static final int SLOT_POLLEN_1 = 0; + public static final int SLOTS_POLLEN_COUNT = 4; + public static final int SLOT_SIEVE = 4; + + public InventoryAlvearySieve(TileAlvearySieve alvearySieve) { + super(alvearySieve, 5, "Items", 1); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return ItemStackUtil.isIdenticalItem(ForestryItem.craftingMaterial.getItemStack(1, 3), itemStack); + } + + public boolean canStorePollen() { + if (getStackInSlot(SLOT_SIEVE) == null) { + return false; + } + + for (int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { + if (getStackInSlot(i) == null) { + return true; + } + } + + return false; + } + + public void storePollenStack(ItemStack itemstack) { + for (int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { + if (getStackInSlot(i) == null) { + setInventorySlotContents(i, itemstack); + return; + } + } + } + + /* ICrafter */ + @Override + public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { + if (slotIndex == SLOT_SIEVE) { + for (int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { + setInventorySlotContents(i, null); + } + return getStackInSlot(SLOT_SIEVE); + } else { + setInventorySlotContents(SLOT_SIEVE, null); + return getStackInSlot(slotIndex); + } + } +} diff --git a/src/main/java/forestry/apiculture/inventory/InventoryApiary.java b/src/main/java/forestry/apiculture/inventory/InventoryApiary.java new file mode 100644 index 000000000..ef82a2ab8 --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/InventoryApiary.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import java.util.ArrayList; +import java.util.Collection; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import forestry.api.apiculture.IHiveFrame; +import forestry.apiculture.tiles.TileApiary; +import forestry.core.inventory.wrappers.InventoryMapper; +import forestry.core.utils.SlotUtil; + +public class InventoryApiary extends InventoryTileBeeHousing { + public static final int SLOT_FRAMES_1 = 9; + public static final int SLOT_FRAMES_COUNT = 3; + + public InventoryApiary(TileApiary tile) { + super(tile, 12, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (SlotUtil.isSlotInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) { + return (itemStack.getItem() instanceof IHiveFrame) && (getStackInSlot(slotIndex) == null); + } + + return super.canSlotAccept(slotIndex, itemStack); + } + + // override for pipe automation + @Override + public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { + if (SlotUtil.isSlotInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) { + return false; + } + return super.isItemValidForSlot(slotIndex, itemStack); + } + + public IInventory getFrameInventory() { + return new InventoryMapper(this, SLOT_FRAMES_1, SLOT_FRAMES_COUNT); + } + + public Collection getFrames() { + Collection hiveFrames = new ArrayList<>(SLOT_FRAMES_COUNT); + + for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { + ItemStack stackInSlot = getStackInSlot(i); + if (stackInSlot == null) { + continue; + } + + Item itemInSlot = stackInSlot.getItem(); + if (itemInSlot instanceof IHiveFrame) { + hiveFrames.add((IHiveFrame) itemInSlot); + } + } + + return hiveFrames; + } +} diff --git a/src/main/java/forestry/apiculture/inventory/InventoryHygroregulator.java b/src/main/java/forestry/apiculture/inventory/InventoryHygroregulator.java new file mode 100644 index 000000000..220bafa1e --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/InventoryHygroregulator.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.apiculture.multiblock.TileAlvearyHygroregulator; +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; + +public class InventoryHygroregulator extends InventoryAdapterTile { + public static final short SLOT_INPUT = 0; + + public InventoryHygroregulator(TileAlvearyHygroregulator alvearyHygroregulator) { + super(alvearyHygroregulator, 1, "CanInv"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_INPUT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + return false; + } +} diff --git a/src/main/java/forestry/apiculture/inventory/InventorySwarmer.java b/src/main/java/forestry/apiculture/inventory/InventorySwarmer.java new file mode 100644 index 000000000..5e2f2bccd --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/InventorySwarmer.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.api.apiculture.BeeManager; +import forestry.apiculture.multiblock.TileAlvearySwarmer; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.ItemStackUtil; + +public class InventorySwarmer extends InventoryAdapterTile { + public InventorySwarmer(TileAlvearySwarmer alvearySwarmer) { + super(alvearySwarmer, 4, "SwarmInv"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return ItemStackUtil.containsItemStack(BeeManager.inducers.keySet(), itemStack); + } +} diff --git a/src/main/java/forestry/core/items/IInventoriedItem.java b/src/main/java/forestry/apiculture/inventory/InventoryTileBeeHousing.java similarity index 52% rename from src/main/java/forestry/core/items/IInventoriedItem.java rename to src/main/java/forestry/apiculture/inventory/InventoryTileBeeHousing.java index 45301873e..6fee0535c 100644 --- a/src/main/java/forestry/core/items/IInventoriedItem.java +++ b/src/main/java/forestry/apiculture/inventory/InventoryTileBeeHousing.java @@ -1,15 +1,29 @@ -/******************************************************************************* - * 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.items; - -public interface IInventoriedItem { - -} +/******************************************************************************* + * 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.apiculture.inventory; + +import forestry.apiculture.InventoryBeeHousing; +import forestry.apiculture.tiles.TileAbstractBeeHousing; + +public class InventoryTileBeeHousing extends InventoryBeeHousing { + private final TileAbstractBeeHousing tile; + + public InventoryTileBeeHousing(TileAbstractBeeHousing tile, int size, String name) { + super(size, name, tile.getAccessHandler()); + this.tile = tile; + } + + @Override + public void markDirty() { + super.markDirty(); + tile.markDirty(); + } +} diff --git a/src/main/java/forestry/apiculture/inventory/ItemInventoryBeealyzer.java b/src/main/java/forestry/apiculture/inventory/ItemInventoryBeealyzer.java new file mode 100644 index 000000000..aeca6751e --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/ItemInventoryBeealyzer.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import forestry.api.apiculture.BeeManager; +import forestry.core.config.Config; +import forestry.core.gui.IHintSource; +import forestry.core.inventory.ItemInventoryAlyzer; + +public class ItemInventoryBeealyzer extends ItemInventoryAlyzer implements IHintSource { + + public ItemInventoryBeealyzer(EntityPlayer player, ItemStack itemStack) { + super(BeeManager.beeRoot, player, itemStack); + } + + /* IHintSource */ + @Override + public List getHints() { + return Config.hints.get("beealyzer"); + } +} diff --git a/src/main/java/forestry/apiculture/inventory/ItemInventoryHabitatLocator.java b/src/main/java/forestry/apiculture/inventory/ItemInventoryHabitatLocator.java new file mode 100644 index 000000000..28cb6413d --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/ItemInventoryHabitatLocator.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import com.google.common.collect.ImmutableSet; + +import java.util.List; +import java.util.Set; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.biome.BiomeGenBase; + +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.IBee; +import forestry.api.core.IErrorSource; +import forestry.api.core.IErrorState; +import forestry.apiculture.items.HabitatLocatorLogic; +import forestry.apiculture.items.ItemHabitatLocator; +import forestry.core.config.Config; +import forestry.core.config.ForestryItem; +import forestry.core.errors.EnumErrorCode; +import forestry.core.gui.IHintSource; +import forestry.core.inventory.ItemInventory; + +public class ItemInventoryHabitatLocator extends ItemInventory implements IErrorSource, IHintSource { + + private static final short SLOT_ENERGY = 2; + private static final short SLOT_SPECIMEN = 0; + private static final short SLOT_ANALYZED = 1; + + private final HabitatLocatorLogic locatorLogic; + + public ItemInventoryHabitatLocator(EntityPlayer player, ItemStack itemstack) { + super(player, 3, itemstack); + ItemHabitatLocator habitatLocator = (ItemHabitatLocator) itemstack.getItem(); + this.locatorLogic = habitatLocator.getLocatorLogic(); + } + + private static boolean isEnergy(ItemStack itemstack) { + if (itemstack == null || itemstack.stackSize <= 0) { + return false; + } + + return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + } + + @Override + public void onSlotClick(EntityPlayer player) { + + if (getStackInSlot(SLOT_ANALYZED) != null) { + if (locatorLogic.isBiomeFound()) { + return; + } + } else if (getStackInSlot(SLOT_SPECIMEN) != null) { + // Requires energy + if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { + return; + } + + // Decrease energy + decrStackSize(SLOT_ENERGY, 1); + + setInventorySlotContents(SLOT_ANALYZED, getStackInSlot(SLOT_SPECIMEN)); + setInventorySlotContents(SLOT_SPECIMEN, null); + } + + IBee bee = BeeManager.beeRoot.getMember(getStackInSlot(SLOT_ANALYZED)); + + // No bee, abort + if (bee == null) { + return; + } + + locatorLogic.startBiomeSearch(bee, player); + } + + public Set getBiomesToSearch() { + return locatorLogic.getTargetBiomes(); + } + + /* IHintSource */ + @Override + public List getHints() { + return Config.hints.get("habitat.locator"); + } + + /* IErrorSource */ + @Override + public ImmutableSet getErrorStates() { + if (getStackInSlot(SLOT_ANALYZED) != null) { + return ImmutableSet.of(); + } + + ImmutableSet.Builder errorStates = ImmutableSet.builder(); + + ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); + if (!BeeManager.beeRoot.isMember(specimen)) { + errorStates.add(EnumErrorCode.NOTHINGANALYZE); + } + + if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { + errorStates.add(EnumErrorCode.NOHONEY); + } + + return errorStates.build(); + } + + /* IFilterSlotDelegate */ + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_ENERGY) { + Item item = itemStack.getItem(); + return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item(); + } else if (slotIndex == SLOT_SPECIMEN) { + return BeeManager.beeRoot.isMember(itemStack); + } + return false; + } + +} diff --git a/src/main/java/forestry/apiculture/inventory/ItemInventoryImprinter.java b/src/main/java/forestry/apiculture/inventory/ItemInventoryImprinter.java new file mode 100644 index 000000000..cc3f8204c --- /dev/null +++ b/src/main/java/forestry/apiculture/inventory/ItemInventoryImprinter.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * 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.apiculture.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.IAlleleBeeSpecies; +import forestry.api.apiculture.IBee; +import forestry.apiculture.genetics.Bee; +import forestry.core.inventory.ItemInventory; + +public class ItemInventoryImprinter extends ItemInventory { + private static final short specimenSlot = 0; + private static final short imprintedSlot = 1; + + private int primaryIndex = 0; + private int secondaryIndex = 0; + + public ItemInventoryImprinter(EntityPlayer player, ItemStack itemStack) { + super(player, 2, itemStack); + } + + public void advancePrimary() { + if (primaryIndex < BeeManager.beeRoot.getIndividualTemplates().size() - 1) { + primaryIndex++; + } else { + primaryIndex = 0; + } + } + + public void advanceSecondary() { + if (secondaryIndex < BeeManager.beeRoot.getIndividualTemplates().size() - 1) { + secondaryIndex++; + } else { + secondaryIndex = 0; + } + } + + public void regressPrimary() { + if (primaryIndex > 0) { + primaryIndex--; + } else { + primaryIndex = BeeManager.beeRoot.getIndividualTemplates().size() - 1; + } + } + + public void regressSecondary() { + if (secondaryIndex > 0) { + secondaryIndex--; + } else { + secondaryIndex = BeeManager.beeRoot.getIndividualTemplates().size() - 1; + } + } + + public IAlleleBeeSpecies getPrimary() { + return BeeManager.beeRoot.getIndividualTemplates().get(primaryIndex).getGenome().getPrimary(); + } + + public IAlleleBeeSpecies getSecondary() { + return BeeManager.beeRoot.getIndividualTemplates().get(secondaryIndex).getGenome().getPrimary(); + } + + public IBee getSelectedBee() { + return new Bee(BeeManager.beeRoot.templateAsGenome( + BeeManager.beeRoot.getGenomeTemplates().get(BeeManager.beeRoot.getIndividualTemplates().get(primaryIndex).getIdent()), + BeeManager.beeRoot.getGenomeTemplates().get(BeeManager.beeRoot.getIndividualTemplates().get(secondaryIndex).getIdent()))); + } + + public int getPrimaryIndex() { + return primaryIndex; + } + + public int getSecondaryIndex() { + return secondaryIndex; + } + + public void setPrimaryIndex(int index) { + primaryIndex = index; + } + + public void setSecondaryIndex(int index) { + secondaryIndex = index; + } + + @Override + public void onSlotClick(EntityPlayer player) { + ItemStack specimen = getStackInSlot(specimenSlot); + if (specimen == null) { + return; + } + + // Only imprint bees + if (!BeeManager.beeRoot.isMember(specimen)) { + return; + } + + // Needs space + if (getStackInSlot(imprintedSlot) != null) { + return; + } + + IBee imprint = getSelectedBee(); + if (imprint == null) { + return; + } + + NBTTagCompound nbttagcompound = new NBTTagCompound(); + imprint.writeToNBT(nbttagcompound); + specimen.setTagCompound(nbttagcompound); + + setInventorySlotContents(imprintedSlot, specimen); + setInventorySlotContents(specimenSlot, null); + } + + @Override + public String getInventoryName() { + return "Imprinter"; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return BeeManager.beeRoot.isMember(itemStack); + } + +} diff --git a/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java b/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java new file mode 100644 index 000000000..7787d1e85 --- /dev/null +++ b/src/main/java/forestry/apiculture/items/HabitatLocatorLogic.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * 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.apiculture.items; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import net.minecraftforge.common.BiomeDictionary; + +import forestry.api.apiculture.IBee; +import forestry.apiculture.network.PacketHabitatBiomePointer; +import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.Vect; + +public class HabitatLocatorLogic { + private static final int maxChecksPerTick = 100; + private static final int maxSearchRadiusIterations = 500; + private static final int spacing = 20; + + private static final Set waterBiomes = new HashSet<>(); + private static final Set netherBiomes = new HashSet<>(); + private static final Set endBiomes = new HashSet<>(); + + static { + Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.BEACH)); + Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.OCEAN)); + Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.RIVER)); + + Collections.addAll(netherBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.NETHER)); + + Collections.addAll(endBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.END)); + } + + private Set targetBiomes = new HashSet<>(); + private boolean biomeFound = false; + private int searchRadiusIteration = 0; + private int searchAngleIteration = 0; + private Vect searchCenter; + + public boolean isBiomeFound() { + return biomeFound; + } + + public Set getTargetBiomes() { + return targetBiomes; + } + + public void startBiomeSearch(IBee bee, EntityPlayer player) { + this.targetBiomes = new HashSet<>(bee.getSuitableBiomes()); + this.searchAngleIteration = 0; + this.searchRadiusIteration = 0; + this.biomeFound = false; + this.searchCenter = new Vect(player); + + BiomeGenBase currentBiome = player.worldObj.getBiomeGenForCoords(searchCenter.x, searchCenter.z); + removeInvalidBiomes(currentBiome, targetBiomes); + + // reset the locator coordinates + Proxies.render.setHabitatLocatorTexture(null, null); + } + + public void onUpdate(World world, Entity player) { + if (world.isRemote) { + return; + } + + if (targetBiomes.isEmpty()) { + return; + } + + // once we've found the biome, slow down to conserve cpu and network data + if (biomeFound && world.getTotalWorldTime() % 20 != 0) { + return; + } + + ChunkCoordinates target = findNearestBiome(player, targetBiomes); + + // send an update if we find the biome + if (target != null && player instanceof EntityPlayerMP) { + Proxies.net.sendToPlayer(new PacketHabitatBiomePointer(target), (EntityPlayerMP) player); + biomeFound = true; + } + } + + private ChunkCoordinates findNearestBiome(Entity player, Collection biomesToSearch) { + Vect playerPos = new Vect(player); + + // If we are in a valid spot, we point to ourselves. + ChunkCoordinates coordinates = getChunkCoordinates(playerPos, player.worldObj, biomesToSearch); + if (coordinates != null) { + searchAngleIteration = 0; + searchRadiusIteration = 0; + return new ChunkCoordinates(playerPos.x, playerPos.y, playerPos.z); + } + + // check in a circular pattern, starting at the center and increasing radius each step + final int radius = spacing * (searchRadiusIteration + 1); + + double angleSpacing = 2.0f * Math.asin(spacing / (2.0 * radius)); + + // round to nearest divisible angle, for an even distribution + angleSpacing = 2.0 * Math.PI / Math.round(2.0 * Math.PI / angleSpacing); + + // do a limited number of checks per tick + for (int i = 0; i < maxChecksPerTick; i++) { + + double angle = angleSpacing * searchAngleIteration; + if (angle > 2.0 * Math.PI) { + searchAngleIteration = 0; + searchRadiusIteration++; + if (searchRadiusIteration > maxSearchRadiusIterations) { + searchAngleIteration = 0; + searchRadiusIteration = 0; + searchCenter = playerPos; + } + return null; + } else { + searchAngleIteration++; + } + + int xOffset = Math.round((float) (radius * Math.cos(angle))); + int zOffset = Math.round((float) (radius * Math.sin(angle))); + Vect pos = searchCenter.add(xOffset, 0, zOffset); + + coordinates = getChunkCoordinates(pos, player.worldObj, biomesToSearch); + if (coordinates != null) { + searchAngleIteration = 0; + searchRadiusIteration = 0; + return coordinates; + } + } + + return null; + } + + private static ChunkCoordinates getChunkCoordinates(Vect pos, World world, Collection biomesToSearch) { + + // to avoid reporting very tiny patches, check around the point want + final int minBiomeRadius = 8; + + BiomeGenBase biome; + + biome = world.getBiomeGenForCoords(pos.x, pos.z); + if (!biomesToSearch.contains(biome)) { + return null; + } + + biome = world.getBiomeGenForCoords(pos.x - minBiomeRadius, pos.z); + if (!biomesToSearch.contains(biome)) { + return null; + } + + biome = world.getBiomeGenForCoords(pos.x + minBiomeRadius, pos.z); + if (!biomesToSearch.contains(biome)) { + return null; + } + + biome = world.getBiomeGenForCoords(pos.x, pos.z - minBiomeRadius); + if (!biomesToSearch.contains(biome)) { + return null; + } + + biome = world.getBiomeGenForCoords(pos.x, pos.z + minBiomeRadius); + if (!biomesToSearch.contains(biome)) { + return null; + } + + return new ChunkCoordinates(pos.x, pos.y, pos.z); + } + + private static void removeInvalidBiomes(BiomeGenBase currentBiome, Set biomesToSearch) { + + biomesToSearch.removeAll(waterBiomes); + + if (BiomeDictionary.isBiomeOfType(currentBiome, BiomeDictionary.Type.NETHER)) { + biomesToSearch.retainAll(netherBiomes); + } else { + biomesToSearch.removeAll(netherBiomes); + } + + if (BiomeDictionary.isBiomeOfType(currentBiome, BiomeDictionary.Type.END)) { + biomesToSearch.retainAll(endBiomes); + } else { + biomesToSearch.removeAll(endBiomes); + } + } +} diff --git a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java deleted file mode 100755 index 2b5f7dae9..000000000 --- a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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.apiculture.items; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import forestry.api.apiculture.BeeManager; -import forestry.api.core.ForestryAPI; -import forestry.api.core.Tabs; -import forestry.api.genetics.ISpeciesRoot; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; -import forestry.core.items.ItemAlyzer; -import forestry.core.network.GuiId; - -public class ItemBeealyzer extends ItemAlyzer { - - public ItemBeealyzer() { - super(); - setMaxStackSize(1); - setCreativeTab(Tabs.tabApiculture); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.BeealyzerGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ); - } - - return itemstack; - } - - public static class BeealyzerInventory extends AlyzerInventory implements IHintSource { - - public BeealyzerInventory(EntityPlayer player, ItemStack itemStack) { - super(player, 7, itemStack); - } - - @Override - protected ISpeciesRoot getSpeciesRoot() { - return BeeManager.beeRoot; - } - - // / IHINTSOURCE - @Override - public String[] getHints() { - return Config.hints.get("beealyzer"); - } - } - -} diff --git a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java index 2364cef78..2fb41ca8a 100644 --- a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java +++ b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java @@ -10,77 +10,50 @@ ******************************************************************************/ package forestry.apiculture.items; -import com.google.common.collect.ImmutableSet; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.BiomeDictionary; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.apiculture.BeeManager; -import forestry.api.apiculture.IBee; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.api.core.ForestryAPI; -import forestry.api.core.IErrorSource; -import forestry.api.core.IErrorState; import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; -import forestry.apiculture.network.PacketHabitatBiomePointer; import forestry.apiculture.render.TextureHabitatLocator; -import forestry.core.config.Config; -import forestry.core.config.ForestryItem; -import forestry.core.errors.EnumErrorCode; -import forestry.core.gui.IHintSource; -import forestry.core.inventory.ItemInventory; -import forestry.core.items.ItemInventoried; +import forestry.core.items.ItemWithGui; import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; -import forestry.core.utils.vect.Vect; - -public class ItemHabitatLocator extends ItemInventoried { +public class ItemHabitatLocator extends ItemWithGui { private static final String iconName = "forestry:biomefinder"; - private Set targetBiomes = new HashSet<>(); - private boolean biomeFound = false; - private int searchRadiusIteration = 0; - private int searchAngleIteration = 0; - private Vect searchCenter; + private final HabitatLocatorLogic locatorLogic; public ItemHabitatLocator() { - super(); + super(GuiId.HabitatLocatorGUI); setMaxStackSize(1); setCreativeTab(Tabs.tabApiculture); + locatorLogic = new HabitatLocatorLogic(); + } + + public HabitatLocatorLogic getLocatorLogic() { + return locatorLogic; } @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - + public void onUpdate(ItemStack p_77663_1_, World world, Entity player, int p_77663_4_, boolean p_77663_5_) { if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.HabitatLocatorGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ); + locatorLogic.onUpdate(world, player); } - - return itemstack; } /* TEXTURES */ @@ -107,262 +80,4 @@ public class ItemHabitatLocator extends ItemInventoried { list.add(StringUtil.localize("gui.temperature") + ": " + AlleleManager.climateHelper.toDisplay(temperature)); list.add(StringUtil.localize("gui.humidity") + ": " + AlleleManager.climateHelper.toDisplay(humidity)); } - - private void startBiomeSearch(IBee bee, EntityPlayer player) { - - this.targetBiomes = new HashSet<>(bee.getSuitableBiomes()); - this.searchAngleIteration = 0; - this.searchRadiusIteration = 0; - this.biomeFound = false; - this.searchCenter = new Vect(player); - - BiomeGenBase currentBiome = player.worldObj.getBiomeGenForCoords(searchCenter.x, searchCenter.z); - removeInvalidBiomes(currentBiome, targetBiomes); - - // reset the locator coordinates - Proxies.render.setHabitatLocatorTexture(null, null); - } - - @Override - public void onUpdate(ItemStack p_77663_1_, World world, Entity player, int p_77663_4_, boolean p_77663_5_) { - - if (world.isRemote) { - return; - } - - if (targetBiomes.isEmpty()) { - return; - } - - // once we've found the biome, slow down to conserve cpu and network data - if (biomeFound && world.getTotalWorldTime() % 20 != 0) { - return; - } - - ChunkCoordinates target = findNearestBiome(player, targetBiomes); - - // send an update if we find the biome - if (target != null && player instanceof EntityPlayerMP) { - Proxies.net.sendToPlayer(new PacketHabitatBiomePointer(target), (EntityPlayerMP) player); - biomeFound = true; - } - } - - private ChunkCoordinates findNearestBiome(Entity player, Collection biomesToSearch) { - - final int maxChecksPerTick = 100; - final int maxSearchRadiusIterations = 500; - final int spacing = 20; - - Vect playerPos = new Vect(player); - - // If we are in a valid spot, we point to ourselves. - ChunkCoordinates coordinates = getChunkCoordinates(playerPos, player.worldObj, biomesToSearch); - if (coordinates != null) { - searchAngleIteration = 0; - searchRadiusIteration = 0; - return new ChunkCoordinates(playerPos.x, playerPos.y, playerPos.z); - } - - // check in a circular pattern, starting at the center and increasing radius each step - final int radius = spacing * (searchRadiusIteration + 1); - - double angleSpacing = 2.0f * Math.asin(spacing / (2.0 * radius)); - - // round to nearest divisible angle, for an even distribution - angleSpacing = 2.0 * Math.PI / Math.round(2.0 * Math.PI / angleSpacing); - - // do a limited number of checks per tick - for (int i = 0; i < maxChecksPerTick; i++) { - - double angle = angleSpacing * searchAngleIteration; - if (angle > 2.0 * Math.PI) { - searchAngleIteration = 0; - searchRadiusIteration++; - if (searchRadiusIteration > maxSearchRadiusIterations) { - searchAngleIteration = 0; - searchRadiusIteration = 0; - searchCenter = playerPos; - } - return null; - } else { - searchAngleIteration++; - } - - int xOffset = Math.round((float) (radius * Math.cos(angle))); - int zOffset = Math.round((float) (radius * Math.sin(angle))); - Vect pos = searchCenter.add(xOffset, 0, zOffset); - - coordinates = getChunkCoordinates(pos, player.worldObj, biomesToSearch); - if (coordinates != null) { - searchAngleIteration = 0; - searchRadiusIteration = 0; - return coordinates; - } - } - - return null; - } - - private static ChunkCoordinates getChunkCoordinates(Vect pos, World world, Collection biomesToSearch) { - - // to avoid reporting very tiny patches, check around the point want - final int minBiomeRadius = 8; - - BiomeGenBase biome; - - biome = world.getBiomeGenForCoords(pos.x, pos.z); - if (!biomesToSearch.contains(biome)) { - return null; - } - - biome = world.getBiomeGenForCoords(pos.x - minBiomeRadius, pos.z); - if (!biomesToSearch.contains(biome)) { - return null; - } - - biome = world.getBiomeGenForCoords(pos.x + minBiomeRadius, pos.z); - if (!biomesToSearch.contains(biome)) { - return null; - } - - biome = world.getBiomeGenForCoords(pos.x, pos.z - minBiomeRadius); - if (!biomesToSearch.contains(biome)) { - return null; - } - - biome = world.getBiomeGenForCoords(pos.x, pos.z + minBiomeRadius); - if (!biomesToSearch.contains(biome)) { - return null; - } - - return new ChunkCoordinates(pos.x, pos.y, pos.z); - } - - private static final Set waterBiomes = new HashSet<>(); - private static final Set netherBiomes = new HashSet<>(); - private static final Set endBiomes = new HashSet<>(); - - static { - Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.BEACH)); - Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.OCEAN)); - Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.RIVER)); - - Collections.addAll(netherBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.NETHER)); - - Collections.addAll(endBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.END)); - } - - private static void removeInvalidBiomes(BiomeGenBase currentBiome, Set biomesToSearch) { - - biomesToSearch.removeAll(waterBiomes); - - if (BiomeDictionary.isBiomeOfType(currentBiome, BiomeDictionary.Type.NETHER)) { - biomesToSearch.retainAll(netherBiomes); - } else { - biomesToSearch.removeAll(netherBiomes); - } - - if (BiomeDictionary.isBiomeOfType(currentBiome, BiomeDictionary.Type.END)) { - biomesToSearch.retainAll(endBiomes); - } else { - biomesToSearch.removeAll(endBiomes); - } - } - - public static class HabitatLocatorInventory extends ItemInventory implements IErrorSource, IHintSource { - - private static final short SLOT_ENERGY = 2; - private static final short SLOT_SPECIMEN = 0; - private static final short SLOT_ANALYZED = 1; - - private final ItemHabitatLocator habitatLocator; - - public HabitatLocatorInventory(EntityPlayer player, ItemStack itemstack) { - super(player, 3, itemstack); - this.habitatLocator = (ItemHabitatLocator) itemstack.getItem(); - } - - private static boolean isEnergy(ItemStack itemstack) { - if (itemstack == null || itemstack.stackSize <= 0) { - return false; - } - - return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); - } - - @Override - public void onSlotClick(EntityPlayer player) { - - if (getStackInSlot(SLOT_ANALYZED) != null) { - if (habitatLocator.biomeFound) { - return; - } - } else if (getStackInSlot(SLOT_SPECIMEN) != null) { - // Requires energy - if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { - return; - } - - // Decrease energy - decrStackSize(SLOT_ENERGY, 1); - - setInventorySlotContents(SLOT_ANALYZED, getStackInSlot(SLOT_SPECIMEN)); - setInventorySlotContents(SLOT_SPECIMEN, null); - } - - IBee bee = BeeManager.beeRoot.getMember(getStackInSlot(SLOT_ANALYZED)); - - // No bee, abort - if (bee == null) { - return; - } - - habitatLocator.startBiomeSearch(bee, player); - } - - public Set getBiomesToSearch() { - return habitatLocator.targetBiomes; - } - - // / IHINTSOURCE - @Override - public String[] getHints() { - return Config.hints.get("habitatlocator"); - } - - // / IERRORSOURCE - @Override - public ImmutableSet getErrorStates() { - if (getStackInSlot(SLOT_ANALYZED) != null) { - return ImmutableSet.of(); - } - - ImmutableSet.Builder errorStates = ImmutableSet.builder(); - - ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); - if (!BeeManager.beeRoot.isMember(specimen)) { - errorStates.add(EnumErrorCode.NOTHINGANALYZE); - } - - if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { - errorStates.add(EnumErrorCode.NOHONEY); - } - - return errorStates.build(); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_ENERGY) { - Item item = itemStack.getItem(); - return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item(); - } else if (slotIndex == SLOT_SPECIMEN) { - return BeeManager.beeRoot.isMember(itemStack); - } - return false; - } - - } - } diff --git a/src/main/java/forestry/apiculture/items/ItemImprinter.java b/src/main/java/forestry/apiculture/items/ItemImprinter.java deleted file mode 100755 index 7fd4ac30f..000000000 --- a/src/main/java/forestry/apiculture/items/ItemImprinter.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * 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.apiculture.items; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - -import forestry.api.apiculture.BeeManager; -import forestry.api.apiculture.IAlleleBeeSpecies; -import forestry.api.apiculture.IBee; -import forestry.api.core.ForestryAPI; -import forestry.api.core.Tabs; -import forestry.apiculture.genetics.Bee; -import forestry.core.inventory.ItemInventory; -import forestry.core.items.ItemForestry; -import forestry.core.network.GuiId; - -public class ItemImprinter extends ItemForestry { - - public static class ImprinterInventory extends ItemInventory { - - private static final short specimenSlot = 0; - private static final short imprintedSlot = 1; - - private int primaryIndex = 0; - private int secondaryIndex = 0; - - public ImprinterInventory(EntityPlayer player, ItemStack itemStack) { - super(player, 2, itemStack); - } - - public void advancePrimary() { - if (primaryIndex < BeeManager.beeRoot.getIndividualTemplates().size() - 1) { - primaryIndex++; - } else { - primaryIndex = 0; - } - } - - public void advanceSecondary() { - if (secondaryIndex < BeeManager.beeRoot.getIndividualTemplates().size() - 1) { - secondaryIndex++; - } else { - secondaryIndex = 0; - } - } - - public void regressPrimary() { - if (primaryIndex > 0) { - primaryIndex--; - } else { - primaryIndex = BeeManager.beeRoot.getIndividualTemplates().size() - 1; - } - } - - public void regressSecondary() { - if (secondaryIndex > 0) { - secondaryIndex--; - } else { - secondaryIndex = BeeManager.beeRoot.getIndividualTemplates().size() - 1; - } - } - - public IAlleleBeeSpecies getPrimary() { - return BeeManager.beeRoot.getIndividualTemplates().get(primaryIndex).getGenome().getPrimary(); - } - - public IAlleleBeeSpecies getSecondary() { - return BeeManager.beeRoot.getIndividualTemplates().get(secondaryIndex).getGenome().getPrimary(); - } - - public IBee getSelectedBee() { - return new Bee(BeeManager.beeRoot.templateAsGenome( - BeeManager.beeRoot.getGenomeTemplates().get(BeeManager.beeRoot.getIndividualTemplates().get(primaryIndex).getIdent()), - BeeManager.beeRoot.getGenomeTemplates().get(BeeManager.beeRoot.getIndividualTemplates().get(secondaryIndex).getIdent()))); - } - - public int getPrimaryIndex() { - return primaryIndex; - } - - public int getSecondaryIndex() { - return secondaryIndex; - } - - public void setPrimaryIndex(int index) { - primaryIndex = index; - } - - public void setSecondaryIndex(int index) { - secondaryIndex = index; - } - - @Override - public void onSlotClick(EntityPlayer player) { - ItemStack specimen = getStackInSlot(specimenSlot); - if (specimen == null) { - return; - } - - // Only imprint bees - if (!BeeManager.beeRoot.isMember(specimen)) { - return; - } - - // Needs space - if (getStackInSlot(imprintedSlot) != null) { - return; - } - - IBee imprint = getSelectedBee(); - if (imprint == null) { - return; - } - - NBTTagCompound nbttagcompound = new NBTTagCompound(); - imprint.writeToNBT(nbttagcompound); - specimen.setTagCompound(nbttagcompound); - - setInventorySlotContents(imprintedSlot, specimen); - setInventorySlotContents(specimenSlot, null); - } - - @Override - public String getInventoryName() { - return "Imprinter"; - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return BeeManager.beeRoot.isMember(itemStack); - } - - } - - public ItemImprinter() { - super(); - setCreativeTab(Tabs.tabApiculture); - setMaxStackSize(1); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.ImprinterGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } - - return itemstack; - } - -} diff --git a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java index ee954a05c..a95dd7f62 100644 --- a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java @@ -35,7 +35,7 @@ import forestry.api.apiculture.IBeekeepingLogic; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.IClimateControlled; -import forestry.apiculture.BeeHousingInventory; +import forestry.apiculture.InventoryBeeHousing; import forestry.core.access.EnumAccess; import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; @@ -52,7 +52,7 @@ import forestry.core.utils.BlockUtil; public class AlvearyController extends RectangularMultiblockControllerBase implements IAlvearyController, IClimateControlled { - private final BeeHousingInventory inventory; + private final InventoryBeeHousing inventory; private final IBeekeepingLogic beekeepingLogic; private BiomeGenBase cachedBiome; @@ -71,7 +71,7 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple public AlvearyController(World world) { super(world); - this.inventory = new BeeHousingInventory(9, "Items", getAccessHandler()); + this.inventory = new InventoryBeeHousing(9, "Items", getAccessHandler()); this.beekeepingLogic = BeeManager.beeRoot.createBeekeepingLogic(this); this.beeModifiers.add(new AlvearyBeeModifier()); diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java index 9eda560a9..e421046b8 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java @@ -11,7 +11,6 @@ package forestry.apiculture.multiblock; import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; @@ -23,21 +22,19 @@ import net.minecraftforge.fluids.IFluidHandler; import forestry.api.apiculture.IAlvearyComponent; import forestry.api.core.IClimateControlled; import forestry.apiculture.blocks.BlockAlveary; +import forestry.apiculture.inventory.InventoryHygroregulator; import forestry.core.config.Constants; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.Fluids; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.tiles.ILiquidTankTile; public class TileAlvearyHygroregulator extends TileAlvearyWithGui implements IInventory, ILiquidTankTile, IFluidHandler, IAlvearyComponent.Climatiser { - private final HygroregulatorRecipe[] recipes; - /* MEMBERS */ private final TankManager tankManager; private final FilteredTank liquidTank; private final IInventoryAdapter inventory; @@ -48,7 +45,7 @@ public class TileAlvearyHygroregulator extends TileAlvearyWithGui implements IIn public TileAlvearyHygroregulator() { super(TileAlveary.HYGRO_META, GuiId.HygroregulatorGUI); - this.inventory = new HygroInventory(this); + this.inventory = new InventoryHygroregulator(this); Fluid water = Fluids.WATER.getFluid(); Fluid lava = Fluids.LAVA.getFluid(); @@ -181,9 +178,7 @@ public class TileAlvearyHygroregulator extends TileAlvearyWithGui implements IIn return tankManager.getTankInfo(from); } - /* RECIPE MANAGMENT */ private static class HygroregulatorRecipe { - public final FluidStack liquid; public final int transferTime; public final float humidChange; @@ -196,21 +191,4 @@ public class TileAlvearyHygroregulator extends TileAlvearyWithGui implements IIn this.tempChange = tempChange; } } - - public static class HygroInventory extends TileInventoryAdapter { - public static final short SLOT_INPUT = 0; - - public HygroInventory(TileAlvearyHygroregulator alvearyHygroregulator) { - super(alvearyHygroregulator, 1, "CanInv"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_INPUT) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.liquidTank.accepts(fluid); - } - return false; - } - } } diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java index 3eef23b7b..0ed1fb244 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java @@ -13,6 +13,7 @@ package forestry.apiculture.multiblock; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; @@ -104,7 +105,7 @@ public class TileAlvearyPlain extends TileAlveary implements IClimatised, IHintS /* IHintSource */ @Override - public String[] getHints() { + public List getHints() { return Config.hints.get("apiary"); } diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java index bb4b60fa7..df19e8cec 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.apiculture.multiblock; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import forestry.api.apiculture.DefaultBeeListener; @@ -21,22 +20,20 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; import forestry.api.genetics.ISpeciesRoot; import forestry.apiculture.blocks.BlockAlveary; -import forestry.core.config.ForestryItem; +import forestry.apiculture.inventory.InventoryAlvearySieve; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.tiles.ICrafter; -import forestry.core.utils.ItemStackUtil; -public class TileAlvearySieve extends TileAlvearyWithGui implements ICrafter, IAlvearyComponent.BeeListener { +public class TileAlvearySieve extends TileAlvearyWithGui implements IAlvearyComponent.BeeListener { private final IBeeListener beeListener; - private final AlvearySieveInventory inventory; + private final InventoryAlvearySieve inventory; public TileAlvearySieve() { super(TileAlveary.SIEVE_META, GuiId.AlvearySieveGUI); - this.inventory = new AlvearySieveInventory(this); - this.beeListener = new AlvearySieveBeeListener(this); + this.inventory = new InventoryAlvearySieve(this); + this.beeListener = new AlvearySieveBeeListener(inventory); } @Override @@ -44,12 +41,15 @@ public class TileAlvearySieve extends TileAlvearyWithGui implements ICrafter, IA return inventory; } + public ICrafter getCrafter() { + return inventory; + } + @Override public IBeeListener getBeeListener() { return beeListener; } - /* TEXTURES & INTERNAL */ @Override public int getIcon(int side) { if (side == 0 || side == 1) { @@ -58,32 +58,16 @@ public class TileAlvearySieve extends TileAlvearyWithGui implements ICrafter, IA return BlockAlveary.SIEVE; } - /* ICRAFTER */ - @Override - public boolean canTakeStack(int slotIndex) { - return true; - } + static class AlvearySieveBeeListener extends DefaultBeeListener { + private final InventoryAlvearySieve inventory; - @Override - public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { - return inventory.takenFromSlot(slotIndex); - } - - @Override - public ItemStack getResult() { - return null; - } - - private static class AlvearySieveBeeListener extends DefaultBeeListener { - private final TileAlvearySieve tile; - - public AlvearySieveBeeListener(TileAlvearySieve tile) { - this.tile = tile; + public AlvearySieveBeeListener(InventoryAlvearySieve inventory) { + this.inventory = inventory; } @Override public boolean onPollenRetrieved(IIndividual pollen) { - if (!tile.inventory.canStorePollen()) { + if (!inventory.canStorePollen()) { return false; } @@ -91,61 +75,10 @@ public class TileAlvearySieve extends TileAlvearyWithGui implements ICrafter, IA ItemStack pollenStack = speciesRoot.getMemberStack(pollen, EnumGermlingType.POLLEN.ordinal()); if (pollenStack != null) { - tile.inventory.storePollenStack(pollenStack); + inventory.storePollenStack(pollenStack); return true; } return false; } } - - public static class AlvearySieveInventory extends TileInventoryAdapter { - public static final int SLOT_POLLEN_1 = 0; - public static final int SLOTS_POLLEN_COUNT = 4; - public static final int SLOT_SIEVE = 4; - - public AlvearySieveInventory(TileAlvearySieve alvearySieve) { - super(alvearySieve, 5, "Items", 1); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return ItemStackUtil.isIdenticalItem(ForestryItem.craftingMaterial.getItemStack(1, 3), itemStack); - } - - private boolean canStorePollen() { - if (getStackInSlot(SLOT_SIEVE) == null) { - return false; - } - - for (int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { - if (getStackInSlot(i) == null) { - return true; - } - } - - return false; - } - - private void storePollenStack(ItemStack itemstack) { - for (int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { - if (getStackInSlot(i) == null) { - setInventorySlotContents(i, itemstack); - return; - } - } - } - - public ItemStack takenFromSlot(int slotIndex) { - if (slotIndex == SLOT_SIEVE) { - for (int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { - setInventorySlotContents(i, null); - } - return getStackInSlot(SLOT_SIEVE); - } else { - setInventorySlotContents(SLOT_SIEVE, null); - return getStackInSlot(slotIndex); - } - } - } - } diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java index c099885a9..f6cd2a1b6 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java @@ -23,13 +23,13 @@ import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBee; import forestry.apiculture.blocks.BlockAlveary; +import forestry.apiculture.inventory.InventorySwarmer; import forestry.apiculture.network.PacketActiveUpdate; import forestry.apiculture.worldgen.Hive; import forestry.apiculture.worldgen.HiveDecorator; import forestry.apiculture.worldgen.HiveDescriptionSwarmer; import forestry.core.access.EnumAccess; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.network.GuiId; @@ -39,13 +39,13 @@ import forestry.core.utils.ItemStackUtil; public class TileAlvearySwarmer extends TileAlvearyWithGui implements ISidedInventory, IActivatable, IAlvearyComponent.Active { - private final SwarmerInventory inventory; + private final InventorySwarmer inventory; private final Stack pendingSpawns = new Stack<>(); private boolean active; public TileAlvearySwarmer() { super(TileAlveary.SWARMER_META, GuiId.AlvearySwarmerGUI); - this.inventory = new SwarmerInventory(this); + this.inventory = new InventorySwarmer(this); } @Override @@ -227,15 +227,4 @@ public class TileAlvearySwarmer extends TileAlvearyWithGui implements ISidedInve Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), worldObj); } } - - private static class SwarmerInventory extends TileInventoryAdapter { - public SwarmerInventory(TileAlvearySwarmer alvearySwarmer) { - super(alvearySwarmer, 4, "SwarmInv"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return ItemStackUtil.containsItemStack(BeeManager.inducers.keySet(), itemStack); - } - } } diff --git a/src/main/java/forestry/apiculture/render/RenderCandleBlock.java b/src/main/java/forestry/apiculture/render/RenderCandleBlock.java index b3d9291ca..3d9a3042d 100644 --- a/src/main/java/forestry/apiculture/render/RenderCandleBlock.java +++ b/src/main/java/forestry/apiculture/render/RenderCandleBlock.java @@ -21,7 +21,7 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import forestry.apiculture.blocks.BlockCandle; import forestry.apiculture.tiles.TileCandle; -import forestry.core.ForestryClient; +import forestry.core.proxy.ProxyRenderClient; public class RenderCandleBlock implements ISimpleBlockRenderingHandler { @@ -32,7 +32,7 @@ public class RenderCandleBlock implements ISimpleBlockRenderingHandler { @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { - if (block.getRenderType() == ForestryClient.candleRenderId) { + if (block.getRenderType() == ProxyRenderClient.getCandleRenderId()) { renderBlockCandle(world, x, y, z, (BlockCandle) block); } return true; @@ -45,7 +45,7 @@ public class RenderCandleBlock implements ISimpleBlockRenderingHandler { @Override public int getRenderId() { - return ForestryClient.candleRenderId; + return ProxyRenderClient.getCandleRenderId(); } private static boolean renderBlockCandle(IBlockAccess world, int x, int y, int z, BlockCandle block) { diff --git a/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java b/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java index cff88e343..913e55f4c 100644 --- a/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java +++ b/src/main/java/forestry/apiculture/tiles/TileAbstractBeeHousing.java @@ -25,11 +25,10 @@ import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeekeepingLogic; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.apiculture.BeeHousingInventory; import forestry.apiculture.gui.IGuiBeeHousingInventory; -import forestry.core.config.Config; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.GuiId; import forestry.core.network.IStreamableGui; import forestry.core.proxy.Proxies; import forestry.core.tiles.IClimatised; @@ -42,8 +41,8 @@ public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHou // CLIENT private int breedingProgressPercent = 0; - protected TileAbstractBeeHousing() { - setHints(Config.hints.get("apiary")); + protected TileAbstractBeeHousing(GuiId guiId, String hintKey) { + super(guiId, hintKey); this.beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); } @@ -175,19 +174,4 @@ public abstract class TileAbstractBeeHousing extends TileBase implements IBeeHou return Vec3.createVectorHelper(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); } - public static class TileBeeHousingInventory extends BeeHousingInventory { - private final TileAbstractBeeHousing tile; - - public TileBeeHousingInventory(TileAbstractBeeHousing tile, int size, String name) { - super(size, name, tile.getAccessHandler()); - this.tile = tile; - } - - @Override - public void markDirty() { - super.markDirty(); - tile.markDirty(); - } - } - } diff --git a/src/main/java/forestry/apiculture/tiles/TileApiaristChest.java b/src/main/java/forestry/apiculture/tiles/TileApiaristChest.java index 3c7cf2f2b..91274dc14 100644 --- a/src/main/java/forestry/apiculture/tiles/TileApiaristChest.java +++ b/src/main/java/forestry/apiculture/tiles/TileApiaristChest.java @@ -27,7 +27,7 @@ public class TileApiaristChest extends TileNaturalistChest { private boolean checkedForLegacyBlock = false; public TileApiaristChest() { - super(BeeManager.beeRoot, GuiId.ApiaristChestGUI.ordinal()); + super(BeeManager.beeRoot, GuiId.ApiaristChestGUI); } @Override diff --git a/src/main/java/forestry/apiculture/tiles/TileApiary.java b/src/main/java/forestry/apiculture/tiles/TileApiary.java index 2bfbb5925..ea0e2a73f 100644 --- a/src/main/java/forestry/apiculture/tiles/TileApiary.java +++ b/src/main/java/forestry/apiculture/tiles/TileApiary.java @@ -16,7 +16,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -36,11 +35,9 @@ import forestry.api.apiculture.IBeeListener; import forestry.api.apiculture.IBeeModifier; import forestry.api.apiculture.IBeekeepingMode; import forestry.api.apiculture.IHiveFrame; -import forestry.api.core.ForestryAPI; +import forestry.apiculture.inventory.InventoryApiary; import forestry.apiculture.trigger.ApicultureTriggers; -import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.GuiId; -import forestry.core.utils.SlotUtil; import buildcraft.api.statements.ITriggerExternal; @@ -48,12 +45,13 @@ public class TileApiary extends TileAbstractBeeHousing { private static final IBeeModifier beeModifier = new ApiaryBeeModifier(); private final IBeeListener beeListener; - private final ApiaryInventory inventory; + private final InventoryApiary inventory; public TileApiary() { + super(GuiId.ApiaryGUI, "apiary"); this.beeListener = new ApiaryBeeListener(this); - ApiaryInventory apiaryInventory = new ApiaryInventory(this, 12, "Items"); + InventoryApiary apiaryInventory = new InventoryApiary(this); this.inventory = apiaryInventory; setInternalInventory(apiaryInventory); } @@ -63,11 +61,6 @@ public class TileApiary extends TileAbstractBeeHousing { return inventory; } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.ApiaryGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); - } - @Override public Collection getBeeModifiers() { List beeModifiers = new ArrayList<>(); @@ -128,55 +121,6 @@ public class TileApiary extends TileAbstractBeeHousing { } } - public static class ApiaryInventory extends TileBeeHousingInventory { - public static final int SLOT_FRAMES_1 = 9; - public static final int SLOT_FRAMES_COUNT = 3; - - public ApiaryInventory(TileApiary tile, int size, String name) { - super(tile, size, name); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (SlotUtil.isSlotInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) { - return (itemStack.getItem() instanceof IHiveFrame) && (getStackInSlot(slotIndex) == null); - } - - return super.canSlotAccept(slotIndex, itemStack); - } - - // override for pipe automation - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { - if (SlotUtil.isSlotInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) { - return false; - } - return super.isItemValidForSlot(slotIndex, itemStack); - } - - public IInventory getFrameInventory() { - return new InventoryMapper(this, SLOT_FRAMES_1, SLOT_FRAMES_COUNT); - } - - public Collection getFrames() { - Collection hiveFrames = new ArrayList<>(SLOT_FRAMES_COUNT); - - for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { - ItemStack stackInSlot = getStackInSlot(i); - if (stackInSlot == null) { - continue; - } - - Item itemInSlot = stackInSlot.getItem(); - if (itemInSlot instanceof IHiveFrame) { - hiveFrames.add((IHiveFrame) itemInSlot); - } - } - - return hiveFrames; - } - } - /* ITRIGGERPROVIDER */ @Optional.Method(modid = "BuildCraftAPI|statements") @Override diff --git a/src/main/java/forestry/apiculture/tiles/TileBeehouse.java b/src/main/java/forestry/apiculture/tiles/TileBeehouse.java index 56f41695b..4843c5933 100644 --- a/src/main/java/forestry/apiculture/tiles/TileBeehouse.java +++ b/src/main/java/forestry/apiculture/tiles/TileBeehouse.java @@ -12,15 +12,13 @@ package forestry.apiculture.tiles; import java.util.Collections; -import net.minecraft.entity.player.EntityPlayer; - import forestry.api.apiculture.DefaultBeeListener; import forestry.api.apiculture.DefaultBeeModifier; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousingInventory; import forestry.api.apiculture.IBeeListener; import forestry.api.apiculture.IBeeModifier; -import forestry.api.core.ForestryAPI; +import forestry.apiculture.inventory.InventoryTileBeeHousing; import forestry.core.network.GuiId; public class TileBeehouse extends TileAbstractBeeHousing { @@ -30,9 +28,10 @@ public class TileBeehouse extends TileAbstractBeeHousing { private final IBeeHousingInventory beeInventory; public TileBeehouse() { + super(GuiId.BeehouseGUI, "bee.house"); this.beeListener = new DefaultBeeListener(); - TileBeeHousingInventory beeHousingInventory = new TileBeeHousingInventory(this, 12, "Items"); + InventoryTileBeeHousing beeHousingInventory = new InventoryTileBeeHousing(this, 12, "Items"); beeHousingInventory.disableAutomation(); this.beeInventory = beeHousingInventory; @@ -44,11 +43,6 @@ public class TileBeehouse extends TileAbstractBeeHousing { return beeInventory; } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.BeehouseGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); - } - @Override public Iterable getBeeModifiers() { return Collections.singleton(beeModifier); diff --git a/src/main/java/forestry/apiculture/trigger/TriggerNoFrames.java b/src/main/java/forestry/apiculture/trigger/TriggerNoFrames.java index 8d0376be1..070ec4bcf 100755 --- a/src/main/java/forestry/apiculture/trigger/TriggerNoFrames.java +++ b/src/main/java/forestry/apiculture/trigger/TriggerNoFrames.java @@ -14,6 +14,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; +import forestry.apiculture.inventory.InventoryApiary; import forestry.apiculture.tiles.TileApiary; import forestry.core.triggers.Trigger; @@ -38,7 +39,7 @@ public class TriggerNoFrames extends Trigger { TileApiary apiary = (TileApiary) tile; - TileApiary.ApiaryInventory inventory = (TileApiary.ApiaryInventory) apiary.getInternalInventory(); + InventoryApiary inventory = (InventoryApiary) apiary.getInternalInventory(); return inventory.getFrames().size() == 0; } diff --git a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java index ca1741a74..0115034c9 100755 --- a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java @@ -39,6 +39,7 @@ import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IFlower; +import forestry.apiculture.inventory.InventoryApiary; import forestry.apiculture.tiles.TileApiary; import forestry.arboriculture.worldgen.BlockTypeLog; import forestry.arboriculture.worldgen.BlockTypeVanillaStairs; @@ -303,7 +304,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { ItemStack randomVillageDrone = getRandomVillageBeeStack(world, xCoord, yCoord, zCoord, EnumBeeType.DRONE); apiary.getBeeInventory().setDrone(randomVillageDrone); - for (int i = TileApiary.ApiaryInventory.SLOT_FRAMES_1; i < TileApiary.ApiaryInventory.SLOT_FRAMES_1 + TileApiary.ApiaryInventory.SLOT_FRAMES_COUNT; i++) { + for (int i = InventoryApiary.SLOT_FRAMES_1; i < InventoryApiary.SLOT_FRAMES_1 + InventoryApiary.SLOT_FRAMES_COUNT; i++) { ItemStack randomFrame = getRandomFrame(world.rand); apiary.setInventorySlotContents(i, randomFrame); } diff --git a/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java b/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java index b7c9d4556..16e6d8827 100755 --- a/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java +++ b/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java @@ -16,7 +16,7 @@ import net.minecraft.world.World; import forestry.api.arboriculture.TreeManager; import forestry.arboriculture.gui.GuiTreealyzer; -import forestry.arboriculture.items.ItemTreealyzer.TreealyzerInventory; +import forestry.arboriculture.inventory.ItemInventoryTreealyzer; import forestry.core.GuiHandlerBase; import forestry.core.gui.ContainerAlyzer; import forestry.core.network.GuiId; @@ -42,7 +42,7 @@ public class GuiHandlerArboriculture extends GuiHandlerBase { return null; } - return new ContainerAlyzer(new TreealyzerInventory(player, equipped), player); + return new ContainerAlyzer(new ItemInventoryTreealyzer(player, equipped), player); default: return null; @@ -70,7 +70,7 @@ public class GuiHandlerArboriculture extends GuiHandlerBase { return null; } - return new GuiTreealyzer(player, new TreealyzerInventory(player, equipped)); + return new GuiTreealyzer(player, new ItemInventoryTreealyzer(player, equipped)); default: return null; diff --git a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java index 72ff0f25f..9b5f965c2 100755 --- a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java +++ b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java @@ -33,8 +33,8 @@ import forestry.api.genetics.IAlleleInteger; import forestry.api.genetics.IFruitFamily; import forestry.arboriculture.genetics.TreeGenome; import forestry.arboriculture.genetics.alleles.AlleleFruit; +import forestry.arboriculture.inventory.ItemInventoryTreealyzer; import forestry.arboriculture.items.ItemGermlingGE; -import forestry.arboriculture.items.ItemTreealyzer.TreealyzerInventory; import forestry.core.config.ForestryItem; import forestry.core.genetics.alleles.AlleleBoolean; import forestry.core.genetics.alleles.AllelePlantType; @@ -44,8 +44,8 @@ import forestry.core.utils.StringUtil; public class GuiTreealyzer extends GuiAlyzer { - public GuiTreealyzer(EntityPlayer player, TreealyzerInventory inventory) { - super("rootTrees", player, new ContainerAlyzer(inventory, player), inventory, "gui.treealyzer"); + public GuiTreealyzer(EntityPlayer player, ItemInventoryTreealyzer inventory) { + super(TreeManager.treeRoot, player, new ContainerAlyzer(inventory, player), inventory, "gui.treealyzer"); ArrayList treeList = new ArrayList<>(); ((ItemGermlingGE) ForestryItem.sapling.item()).addCreativeItems(treeList, false); @@ -64,8 +64,8 @@ public class GuiTreealyzer extends GuiAlyzer { int page = 0; ITree tree = null; EnumGermlingType treeType = EnumGermlingType.SAPLING; - for (int k = 1; k < TreealyzerInventory.SLOT_ANALYZE_5 + 1; k++) { - if (k == TreealyzerInventory.SLOT_ENERGY) { + for (int k = 1; k < ItemInventoryTreealyzer.SLOT_ANALYZE_5 + 1; k++) { + if (k == ItemInventoryTreealyzer.SLOT_ENERGY) { continue; } diff --git a/src/main/java/forestry/arboriculture/inventory/ItemInventoryTreealyzer.java b/src/main/java/forestry/arboriculture/inventory/ItemInventoryTreealyzer.java new file mode 100644 index 000000000..f5aa6e9ef --- /dev/null +++ b/src/main/java/forestry/arboriculture/inventory/ItemInventoryTreealyzer.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.arboriculture.inventory; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import forestry.api.arboriculture.TreeManager; +import forestry.core.config.Config; +import forestry.core.gui.IHintSource; +import forestry.core.inventory.ItemInventoryAlyzer; +import forestry.core.utils.GeneticsUtil; + +public class ItemInventoryTreealyzer extends ItemInventoryAlyzer implements IHintSource { + + public ItemInventoryTreealyzer(EntityPlayer player, ItemStack itemStack) { + super(TreeManager.treeRoot, player, itemStack); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (!TreeManager.treeRoot.isMember(itemStack)) { + ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(itemStack); + if (ersatz != null) { + return super.canSlotAccept(slotIndex, ersatz); + } + } + return super.canSlotAccept(slotIndex, itemStack); + } + + @Override + public void onSlotClick(EntityPlayer player) { + ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); + if (!TreeManager.treeRoot.isMember(specimen)) { + ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(specimen); + if (ersatz != null) { + setInventorySlotContents(SLOT_SPECIMEN, ersatz); + } + } + + super.onSlotClick(player); + } + + /* IHintSource */ + @Override + public List getHints() { + return Config.hints.get("treealyzer"); + } +} diff --git a/src/main/java/forestry/arboriculture/items/ItemGrafter.java b/src/main/java/forestry/arboriculture/items/ItemGrafter.java index 54025e0e6..4f972d07d 100755 --- a/src/main/java/forestry/arboriculture/items/ItemGrafter.java +++ b/src/main/java/forestry/arboriculture/items/ItemGrafter.java @@ -23,11 +23,9 @@ import forestry.api.core.Tabs; import forestry.core.items.ItemForestry; public class ItemGrafter extends ItemForestry implements IToolGrafter { - private final float efficiencyOnProperMaterial; public ItemGrafter(int maxDamage) { - super(); setMaxStackSize(1); efficiencyOnProperMaterial = 4.0F; setMaxDamage(maxDamage); @@ -53,11 +51,6 @@ public class ItemGrafter extends ItemForestry implements IToolGrafter { return true; } - /*@Override - public float getDamageVsEntity(Entity entity, ItemStack itemstack) { - return 1; - }*/ - @Override public boolean isFull3D() { return true; @@ -67,5 +60,4 @@ public class ItemGrafter extends ItemForestry implements IToolGrafter { public float getSaplingModifier(ItemStack stack, World world, EntityPlayer player, int x, int y, int z) { return 100f; } - } diff --git a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java deleted file mode 100755 index 8dcd01b4e..000000000 --- a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * 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.arboriculture.items; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import forestry.api.arboriculture.TreeManager; -import forestry.api.core.ForestryAPI; -import forestry.api.core.Tabs; -import forestry.api.genetics.ISpeciesRoot; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; -import forestry.core.items.ItemAlyzer; -import forestry.core.network.GuiId; -import forestry.core.utils.GeneticsUtil; - -public class ItemTreealyzer extends ItemAlyzer { - - public ItemTreealyzer() { - super(); - setMaxStackSize(1); - setCreativeTab(Tabs.tabArboriculture); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.TreealyzerGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } - - return itemstack; - } - - public static class TreealyzerInventory extends AlyzerInventory implements IHintSource { - - public TreealyzerInventory(EntityPlayer player, ItemStack itemStack) { - super(player, 7, itemStack); - } - - @Override - protected ISpeciesRoot getSpeciesRoot() { - return TreeManager.treeRoot; - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (!TreeManager.treeRoot.isMember(itemStack)) { - ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(itemStack); - if (ersatz != null) { - return super.canSlotAccept(slotIndex, ersatz); - } - } - return super.canSlotAccept(slotIndex, itemStack); - } - - @Override - public void onSlotClick(EntityPlayer player) { - ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); - if (!TreeManager.treeRoot.isMember(specimen)) { - ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(specimen); - if (ersatz != null) { - setInventorySlotContents(SLOT_SPECIMEN, ersatz); - } - } - - super.onSlotClick(player); - } - - // / IHINTSOURCE - @Override - public String[] getHints() { - return Config.hints.get("treealyzer"); - } - } - -} diff --git a/src/main/java/forestry/arboriculture/tiles/TileArboristChest.java b/src/main/java/forestry/arboriculture/tiles/TileArboristChest.java index 135a63521..e1e23acf0 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileArboristChest.java +++ b/src/main/java/forestry/arboriculture/tiles/TileArboristChest.java @@ -16,8 +16,6 @@ import forestry.core.tiles.TileNaturalistChest; public class TileArboristChest extends TileNaturalistChest { public TileArboristChest() { - super(TreeManager.treeRoot, GuiId.ArboristChestGUI.ordinal()); + super(TreeManager.treeRoot, GuiId.ArboristChestGUI); } - - } diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index a7686d3c9..81d4a6380 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -46,10 +46,10 @@ import forestry.api.genetics.IFruitBearer; import forestry.api.genetics.IFruitFamily; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; +import forestry.api.lepidopterology.ButterflyManager; import forestry.api.lepidopterology.IButterfly; import forestry.api.lepidopterology.IButterflyGenome; import forestry.api.lepidopterology.IButterflyNursery; -import forestry.api.lepidopterology.IButterflyRoot; import forestry.arboriculture.genetics.Tree; import forestry.arboriculture.genetics.TreeDefinition; import forestry.arboriculture.genetics.alleles.AlleleFruit; @@ -113,7 +113,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru if (nbttagcompound.hasKey("CATER")) { maturationTime = nbttagcompound.getInteger("CATMAT"); - caterpillar = (IButterfly) AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies").getMember(nbttagcompound.getCompoundTag("CATER")); + caterpillar = ButterflyManager.butterflyRoot.getMember(nbttagcompound.getCompoundTag("CATER")); } if (nbttagcompound.hasKey("Decorative")) { //legacy @@ -541,8 +541,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru } private static void attemptButterflySpawn(World world, IButterfly butterfly, double x, double y, double z) { - IButterflyRoot butterflyRoot = (IButterflyRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"); - if (butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), x, y + 0.1f, z) != null) { + if (ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), x, y + 0.1f, z) != null) { Log.finest("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), x, y, z); } } diff --git a/src/main/java/forestry/core/ForestryClient.java b/src/main/java/forestry/core/ForestryClient.java deleted file mode 100755 index f38f9e7ad..000000000 --- a/src/main/java/forestry/core/ForestryClient.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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; - -import cpw.mods.fml.client.registry.RenderingRegistry; - -import forestry.apiculture.render.RenderCandleBlock; -import forestry.core.proxy.Proxies; -import forestry.core.render.RenderBlock; - -public class ForestryClient extends ForestryCore { - - public static int byBlockModelId; - public static int candleRenderId; - - @Override - public void init(Object basemod) { - - super.init(basemod); - - byBlockModelId = Proxies.render.getNextAvailableRenderId(); - candleRenderId = Proxies.render.getNextAvailableRenderId(); - - RenderBlock renderHandler = new RenderBlock(); - RenderingRegistry.registerBlockHandler(byBlockModelId, renderHandler); - RenderingRegistry.registerBlockHandler(candleRenderId, new RenderCandleBlock()); - } - - @Override - public void postInit() { - super.postInit(); - } - -} diff --git a/src/main/java/forestry/core/ForestryCore.java b/src/main/java/forestry/core/ForestryCore.java deleted file mode 100755 index 662d24ca8..000000000 --- a/src/main/java/forestry/core/ForestryCore.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * 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; - -import com.google.common.collect.ImmutableList; - -import java.io.File; - -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.server.MinecraftServer; - -import net.minecraftforge.common.MinecraftForge; - -import cpw.mods.fml.common.event.FMLInterModComms; -import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.registry.GameRegistry; - -import forestry.api.core.ForestryAPI; -import forestry.api.fuels.EngineBronzeFuel; -import forestry.api.fuels.EngineCopperFuel; -import forestry.api.fuels.FermenterFuel; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.MoistenerFuel; -import forestry.api.fuels.RainSubstrate; -import forestry.core.config.Config; -import forestry.core.config.Constants; -import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; -import forestry.core.errors.EnumErrorCode; -import forestry.core.errors.ErrorStateRegistry; -import forestry.core.fluids.Fluids; -import forestry.core.multiblock.MultiblockEventHandler; -import forestry.core.proxy.Proxies; -import forestry.core.worldgen.WorldGenerator; -import forestry.plugins.PluginManager; - -public class ForestryCore { - - public void preInit(File modLocation, Object basemod) { - ForestryAPI.instance = basemod; - ForestryAPI.forestryConstants = new Constants(); - ForestryAPI.errorStateRegistry = new ErrorStateRegistry(); - - // Register event handler - MinecraftForge.EVENT_BUS.register(new EventHandlerCore()); - MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler()); - - Config.load(); - - EnumErrorCode.init(); - - PluginManager.runSetup(); - PluginManager.runPreInit(); - } - - public void init(Object basemod) { - // Set fuels and resources for the fermenter - FuelManager.fermenterFuel.put(ForestryItem.fertilizerCompound.getItemStack(), new FermenterFuel(ForestryItem.fertilizerCompound.getItemStack(), - GameMode.getGameMode().getIntegerSetting("fermenter.value.fertilizer"), GameMode.getGameMode().getIntegerSetting("fermenter.cycles.fertilizer"))); - FuelManager.fermenterFuel.put(ForestryItem.fertilizerBio.getItemStack(), new FermenterFuel(ForestryItem.fertilizerBio.getItemStack(), GameMode - .getGameMode().getIntegerSetting("fermenter.value.compost"), GameMode.getGameMode().getIntegerSetting("fermenter.cycles.compost"))); - FuelManager.fermenterFuel.put(ForestryItem.mulch.getItemStack(), new FermenterFuel(ForestryItem.mulch.getItemStack(), GameMode.getGameMode() - .getIntegerSetting("fermenter.value.compost"), GameMode.getGameMode().getIntegerSetting("fermenter.cycles.compost"))); - - // Add moistener resources - FuelManager.moistenerResource.put(new ItemStack(Items.wheat), new MoistenerFuel(new ItemStack(Items.wheat), ForestryItem.mouldyWheat.getItemStack(), 0, - 300)); - FuelManager.moistenerResource.put(ForestryItem.mouldyWheat.getItemStack(), new MoistenerFuel(ForestryItem.mouldyWheat.getItemStack(), ForestryItem.decayingWheat.getItemStack(), 1, 600)); - FuelManager.moistenerResource.put(ForestryItem.decayingWheat.getItemStack(), new MoistenerFuel(ForestryItem.decayingWheat.getItemStack(), - ForestryItem.mulch.getItemStack(), 2, 900)); - - // Set fuels for our own engines - FuelManager.copperEngineFuel.put(ForestryItem.peat.getItemStack(), new EngineCopperFuel(ForestryItem.peat.getItemStack(), - Constants.ENGINE_COPPER_FUEL_VALUE_PEAT, Constants.ENGINE_COPPER_CYCLE_DURATION_PEAT)); - FuelManager.copperEngineFuel.put(ForestryItem.bituminousPeat.getItemStack(), new EngineCopperFuel(ForestryItem.bituminousPeat.getItemStack(), - Constants.ENGINE_COPPER_FUEL_VALUE_BITUMINOUS_PEAT, Constants.ENGINE_COPPER_CYCLE_DURATION_BITUMINOUS_PEAT)); - - FuelManager.bronzeEngineFuel.put(Fluids.BIOMASS.getFluid(), new EngineBronzeFuel(Fluids.BIOMASS.getFluid(), - Constants.ENGINE_FUEL_VALUE_BIOMASS, (int) (Constants.ENGINE_CYCLE_DURATION_BIOMASS * GameMode.getGameMode().getFloatSetting("fuel.biomass.biogas")), 1)); - FuelManager.bronzeEngineFuel.put(Fluids.WATER.getFluid(), new EngineBronzeFuel(Fluids.WATER.getFluid(), - Constants.ENGINE_FUEL_VALUE_WATER, Constants.ENGINE_CYCLE_DURATION_WATER, 3)); - FuelManager.bronzeEngineFuel.put(Fluids.MILK.getFluid(), new EngineBronzeFuel(Fluids.MILK.getFluid(), - Constants.ENGINE_FUEL_VALUE_MILK, Constants.ENGINE_CYCLE_DURATION_MILK, 3)); - FuelManager.bronzeEngineFuel.put(Fluids.SEEDOIL.getFluid(), new EngineBronzeFuel(Fluids.SEEDOIL.getFluid(), - Constants.ENGINE_FUEL_VALUE_SEED_OIL, Constants.ENGINE_CYCLE_DURATION_SEED_OIL, 1)); - FuelManager.bronzeEngineFuel.put(Fluids.HONEY.getFluid(), new EngineBronzeFuel(Fluids.HONEY.getFluid(), - Constants.ENGINE_FUEL_VALUE_HONEY, Constants.ENGINE_CYCLE_DURATION_HONEY, 1)); - FuelManager.bronzeEngineFuel.put(Fluids.JUICE.getFluid(), new EngineBronzeFuel(Fluids.JUICE.getFluid(), - Constants.ENGINE_FUEL_VALUE_JUICE, Constants.ENGINE_CYCLE_DURATION_JUICE, 1)); - - // Set rain substrates - FuelManager.rainSubstrate.put(ForestryItem.iodineCharge.getItemStack(), new RainSubstrate(ForestryItem.iodineCharge.getItemStack(), - Constants.RAINMAKER_RAIN_DURATION_IODINE, 0.01f)); - FuelManager.rainSubstrate.put(ForestryItem.craftingMaterial.getItemStack(1, 4), new RainSubstrate(ForestryItem.craftingMaterial.getItemStack(1, 4), 0.075f)); - - // Register gui handler - NetworkRegistry.INSTANCE.registerGuiHandler(basemod, new GuiHandler()); - - PluginManager.runInit(); - } - - public void postInit() { - PluginManager.runPostInit(); - - // Register world generator - WorldGenerator worldGenerator = new WorldGenerator(); - GameRegistry.registerWorldGenerator(worldGenerator, 0); - - // Register tick handlers - Proxies.common.registerTickHandlers(worldGenerator); - - // Handle IMC messages. - processIMCMessages(FMLInterModComms.fetchRuntimeMessages(ForestryAPI.instance)); - } - - public void serverStarting(MinecraftServer server) { - PluginManager.serverStarting(server); - } - - public void processIMCMessages(ImmutableList messages) { - PluginManager.processIMCMessages(messages); - } - -} diff --git a/src/main/java/forestry/core/GuiHandler.java b/src/main/java/forestry/core/GuiHandler.java index 143589242..4ca41581a 100755 --- a/src/main/java/forestry/core/GuiHandler.java +++ b/src/main/java/forestry/core/GuiHandler.java @@ -18,11 +18,11 @@ import cpw.mods.fml.common.network.IGuiHandler; import forestry.core.circuits.ContainerSolderingIron; import forestry.core.circuits.GuiSolderingIron; -import forestry.core.circuits.ItemSolderingIron.SolderingInventory; import forestry.core.gui.ContainerAnalyzer; import forestry.core.gui.ContainerEscritoire; import forestry.core.gui.GuiAnalyzer; import forestry.core.gui.GuiEscritoire; +import forestry.core.inventory.ItemInventorySolderingIron; import forestry.core.network.GuiId; import forestry.core.tiles.TileAnalyzer; import forestry.core.tiles.TileEscritoire; @@ -49,7 +49,7 @@ public class GuiHandler extends GuiHandlerBase { if (equipped == null) { return null; } - return new GuiSolderingIron(player, new SolderingInventory(player, equipped)); + return new GuiSolderingIron(player, new ItemInventorySolderingIron(player, equipped)); default: for (IGuiHandler handler : PluginManager.guiHandlers) { @@ -84,7 +84,7 @@ public class GuiHandler extends GuiHandlerBase { if (equipped == null) { return null; } - return new ContainerSolderingIron(player, new SolderingInventory(player, equipped)); + return new ContainerSolderingIron(player, new ItemInventorySolderingIron(player, equipped)); default: for (IGuiHandler handler : PluginManager.guiHandlers) { diff --git a/src/main/java/forestry/core/GuiHandlerBase.java b/src/main/java/forestry/core/GuiHandlerBase.java index bf0802a91..ed2e8c2a5 100755 --- a/src/main/java/forestry/core/GuiHandlerBase.java +++ b/src/main/java/forestry/core/GuiHandlerBase.java @@ -18,6 +18,7 @@ import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.genetics.ISpeciesRoot; import forestry.core.gui.ContainerNaturalistInventory; import forestry.core.gui.GuiNaturalistInventory; +import forestry.core.network.GuiId; import forestry.core.tiles.TileNaturalistChest; import forestry.core.tiles.TileUtil; @@ -33,8 +34,8 @@ public abstract class GuiHandlerBase implements IGuiHandler { return new ContainerNaturalistInventory(player.inventory, TileUtil.getTile(world, x, y, z, TileNaturalistChest.class), page); } - public static int encodeGuiData(int guiId, int data) { - return data << 8 | guiId; + public static int encodeGuiData(GuiId guiId, int data) { + return data << 8 | guiId.ordinal(); } protected static int decodeGuiID(int guiId) { diff --git a/src/main/java/forestry/core/blocks/BlockBase.java b/src/main/java/forestry/core/blocks/BlockBase.java index dd598e79f..5a09bf9ba 100644 --- a/src/main/java/forestry/core/blocks/BlockBase.java +++ b/src/main/java/forestry/core/blocks/BlockBase.java @@ -40,7 +40,7 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.core.access.IAccessHandler; import forestry.core.circuits.ISocketable; import forestry.core.fluids.FluidHelper; -import forestry.core.proxy.Proxies; +import forestry.core.proxy.ProxyRenderClient; import forestry.core.tiles.MachineDefinition; import forestry.core.tiles.TileBase; import forestry.core.tiles.TileForestry; @@ -90,7 +90,7 @@ public class BlockBase extends BlockForestry { @Override public int getRenderType() { if (hasTESR) { - return Proxies.common.getByBlockModelId(); + return ProxyRenderClient.getByBlockModelRenderId(); } else { return 0; } diff --git a/src/main/java/forestry/core/circuits/Circuit.java b/src/main/java/forestry/core/circuits/Circuit.java index 724e54d09..67721a09f 100755 --- a/src/main/java/forestry/core/circuits/Circuit.java +++ b/src/main/java/forestry/core/circuits/Circuit.java @@ -70,7 +70,6 @@ public abstract class Circuit implements ICircuit { } public static ICircuit energyElectricChoke1; - public static ICircuit energyFireDampener1; public static ICircuit energyElectricEfficiency1; public static ICircuit energyElectricBoost1; public static ICircuit energyElectricBoost2; diff --git a/src/main/java/forestry/core/circuits/CircuitBoard.java b/src/main/java/forestry/core/circuits/CircuitBoard.java index 5936be72e..2119ef0d1 100755 --- a/src/main/java/forestry/core/circuits/CircuitBoard.java +++ b/src/main/java/forestry/core/circuits/CircuitBoard.java @@ -42,12 +42,12 @@ public class CircuitBoard implements ICircuitBoard { @Override public int getPrimaryColor() { - return type.primaryColor; + return type.getPrimaryColor(); } @Override public int getSecondaryColor() { - return type.secondaryColor; + return type.getSecondaryColor(); } @Override diff --git a/src/main/java/forestry/core/circuits/CircuitRecipe.java b/src/main/java/forestry/core/circuits/CircuitRecipe.java new file mode 100644 index 000000000..17dc0721f --- /dev/null +++ b/src/main/java/forestry/core/circuits/CircuitRecipe.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.circuits; + +import net.minecraft.item.ItemStack; + +import forestry.api.circuits.ICircuit; +import forestry.api.circuits.ICircuitLayout; + +public class CircuitRecipe { + + private final ICircuitLayout layout; + private final ItemStack resource; + private final ICircuit circuit; + + public CircuitRecipe(ICircuitLayout layout, ItemStack resource, ICircuit circuit) { + this.resource = resource; + this.layout = layout; + this.circuit = circuit; + } + + public boolean matches(ICircuitLayout layout, ItemStack itemstack) { + if (!this.layout.getUID().equals(layout.getUID())) { + return false; + } + + return itemstack.isItemEqual(resource); + } + + public ICircuit getCircuit() { + return circuit; + } + + public ItemStack getResource() { + return resource; + } +} diff --git a/src/main/java/forestry/core/circuits/ContainerSolderingIron.java b/src/main/java/forestry/core/circuits/ContainerSolderingIron.java index 730424a09..1af798710 100755 --- a/src/main/java/forestry/core/circuits/ContainerSolderingIron.java +++ b/src/main/java/forestry/core/circuits/ContainerSolderingIron.java @@ -14,20 +14,20 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import forestry.api.circuits.ICircuitLayout; -import forestry.core.circuits.ItemSolderingIron.SolderingInventory; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.IGuiSelectable; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.core.inventory.ItemInventorySolderingIron; import forestry.core.network.IForestryPacketClient; import forestry.core.network.IForestryPacketServer; import forestry.core.network.PacketGuiLayoutSelect; import forestry.core.network.PacketGuiSelectRequest; import forestry.core.proxy.Proxies; -public class ContainerSolderingIron extends ContainerItemInventory implements IGuiSelectable { +public class ContainerSolderingIron extends ContainerItemInventory implements IGuiSelectable { - public ContainerSolderingIron(EntityPlayer player, SolderingInventory inventory) { + public ContainerSolderingIron(EntityPlayer player, ItemInventorySolderingIron inventory) { super(inventory, player.inventory, 8, 123); // Input diff --git a/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java b/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java index 763e304ea..9fc24e09c 100755 --- a/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java +++ b/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java @@ -14,13 +14,25 @@ public enum EnumCircuitBoardType { BASIC((short) 1, 0x191919, 0x6dcff6), ENHANCED((short) 2, 0x191919, 0xcb7c32), REFINED((short) 3, 0x191919, 0xc9c9c9), INTRICATE((short) 4, 0x191919, 0xe2cb6b); - final short sockets; - final int primaryColor; - final int secondaryColor; + private final short sockets; + private final int primaryColor; + private final int secondaryColor; EnumCircuitBoardType(short sockets, int primaryColor, int secondaryColor) { this.sockets = sockets; this.primaryColor = primaryColor; this.secondaryColor = secondaryColor; } + + public short getSockets() { + return sockets; + } + + public int getPrimaryColor() { + return primaryColor; + } + + public int getSecondaryColor() { + return secondaryColor; + } } diff --git a/src/main/java/forestry/core/circuits/GuiSolderingIron.java b/src/main/java/forestry/core/circuits/GuiSolderingIron.java index f5e359498..9c3a7c257 100755 --- a/src/main/java/forestry/core/circuits/GuiSolderingIron.java +++ b/src/main/java/forestry/core/circuits/GuiSolderingIron.java @@ -20,15 +20,14 @@ import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitLayout; import forestry.api.circuits.ICircuitSocketType; import forestry.api.farming.FarmDirection; -import forestry.core.circuits.ItemSolderingIron.CircuitRecipe; -import forestry.core.circuits.ItemSolderingIron.SolderingInventory; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; +import forestry.core.inventory.ItemInventorySolderingIron; import forestry.core.utils.StringUtil; -public class GuiSolderingIron extends GuiForestry { +public class GuiSolderingIron extends GuiForestry { - public GuiSolderingIron(EntityPlayer player, SolderingInventory inventory) { + public GuiSolderingIron(EntityPlayer player, ItemInventorySolderingIron inventory) { super(Constants.TEXTURE_PATH_GUI + "/solder.png", new ContainerSolderingIron(player, inventory), inventory); xSize = 176; @@ -46,11 +45,11 @@ public class GuiSolderingIron extends GuiForestry recipes = new ArrayList<>(); - - @Override - public void addRecipe(ICircuitLayout layout, ItemStack resource, ICircuit circuit) { - if (layout == null) { - throw new IllegalArgumentException("layout may not be null"); - } - if (resource == null) { - throw new IllegalArgumentException("resource may not be null"); - } - if (circuit == null) { - throw new IllegalArgumentException("circuit may not be null"); - } - recipes.add(new CircuitRecipe(layout, resource, circuit)); - } - - public static ICircuit getCircuit(ICircuitLayout layout, ItemStack resource) { - CircuitRecipe circuitRecipe = getMatchingRecipe(layout, resource); - if (circuitRecipe == null) { - return null; - } - return circuitRecipe.circuit; - } - - public static CircuitRecipe getMatchingRecipe(ICircuitLayout layout, ItemStack resource) { - if (layout == null || resource == null) { - return null; - } - - for (CircuitRecipe recipe : recipes) { - if (recipe.matches(layout, resource)) { - return recipe; - } - } - - return null; - } - } - - // / INVENTORY MANAGMENT - public static class SolderingInventory extends ItemInventory implements IErrorSource { - - private final RevolvingList layouts = new RevolvingList<>(ChipsetManager.circuitRegistry.getRegisteredLayouts().values()); - - private static final short blankSlot = 0; - private static final short finishedSlot = 1; - private static final short ingredientSlot1 = 2; - private static final short ingredientSlotCount = 4; - - public SolderingInventory(EntityPlayer player, ItemStack itemStack) { - super(player, 6, itemStack); - - layouts.setCurrent(ChipsetManager.circuitRegistry.getDefaultLayout()); - } - - @Override - public int getInventoryStackLimit() { - return 1; - } - - public ICircuitLayout getLayout() { - return layouts.getCurrent(); - } - - public void setLayout(String uid) { - layouts.setCurrent(ChipsetManager.circuitRegistry.getLayout(uid)); - } - - public void advanceLayout() { - layouts.rotateRight(); - } - - public void regressLayout() { - layouts.rotateLeft(); - } - - private ICircuit[] getCircuits(boolean doConsume) { - - ICircuit[] circuits = new ICircuit[ingredientSlotCount]; - - for (short i = 0; i < ingredientSlotCount; i++) { - ItemStack ingredient = getStackInSlot(ingredientSlot1 + i); - if (ingredient == null) { - continue; - } - - CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), ingredient); - if (recipe == null) { - continue; - } - - // / Make sure we don't exceed this circuits limit per chipset - if (getCount(recipe.circuit, circuits) >= recipe.circuit.getLimit()) { - continue; - } - - if (doConsume) { - decrStackSize(ingredientSlot1 + i, recipe.resource.stackSize); - } - circuits[i] = recipe.circuit; - } - - return circuits; - } - - @Override - public void onSlotClick(EntityPlayer player) { - if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) { - return; - } - - ItemStack blank = getStackInSlot(blankSlot); - // Requires blank slot - if (blank == null) { - return; - } - if (blank.stackSize > 1) { - return; - } - if (getStackInSlot(finishedSlot) != null) { - return; - } - - // Need a chipset item - if (!ChipsetManager.circuitRegistry.isChipset(blank)) { - return; - } - - // Illegal type - if (blank.getItemDamage() < 0 || blank.getItemDamage() >= EnumCircuitBoardType.values().length) { - return; - } - - EnumCircuitBoardType type = EnumCircuitBoardType.values()[blank.getItemDamage()]; - if (getCircuitCount() != type.sockets) { - return; - } - - ICircuit[] circuits = getCircuits(true); - - ItemStack circuitBoard = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuits); - - setInventorySlotContents(finishedSlot, circuitBoard); - setInventorySlotContents(blankSlot, null); - } - - private int getCircuitCount() { - ICircuit[] circuits = getCircuits(false); - int count = 0; - for (ICircuit circuit : circuits) { - if (circuit != null) { - count++; - } - } - return count; - } - - public static int getCount(ICircuit circuit, ICircuit[] circuits) { - int count = 0; - for (ICircuit other : circuits) { - if (other != null && other.getUID().equals(circuit.getUID())) { - count++; - } - } - return count; - } - - @Override - public ImmutableSet getErrorStates() { - ImmutableSet.Builder errorStates = ImmutableSet.builder(); - - if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) { - errorStates.add(EnumErrorCode.NOCIRCUITLAYOUT); - } - - ItemStack blankCircuitBoard = getStackInSlot(blankSlot); - - if (blankCircuitBoard == null) { - errorStates.add(EnumErrorCode.NOCIRCUITBOARD); - } else { - EnumCircuitBoardType type = EnumCircuitBoardType.values()[blankCircuitBoard.getItemDamage()]; - - int circuitCount = 0; - for (short i = 0; i < type.sockets; i++) { - if (getStackInSlot(ingredientSlot1 + i) != null) { - circuitCount++; - } - } - - if (circuitCount != type.sockets) { - errorStates.add(EnumErrorCode.CIRCUITMISMATCH); - } else { - int count = getCircuitCount(); - if (count != type.sockets) { - errorStates.add(EnumErrorCode.NOCIRCUITLAYOUT); - } - } - } - - return errorStates.build(); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (itemStack == null) { - return false; - } - - Item item = itemStack.getItem(); - if (slotIndex == blankSlot) { - return item instanceof ItemCircuitBoard; - } else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) { - CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), itemStack); - return recipe != null; - } - return false; - } - } - - public ItemSolderingIron() { - super(); - setMaxStackSize(1); - setMaxDamage(5); - } - - @Override - public boolean isFull3D() { - return true; - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.SolderingIronGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } - - return itemstack; - } -} diff --git a/src/main/java/forestry/core/circuits/SolderManager.java b/src/main/java/forestry/core/circuits/SolderManager.java new file mode 100644 index 000000000..e07215e61 --- /dev/null +++ b/src/main/java/forestry/core/circuits/SolderManager.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.circuits; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; + +import forestry.api.circuits.ICircuit; +import forestry.api.circuits.ICircuitLayout; +import forestry.api.circuits.ISolderManager; + +public class SolderManager implements ISolderManager { + private static final List recipes = new ArrayList<>(); + + @Override + public void addRecipe(ICircuitLayout layout, ItemStack resource, ICircuit circuit) { + if (layout == null) { + throw new IllegalArgumentException("layout may not be null"); + } + if (resource == null) { + throw new IllegalArgumentException("resource may not be null"); + } + if (circuit == null) { + throw new IllegalArgumentException("circuit may not be null"); + } + recipes.add(new CircuitRecipe(layout, resource, circuit)); + } + + public static ICircuit getCircuit(ICircuitLayout layout, ItemStack resource) { + CircuitRecipe circuitRecipe = getMatchingRecipe(layout, resource); + if (circuitRecipe == null) { + return null; + } + return circuitRecipe.getCircuit(); + } + + public static CircuitRecipe getMatchingRecipe(ICircuitLayout layout, ItemStack resource) { + if (layout == null || resource == null) { + return null; + } + + for (CircuitRecipe recipe : recipes) { + if (recipe.matches(layout, resource)) { + return recipe; + } + } + + return null; + } +} diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index 61305dc0e..3e3451b28 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -10,15 +10,15 @@ ******************************************************************************/ package forestry.core.config; +import com.google.common.collect.LinkedListMultimap; + import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Properties; import java.util.Set; @@ -35,9 +35,6 @@ public class Config { public static final String CATEGORY_COMMON = "common"; public static final String CATEGORY_FLUIDS = "fluids"; - public static final String CATEGORY_DEBUG = "debug"; - - public static forestry.core.config.deprecated.Configuration configOld; public static LocalizedConfiguration configCommon; public static LocalizedConfiguration configFluid; @@ -98,7 +95,7 @@ public class Config { // Hints public static boolean enableHints = true; - public static final Map hints = new HashMap<>(); + public static final LinkedListMultimap hints = LinkedListMultimap.create(); public static boolean enableEnergyStat = true; public static boolean isStructureEnabled(String uid) { @@ -130,53 +127,16 @@ public class Config { } public static void load() { + File configCommonFile = new File(Forestry.instance.getConfigFolder(), CATEGORY_COMMON + ".cfg"); + loadConfigCommon(configCommonFile); - configOld = new forestry.core.config.deprecated.Configuration(); - - final String oldConfigCommon = CATEGORY_COMMON + ".conf"; - final String newConfigCommon = CATEGORY_COMMON + ".cfg"; - File newConfigCommonFile = new File(Forestry.instance.getConfigFolder(), newConfigCommon); - File oldConfigCommonFile = new File(Forestry.instance.getConfigFolder(), oldConfigCommon); - if (oldConfigCommonFile.exists()) { - loadOldConfigCommon(); - - final String oldConfigRenamed = CATEGORY_COMMON + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigCommonFile.renameTo(oldConfigFileRenamed)) { - Log.info("Migrated " + CATEGORY_COMMON + " settings to the new file '" + newConfigCommon + "' and renamed '" + oldConfigCommon + "' to '" + oldConfigRenamed + "'."); - } - } - loadNewConfigCommon(newConfigCommonFile); - - final String oldConfigFluids = CATEGORY_FLUIDS + ".conf"; - final String newConfigFluids = CATEGORY_FLUIDS + ".cfg"; - File newConfigFluidsFile = new File(Forestry.instance.getConfigFolder(), newConfigFluids); - File oldConfigFluidsFile = new File(Forestry.instance.getConfigFolder(), oldConfigFluids); - if (oldConfigFluidsFile.exists()) { - loadOldConfigFluids(); - - final String oldConfigRenamed = CATEGORY_FLUIDS + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigFluidsFile.renameTo(oldConfigFileRenamed)) { - Log.info("Migrated " + CATEGORY_FLUIDS + " settings to the new file '" + newConfigFluids + "' and renamed '" + oldConfigFluids + "' to '" + oldConfigRenamed + "'."); - } - } - loadNewConfigFluids(newConfigFluidsFile); - - final String oldConfigDebug = CATEGORY_DEBUG + ".conf"; - File oldConfigDebugFile = new File(Forestry.instance.getConfigFolder(), oldConfigDebug); - if (oldConfigDebugFile.exists()) { - final String oldConfigRenamed = CATEGORY_DEBUG + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigDebugFile.renameTo(oldConfigFileRenamed)) { - Log.info("Renamed '" + oldConfigDebug + "' to '" + oldConfigRenamed + "'."); - } - } + File configFluidsFile = new File(Forestry.instance.getConfigFolder(), CATEGORY_FLUIDS + ".cfg"); + loadConfigFluids(configFluidsFile); loadHints(); } - private static void loadNewConfigCommon(File configFileCommon) { + private static void loadConfigCommon(File configFileCommon) { configCommon = new LocalizedConfiguration(configFileCommon, "1.1.0"); @@ -279,139 +239,7 @@ public class Config { configCommon.save(); } - private static void loadOldConfigCommon() { - forestry.core.config.deprecated.Property property; - - property = configOld.get("difficulty.gamemode", CATEGORY_COMMON, "EASY"); - property.comment = "set to your preferred game mode. available modes are OP, EASY, NORMAL, HARD. mismatch with the server may cause visual glitches with recipes. setting an unavailable mode will create a new mode definition file."; - gameMode = property.value; - - property = configOld.get("performance.particleFX.enabled", CATEGORY_COMMON, true); - property.comment = "set to false to disable particle fx on slower machines"; - enableParticleFX = Boolean.parseBoolean(property.value); - - // RetroGen - - String retroGenMessage = "Forestry will attempt worldGen in chunks that were created before the mod was added."; - property = configOld.get("world.retrogen.normal", CATEGORY_COMMON, false); - property.comment = "Set to true, " + retroGenMessage; - doRetrogen = Boolean.parseBoolean(property.value); - - String forcedRetroGenMessage = "Forestry will attempt worldGen in all chunks for this game instance. Config option will be set to false after this run."; - String forcedRetroGenKey = "world.retrogen.forced"; - property = configOld.get(forcedRetroGenKey, CATEGORY_COMMON, false); - property.comment = "Set to true, " + forcedRetroGenMessage; - forceRetrogen = Boolean.parseBoolean(property.value); - - if (forceRetrogen) { - Log.info(forcedRetroGenMessage); - configOld.set(forcedRetroGenKey, CATEGORY_COMMON, false); - doRetrogen = true; - } else if (doRetrogen) { - Log.info(retroGenMessage); - } - - property = configOld.get("world.generate.apatite", CATEGORY_COMMON, true); - property.comment = "set to false to force forestry to skip generating own apatite ore blocks in the world"; - generateApatiteOre = Boolean.parseBoolean(property.value); - - property = configOld.get("world.generate.beehives.rate", CATEGORY_COMMON, generateBeehivesAmount); - property.comment = "set how many beehives spawn. Default is 1.0, double is 2.0, half is 0.5 etc."; - generateBeehivesAmount = Float.parseFloat(property.value); - - property = configOld.get("world.generate.beehives", CATEGORY_COMMON, true); - property.comment = "set to false to force forestry to skip generating beehives in the world"; - boolean generateBeehives = Boolean.parseBoolean(property.value); - if (!generateBeehives) { - generateBeehivesAmount = 0.0f; - } - - property = configOld.get("world.generate.beehives.debug", CATEGORY_DEBUG, false); - property.comment = "Set to true to force Forestry to try to generate a beehive at every possible location."; - generateBeehivesDebug = Boolean.parseBoolean(property.value); - - property = configOld.get("world.generate.copper", CATEGORY_COMMON, true); - property.comment = "set to false to force forestry to skip generating own copper ore blocks in the world"; - generateCopperOre = Boolean.parseBoolean(property.value); - - property = configOld.get("world.generate.tin", CATEGORY_COMMON, true); - property.comment = "set to false to force forestry to skip generating own tin ore blocks in the world"; - generateTinOre = Boolean.parseBoolean(property.value); - - property = configOld.get("world.generate.villager", CATEGORY_COMMON, true); - property.comment = "set to false to disable the creation of forestry villagers and their houses"; - enableVillagers = Boolean.parseBoolean(property.value); - - property = configOld.get("crafting.bronze.enabled", CATEGORY_COMMON, true); - property.comment = "set to false to disable crafting recipe for bronze"; - craftingBronzeEnabled = Boolean.parseBoolean(property.value); - - property = configOld.get("crafting.stamps.enabled", CATEGORY_COMMON, true); - property.comment = "set to false to disable crafting recipes for all types of stamps."; - craftingStampsEnabled = Boolean.parseBoolean(property.value); - - String defaultCollectors = "20n;50n;100n;200n"; - property = configOld.get("crafting.stamps.collector", CATEGORY_COMMON, defaultCollectors); - property.comment = "if crafting of stamps is generally allowed, these stamps are still excluded from crafting."; - try { - collectorStamps.addAll(Arrays.asList(parseStamps(property.value))); - } catch (Exception ex) { - configOld.set("crafting.stamps.collector", CATEGORY_COMMON, defaultCollectors); - collectorStamps.addAll(Arrays.asList(parseStamps(defaultCollectors))); - } - - property = configOld.get("tweaks.mailalert.enabled", CATEGORY_COMMON, true); - property.comment = "set to false to disable the mail alert box"; - mailAlertEnabled = Boolean.parseBoolean(property.value); - - property = configOld.get("tweaks.gui.tab.speed", CATEGORY_COMMON, guiTabSpeed); - property.comment = "set the speed at which the gui side tabs open and close."; - guiTabSpeed = Integer.parseInt(property.value); - - property = configOld.get("genetics.clear.invalid.chromosomes", CATEGORY_COMMON, clearInvalidChromosomes); - property.comment = "set to true to clear chromosomes which contain invalid alleles. might rescue your save if it is crashing after the removal of a bee addon."; - clearInvalidChromosomes = Boolean.parseBoolean(property.value); - - property = configOld.get("difficulty.dungeonloot.rare", CATEGORY_COMMON, false); - property.comment = "set to true to make dungeon loot generated by forestry rarer"; - dungeonLootRare = Boolean.parseBoolean(property.value); - - property = configOld.get("performance.backpacks.resupply", CATEGORY_COMMON, true); - property.comment = "leaving this enabled will cycle the list of active players PER INGAME TICK to check for resupply via backpack. you want to set this to false on busy servers."; - Config.enableBackpackResupply = Boolean.parseBoolean(property.value); - - property = configOld.get("tweaks.hints.disabled", CATEGORY_COMMON, false); - property.comment = "set to true to disable hints on machine and engine guis."; - Config.enableHints = !Boolean.parseBoolean(property.value); - property = configOld.get("tweaks.energystat.disabled", CATEGORY_COMMON, true); - property.comment = "set to true to disable energy statistics on energy consumers."; - Config.enableEnergyStat = !Boolean.parseBoolean(property.value); - - property = configOld.get("tweaks.permissions.disabled", CATEGORY_COMMON, false); - property.comment = "set to true to disable access restrictions on forestry machines."; - Config.enablePermissions = !Boolean.parseBoolean(property.value); - - property = configOld.get("tweaks.farms.squared", CATEGORY_COMMON, false); - property.comment = "set to true to have farms use a square layout instead of a diamond one."; - Config.squareFarms = Boolean.parseBoolean(property.value); - - property = configOld.get("tweaks.farms.exutilenderlily", CATEGORY_COMMON, true); - property.comment = "set to false to disable multifarm support for ExtraUtilities Ender-lily seeds."; - enableExUtilEnderLily = Boolean.parseBoolean(property.value); - - property = configOld.get("tweaks.farms.magicalcropssupport", CATEGORY_COMMON, true); - property.comment = "set to false to disable multifarm support for Magical Crops crops."; - enableMagicalCropsSupport = Boolean.parseBoolean(property.value); - - property = configOld.get("structures.schemata.disabled", CATEGORY_COMMON, ""); - property.comment = "add schemata keys to disable them. current keys: alveary3x3;farm3x3;farm3x4;farm3x5;farm4x4;farm5x5"; - disabledStructures.addAll(Arrays.asList(parseStructureKeys(property.value))); - for (String str : disabledStructures) { - Log.finer("Disabled structure '%s'.", str); - } - } - - private static void loadNewConfigFluids(File configFile) { + private static void loadConfigFluids(File configFile) { configFluid = new LocalizedConfiguration(configFile, "1.0.0"); for (Fluids fluid : Fluids.forestryFluids) { @@ -435,23 +263,6 @@ public class Config { configFluid.save(); } - private static void loadOldConfigFluids() { - forestry.core.config.deprecated.Property property; - for (Fluids fluid : Fluids.forestryFluids) { - property = configOld.get("disable.fluid." + fluid.getTag(), CATEGORY_FLUIDS, false); - property.comment = "set to true to disable the fluid for " + fluid.getTag(); - if (Boolean.parseBoolean(property.value)) { - Config.disabledFluids.add(fluid.getTag()); - } - - property = configOld.get("disable.fluidBlock." + fluid.getTag(), CATEGORY_FLUIDS, false); - property.comment = "set to true to disable the in-world FluidBlock for " + fluid.getTag(); - if (Boolean.parseBoolean(property.value)) { - Config.disabledBlocks.add(fluid.getTag()); - } - } - } - private static void CopyFileToFS(File destination, String resourcePath) { InputStream stream = Config.class.getResourceAsStream(resourcePath); OutputStream outstream; @@ -488,7 +299,12 @@ public class Config { } for (String key : prop.stringPropertyNames()) { - hints.put(key, parseHints(prop.getProperty(key))); + String[] parsedHints = parseHints(prop.getProperty(key)); + if (parsedHints != null) { + for (String parsedHint : parsedHints) { + hints.put(key, parsedHint); + } + } } } @@ -499,21 +315,4 @@ public class Config { return list.split("[;]+"); } } - - private static String[] parseStructureKeys(String list) { - if (list.isEmpty()) { - return new String[0]; - } else { - return list.split("[;]+"); - } - - } - - private static String[] parseStamps(String list) { - if (list.isEmpty()) { - return new String[0]; - } else { - return list.split("[;]+"); - } - } } diff --git a/src/main/java/forestry/core/config/ForestryBlock.java b/src/main/java/forestry/core/config/ForestryBlock.java index 2cac534ab..184dafa3f 100755 --- a/src/main/java/forestry/core/config/ForestryBlock.java +++ b/src/main/java/forestry/core/config/ForestryBlock.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.core.config; -import java.util.EnumSet; - import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; @@ -82,8 +80,8 @@ public enum ForestryBlock { private Block block; public void registerBlock(Block block, Class itemClass, String name) { - if (!EnumSet.of(Stage.PRE_INIT).contains(PluginManager.getStage())) { - throw new RuntimeException("Tried to register Block outside of Pre-Init"); + if (PluginManager.getStage() != Stage.SETUP) { + throw new RuntimeException("Tried to register Block outside of Setup"); } this.block = block; block.setBlockName("for." + name); diff --git a/src/main/java/forestry/core/config/ForestryItem.java b/src/main/java/forestry/core/config/ForestryItem.java index ae3f27caf..83d7e5f34 100755 --- a/src/main/java/forestry/core/config/ForestryItem.java +++ b/src/main/java/forestry/core/config/ForestryItem.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.core.config; -import java.util.EnumSet; - import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -201,8 +199,8 @@ public enum ForestryItem { private Item item; public void registerItem(Item item, String name) { - if (!EnumSet.of(Stage.PRE_INIT, Stage.INIT).contains(PluginManager.getStage())) { - throw new RuntimeException("Tried to register Item outside of Pre-Init or Init"); + if (PluginManager.getStage() != Stage.SETUP) { + throw new RuntimeException("Tried to register Item outside of Setup"); } this.item = item; item.setUnlocalizedName("for." + name); diff --git a/src/main/java/forestry/core/config/GameMode.java b/src/main/java/forestry/core/config/GameMode.java index b9cd794c1..d1191252c 100644 --- a/src/main/java/forestry/core/config/GameMode.java +++ b/src/main/java/forestry/core/config/GameMode.java @@ -18,21 +18,10 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import forestry.Forestry; -import forestry.api.core.ForestryAPI; import forestry.api.core.IGameMode; import forestry.core.utils.Log; public class GameMode implements IGameMode { - - public static IGameMode getGameMode() { - - if (ForestryAPI.activeMode == null) { - ForestryAPI.activeMode = new GameMode(Config.gameMode); - } - - return ForestryAPI.activeMode; - } - private static final String GAMEMODE_KEY = "gamemode"; private String identifier = "EASY"; private final String category; @@ -83,21 +72,9 @@ public class GameMode implements IGameMode { this.identifier = identifier; this.category = "gamemodes/" + identifier; - final String oldConfig = category + ".conf"; - final String newConfig = category + ".cfg"; - File newConfigFile = new File(Forestry.instance.getConfigFolder(), newConfig); - File oldConfigFile = new File(Forestry.instance.getConfigFolder(), oldConfig); - if (oldConfigFile.exists()) { - loadOldConfig(); + File configFile = new File(Forestry.instance.getConfigFolder(), category + ".cfg"); - final String oldConfigRenamed = category + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigFile.renameTo(oldConfigFileRenamed)) { - Log.info("Migrated " + category + " settings to the new file '" + newConfig + "' and renamed '" + oldConfig + "' to '" + oldConfigRenamed + "'."); - } - } - - LocalizedConfiguration config = new LocalizedConfiguration(newConfigFile, "1.0.0"); + LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0"); initSettingFloat(config, "energy", "demand.modifier", ENERGY_DEMAND_MODIFIER); initSettingBoolean(config, "energy", "engine.clockwork", true); @@ -141,140 +118,32 @@ public class GameMode implements IGameMode { config.save(); } - private void loadOldConfig() { - initSettingFloat_old("energy.demand.modifier", ENERGY_DEMAND_MODIFIER, -1, "modifies the energy required to activate machines, as well as the max amount of energy stored and accepted."); - initSettingInt_old("farms.fertilizer.value", FARM_FERTILIZER_VALUE, -1, "modifies the time a piece of fertilizer lasts in a farm."); - - initSettingFloat_old("fuel.ethanol.generator", FUEL_MODIFIER, -1, "modifies the energy provided by ethanol in a Bio Generator."); - initSettingFloat_old("fuel.ethanol.combustion", FUEL_MODIFIER, -1, "modifies the energy provided by ethanol in Buildcraft Combustion Engines."); - initSettingFloat_old("fuel.biomass.generator", FUEL_MODIFIER, -1, "modifies the energy provided by Biomass in a Bio Generator."); - initSettingFloat_old("fuel.biomass.biogas", FUEL_MODIFIER, -1, "modifies the energy provided by Biomass in Biogas Engines."); - - initSettingStack_old("recipe.output.fertilizer.apatite", recipeFertilizerOutputApatite, "amount of fertilizer yielded by the recipe using apatite."); - initSettingStack_old("recipe.output.fertilizer.ash", recipeFertilizerOutputAsh, "amount of fertilizer yielded by the recipe using ash."); - initSettingStack_old("recipe.output.compost.wheat", recipeCompostOutputWheat, "amount of compost yielded by the recipe using wheat."); - initSettingStack_old("recipe.output.compost.ash", recipeCompostOutputAsh, "amount of compost yielded by the recipe using ash."); - initSettingStack_old("recipe.output.humus.fertilizer", recipeHumusOutputFertilizer, "amount of humus yielded by the recipe using fertilizer."); - initSettingStack_old("recipe.output.humus.compost", recipeHumusOutputCompost, "amount of humus yielded by the recipe using compost."); - initSettingStack_old("recipe.output.bogearth.bucket", recipeBogEarthOutputBucket, "amount of bog earth yielded by the recipe using buckets."); - initSettingStack_old("recipe.output.bogearth.can", recipeBogEarthOutputCans, "amount of bog earth yielded by the recipes using cans, cells or capsules."); - - initSettingStack_old("recipe.output.can", recipeCanOutput, "amount yielded by the recipe for tin cans."); - initSettingStack_old("recipe.output.capsule", recipeCapsuleOutput, "amount yielded by the recipe for wax capsules."); - initSettingStack_old("recipe.output.refractory", recipeRefractoryOutput, "amount yielded by the recipe for refractory capsules."); - - initSettingInt_old("fermenter.cycles.fertilizer", FERMENTATION_DURATION_FERTILIZER, -1, "modifies the amount of cycles fertilizer can keep a fermenter going."); - initSettingInt_old("fermenter.cycles.compost", FERMENTATION_DURATION_COMPOST, -1, "modifies the amount of cycles compost can keep a fermenter going."); - - initSettingInt_old("fermenter.value.fertilizer", FERMENTED_CYCLE_FERTILIZER, -1, "modifies the amount of biomass per cycle a fermenter will produce using fertilizer."); - initSettingInt_old("fermenter.value.compost", FERMENTED_CYCLE_COMPOST, -1, "modifies the amount of biomass per cycle a fermenter will produce using compost."); - - initSettingInt_old("fermenter.yield.sapling", FERMENTED_SAPLING, FERMENTED_SAPLING * 8, "modifies the base amount of biomass a sapling will yield in a fermenter, affected by sappiness trait."); - initSettingInt_old("fermenter.yield.cactus", FERMENTED_CACTI, FERMENTED_CACTI * 8, "modifies the amount of biomass a piece of cactus will yield in a fermenter."); - initSettingInt_old("fermenter.yield.wheat", FERMENTED_WHEAT, FERMENTED_WHEAT * 8, "modifies the amount of biomass a piece of wheat will yield in a fermenter."); - initSettingInt_old("fermenter.yield.cane", FERMENTED_CANE, FERMENTED_CANE * 8, "modifies the amount of biomass a piece of sugar cane will yield in a fermenter."); - initSettingInt_old("fermenter.yield.mushroom", FERMENTED_MUSHROOM, FERMENTED_MUSHROOM * 8, "modifies the amount of biomass a mushroom will yield in a fermenter."); - - initSettingInt_old("squeezer.liquid.seed", SQUEEZED_LIQUID_SEED, SQUEEZED_LIQUID_SEED * 8, "modifies the amount of seed oil squeezed from a single seed. other sources are based off this."); - initSettingInt_old("squeezer.liquid.apple", SQUEEZED_LIQUID_APPLE, SQUEEZED_LIQUID_APPLE * 8, "modifies the amount of juice squeezed from a single apple. other sources are based off this."); - initSettingInt_old("squeezer.mulch.apple", SQUEEZED_MULCH_APPLE, SQUEEZED_MULCH_APPLE * 8, "modifies the chance of mulch per squeezed apple."); - initSettingBoolean_old("energy.engine.clockwork", true, "set to false to disable the clockwork engine."); - } - - private void initSettingFloat(LocalizedConfiguration config, String category, String name, float def) { + private void initSettingFloat(LocalizedConfiguration config, String category, String name, float defaultValue) { String fullName = category + '.' + name; - // legacy conversion of old format to new format - { - Float oldSetting = floatSettings.get(fullName); - if (oldSetting != null) { - def = oldSetting; - } - } - float floatValue = config.getFloatLocalized(GAMEMODE_KEY + '.' + category, name, def, 0.0f, 10.0f); + float floatValue = config.getFloatLocalized(GAMEMODE_KEY + '.' + category, name, defaultValue, 0.0f, 10.0f); floatSettings.put(fullName, floatValue); } - private void initSettingInt(LocalizedConfiguration config, String category, String key, int def) { + private void initSettingInt(LocalizedConfiguration config, String category, String key, int defaultValue) { String fullKey = category + '.' + key; - // legacy conversion of old format to new format - { - Integer oldSetting = integerSettings.get(fullKey); - if (oldSetting != null) { - def = oldSetting; - } - } - int intValue = config.getIntLocalized(GAMEMODE_KEY + '.' + category, key, def, 0, 2000); + int intValue = config.getIntLocalized(GAMEMODE_KEY + '.' + category, key, defaultValue, 0, 2000); integerSettings.put(fullKey, intValue); } - private void initSettingStack(LocalizedConfiguration config, String category, String key, ItemStack def) { + private void initSettingStack(LocalizedConfiguration config, String category, String key, ItemStack defaultValue) { String fullKey = category + '.' + key; - // legacy conversion of old format to new format - { - ItemStack oldSetting = stackSettings.get(fullKey); - if (oldSetting != null) { - def = oldSetting; - } - } - int stackSize = config.getIntLocalized(GAMEMODE_KEY + '.' + category, key, def.stackSize, 0, 64); - ItemStack changed = def.copy(); + int stackSize = config.getIntLocalized(GAMEMODE_KEY + '.' + category, key, defaultValue.stackSize, 0, 64); + ItemStack changed = defaultValue.copy(); changed.stackSize = stackSize; stackSettings.put(fullKey, changed); } - private void initSettingBoolean(LocalizedConfiguration config, String category, String key, boolean def) { + private void initSettingBoolean(LocalizedConfiguration config, String category, String key, boolean defaultValue) { String fullKey = category + '.' + key; - // legacy conversion of old format to new format - { - Boolean oldSetting = booleanSettings.get(fullKey); - if (oldSetting != null) { - def = oldSetting; - } - } - boolean booleanValue = config.getBooleanLocalized(GAMEMODE_KEY + '.' + category, key, def); + boolean booleanValue = config.getBooleanLocalized(GAMEMODE_KEY + '.' + category, key, defaultValue); booleanSettings.put(fullKey, booleanValue); } - private void initSettingStack_old(String ident, ItemStack def, String comment) { - forestry.core.config.deprecated.Property property = Config.configOld.get(ident, category, def.stackSize); - property.comment = comment; - ItemStack changed = def.copy(); - changed.stackSize = Integer.parseInt(property.value); - stackSettings.put(ident, changed); - } - - private void initSettingInt_old(String ident, int def, int max, String comment) { - forestry.core.config.deprecated.Property property = Config.configOld.get(ident, category, def); - if (max < 0) { - property.comment = comment; - integerSettings.put(ident, Integer.parseInt(property.value)); - } else { - property.comment = comment + " (max: " + max + ")"; - integerSettings.put(ident, Math.min(Integer.parseInt(property.value), max)); - } - Config.configOld.set(ident, category, integerSettings.get(ident)); - - } - - private void initSettingFloat_old(String ident, float def, float max, String comment) { - forestry.core.config.deprecated.Property property = Config.configOld.get(ident, category, def); - if (max < 0) { - property.comment = comment; - floatSettings.put(ident, Float.parseFloat(property.value)); - } else { - property.comment = comment + " (max: " + max + ")"; - floatSettings.put(ident, Math.min(Float.parseFloat(property.value), max)); - } - Config.configOld.set(ident, category, floatSettings.get(ident)); - } - - private void initSettingBoolean_old(String ident, boolean def, String comment) { - forestry.core.config.deprecated.Property property = Config.configOld.get(ident, category, def); - property.comment = comment; - booleanSettings.put(ident, Boolean.parseBoolean(property.value)); - Config.configOld.set(ident, category, booleanSettings.get(ident)); - } - @Override public int getIntegerSetting(String ident) { if (integerSettings.containsKey(ident)) { diff --git a/src/main/java/forestry/core/config/deprecated/Configuration.java b/src/main/java/forestry/core/config/deprecated/Configuration.java deleted file mode 100644 index 82f8d6230..000000000 --- a/src/main/java/forestry/core/config/deprecated/Configuration.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * 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.config.deprecated; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.util.ArrayList; -import java.util.Locale; -import java.util.TreeMap; - -import net.minecraftforge.common.config.Configuration.UnicodeInputStreamReader; - -import forestry.core.config.Constants; -import forestry.core.proxy.Proxies; - -@Deprecated -public class Configuration { - - private final TreeMap> categorized = new TreeMap<>(); - - public Property get(String key, String category, boolean defaultVal) { - - Property existing = getExisting(key, category); - if (existing != null) { - return existing; - } - - // Create new property since none exists yet. - Property property = new Property(key, Boolean.toString(defaultVal)); - categorized.get(category).add(property); - return property; - } - - public Property get(String key, String category, int defaultVal) { - - Property existing = getExisting(key, category); - if (existing != null) { - return existing; - } - - // Create new property since none exists yet. - Property property = new Property(key, Integer.toString(defaultVal)); - categorized.get(category).add(property); - return property; - } - - public Property get(String key, String category, float defaultVal) { - - Property existing = getExisting(key, category); - if (existing != null) { - return existing; - } - - // Create new property since none exists yet. - Property property = new Property(key, Float.toString(defaultVal)); - categorized.get(category).add(property); - return property; - } - - public Property get(String key, String category, String defaultVal) { - - Property existing = getExisting(key, category); - if (existing != null) { - return existing; - } - - // Create new property since none exists yet. - Property property = new Property(key, defaultVal); - categorized.get(category).add(property); - return property; - } - - public void set(String key, String category, boolean val) { - Property existing = getExisting(key, category); - if (existing != null) { - existing.value = Boolean.toString(val); - return; - } - - // Create new property since none exists yet. - Property property = new Property(key, Boolean.toString(val)); - categorized.get(category).add(property); - - } - - public void set(String key, String category, String val) { - Property existing = getExisting(key, category); - if (existing != null) { - existing.value = val; - return; - } - - // Create new property since none exists yet. - Property property = new Property(key, val); - categorized.get(category).add(property); - - } - - public void set(String key, String category, int val) { - Property existing = getExisting(key, category); - if (existing != null) { - existing.value = Integer.toString(val); - return; - } - - // Create new property since none exists yet. - Property property = new Property(key, Integer.toString(val)); - categorized.get(category).add(property); - - } - - public void set(String key, String category, float val) { - Property existing = getExisting(key, category); - if (existing != null) { - existing.value = Float.toString(val); - return; - } - - // Create new property since none exists yet. - Property property = new Property(key, Float.toString(val)); - categorized.get(category).add(property); - - } - - public Property getExisting(String key, String category) { - if (!categorized.containsKey(category)) { - loadCategory(category); - } - - for (Property property : categorized.get(category)) { - if (property.key.equals(key)) { - return property; - } - } - - return null; - } - - public File getCategoryFile(String category) { - return new File(Proxies.common.getForestryRoot(), "config/" + Constants.MOD.toLowerCase(Locale.ENGLISH) + "/" + category + ".conf"); - } - - public void loadCategory(String category) { - - File file = getCategoryFile(category); - - categorized.remove(category); - categorized.put(category, new ArrayList()); - - try { - - if (file.getParentFile() != null) { - file.getParentFile().mkdirs(); - } - - if (!file.exists()) { - return; - } - - if (!file.canRead()) { - return; - } - - UnicodeInputStreamReader filein = new UnicodeInputStreamReader(new FileInputStream(file), "UTF-8"); - BufferedReader reader = new BufferedReader(filein); - - String lastComment = null; - String line; - - while (true) { - line = reader.readLine(); - - if (line == null) { - break; - } - - if (line.startsWith("#")) { - if (line.length() > 3) { - lastComment = line.substring(2, line.length() - 1); - } - continue; - } - - if (!line.contains("=")) { - continue; - } - - String[] tokens = line.split("="); - Property property; - if (tokens.length > 1) { - property = new Property(tokens[0], tokens[1].trim()); - } else { - property = new Property(tokens[0], ""); - } - - if (lastComment != null) { - property.comment = lastComment; - lastComment = null; - } - categorized.get(category).add(property); - } - - reader.close(); - - } catch (Exception ex) { - ex.printStackTrace(); - } - } -} diff --git a/src/main/java/forestry/core/fluids/FakeTankUpdateHandler.java b/src/main/java/forestry/core/fluids/FakeTankUpdateHandler.java index 872741544..b474deb01 100644 --- a/src/main/java/forestry/core/fluids/FakeTankUpdateHandler.java +++ b/src/main/java/forestry/core/fluids/FakeTankUpdateHandler.java @@ -14,7 +14,7 @@ import forestry.core.fluids.tanks.StandardTank; public class FakeTankUpdateHandler implements ITankUpdateHandler { - public static FakeTankUpdateHandler instance = new FakeTankUpdateHandler(); + public static final FakeTankUpdateHandler instance = new FakeTankUpdateHandler(); private FakeTankUpdateHandler() { diff --git a/src/main/java/forestry/core/fluids/PipetteContents.java b/src/main/java/forestry/core/fluids/PipetteContents.java new file mode 100644 index 000000000..ff654ebe3 --- /dev/null +++ b/src/main/java/forestry/core/fluids/PipetteContents.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.fluids; + +import java.util.List; + +import net.minecraft.nbt.NBTTagCompound; + +import net.minecraftforge.fluids.FluidStack; + +import forestry.api.core.INBTTagable; + +public class PipetteContents implements INBTTagable { + private FluidStack contents; + + public PipetteContents(NBTTagCompound nbttagcompound) { + if (nbttagcompound != null) { + readFromNBT(nbttagcompound); + } + } + + public FluidStack getContents() { + return contents; + } + + public void setContents(FluidStack contents) { + this.contents = contents; + } + + public boolean isFull() { + if (contents == null) { + return false; + } + + return contents.getFluid().getID() > 0 && contents.amount >= 1000; + } + + public void addTooltip(List list) { + if (contents == null) { + return; + } + + String descr = contents.getFluid().getLocalizedName(contents); + descr += " (" + contents.amount + " mb)"; + + list.add(descr); + } + + /* INBTTagable */ + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + contents = FluidStack.loadFluidStackFromNBT(nbttagcompound); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + if (contents != null) { + contents.writeToNBT(nbttagcompound); + } + } +} diff --git a/src/main/java/forestry/core/gui/ContainerAlyzer.java b/src/main/java/forestry/core/gui/ContainerAlyzer.java index 334d86f21..5abd5dcfe 100644 --- a/src/main/java/forestry/core/gui/ContainerAlyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAlyzer.java @@ -1,52 +1,25 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import forestry.core.gui.slots.SlotFiltered; -import forestry.core.items.ItemAlyzer; +import forestry.core.inventory.ItemInventoryAlyzer; -public class ContainerAlyzer extends ContainerItemInventory { +public class ContainerAlyzer extends ContainerItemInventory { - public ContainerAlyzer(ItemAlyzer.AlyzerInventory inventory, EntityPlayer player) { + public ContainerAlyzer(ItemInventoryAlyzer inventory, EntityPlayer player) { super(inventory, player.inventory, 43, 156); final int xPosLeftSlots = 223; - // Energy - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_ENERGY, xPosLeftSlots, 8)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_ENERGY, xPosLeftSlots, 8)); - // Bee to analyze - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_SPECIMEN, xPosLeftSlots, 26)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_SPECIMEN, xPosLeftSlots, 26)); - // Analyzed bee - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_ANALYZE_1, xPosLeftSlots, 57)); - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_ANALYZE_2, xPosLeftSlots, 75)); - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_ANALYZE_3, xPosLeftSlots, 93)); - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_ANALYZE_4, xPosLeftSlots, 111)); - this.addSlotToContainer(new SlotFiltered(inventory, ItemAlyzer.AlyzerInventory.SLOT_ANALYZE_5, xPosLeftSlots, 129)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_ANALYZE_1, xPosLeftSlots, 57)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_ANALYZE_2, xPosLeftSlots, 75)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_ANALYZE_3, xPosLeftSlots, 93)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_ANALYZE_4, xPosLeftSlots, 111)); + addSlotToContainer(new SlotFiltered(inventory, ItemInventoryAlyzer.SLOT_ANALYZE_5, xPosLeftSlots, 129)); } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) { - - if (entityplayer.worldObj.isRemote) { - return; - } - - // Last slot is the energy slot, so we don't save that one. - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (i == ItemAlyzer.AlyzerInventory.SLOT_ENERGY) { - continue; - } - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) { - continue; - } - - entityplayer.dropPlayerItemWithRandomChoice(stack, true); - inventory.setInventorySlotContents(i, null); - } - } - } diff --git a/src/main/java/forestry/core/gui/ContainerAnalyzer.java b/src/main/java/forestry/core/gui/ContainerAnalyzer.java index 9d5715d59..cc942d58c 100755 --- a/src/main/java/forestry/core/gui/ContainerAnalyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAnalyzer.java @@ -15,6 +15,7 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.core.gui.slots.SlotWorking; +import forestry.core.inventory.InventoryAnalyzer; import forestry.core.tiles.TileAnalyzer; public class ContainerAnalyzer extends ContainerLiquidTanks { @@ -25,20 +26,20 @@ public class ContainerAnalyzer extends ContainerLiquidTanks { // Input buffer for (int i = 0; i < 3; i++) { for (int k = 0; k < 2; k++) { - addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18)); + addSlotToContainer(new SlotFiltered(tile, InventoryAnalyzer.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18)); } } // Analyze slot - addSlotToContainer(new SlotWorking(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59)); + addSlotToContainer(new SlotWorking(tile, InventoryAnalyzer.SLOT_ANALYZE, 73, 59)); // Can slot - addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_CAN, 143, 24)); + addSlotToContainer(new SlotFiltered(tile, InventoryAnalyzer.SLOT_CAN, 143, 24)); // Output buffer for (int i = 0; i < 2; i++) { for (int k = 0; k < 2; k++) { - addSlotToContainer(new SlotOutput(tile, TileAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18)); + addSlotToContainer(new SlotOutput(tile, InventoryAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18)); } } } diff --git a/src/main/java/forestry/core/gui/ContainerEscritoire.java b/src/main/java/forestry/core/gui/ContainerEscritoire.java index 922b62bca..3ddbc57d0 100755 --- a/src/main/java/forestry/core/gui/ContainerEscritoire.java +++ b/src/main/java/forestry/core/gui/ContainerEscritoire.java @@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.core.inventory.InventoryEscritoire; import forestry.core.network.PacketGuiSelectRequest; import forestry.core.network.PacketGuiUpdate; import forestry.core.proxy.Proxies; @@ -33,15 +34,15 @@ public class ContainerEscritoire extends ContainerTile implement this.player = player; // Analyze slot - addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(this.tile).setStackLimit(1)); + addSlotToContainer(new SlotFiltered(this.tile, InventoryEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(this.tile).setStackLimit(1)); - for (int i = 0; i < TileEscritoire.SLOTS_INPUT_COUNT; i++) { - addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setBlockedTexture("slots/blocked_2")); + for (int i = 0; i < InventoryEscritoire.SLOTS_INPUT_COUNT; i++) { + addSlotToContainer(new SlotFiltered(this.tile, InventoryEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setBlockedTexture("slots/blocked_2")); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - addSlotToContainer(new SlotOutput(this.tile, TileEscritoire.SLOT_RESULTS_1 + (i * 2) + j, 177 + j * 18, 85 + i * 18)); + addSlotToContainer(new SlotOutput(this.tile, InventoryEscritoire.SLOT_RESULTS_1 + (i * 2) + j, 177 + j * 18, 85 + i * 18)); } } } diff --git a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java index f843c449c..aa4caad89 100755 --- a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java +++ b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java @@ -13,6 +13,7 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketGuiSelectRequest; @@ -22,7 +23,6 @@ public class ContainerNaturalistInventory extends ContainerTile protected final Map iconStacks = new HashMap<>(); - protected GuiAlyzer(String speciesRoot, EntityPlayer player, ContainerAlyzer container, IInventory inventory, String guiName) { + protected GuiAlyzer(ISpeciesRoot speciesRoot, EntityPlayer player, ContainerAlyzer container, IInventory inventory, String guiName) { super(Constants.TEXTURE_PATH_GUI + "/beealyzer2.png", container, inventory); this.xSize = 246; @@ -64,7 +64,7 @@ public abstract class GuiAlyzer extends GuiForestry this.guiName = guiName; - this.speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(speciesRoot); + this.speciesRoot = speciesRoot; this.breedingTracker = this.speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile()); } diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index bdd0e1200..1182aa806 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -65,7 +65,7 @@ public abstract class GuiForestry ext protected final C container; protected final FontColour fontColor; public final ResourceLocation textureFile; - protected WidgetManager widgetManager; + protected final WidgetManager widgetManager; protected LedgerManager ledgerManager; protected GuiForestry(String texture, C container, I inventory) { @@ -112,8 +112,8 @@ public abstract class GuiForestry ext if (Config.enableHints && inventory instanceof IHintSource) { IHintSource hintSource = (IHintSource) inventory; - String[] hints = hintSource.getHints(); - if (hints != null && hints.length > 0) { + List hints = hintSource.getHints(); + if (hints != null && hints.size() > 0) { ledgerManager.add(new HintLedger(ledgerManager, hintSource)); } } diff --git a/src/main/java/forestry/core/gui/IHintSource.java b/src/main/java/forestry/core/gui/IHintSource.java index c985f1af9..9d9911eda 100644 --- a/src/main/java/forestry/core/gui/IHintSource.java +++ b/src/main/java/forestry/core/gui/IHintSource.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core.gui; +import java.util.List; + public interface IHintSource { - String[] getHints(); + List getHints(); } diff --git a/src/main/java/forestry/core/gui/ledgers/HintLedger.java b/src/main/java/forestry/core/gui/ledgers/HintLedger.java index e8c136c89..d10978e8c 100644 --- a/src/main/java/forestry/core/gui/ledgers/HintLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/HintLedger.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.gui.ledgers; +import java.util.List; import java.util.Random; import net.minecraft.client.Minecraft; @@ -27,11 +28,12 @@ public class HintLedger extends Ledger { public HintLedger(LedgerManager manager, IHintSource tile) { super(manager, "hint"); - String[] hints = tile.getHints(); - int position = new Random().nextInt(hints.length); + List hints = tile.getHints(); + int position = new Random().nextInt(hints.size()); + String hint = hints.get(position); - hintString = StringUtil.localize("hints." + hints[position] + ".desc"); - hintTooltip = StringUtil.localize("hints." + hints[position] + ".tag"); + hintString = StringUtil.localize("hints." + hint + ".desc"); + hintTooltip = StringUtil.localize("hints." + hint + ".tag"); Minecraft minecraft = Proxies.common.getClientInstance(); FontRenderer fontRenderer = minecraft.fontRenderer; diff --git a/src/main/java/forestry/core/gui/slots/SlotWatched.java b/src/main/java/forestry/core/gui/slots/SlotWatched.java index 712e0bfc2..dc6d14fd8 100644 --- a/src/main/java/forestry/core/gui/slots/SlotWatched.java +++ b/src/main/java/forestry/core/gui/slots/SlotWatched.java @@ -27,24 +27,6 @@ public abstract class SlotWatched extends SlotForestry { return this; } - @Override - public boolean getHasStack() { - if (crafter != null && !crafter.canTakeStack(getSlotIndex())) { - return false; - } else { - return super.getHasStack(); - } - } - - @Override - public ItemStack decrStackSize(int i) { - if (crafter != null && !crafter.canTakeStack(getSlotIndex())) { - return null; - } else { - return super.decrStackSize(i); - } - } - @Override public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) { if (crafter != null) { diff --git a/src/main/java/forestry/core/inventory/TileInventoryAdapter.java b/src/main/java/forestry/core/inventory/InventoryAdapterTile.java old mode 100755 new mode 100644 similarity index 85% rename from src/main/java/forestry/core/inventory/TileInventoryAdapter.java rename to src/main/java/forestry/core/inventory/InventoryAdapterTile.java index 882783065..c63a62934 --- a/src/main/java/forestry/core/inventory/TileInventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/InventoryAdapterTile.java @@ -15,15 +15,15 @@ import net.minecraft.tileentity.TileEntity; import forestry.core.access.IRestrictedAccess; -public class TileInventoryAdapter extends InventoryAdapterRestricted { +public class InventoryAdapterTile extends InventoryAdapterRestricted { protected final T tile; - public TileInventoryAdapter(T tile, int size, String name) { + public InventoryAdapterTile(T tile, int size, String name) { this(tile, size, name, 64); } - public TileInventoryAdapter(T tile, int size, String name, int stackLimit) { + public InventoryAdapterTile(T tile, int size, String name, int stackLimit) { super(size, name, stackLimit, tile.getAccessHandler()); this.tile = tile; } diff --git a/src/main/java/forestry/core/inventory/InventoryAnalyzer.java b/src/main/java/forestry/core/inventory/InventoryAnalyzer.java new file mode 100644 index 000000000..44d73d33c --- /dev/null +++ b/src/main/java/forestry/core/inventory/InventoryAnalyzer.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.api.arboriculture.TreeManager; +import forestry.api.genetics.AlleleManager; +import forestry.core.fluids.FluidHelper; +import forestry.core.tiles.TileAnalyzer; +import forestry.core.utils.GeneticsUtil; +import forestry.core.utils.SlotUtil; +import forestry.plugins.PluginManager; + +public class InventoryAnalyzer extends InventoryAdapterTile { + public static final short SLOT_ANALYZE = 0; + public static final short SLOT_CAN = 1; + public static final short SLOT_INPUT_1 = 2; + public static final short SLOT_INPUT_COUNT = 6; + public static final short SLOT_OUTPUT_1 = 8; + public static final short SLOT_OUTPUT_COUNT = 4; + + public InventoryAnalyzer(TileAnalyzer analyzer) { + super(analyzer, 12, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (SlotUtil.isSlotInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)) { + return AlleleManager.alleleRegistry.isIndividual(itemStack) || GeneticsUtil.getGeneticEquivalent(itemStack) != null; + } else if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return SlotUtil.isSlotInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT); + } + + @Override + public void setInventorySlotContents(int slotId, ItemStack itemStack) { + if (PluginManager.Module.ARBORICULTURE.isEnabled() && !TreeManager.treeRoot.isMember(itemStack)) { + ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(itemStack); + if (ersatz != null) { + itemStack = ersatz; + } + } + + super.setInventorySlotContents(slotId, itemStack); + } +} diff --git a/src/main/java/forestry/core/inventory/InventoryConcatenator.java b/src/main/java/forestry/core/inventory/InventoryConcatenator.java deleted file mode 100755 index 2f2336234..000000000 --- a/src/main/java/forestry/core/inventory/InventoryConcatenator.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * 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.inventory; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -/** - * Allows you to deal with multiple inventories through a single interface. - * - * @author CovertJaguar - */ -public class InventoryConcatenator implements IInventory { - - private final List slotMap = new ArrayList<>(); - private final List invMap = new ArrayList<>(); - - private InventoryConcatenator() { - } - - public static InventoryConcatenator make() { - return new InventoryConcatenator(); - } - - public InventoryConcatenator add(IInventory inv) { - for (int slot = 0; slot < inv.getSizeInventory(); slot++) { - slotMap.add(slot); - invMap.add(inv); - } - return this; - } - - @Override - public int getSizeInventory() { - return slotMap.size(); - } - - @Override - public ItemStack getStackInSlot(int slot) { - return invMap.get(slot).getStackInSlot(slotMap.get(slot)); - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - return invMap.get(slot).decrStackSize(slotMap.get(slot), amount); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return invMap.get(slot).getStackInSlotOnClosing(slotMap.get(slot)); - } - - @Override - public void setInventorySlotContents(int slot, ItemStack stack) { - invMap.get(slot).setInventorySlotContents(slotMap.get(slot), stack); - } - - @Override - public String getInventoryName() { - return ""; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public void markDirty() { - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return true; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(int slot, ItemStack stack) { - return invMap.get(slot).isItemValidForSlot(slotMap.get(slot), stack); - } -} diff --git a/src/main/java/forestry/core/inventory/InventoryEscritoire.java b/src/main/java/forestry/core/inventory/InventoryEscritoire.java new file mode 100644 index 000000000..59357c05e --- /dev/null +++ b/src/main/java/forestry/core/inventory/InventoryEscritoire.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * 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.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IIndividual; +import forestry.core.tiles.TileEscritoire; +import forestry.core.utils.GeneticsUtil; +import forestry.core.utils.SlotUtil; + +public class InventoryEscritoire extends InventoryAdapterTile { + public static final short SLOT_ANALYZE = 0; + public static final short SLOT_RESULTS_1 = 1; + public static final short SLOTS_RESULTS_COUNT = 6; + public static final short SLOT_INPUT_1 = 7; + public static final short SLOTS_INPUT_COUNT = 5; + + public InventoryEscritoire(TileEscritoire escritoire) { + super(escritoire, 12, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + tile.getGame().getSampleSize(SLOTS_INPUT_COUNT)) { + ItemStack specimen = getStackInSlot(SLOT_ANALYZE); + if (specimen == null) { + return false; + } + IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen); + return individual != null && individual.getGenome().getPrimary().getResearchSuitability(itemStack) > 0; + } + + if (slotIndex == SLOT_ANALYZE) { + return AlleleManager.alleleRegistry.isIndividual(itemStack); + } + + return false; + } + + @Override + public boolean isLocked(int slotIndex) { + if (slotIndex == SLOT_ANALYZE) { + return false; + } + + if (getStackInSlot(SLOT_ANALYZE) == null) { + return true; + } + + if (SlotUtil.isSlotInRange(slotIndex, SLOT_INPUT_1, SLOTS_INPUT_COUNT)) { + if (slotIndex >= SLOT_INPUT_1 + tile.getGame().getSampleSize(SLOTS_INPUT_COUNT)) { + return true; + } + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return SlotUtil.isSlotInRange(slotIndex, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT); + } + + @Override + public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { + super.setInventorySlotContents(slotIndex, itemstack); + if (tile.getWorld() == null) { + return; + } + if (slotIndex == SLOT_ANALYZE && !tile.getWorld().isRemote) { + if (!AlleleManager.alleleRegistry.isIndividual(getStackInSlot(SLOT_ANALYZE)) && getStackInSlot(SLOT_ANALYZE) != null) { + ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_ANALYZE)); + if (ersatz != null) { + setInventorySlotContents(SLOT_ANALYZE, ersatz); + } + } + tile.getGame().initialize(getStackInSlot(SLOT_ANALYZE)); + } + } +} diff --git a/src/main/java/forestry/core/inventory/InventoryNaturalistChest.java b/src/main/java/forestry/core/inventory/InventoryNaturalistChest.java new file mode 100644 index 000000000..9f0073bb9 --- /dev/null +++ b/src/main/java/forestry/core/inventory/InventoryNaturalistChest.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.api.genetics.ISpeciesRoot; +import forestry.core.tiles.TileNaturalistChest; + +public class InventoryNaturalistChest extends InventoryAdapterTile { + private final ISpeciesRoot speciesRoot; + + public InventoryNaturalistChest(TileNaturalistChest tile, ISpeciesRoot speciesRoot) { + super(tile, 125, "Items"); + this.speciesRoot = speciesRoot; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemstack) { + return speciesRoot.isMember(itemstack); + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return true; + } +} diff --git a/src/main/java/forestry/core/inventory/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java index 55ba0ebaa..6ab14c64c 100755 --- a/src/main/java/forestry/core/inventory/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -21,7 +21,6 @@ import net.minecraft.nbt.NBTTagList; import forestry.core.tiles.IFilterSlotDelegate; public abstract class ItemInventory implements IInventory, IFilterSlotDelegate { - private static final String KEY_ITEMS = "Items"; // legacy private static final String KEY_SLOTS = "Slots"; private static final String KEY_UID = "UID"; @@ -293,7 +292,7 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate { return toReturn; } - /* Filter Slot Delegate */ + /* IFilterSlotDelegate */ @Override public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { return true; diff --git a/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java b/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java new file mode 100644 index 000000000..8e9589c58 --- /dev/null +++ b/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * 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.inventory; + +import com.google.common.collect.ImmutableSet; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import forestry.api.core.IErrorSource; +import forestry.api.core.IErrorState; +import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; +import forestry.core.config.ForestryItem; +import forestry.core.errors.EnumErrorCode; + +public abstract class ItemInventoryAlyzer extends ItemInventory implements IErrorSource { + public static final int SLOT_SPECIMEN = 0; + public static final int SLOT_ANALYZE_1 = 1; + public static final int SLOT_ANALYZE_2 = 2; + public static final int SLOT_ANALYZE_3 = 3; + public static final int SLOT_ANALYZE_4 = 4; + public static final int SLOT_ANALYZE_5 = 6; + public static final int SLOT_ENERGY = 5; + + private final ISpeciesRoot speciesRoot; + + public ItemInventoryAlyzer(ISpeciesRoot speciesRoot, EntityPlayer player, ItemStack itemstack) { + super(player, 7, itemstack); + this.speciesRoot = speciesRoot; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_ENERGY) { + return isEnergy(itemStack); + } + + if (!speciesRoot.isMember(itemStack)) { + return false; + } + + // only allow one slot to be used at a time + if (hasSpecimen() && getStackInSlot(slotIndex) == null) { + return false; + } + + if (slotIndex == SLOT_SPECIMEN) { + return true; + } + + IIndividual individual = speciesRoot.getMember(itemStack); + return individual.isAnalyzed(); + } + + @Override + public void onSlotClick(EntityPlayer player) { + // Source slot to analyze empty + ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); + if (specimen == null) { + return; + } + + IIndividual individual = speciesRoot.getMember(specimen); + // No individual, abort + if (individual == null) { + return; + } + + // Analyze if necessary + if (!individual.isAnalyzed()) { + + // Requires energy + if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { + return; + } + + individual.analyze(); + if (player != null) { + IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile()); + breedingTracker.registerSpecies(individual.getGenome().getPrimary()); + breedingTracker.registerSpecies(individual.getGenome().getSecondary()); + } + + NBTTagCompound nbttagcompound = new NBTTagCompound(); + individual.writeToNBT(nbttagcompound); + specimen.setTagCompound(nbttagcompound); + + // Decrease energy + decrStackSize(SLOT_ENERGY, 1); + } + + setInventorySlotContents(SLOT_ANALYZE_1, specimen); + setInventorySlotContents(SLOT_SPECIMEN, null); + } + + @Override + public final ImmutableSet getErrorStates() { + ImmutableSet.Builder errorStates = ImmutableSet.builder(); + + if (!hasSpecimen()) { + errorStates.add(EnumErrorCode.NOTHINGANALYZE); + } + + if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { + errorStates.add(EnumErrorCode.NOHONEY); + } + + return errorStates.build(); + } + + private static boolean isEnergy(ItemStack itemstack) { + if (itemstack == null || itemstack.stackSize <= 0) { + return false; + } + + return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + } + + private boolean hasSpecimen() { + for (int i = SLOT_SPECIMEN; i <= SLOT_ANALYZE_5; i++) { + if (i == SLOT_ENERGY) { + continue; + } + + ItemStack itemStack = getStackInSlot(i); + if (itemStack != null) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java b/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java new file mode 100644 index 000000000..30bdd0001 --- /dev/null +++ b/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java @@ -0,0 +1,218 @@ +/******************************************************************************* + * 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.inventory; + +import com.google.common.collect.ImmutableSet; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.ICircuit; +import forestry.api.circuits.ICircuitLayout; +import forestry.api.core.IErrorSource; +import forestry.api.core.IErrorState; +import forestry.core.circuits.CircuitRecipe; +import forestry.core.circuits.CircuitRegistry; +import forestry.core.circuits.EnumCircuitBoardType; +import forestry.core.circuits.ItemCircuitBoard; +import forestry.core.circuits.SolderManager; +import forestry.core.config.Config; +import forestry.core.errors.EnumErrorCode; +import forestry.core.gui.IHintSource; +import forestry.core.utils.datastructures.RevolvingList; + +public class ItemInventorySolderingIron extends ItemInventory implements IErrorSource, IHintSource { + + private final RevolvingList layouts = new RevolvingList<>(ChipsetManager.circuitRegistry.getRegisteredLayouts().values()); + + private static final short blankSlot = 0; + private static final short finishedSlot = 1; + private static final short ingredientSlot1 = 2; + private static final short ingredientSlotCount = 4; + + public ItemInventorySolderingIron(EntityPlayer player, ItemStack itemStack) { + super(player, 6, itemStack); + + layouts.setCurrent(ChipsetManager.circuitRegistry.getDefaultLayout()); + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + public ICircuitLayout getLayout() { + return layouts.getCurrent(); + } + + public void setLayout(String uid) { + layouts.setCurrent(ChipsetManager.circuitRegistry.getLayout(uid)); + } + + public void advanceLayout() { + layouts.rotateRight(); + } + + public void regressLayout() { + layouts.rotateLeft(); + } + + private ICircuit[] getCircuits(boolean doConsume) { + + ICircuit[] circuits = new ICircuit[ingredientSlotCount]; + + for (short i = 0; i < ingredientSlotCount; i++) { + ItemStack ingredient = getStackInSlot(ingredientSlot1 + i); + if (ingredient == null) { + continue; + } + + CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), ingredient); + if (recipe == null) { + continue; + } + + // / Make sure we don't exceed this circuits limit per chipset + if (getCount(recipe.getCircuit(), circuits) >= recipe.getCircuit().getLimit()) { + continue; + } + + if (doConsume) { + decrStackSize(ingredientSlot1 + i, recipe.getResource().stackSize); + } + circuits[i] = recipe.getCircuit(); + } + + return circuits; + } + + @Override + public void onSlotClick(EntityPlayer player) { + if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) { + return; + } + + ItemStack blank = getStackInSlot(blankSlot); + // Requires blank slot + if (blank == null) { + return; + } + if (blank.stackSize > 1) { + return; + } + if (getStackInSlot(finishedSlot) != null) { + return; + } + + // Need a chipset item + if (!ChipsetManager.circuitRegistry.isChipset(blank)) { + return; + } + + // Illegal type + if (blank.getItemDamage() < 0 || blank.getItemDamage() >= EnumCircuitBoardType.values().length) { + return; + } + + EnumCircuitBoardType type = EnumCircuitBoardType.values()[blank.getItemDamage()]; + if (getCircuitCount() != type.getSockets()) { + return; + } + + ICircuit[] circuits = getCircuits(true); + + ItemStack circuitBoard = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuits); + + setInventorySlotContents(finishedSlot, circuitBoard); + setInventorySlotContents(blankSlot, null); + } + + private int getCircuitCount() { + ICircuit[] circuits = getCircuits(false); + int count = 0; + for (ICircuit circuit : circuits) { + if (circuit != null) { + count++; + } + } + return count; + } + + public static int getCount(ICircuit circuit, ICircuit[] circuits) { + int count = 0; + for (ICircuit other : circuits) { + if (other != null && other.getUID().equals(circuit.getUID())) { + count++; + } + } + return count; + } + + @Override + public ImmutableSet getErrorStates() { + ImmutableSet.Builder errorStates = ImmutableSet.builder(); + + if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) { + errorStates.add(EnumErrorCode.NOCIRCUITLAYOUT); + } + + ItemStack blankCircuitBoard = getStackInSlot(blankSlot); + + if (blankCircuitBoard == null) { + errorStates.add(EnumErrorCode.NOCIRCUITBOARD); + } else { + EnumCircuitBoardType type = EnumCircuitBoardType.values()[blankCircuitBoard.getItemDamage()]; + + int circuitCount = 0; + for (short i = 0; i < type.getSockets(); i++) { + if (getStackInSlot(ingredientSlot1 + i) != null) { + circuitCount++; + } + } + + if (circuitCount != type.getSockets()) { + errorStates.add(EnumErrorCode.CIRCUITMISMATCH); + } else { + int count = getCircuitCount(); + if (count != type.getSockets()) { + errorStates.add(EnumErrorCode.NOCIRCUITLAYOUT); + } + } + } + + return errorStates.build(); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (itemStack == null) { + return false; + } + + Item item = itemStack.getItem(); + if (slotIndex == blankSlot) { + return item instanceof ItemCircuitBoard; + } else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) { + CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), itemStack); + return recipe != null; + } + return false; + } + + @Override + public List getHints() { + return Config.hints.get("soldering.iron"); + } +} diff --git a/src/main/java/forestry/core/items/ItemAlyzer.java b/src/main/java/forestry/core/items/ItemAlyzer.java deleted file mode 100644 index 27cc087d4..000000000 --- a/src/main/java/forestry/core/items/ItemAlyzer.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * 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.items; - -import com.google.common.collect.ImmutableSet; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import forestry.api.core.IErrorSource; -import forestry.api.core.IErrorState; -import forestry.api.genetics.IBreedingTracker; -import forestry.api.genetics.IIndividual; -import forestry.api.genetics.ISpeciesRoot; -import forestry.core.config.ForestryItem; -import forestry.core.errors.EnumErrorCode; -import forestry.core.inventory.ItemInventory; - -public abstract class ItemAlyzer extends ItemInventoried { - - public abstract static class AlyzerInventory extends ItemInventory implements IErrorSource { - public static final int SLOT_SPECIMEN = 0; - public static final int SLOT_ANALYZE_1 = 1; - public static final int SLOT_ANALYZE_2 = 2; - public static final int SLOT_ANALYZE_3 = 3; - public static final int SLOT_ANALYZE_4 = 4; - public static final int SLOT_ANALYZE_5 = 6; - public static final int SLOT_ENERGY = 5; - - public AlyzerInventory(EntityPlayer player, int size, ItemStack itemstack) { - super(player, size, itemstack); - } - - protected static boolean isEnergy(ItemStack itemstack) { - if (itemstack == null || itemstack.stackSize <= 0) { - return false; - } - - return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); - } - - private boolean hasSpecimen() { - for (int i = SLOT_SPECIMEN; i <= SLOT_ANALYZE_5; i++) { - if (i == SLOT_ENERGY) { - continue; - } - - ItemStack itemStack = getStackInSlot(i); - if (itemStack != null) { - return true; - } - } - return false; - } - - protected abstract ISpeciesRoot getSpeciesRoot(); - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_ENERGY) { - return isEnergy(itemStack); - } - - ISpeciesRoot speciesRoot = getSpeciesRoot(); - if (!speciesRoot.isMember(itemStack)) { - return false; - } - - // only allow one slot to be used at a time - if (hasSpecimen() && getStackInSlot(slotIndex) == null) { - return false; - } - - if (slotIndex == SLOT_SPECIMEN) { - return true; - } - - IIndividual individual = speciesRoot.getMember(itemStack); - return individual.isAnalyzed(); - } - - @Override - public void onSlotClick(EntityPlayer player) { - // Source slot to analyze empty - ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); - if (specimen == null) { - return; - } - - IIndividual individual = getSpeciesRoot().getMember(specimen); - // No individual, abort - if (individual == null) { - return; - } - - // Analyze if necessary - if (!individual.isAnalyzed()) { - - // Requires energy - if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { - return; - } - - individual.analyze(); - if (player != null) { - IBreedingTracker breedingTracker = getSpeciesRoot().getBreedingTracker(player.worldObj, player.getGameProfile()); - breedingTracker.registerSpecies(individual.getGenome().getPrimary()); - breedingTracker.registerSpecies(individual.getGenome().getSecondary()); - } - - NBTTagCompound nbttagcompound = new NBTTagCompound(); - individual.writeToNBT(nbttagcompound); - specimen.setTagCompound(nbttagcompound); - - // Decrease energy - decrStackSize(SLOT_ENERGY, 1); - } - - setInventorySlotContents(SLOT_ANALYZE_1, specimen); - setInventorySlotContents(SLOT_SPECIMEN, null); - } - - @Override - public final ImmutableSet getErrorStates() { - ImmutableSet.Builder errorStates = ImmutableSet.builder(); - - if (!hasSpecimen()) { - errorStates.add(EnumErrorCode.NOTHINGANALYZE); - } - - if (!isEnergy(getStackInSlot(SLOT_ENERGY))) { - errorStates.add(EnumErrorCode.NOHONEY); - } - - return errorStates.build(); - } - } - -} diff --git a/src/main/java/forestry/core/items/ItemElectronTube.java b/src/main/java/forestry/core/items/ItemElectronTube.java index 7b33cae21..8f2d18f9e 100644 --- a/src/main/java/forestry/core/items/ItemElectronTube.java +++ b/src/main/java/forestry/core/items/ItemElectronTube.java @@ -23,7 +23,7 @@ import net.minecraft.util.EnumChatFormatting; import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuit; import forestry.api.circuits.ICircuitLayout; -import forestry.core.circuits.ItemSolderingIron; +import forestry.core.circuits.SolderManager; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; @@ -39,7 +39,7 @@ public class ItemElectronTube extends ItemOverlay { Multimap circuits = ArrayListMultimap.create(); for (ICircuitLayout circuitLayout : ChipsetManager.circuitRegistry.getRegisteredLayouts().values()) { - ICircuit circuit = ItemSolderingIron.SolderManager.getCircuit(circuitLayout, itemstack); + ICircuit circuit = SolderManager.getCircuit(circuitLayout, itemstack); if (circuit != null) { circuits.put(circuitLayout, circuit); } diff --git a/src/main/java/forestry/core/items/ItemForestry.java b/src/main/java/forestry/core/items/ItemForestry.java index f6667cf04..7e8ab7db3 100755 --- a/src/main/java/forestry/core/items/ItemForestry.java +++ b/src/main/java/forestry/core/items/ItemForestry.java @@ -11,11 +11,7 @@ package forestry.core.items; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; -import net.minecraft.item.ItemDye; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -25,32 +21,10 @@ import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; public class ItemForestry extends Item { - - private boolean isBonemeal = false; - public ItemForestry() { setCreativeTab(CreativeTabForestry.tabForestry); } - public ItemForestry setBonemeal() { - this.isBonemeal = true; - return this; - } - - @Override - public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { - if (isBonemeal) { - if (ItemDye.applyBonemeal(itemstack, world, x, y, z, player)) { - if (!world.isRemote) { - world.playAuxSFX(2005, x, y, z, 0); - } - - return true; - } - } - return super.onItemUse(itemstack, player, world, x, y, z, par7, par8, par9, par10); - } - @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister register) { diff --git a/src/main/java/forestry/mail/items/ItemCatalogue.java b/src/main/java/forestry/core/items/ItemForestryBonemeal.java old mode 100755 new mode 100644 similarity index 55% rename from src/main/java/forestry/mail/items/ItemCatalogue.java rename to src/main/java/forestry/core/items/ItemForestryBonemeal.java index 064411f4f..7da2cc0de --- a/src/main/java/forestry/mail/items/ItemCatalogue.java +++ b/src/main/java/forestry/core/items/ItemForestryBonemeal.java @@ -1,39 +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.mail.items; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import forestry.api.core.ForestryAPI; -import forestry.core.items.ItemForestry; -import forestry.core.network.GuiId; - -public class ItemCatalogue extends ItemForestry { - - public ItemCatalogue() { - super(); - setMaxStackSize(1); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.CatalogueGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } - - return itemstack; - } - - -} +/******************************************************************************* + * 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.items; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemDye; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ItemForestryBonemeal extends ItemForestry { + @Override + public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int par7, float facingX, float facingY, float facingZ) { + if (ItemDye.applyBonemeal(itemstack, world, x, y, z, player)) { + if (!world.isRemote) { + world.playAuxSFX(2005, x, y, z, 0); + } + + return true; + } + return super.onItemUse(itemstack, player, world, x, y, z, par7, facingX, facingY, facingZ); + } +} diff --git a/src/main/java/forestry/core/items/ItemForestryTool.java b/src/main/java/forestry/core/items/ItemForestryTool.java index b6f5272e7..e3fe12545 100755 --- a/src/main/java/forestry/core/items/ItemForestryTool.java +++ b/src/main/java/forestry/core/items/ItemForestryTool.java @@ -31,7 +31,6 @@ public abstract class ItemForestryTool extends ItemForestry { private final List blocksEffectiveAgainst; protected ItemForestryTool(Block[] blocksEffectiveAgainst, ItemStack remnants) { - super(); this.blocksEffectiveAgainst = Arrays.asList(blocksEffectiveAgainst); this.maxStackSize = 1; efficiencyOnProperMaterial = 6F; diff --git a/src/main/java/forestry/core/items/ItemPipette.java b/src/main/java/forestry/core/items/ItemPipette.java index 14c38f361..97faf869c 100755 --- a/src/main/java/forestry/core/items/ItemPipette.java +++ b/src/main/java/forestry/core/items/ItemPipette.java @@ -23,56 +23,14 @@ import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.core.INBTTagable; import forestry.api.core.IToolPipette; import forestry.core.config.Constants; +import forestry.core.fluids.PipetteContents; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; public class ItemPipette extends ItemForestry implements IToolPipette { - static class PipetteContents implements INBTTagable { - - FluidStack contents; - - public PipetteContents(NBTTagCompound nbttagcompound) { - if (nbttagcompound != null) { - readFromNBT(nbttagcompound); - } - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - contents = FluidStack.loadFluidStackFromNBT(nbttagcompound); - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - if (contents != null) { - contents.writeToNBT(nbttagcompound); - } - } - - public boolean isFull() { - if (contents == null) { - return false; - } - - return contents.getFluid().getID() > 0 && contents.amount >= 1000; - } - - public void addTooltip(List list) { - if (contents == null) { - return; - } - - String descr = contents.getFluid().getLocalizedName(contents); - descr += " (" + contents.amount + " mb)"; - - list.add(descr); - } - } - public ItemPipette() { super(); setMaxStackSize(1); @@ -100,27 +58,24 @@ public class ItemPipette extends ItemForestry implements IToolPipette { int limit = getCapacity(itemstack); int filled; - if (contained.contents == null) { - + if (contained.getContents() == null) { if (liquid.amount > limit) { filled = limit; } else { filled = liquid.amount; } - contained.contents = new FluidStack(liquid, filled); + contained.setContents(new FluidStack(liquid, filled)); filled = liquid.amount; - } else { - - if (contained.contents.amount >= limit) { + if (contained.getContents().amount >= limit) { return 0; } - if (!contained.contents.isFluidEqual(liquid)) { + if (!contained.getContents().isFluidEqual(liquid)) { return 0; } - int space = limit - contained.contents.amount; + int space = limit - contained.getContents().amount; if (liquid.amount > space) { filled = space; @@ -128,7 +83,7 @@ public class ItemPipette extends ItemForestry implements IToolPipette { filled = liquid.amount; } - contained.contents.amount += filled; + contained.getContents().amount += filled; } if (doFill) { @@ -174,19 +129,19 @@ public class ItemPipette extends ItemForestry implements IToolPipette { @Override public FluidStack drain(ItemStack pipette, int maxDrain, boolean doDrain) { PipetteContents contained = new PipetteContents(pipette.getTagCompound()); - if (contained.contents == null || contained.contents.getFluid().getID() <= 0) { + if (contained.getContents() == null || contained.getContents().getFluid().getID() <= 0) { return null; } int drained = maxDrain; - if (contained.contents.amount < drained) { - drained = contained.contents.amount; + if (contained.getContents().amount < drained) { + drained = contained.getContents().amount; } if (doDrain) { - contained.contents.amount -= drained; + contained.getContents().amount -= drained; - if (contained.contents.amount <= 0) { + if (contained.getContents().amount <= 0) { pipette.setTagCompound(null); pipette.setItemDamage(0); } else { @@ -196,7 +151,7 @@ public class ItemPipette extends ItemForestry implements IToolPipette { } } - return new FluidStack(contained.contents, drained); + return new FluidStack(contained.getContents(), drained); } @Override diff --git a/src/main/java/forestry/core/items/ItemInventoried.java b/src/main/java/forestry/core/items/ItemWithGui.java old mode 100755 new mode 100644 similarity index 61% rename from src/main/java/forestry/core/items/ItemInventoried.java rename to src/main/java/forestry/core/items/ItemWithGui.java index 51b3de31d..879f78d93 --- a/src/main/java/forestry/core/items/ItemInventoried.java +++ b/src/main/java/forestry/core/items/ItemWithGui.java @@ -13,10 +13,32 @@ package forestry.core.items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import forestry.api.core.ForestryAPI; import forestry.core.gui.ContainerItemInventory; +import forestry.core.network.GuiId; -public abstract class ItemInventoried extends ItemForestry implements IInventoriedItem { +public class ItemWithGui extends ItemForestry { + private final GuiId guiId; + + public ItemWithGui(GuiId guiId) { + this.guiId = guiId; + setMaxStackSize(1); + } + + @Override + public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { + if (!world.isRemote) { + openGui(world, entityplayer); + } + + return itemstack; + } + + protected final void openGui(World world, EntityPlayer entityplayer) { + entityplayer.openGui(ForestryAPI.instance, guiId.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ); + } @Override public boolean onDroppedByPlayer(ItemStack itemstack, EntityPlayer player) { diff --git a/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java b/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java index 42964e59a..b5beb56ff 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockTileEntityBase.java @@ -39,7 +39,6 @@ public abstract class MultiblockTileEntityBase extends IMultiblockPart implement private boolean saveMultiblockData; private NBTTagCompound cachedMultiblockData; - private boolean paused; private GameProfile owner; @@ -48,7 +47,6 @@ public abstract class MultiblockTileEntityBase extends IMultiblockPart implement controller = null; visited = false; saveMultiblockData = false; - paused = false; cachedMultiblockData = null; } diff --git a/src/main/java/forestry/core/network/DataInputStreamForestry.java b/src/main/java/forestry/core/network/DataInputStreamForestry.java index 406d815cd..b175d05dc 100644 --- a/src/main/java/forestry/core/network/DataInputStreamForestry.java +++ b/src/main/java/forestry/core/network/DataInputStreamForestry.java @@ -109,9 +109,14 @@ public class DataInputStreamForestry extends DataInputStream { return varInt; } - public > T readEnum(Class enumClass) throws IOException { - int ordinal = readVarInt(); - return enumClass.getEnumConstants()[ordinal]; + public > T readEnum(T[] enumValues) throws IOException { + int ordinal; + if (enumValues.length <= 256) { + ordinal = readByte(); + } else { + ordinal = readVarInt(); + } + return enumValues[ordinal]; } public NBTTagCompound readNBTTagCompound() throws IOException { diff --git a/src/main/java/forestry/core/network/DataOutputStreamForestry.java b/src/main/java/forestry/core/network/DataOutputStreamForestry.java index 3e7922329..0b55ed927 100644 --- a/src/main/java/forestry/core/network/DataOutputStreamForestry.java +++ b/src/main/java/forestry/core/network/DataOutputStreamForestry.java @@ -86,8 +86,12 @@ public class DataOutputStreamForestry extends DataOutputStream { writeByte(varInt); } - public void writeEnum(Enum enumValue) throws IOException { - writeVarInt(enumValue.ordinal()); + public > void writeEnum(T enumValue, T[] enumValues) throws IOException { + if (enumValues.length <= 256) { + writeByte(enumValue.ordinal()); + } else { + writeVarInt(enumValue.ordinal()); + } } public void writeNBTTagCompound(NBTTagCompound nbttagcompound) throws IOException { diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 9bfe96d34..b1e010c5e 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -18,12 +18,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; - -import com.mojang.authlib.GameProfile; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.util.FakePlayerFactory; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.FMLCommonHandler; @@ -56,10 +52,6 @@ public class ProxyCommon { return new File("."); } - public int getByBlockModelId() { - return 0; - } - public boolean isOp(EntityPlayer player) { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); return server.getConfigurationManager().func_152596_g(player.getGameProfile()); diff --git a/src/main/java/forestry/core/proxy/ProxyCommonClient.java b/src/main/java/forestry/core/proxy/ProxyCommonClient.java index f1368677d..6bee8be2f 100644 --- a/src/main/java/forestry/core/proxy/ProxyCommonClient.java +++ b/src/main/java/forestry/core/proxy/ProxyCommonClient.java @@ -19,13 +19,10 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import com.mojang.authlib.GameProfile; - import cpw.mods.fml.common.FMLCommonHandler; import org.lwjgl.input.Keyboard; -import forestry.core.ForestryClient; import forestry.core.TickHandlerCoreClient; import forestry.core.multiblock.MultiblockClientTickHandler; import forestry.core.worldgen.WorldGenerator; @@ -50,11 +47,6 @@ public class ProxyCommonClient extends ProxyCommon { return getClientInstance().theWorld; } - @Override - public int getByBlockModelId() { - return ForestryClient.byBlockModelId; - } - @Override public boolean isOp(EntityPlayer player) { return false; diff --git a/src/main/java/forestry/core/proxy/ProxyRender.java b/src/main/java/forestry/core/proxy/ProxyRender.java index 0dc6de5dd..27d5ca1c3 100755 --- a/src/main/java/forestry/core/proxy/ProxyRender.java +++ b/src/main/java/forestry/core/proxy/ProxyRender.java @@ -22,8 +22,7 @@ import forestry.core.tiles.MachineDefinition; public class ProxyRender { - public int getNextAvailableRenderId() { - return 0; + public void init() { } public boolean fancyGraphicsEnabled() { diff --git a/src/main/java/forestry/core/proxy/ProxyRenderClient.java b/src/main/java/forestry/core/proxy/ProxyRenderClient.java index 17f49b142..944b1a0a2 100644 --- a/src/main/java/forestry/core/proxy/ProxyRenderClient.java +++ b/src/main/java/forestry/core/proxy/ProxyRenderClient.java @@ -28,6 +28,7 @@ import cpw.mods.fml.common.registry.VillagerRegistry; import forestry.apiculture.entities.EntityFXBee; import forestry.apiculture.render.ParticleRenderer; +import forestry.apiculture.render.RenderCandleBlock; import forestry.apiculture.render.TextureHabitatLocator; import forestry.core.config.Config; import forestry.core.entities.EntityFXHoneydust; @@ -47,9 +48,25 @@ import forestry.core.tiles.MachineDefinition; public class ProxyRenderClient extends ProxyRender { + private static int byBlockModelId; + private static int candleRenderId; + + public static int getCandleRenderId() { + return candleRenderId; + } + + public static int getByBlockModelRenderId() { + return byBlockModelId; + } + @Override - public int getNextAvailableRenderId() { - return RenderingRegistry.getNextAvailableRenderId(); + public void init() { + byBlockModelId = RenderingRegistry.getNextAvailableRenderId(); + candleRenderId = RenderingRegistry.getNextAvailableRenderId(); + + RenderBlock renderHandler = new RenderBlock(); + RenderingRegistry.registerBlockHandler(byBlockModelId, renderHandler); + RenderingRegistry.registerBlockHandler(candleRenderId, new RenderCandleBlock()); } @Override diff --git a/src/main/java/forestry/core/render/RenderBlock.java b/src/main/java/forestry/core/render/RenderBlock.java index b5e747e05..79b93d3f5 100644 --- a/src/main/java/forestry/core/render/RenderBlock.java +++ b/src/main/java/forestry/core/render/RenderBlock.java @@ -18,7 +18,7 @@ import net.minecraft.world.IBlockAccess; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; -import forestry.core.ForestryClient; +import forestry.core.proxy.ProxyRenderClient; public class RenderBlock implements ISimpleBlockRenderingHandler { @@ -27,7 +27,7 @@ public class RenderBlock implements ISimpleBlockRenderingHandler { @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { - if (block.getRenderType() == ForestryClient.byBlockModelId) { + if (block.getRenderType() == ProxyRenderClient.getByBlockModelRenderId()) { TileRendererIndex index = new TileRendererIndex(block, metadata); if (byBlockRenderer.containsKey(index)) { byBlockRenderer.get(index).inventoryRender(-0.5, -0.5, -0.5); @@ -48,7 +48,7 @@ public class RenderBlock implements ISimpleBlockRenderingHandler { @Override public int getRenderId() { - return ForestryClient.byBlockModelId; + return ProxyRenderClient.getByBlockModelRenderId(); } } diff --git a/src/main/java/forestry/core/render/RenderEscritoire.java b/src/main/java/forestry/core/render/RenderEscritoire.java index f88a45cec..d78825b92 100755 --- a/src/main/java/forestry/core/render/RenderEscritoire.java +++ b/src/main/java/forestry/core/render/RenderEscritoire.java @@ -22,6 +22,7 @@ import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; import forestry.core.config.Constants; +import forestry.core.inventory.InventoryEscritoire; import forestry.core.proxy.Proxies; import forestry.core.tiles.TileEscritoire; @@ -56,7 +57,7 @@ public class RenderEscritoire extends TileEntitySpecialRenderer implements IBloc @Override public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { TileEscritoire tile = (TileEscritoire) tileentity; - render(tile.getStackInSlot(TileEscritoire.SLOT_ANALYZE), tile.getOrientation(), x, y, z); + render(tile.getStackInSlot(InventoryEscritoire.SLOT_ANALYZE), tile.getOrientation(), x, y, z); } private void render(ItemStack itemstack, ForgeDirection orientation, double x, double y, double z) { diff --git a/src/main/java/forestry/core/tiles/EscritoireGame.java b/src/main/java/forestry/core/tiles/EscritoireGame.java index 24f49f70c..b8c97780d 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGame.java +++ b/src/main/java/forestry/core/tiles/EscritoireGame.java @@ -30,7 +30,8 @@ public class EscritoireGame implements INBTTagable, IStreamable { public static final int BOUNTY_MAX = 16; public enum Status { - EMPTY, PLAYING, FAILURE, SUCCESS + EMPTY, PLAYING, FAILURE, SUCCESS; + public static final Status[] VALUES = values(); } private final EscritoireGameBoard gameBoard = new EscritoireGameBoard(); @@ -79,14 +80,14 @@ public class EscritoireGame implements INBTTagable, IStreamable { public void writeData(DataOutputStreamForestry data) throws IOException { data.writeInt(bountyLevel); gameBoard.writeData(data); - data.writeEnum(status); + data.writeEnum(status, Status.VALUES); } @Override public void readData(DataInputStreamForestry data) throws IOException { bountyLevel = data.readInt(); gameBoard.readData(data); - status = data.readEnum(Status.class); + status = data.readEnum(Status.VALUES); } /* INTERACTION */ diff --git a/src/main/java/forestry/core/tiles/EscritoireGameToken.java b/src/main/java/forestry/core/tiles/EscritoireGameToken.java index f7207eef3..c794d5d99 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGameToken.java +++ b/src/main/java/forestry/core/tiles/EscritoireGameToken.java @@ -30,7 +30,8 @@ public class EscritoireGameToken implements INBTTagable, IStreamable { PROBED, // shown by escritoire probe action SELECTED, // selected by the user as the first half of a match MATCHED, // successfully matched - FAILED // failed to match + FAILED; // failed to match + public static final State[] VALUES = values(); } private static final String[] OVERLAY_NONE = new String[0]; @@ -153,13 +154,13 @@ public class EscritoireGameToken implements INBTTagable, IStreamable { /* IStreamable */ @Override public void writeData(DataOutputStreamForestry data) throws IOException { - data.writeEnum(state); + data.writeEnum(state, State.VALUES); data.writeItemStack(tokenStack); } @Override public void readData(DataInputStreamForestry data) throws IOException { - state = data.readEnum(State.class); + state = data.readEnum(State.VALUES); tokenStack = data.readItemStack(); } } diff --git a/src/main/java/forestry/core/tiles/ICrafter.java b/src/main/java/forestry/core/tiles/ICrafter.java index 7f576e239..19aecb602 100644 --- a/src/main/java/forestry/core/tiles/ICrafter.java +++ b/src/main/java/forestry/core/tiles/ICrafter.java @@ -14,11 +14,5 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; public interface ICrafter { - ItemStack takenFromSlot(int slotIndex, EntityPlayer player); - - ItemStack getResult(); - - boolean canTakeStack(int slotIndex); - } diff --git a/src/main/java/forestry/core/tiles/TileAnalyzer.java b/src/main/java/forestry/core/tiles/TileAnalyzer.java index 4b1bd1da0..eb72a2f5b 100644 --- a/src/main/java/forestry/core/tiles/TileAnalyzer.java +++ b/src/main/java/forestry/core/tiles/TileAnalyzer.java @@ -12,7 +12,6 @@ package forestry.core.tiles; import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -25,7 +24,6 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import forestry.api.arboriculture.TreeManager; -import forestry.api.core.ForestryAPI; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; import forestry.core.config.Constants; @@ -34,7 +32,7 @@ import forestry.core.fluids.FluidHelper; import forestry.core.fluids.Fluids; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.InventoryAnalyzer; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.inventory.wrappers.InventoryMapper; @@ -45,24 +43,13 @@ import forestry.core.network.PacketItemStackDisplay; import forestry.core.proxy.Proxies; import forestry.core.utils.GeneticsUtil; import forestry.core.utils.InventoryUtil; -import forestry.core.utils.SlotUtil; import forestry.plugins.PluginManager; public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler, IItemStackDisplay { - - /* CONSTANTS */ private static final int TIME_TO_ANALYZE = 125; private static final int HONEY_REQUIRED = 100; private static final int ENERGY_PER_WORK_CYCLE = 20320; - public static final short SLOT_ANALYZE = 0; - public static final short SLOT_CAN = 1; - public static final short SLOT_INPUT_1 = 2; - public static final short SLOT_INPUT_COUNT = 6; - public static final short SLOT_OUTPUT_1 = 8; - public static final short SLOT_OUTPUT_COUNT = 4; - - /* MEMBER */ private final FilteredTank resourceTank; private final TankManager tankManager; private final IInventory invInput; @@ -73,18 +60,12 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui /* CONSTRUCTOR */ public TileAnalyzer() { - super(800, Constants.MACHINE_MAX_ENERGY, ENERGY_PER_WORK_CYCLE); - setInternalInventory(new AnalyzerInventoryAdapter(this)); + super(GuiId.AnalyzerGUI, "analyzer", 800, Constants.MACHINE_MAX_ENERGY); + setInternalInventory(new InventoryAnalyzer(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.getFluid()); tankManager = new TankManager(this, resourceTank); - invInput = new InventoryMapper(getInternalInventory(), SLOT_INPUT_1, SLOT_INPUT_COUNT); - invOutput = new InventoryMapper(getInternalInventory(), SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT); - } - - /* GUI */ - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.AnalyzerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + invInput = new InventoryMapper(getInternalInventory(), InventoryAnalyzer.SLOT_INPUT_1, InventoryAnalyzer.SLOT_INPUT_COUNT); + invOutput = new InventoryMapper(getInternalInventory(), InventoryAnalyzer.SLOT_OUTPUT_1, InventoryAnalyzer.SLOT_OUTPUT_COUNT); } /* SAVING & LOADING */ @@ -99,7 +80,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui super.readFromNBT(nbttagcompound); tankManager.readFromNBT(nbttagcompound); - ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE); + ItemStack stackToAnalyze = getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE); if (stackToAnalyze != null) { specimenToAnalyze = AlleleManager.alleleRegistry.getIndividual(stackToAnalyze); } @@ -111,14 +92,14 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui if (updateOnInterval(20)) { // Check if we have suitable items waiting in the can slot - FluidHelper.drainContainers(tankManager, this, SLOT_CAN); + FluidHelper.drainContainers(tankManager, this, InventoryAnalyzer.SLOT_CAN); } } /* WORKING */ @Override public boolean workCycle() { - ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE); + ItemStack stackToAnalyze = getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE); if (stackToAnalyze == null) { return false; } @@ -141,7 +122,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui return false; } - setInventorySlotContents(SLOT_ANALYZE, null); + setInventorySlotContents(InventoryAnalyzer.SLOT_ANALYZE, null); PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay()); Proxies.net.sendNetworkPacket(packet, worldObj); @@ -187,7 +168,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui public boolean hasWork() { moveSpecimenToAnalyzeSlot(); - ItemStack specimen = getStackInSlot(SLOT_ANALYZE); + ItemStack specimen = getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE); boolean hasSpecimen = (specimen != null); boolean hasResource = true; @@ -209,7 +190,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui } private void moveSpecimenToAnalyzeSlot() { - if (getStackInSlot(SLOT_ANALYZE) != null) { + if (getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE) != null) { return; } @@ -235,7 +216,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui return; } - setInventorySlotContents(SLOT_ANALYZE, inputStack); + setInventorySlotContents(InventoryAnalyzer.SLOT_ANALYZE, inputStack); slot.setStackInSlot(null); if (specimenToAnalyze.isAnalyzed()) { @@ -254,7 +235,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui if (worldObj.isRemote) { return individualOnDisplayClient; } - return getStackInSlot(SLOT_ANALYZE); + return getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE); } /* ILiquidTankTile */ @@ -294,38 +275,4 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui return tankManager.getTankInfo(from); } - private static class AnalyzerInventoryAdapter extends TileInventoryAdapter { - public AnalyzerInventoryAdapter(TileAnalyzer analyzer) { - super(analyzer, 12, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (SlotUtil.isSlotInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)) { - return AlleleManager.alleleRegistry.isIndividual(itemStack) || GeneticsUtil.getGeneticEquivalent(itemStack) != null; - } else if (slotIndex == SLOT_CAN) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.resourceTank.accepts(fluid); - } - - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT); - } - - @Override - public void setInventorySlotContents(int slotId, ItemStack itemStack) { - if (PluginManager.Module.ARBORICULTURE.isEnabled() && !TreeManager.treeRoot.isMember(itemStack)) { - ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(itemStack); - if (ersatz != null) { - itemStack = ersatz; - } - } - - super.setInventorySlotContents(slotId, itemStack); - } - } } diff --git a/src/main/java/forestry/core/tiles/TileBase.java b/src/main/java/forestry/core/tiles/TileBase.java index b1374a1f4..588390452 100644 --- a/src/main/java/forestry/core/tiles/TileBase.java +++ b/src/main/java/forestry/core/tiles/TileBase.java @@ -10,27 +10,39 @@ ******************************************************************************/ package forestry.core.tiles; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; +import forestry.api.core.ForestryAPI; +import forestry.core.config.Config; import forestry.core.gui.IHintSource; +import forestry.core.network.GuiId; public abstract class TileBase extends TileForestry implements IHintSource { - public abstract void openGui(EntityPlayer player); + protected final GuiId guiId; + protected final List hints; + + protected TileBase(GuiId guiId, String hintKey) { + this.guiId = guiId; + this.hints = new ArrayList<>(Config.hints.get(hintKey)); + } + + public void openGui(EntityPlayer player) { + if (guiId != null) { + player.openGui(ForestryAPI.instance, guiId.ordinal(), worldObj, xCoord, yCoord, zCoord); + } + } public boolean canDrainWithBucket() { return false; } /* IHintSource */ - private String[] hints; - - protected void setHints(String[] hints) { - this.hints = hints; - } - @Override - public String[] getHints() { + public final List getHints() { return hints; } } diff --git a/src/main/java/forestry/core/tiles/TileEngine.java b/src/main/java/forestry/core/tiles/TileEngine.java index 19a6635d4..7b1840364 100644 --- a/src/main/java/forestry/core/tiles/TileEngine.java +++ b/src/main/java/forestry/core/tiles/TileEngine.java @@ -22,10 +22,12 @@ import net.minecraftforge.common.util.ForgeDirection; import forestry.api.core.IErrorLogic; import forestry.apiculture.network.PacketActiveUpdate; +import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.utils.BlockUtil; import forestry.energy.EnergyManager; @@ -52,12 +54,15 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection, public float progress; protected final EnergyManager energyManager; - protected TileEngine(int maxHeat, int maxEnergy) { + protected TileEngine(GuiId guiId, String hintKey, int maxHeat, int maxEnergy) { + super(guiId, hintKey); this.maxHeat = maxHeat; energyManager = new EnergyManager(2000, maxEnergy); // allow engines to chain, but not have energy sucked out of them energyManager.setReceiveOnly(); + + hints.addAll(Config.hints.get("engine")); } @Override diff --git a/src/main/java/forestry/core/tiles/TileEscritoire.java b/src/main/java/forestry/core/tiles/TileEscritoire.java index 8d2314f22..6499bf421 100644 --- a/src/main/java/forestry/core/tiles/TileEscritoire.java +++ b/src/main/java/forestry/core/tiles/TileEscritoire.java @@ -19,53 +19,35 @@ import net.minecraft.nbt.NBTTagCompound; import com.mojang.authlib.GameProfile; -import forestry.api.core.ForestryAPI; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IIndividual; -import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.InventoryEscritoire; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.network.IStreamableGui; -import forestry.core.render.TankRenderInfo; -import forestry.core.utils.GeneticsUtil; import forestry.core.utils.InventoryUtil; -import forestry.core.utils.SlotUtil; -public class TileEscritoire extends TileBase implements ISidedInventory, IRenderableTile, ICrafter, IStreamableGui { +public class TileEscritoire extends TileBase implements ISidedInventory, ICrafter, IStreamableGui { - public static final short SLOT_ANALYZE = 0; - public static final short SLOT_RESULTS_1 = 1; - public static final short SLOTS_RESULTS_COUNT = 6; - public static final short SLOT_INPUT_1 = 7; - public static final short SLOTS_INPUT_COUNT = 5; - - /* MEMBER */ private final EscritoireGame game = new EscritoireGame(); public TileEscritoire() { - setInternalInventory(new EscritoireInventoryAdapter(this)); - } - - /* GUI */ - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.NaturalistBenchGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + super(GuiId.NaturalistBenchGUI, "escritoire"); + setInternalInventory(new InventoryEscritoire(this)); } /* SAVING & LOADING */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - game.readFromNBT(nbttagcompound); } @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - game.writeToNBT(nbttagcompound); } @@ -84,21 +66,21 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender return; } - IIndividual individual = AlleleManager.alleleRegistry.getIndividual(getStackInSlot(SLOT_ANALYZE)); + IIndividual individual = AlleleManager.alleleRegistry.getIndividual(getStackInSlot(InventoryEscritoire.SLOT_ANALYZE)); if (individual == null) { return; } IAlleleSpecies species = individual.getGenome().getPrimary(); for (ItemStack itemstack : species.getResearchBounty(worldObj, gameProfile, individual, game.getBountyLevel())) { - InventoryUtil.addStack(getInternalInventory(), itemstack, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT, true); + InventoryUtil.addStack(getInternalInventory(), itemstack, InventoryEscritoire.SLOT_RESULTS_1, InventoryEscritoire.SLOTS_RESULTS_COUNT, true); } } private boolean areProbeSlotsFilled() { int filledSlots = 0; - int required = game.getSampleSize(SLOTS_INPUT_COUNT); - for (int i = SLOT_INPUT_1; i < SLOT_INPUT_1 + required; i++) { + int required = game.getSampleSize(InventoryEscritoire.SLOTS_INPUT_COUNT); + for (int i = InventoryEscritoire.SLOT_INPUT_1; i < InventoryEscritoire.SLOT_INPUT_1 + required; i++) { if (getStackInSlot(i) != null) { filledSlots++; } @@ -112,10 +94,10 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender return; } - ItemStack analyze = getStackInSlot(SLOT_ANALYZE); + ItemStack analyze = getStackInSlot(InventoryEscritoire.SLOT_ANALYZE); if (analyze != null && areProbeSlotsFilled()) { - game.probe(analyze, this, SLOT_INPUT_1, SLOTS_INPUT_COUNT); + game.probe(analyze, this, InventoryEscritoire.SLOT_INPUT_1, InventoryEscritoire.SLOTS_INPUT_COUNT); } } @@ -130,96 +112,23 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender game.readData(data); } - @Override - public TankRenderInfo getResourceTankInfo() { - return TankRenderInfo.EMPTY; - } - - @Override - public TankRenderInfo getProductTankInfo() { - return TankRenderInfo.EMPTY; - } + // @Override + // public TankRenderInfo getResourceTankInfo() { + // return TankRenderInfo.EMPTY; + // } + // + // @Override + // public TankRenderInfo getProductTankInfo() { + // return TankRenderInfo.EMPTY; + // } + /* ICrafter */ @Override public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { - if (slotIndex == SLOT_ANALYZE) { + if (slotIndex == InventoryEscritoire.SLOT_ANALYZE) { game.reset(); } return null; } - @Override - public ItemStack getResult() { - return null; - } - - @Override - public boolean canTakeStack(int slotIndex) { - return true; - } - - private static class EscritoireInventoryAdapter extends TileInventoryAdapter { - public EscritoireInventoryAdapter(TileEscritoire escritoire) { - super(escritoire, 12, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + tile.game.getSampleSize(SLOTS_INPUT_COUNT)) { - ItemStack specimen = getStackInSlot(SLOT_ANALYZE); - if (specimen == null) { - return false; - } - IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen); - return individual != null && individual.getGenome().getPrimary().getResearchSuitability(itemStack) > 0; - } - - if (slotIndex == SLOT_ANALYZE) { - return AlleleManager.alleleRegistry.isIndividual(itemStack); - } - - return false; - } - - @Override - public boolean isLocked(int slotIndex) { - if (slotIndex == SLOT_ANALYZE) { - return false; - } - - if (getStackInSlot(SLOT_ANALYZE) == null) { - return true; - } - - if (SlotUtil.isSlotInRange(slotIndex, SLOT_INPUT_1, SLOTS_INPUT_COUNT)) { - if (slotIndex >= SLOT_INPUT_1 + tile.game.getSampleSize(SLOTS_INPUT_COUNT)) { - return true; - } - } - - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT); - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { - super.setInventorySlotContents(slotIndex, itemstack); - if (tile.worldObj == null) { - return; - } - if (slotIndex == SLOT_ANALYZE && !tile.worldObj.isRemote) { - if (!AlleleManager.alleleRegistry.isIndividual(getStackInSlot(SLOT_ANALYZE)) && getStackInSlot(SLOT_ANALYZE) != null) { - ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_ANALYZE)); - if (ersatz != null) { - setInventorySlotContents(SLOT_ANALYZE, ersatz); - } - } - tile.game.initialize(getStackInSlot(SLOT_ANALYZE)); - } - } - } } diff --git a/src/main/java/forestry/core/tiles/TileForestry.java b/src/main/java/forestry/core/tiles/TileForestry.java index f2f233f28..46f5d72cf 100644 --- a/src/main/java/forestry/core/tiles/TileForestry.java +++ b/src/main/java/forestry/core/tiles/TileForestry.java @@ -51,7 +51,7 @@ import buildcraft.api.statements.ITriggerProvider; @Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate, IRestrictedAccess, ITitled, ILocatable { - + private static final ForgeDirection[] forgeDirections = ForgeDirection.values(); private static final Random rand = new Random(); private final AccessHandler accessHandler = new AccessHandler(this); @@ -170,14 +170,15 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE Proxies.net.sendNetworkPacket(packet, worldObj); } + /* IStreamable */ @Override public void writeData(DataOutputStreamForestry data) throws IOException { - data.writeByte(orientation.ordinal()); + data.writeEnum(orientation, forgeDirections); } @Override public void readData(DataInputStreamForestry data) throws IOException { - orientation = ForgeDirection.getOrientation(data.readByte()); + orientation = data.readEnum(forgeDirections); } public void onRemoval() { diff --git a/src/main/java/forestry/core/tiles/TileMill.java b/src/main/java/forestry/core/tiles/TileMill.java index be88354ea..ba0dbe680 100644 --- a/src/main/java/forestry/core/tiles/TileMill.java +++ b/src/main/java/forestry/core/tiles/TileMill.java @@ -14,6 +14,7 @@ import java.io.IOException; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.GuiId; public abstract class TileMill extends TileBase { @@ -22,7 +23,8 @@ public abstract class TileMill extends TileBase { public int charge = 0; public float progress; - protected TileMill() { + protected TileMill(GuiId guiId, String hintKey) { + super(guiId, hintKey); speed = 0.01F; } diff --git a/src/main/java/forestry/core/tiles/TileNaturalistChest.java b/src/main/java/forestry/core/tiles/TileNaturalistChest.java index fb786b9d2..a4355531b 100644 --- a/src/main/java/forestry/core/tiles/TileNaturalistChest.java +++ b/src/main/java/forestry/core/tiles/TileNaturalistChest.java @@ -13,29 +13,39 @@ package forestry.core.tiles; import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import forestry.api.core.ForestryAPI; import forestry.api.genetics.ISpeciesRoot; import forestry.core.GuiHandler; -import forestry.core.config.Config; import forestry.core.gui.IPagedInventory; -import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.InventoryNaturalistChest; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.GuiId; public abstract class TileNaturalistChest extends TileBase implements IPagedInventory { private static final float lidAngleVariationPerTick = 0.1F; - private final int guiID; public float lidAngle; public float prevLidAngle; private int numPlayersUsing; - public TileNaturalistChest(ISpeciesRoot speciesRoot, int guiId) { - setInternalInventory(new NaturalistInventoryAdapter(this, speciesRoot)); - setHints(Config.hints.get("apiarist.chest")); - this.guiID = guiId; + public TileNaturalistChest(ISpeciesRoot speciesRoot, GuiId guiId) { + super(guiId, "naturalist.chest"); + setInternalInventory(new InventoryNaturalistChest(this, speciesRoot)); + } + + public void increaseNumPlayersUsing() { + numPlayersUsing++; + setNeedsNetworkUpdate(); + } + + public void decreaseNumPlayersUsing() { + numPlayersUsing--; + if (numPlayersUsing < 0) { + numPlayersUsing = 0; + } + setNeedsNetworkUpdate(); } @Override @@ -76,16 +86,12 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, sound, 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, guiID, player.worldObj, xCoord, yCoord, zCoord); - } - @Override public void flipPage(EntityPlayer player, int page) { - player.openGui(ForestryAPI.instance, GuiHandler.encodeGuiData(guiID, page), player.worldObj, xCoord, yCoord, zCoord); + player.openGui(ForestryAPI.instance, GuiHandler.encodeGuiData(guiId, page), player.worldObj, xCoord, yCoord, zCoord); } + /* IStreamable */ @Override public void writeData(DataOutputStreamForestry data) throws IOException { super.writeData(data); @@ -97,38 +103,4 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve super.readData(data); numPlayersUsing = data.readInt(); } - - private static class NaturalistInventoryAdapter extends TileInventoryAdapter { - private final ISpeciesRoot speciesRoot; - - public NaturalistInventoryAdapter(TileNaturalistChest tile, ISpeciesRoot speciesRoot) { - super(tile, 125, "Items"); - this.speciesRoot = speciesRoot; - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemstack) { - return speciesRoot.isMember(itemstack); - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { - return true; - } - - @Override - public void openInventory() { - tile.numPlayersUsing++; - tile.setNeedsNetworkUpdate(); - } - - @Override - public void closeInventory() { - tile.numPlayersUsing--; - if (tile.numPlayersUsing < 0) { - tile.numPlayersUsing = 0; - } - tile.setNeedsNetworkUpdate(); - } - } } diff --git a/src/main/java/forestry/core/tiles/TilePowered.java b/src/main/java/forestry/core/tiles/TilePowered.java index cc223aee4..9a80ee0c0 100644 --- a/src/main/java/forestry/core/tiles/TilePowered.java +++ b/src/main/java/forestry/core/tiles/TilePowered.java @@ -20,9 +20,11 @@ import cpw.mods.fml.common.Optional; import forestry.api.core.IErrorLogic; import forestry.core.circuits.ISpeedUpgradable; +import forestry.core.config.Config; import forestry.core.errors.EnumErrorCode; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.GuiId; import forestry.core.network.IStreamableGui; import forestry.core.render.TankRenderInfo; import forestry.energy.EnergyManager; @@ -31,7 +33,6 @@ import buildcraft.api.tiles.IHasWork; @Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles") public abstract class TilePowered extends TileBase implements IRenderableTile, IPowerHandler, IHasWork, ISpeedUpgradable, IStreamableGui { - private static final int WORK_TICK_INTERVAL = 5; // one Forestry work tick happens every WORK_TICK_INTERVAL game ticks private final EnergyManager energyManager; @@ -46,12 +47,14 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I // the number of work ticks that this tile has had no power private int noPowerTime = 0; - protected TilePowered(int maxTransfer, int capacity, int energyPerWorkCycle) { + protected TilePowered(GuiId guiId, String hintKey, int maxTransfer, int capacity) { + super(guiId, hintKey); this.energyManager = new EnergyManager(maxTransfer, capacity); this.energyManager.setReceiveOnly(); - setEnergyPerWorkCycle(energyPerWorkCycle); this.ticksPerWorkCycle = 4; + + hints.addAll(Config.hints.get("powered.machine")); } public int getWorkCounter() { diff --git a/src/main/java/forestry/energy/EnergyManager.java b/src/main/java/forestry/energy/EnergyManager.java index 2ce73888b..48e433baa 100644 --- a/src/main/java/forestry/energy/EnergyManager.java +++ b/src/main/java/forestry/energy/EnergyManager.java @@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -import forestry.core.config.GameMode; +import forestry.api.core.ForestryAPI; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; @@ -31,7 +31,7 @@ public class EnergyManager implements IEnergyHandler, IStreamable { } public static int scaleForDifficulty(int energyPerUse) { - return Math.round(energyPerUse * GameMode.getGameMode().getFloatSetting("energy.demand.modifier")); + return Math.round(energyPerUse * ForestryAPI.activeMode.getFloatSetting("energy.demand.modifier")); } public void setExtractOnly() { diff --git a/src/main/java/forestry/energy/circuits/CircuitFireDampener.java b/src/main/java/forestry/energy/circuits/CircuitFireDampener.java deleted file mode 100755 index 931965f1e..000000000 --- a/src/main/java/forestry/energy/circuits/CircuitFireDampener.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * 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.energy.circuits; - -import forestry.core.circuits.Circuit; -import forestry.energy.tiles.TileEnginePeat; - -public class CircuitFireDampener extends Circuit { - - public CircuitFireDampener(String uid) { - super(uid, false); - } - - @Override - public boolean isCircuitable(Object tile) { - return tile instanceof TileEnginePeat; - } - - @Override - public void onInsertion(int slot, Object tile) { - if (!isCircuitable(tile)) { - return; - } - - } - - @Override - public void onLoad(int slot, Object tile) { - onInsertion(slot, tile); - } - - @Override - public void onRemoval(int slot, Object tile) { - } - - @Override - public void onTick(int slot, Object tile) { - } - -} diff --git a/src/main/java/forestry/energy/gui/ContainerEngineBiogas.java b/src/main/java/forestry/energy/gui/ContainerEngineBiogas.java index 24cb77e86..82b748cff 100644 --- a/src/main/java/forestry/energy/gui/ContainerEngineBiogas.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineBiogas.java @@ -15,6 +15,7 @@ import net.minecraft.inventory.ICrafting; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; +import forestry.energy.inventory.InventoryEngineBiogas; import forestry.energy.tiles.TileEngineBiogas; public class ContainerEngineBiogas extends ContainerLiquidTanks { @@ -22,7 +23,7 @@ public class ContainerEngineBiogas extends ContainerLiquidTanks { @@ -22,7 +23,7 @@ public class ContainerEngineElectric extends ContainerSocketed { @@ -22,7 +23,7 @@ public class ContainerGenerator extends ContainerLiquidTanks { public ContainerGenerator(InventoryPlayer player, TileGenerator tile) { super(tile, player, 8, 84); - this.addSlotToContainer(new SlotFiltered(tile, TileGenerator.SLOT_CAN, 22, 38)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryGenerator.SLOT_CAN, 22, 38)); } @Override diff --git a/src/main/java/forestry/energy/gui/GuiEngineBiogas.java b/src/main/java/forestry/energy/gui/GuiEngineBiogas.java index 56fb78a05..7c5505758 100644 --- a/src/main/java/forestry/energy/gui/GuiEngineBiogas.java +++ b/src/main/java/forestry/energy/gui/GuiEngineBiogas.java @@ -41,11 +41,11 @@ public class GuiEngineBiogas extends GuiEngine height) { squaled = height; } @@ -88,7 +88,7 @@ public class GuiEngineBiogas extends GuiEngine { + public static final short SLOT_CAN = 0; + + public InventoryEngineBiogas(TileEngineBiogas engineBronze) { + super(engineBronze, 1, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + + return false; + } +} diff --git a/src/main/java/forestry/energy/inventory/InventoryEnginePeat.java b/src/main/java/forestry/energy/inventory/InventoryEnginePeat.java new file mode 100644 index 000000000..baa2c3b4e --- /dev/null +++ b/src/main/java/forestry/energy/inventory/InventoryEnginePeat.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.energy.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.api.fuels.FuelManager; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.energy.tiles.TileEnginePeat; + +public class InventoryEnginePeat extends InventoryAdapterTile { + public static final short SLOT_FUEL = 0; + public static final short SLOT_WASTE_1 = 1; + public static final short SLOT_WASTE_COUNT = 4; + + public InventoryEnginePeat(TileEnginePeat engineCopper) { + super(engineCopper, 5, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return slotIndex == SLOT_FUEL && FuelManager.copperEngineFuel.containsKey(itemStack); + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return SlotUtil.isSlotInRange(slotIndex, SLOT_WASTE_1, SLOT_WASTE_COUNT); + } +} diff --git a/src/main/java/forestry/energy/inventory/InventoryGenerator.java b/src/main/java/forestry/energy/inventory/InventoryGenerator.java new file mode 100644 index 000000000..457e5e269 --- /dev/null +++ b/src/main/java/forestry/energy/inventory/InventoryGenerator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.energy.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.energy.tiles.TileGenerator; + +public class InventoryGenerator extends InventoryAdapterTile { + public static final short SLOT_CAN = 0; + + public InventoryGenerator(TileGenerator generator) { + super(generator, 1, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + + return false; + } +} diff --git a/src/main/java/forestry/energy/tiles/InventoryEngineElectric.java b/src/main/java/forestry/energy/tiles/InventoryEngineElectric.java new file mode 100644 index 000000000..58c94e1c9 --- /dev/null +++ b/src/main/java/forestry/energy/tiles/InventoryEngineElectric.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.energy.tiles; + +import net.minecraft.item.ItemStack; + +import forestry.core.inventory.InventoryAdapterTile; + +import ic2.api.item.ElectricItem; + +public class InventoryEngineElectric extends InventoryAdapterTile { + public static final short SLOT_BATTERY = 0; + + public InventoryEngineElectric(TileEngineElectric engineTin) { + super(engineTin, 1, "electrical"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_BATTERY) { + return ElectricItem.manager.getCharge(itemStack) > 0; + } + return false; + } +} diff --git a/src/main/java/forestry/energy/tiles/TileEngineBiogas.java b/src/main/java/forestry/energy/tiles/TileEngineBiogas.java index 3e12c05ce..cbdc55a56 100644 --- a/src/main/java/forestry/energy/tiles/TileEngineBiogas.java +++ b/src/main/java/forestry/energy/tiles/TileEngineBiogas.java @@ -12,11 +12,9 @@ package forestry.energy.tiles; import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; @@ -26,11 +24,9 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.fuels.EngineBronzeFuel; import forestry.api.fuels.FuelManager; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; @@ -38,34 +34,27 @@ import forestry.core.fluids.Fluids; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.tanks.StandardTank; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TileEngine; +import forestry.energy.inventory.InventoryEngineBiogas; public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILiquidTankTile, IFluidHandler { - - /* CONSTANTS */ - public static final short SLOT_CAN = 0; - private final FilteredTank fuelTank; private final FilteredTank heatingTank; private final TankManager tankManager; - public int burnTime; - public int totalTime; - public int currentFluidId = -1; - /** - * true if the engine is too cold and needs to warm itself up. - */ - private boolean shutdown; + + private int burnTime; + private int totalTime; + private int currentFluidId = -1; + private boolean shutdown; // true if the engine is too cold and needs to warm itself up. public TileEngineBiogas() { - super(Constants.ENGINE_BRONZE_HEAT_MAX, 300000); - setHints(Config.hints.get("engine.bronze")); + super(GuiId.EngineBiogasGUI, "engine.bronze", Constants.ENGINE_BRONZE_HEAT_MAX, 300000); - setInternalInventory(new EngineBronzeInventoryAdapter(this)); + setInternalInventory(new InventoryEngineBiogas(this)); fuelTank = new FilteredTank(Constants.ENGINE_TANK_CAPACITY, FuelManager.bronzeEngineFuel.keySet()); fuelTank.tankMode = StandardTank.TankMode.DEFAULT; @@ -74,14 +63,21 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi this.tankManager = new TankManager(this, fuelTank, heatingTank); } - @Override - public TankManager getTankManager() { - return tankManager; + public int getBurnTime() { + return burnTime; + } + + public int getTotalTime() { + return totalTime; + } + + public int getCurrentFluidId() { + return currentFluidId; } @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.EngineBiogasGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + public TankManager getTankManager() { + return tankManager; } @Override @@ -92,7 +88,7 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi } // Check if we have suitable items waiting in the item slot - FluidHelper.drainContainers(tankManager, this, SLOT_CAN); + FluidHelper.drainContainers(tankManager, this, InventoryEngineBiogas.SLOT_CAN); IErrorLogic errorLogic = getErrorLogic(); @@ -359,20 +355,4 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - - private static class EngineBronzeInventoryAdapter extends TileInventoryAdapter { - public EngineBronzeInventoryAdapter(TileEngineBiogas engineBronze) { - super(engineBronze, 1, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_CAN) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.tankManager.accepts(fluid); - } - - return false; - } - } } diff --git a/src/main/java/forestry/energy/tiles/TileEngineClockwork.java b/src/main/java/forestry/energy/tiles/TileEngineClockwork.java index f8f52c7c1..8a11c987a 100644 --- a/src/main/java/forestry/energy/tiles/TileEngineClockwork.java +++ b/src/main/java/forestry/energy/tiles/TileEngineClockwork.java @@ -39,7 +39,7 @@ public class TileEngineClockwork extends TileEngine { private short delay = 0; public TileEngineClockwork() { - super(ENGINE_CLOCKWORK_HEAT_MAX, 10000); + super(null, null, ENGINE_CLOCKWORK_HEAT_MAX, 10000); } @Override diff --git a/src/main/java/forestry/energy/tiles/TileEngineElectric.java b/src/main/java/forestry/energy/tiles/TileEngineElectric.java index be3e564d0..0645f5c12 100644 --- a/src/main/java/forestry/energy/tiles/TileEngineElectric.java +++ b/src/main/java/forestry/energy/tiles/TileEngineElectric.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.energy.tiles; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; @@ -21,21 +20,17 @@ import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitBoard; import forestry.api.circuits.ICircuitSocketType; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.core.circuits.ISocketable; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.inventory.InventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.tiles.TemperatureState; import forestry.core.tiles.TileEngine; import forestry.plugins.PluginIC2; import ic2.api.energy.prefab.BasicSink; -import ic2.api.item.ElectricItem; public class TileEngineElectric extends TileEngine implements ISocketable, IInventory { @@ -52,28 +47,21 @@ public class TileEngineElectric extends TileEngine implements ISocketable, IInve } } - public static final short SLOT_BATTERY = 0; private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); private final EuConfig euConfig = new EuConfig(); private BasicSink ic2EnergySink; public TileEngineElectric() { - super(Constants.ENGINE_ELECTRIC_HEAT_MAX, 100000); - setHints(Config.hints.get("engine.tin")); + super(GuiId.EngineElectricGUI, "engine.tin", Constants.ENGINE_ELECTRIC_HEAT_MAX, 100000); - setInternalInventory(new EngineTinInventoryAdapter(this)); + setInternalInventory(new InventoryEngineElectric(this)); if (PluginIC2.instance.isAvailable()) { ic2EnergySink = new BasicSink(this, euConfig.euStorage, 3); } } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.EngineElectricGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - // / SAVING / LOADING @Override public void readFromNBT(NBTTagCompound nbttagcompound) { @@ -176,8 +164,8 @@ public class TileEngineElectric extends TileEngine implements ISocketable, IInve return; } - if (getInternalInventory().getStackInSlot(SLOT_BATTERY) != null) { - replenishFromBattery(SLOT_BATTERY); + if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) { + replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY); } // Updating of gui delayed to prevent it from going crazy @@ -210,7 +198,7 @@ public class TileEngineElectric extends TileEngine implements ISocketable, IInve return; } - ic2EnergySink.discharge(getInternalInventory().getStackInSlot(slot), euConfig.euForCycle * 3); + ic2EnergySink.discharge(getStackInSlot(slot), euConfig.euForCycle * 3); } // / STATE INFORMATION @@ -315,18 +303,4 @@ public class TileEngineElectric extends TileEngine implements ISocketable, IInve public ICircuitSocketType getSocketType() { return CircuitSocketType.ELECTRIC_ENGINE; } - - private static class EngineTinInventoryAdapter extends TileInventoryAdapter { - public EngineTinInventoryAdapter(TileEngineElectric engineTin) { - super(engineTin, 1, "electrical"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_BATTERY) { - return ElectricItem.manager.getCharge(itemStack) > 0; - } - return false; - } - } } diff --git a/src/main/java/forestry/energy/tiles/TileEnginePeat.java b/src/main/java/forestry/energy/tiles/TileEnginePeat.java index d3480a133..e650d1cbc 100644 --- a/src/main/java/forestry/energy/tiles/TileEnginePeat.java +++ b/src/main/java/forestry/energy/tiles/TileEnginePeat.java @@ -13,7 +13,6 @@ package forestry.energy.tiles; import java.util.Collection; import java.util.LinkedList; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; @@ -28,33 +27,23 @@ import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.registry.GameData; -import forestry.api.core.ForestryAPI; import forestry.api.fuels.FuelManager; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; import forestry.core.errors.EnumErrorCode; import forestry.core.inventory.AdjacentInventoryCache; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.GuiId; import forestry.core.tiles.TemperatureState; import forestry.core.tiles.TileEngine; import forestry.core.utils.InventoryUtil; -import forestry.core.utils.SlotUtil; +import forestry.energy.inventory.InventoryEnginePeat; import forestry.factory.triggers.FactoryTriggers; import buildcraft.api.statements.ITriggerExternal; public class TileEnginePeat extends TileEngine implements ISidedInventory { - - /* CONSTANTS */ - public static final short SLOT_FUEL = 0; - public static final short SLOT_WASTE_1 = 1; - public static final short SLOT_WASTE_COUNT = 4; - - /* MEMBERS */ private Item fuelItem; private int fuelItemMeta; private int burnTime; @@ -64,26 +53,20 @@ public class TileEnginePeat extends TileEngine implements ISidedInventory { private final AdjacentInventoryCache inventoryCache = new AdjacentInventoryCache(this, getTileCache()); public TileEnginePeat() { - super(Constants.ENGINE_COPPER_HEAT_MAX, 200000); - setHints(Config.hints.get("engine.copper")); + super(GuiId.EnginePeatGUI, "engine.copper", Constants.ENGINE_COPPER_HEAT_MAX, 200000); ashForItem = Constants.ENGINE_COPPER_ASH_FOR_ITEM; - setInternalInventory(new EngineCopperInventoryAdapter(this)); - } - - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.EnginePeatGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + setInternalInventory(new InventoryEnginePeat(this)); } private int getFuelSlot() { IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_FUEL) == null) { + if (inventory.getStackInSlot(InventoryEnginePeat.SLOT_FUEL) == null) { return -1; } - if (determineFuelValue(inventory.getStackInSlot(SLOT_FUEL)) > 0) { - return SLOT_FUEL; + if (determineFuelValue(inventory.getStackInSlot(InventoryEnginePeat.SLOT_FUEL)) > 0) { + return InventoryEnginePeat.SLOT_FUEL; } return -1; @@ -91,7 +74,7 @@ public class TileEnginePeat extends TileEngine implements ISidedInventory { private int getFreeWasteSlot() { IInventoryAdapter inventory = getInternalInventory(); - for (int i = SLOT_WASTE_1; i <= SLOT_WASTE_COUNT; i++) { + for (int i = InventoryEnginePeat.SLOT_WASTE_1; i <= InventoryEnginePeat.SLOT_WASTE_COUNT; i++) { if (inventory.getStackInSlot(i) == null) { return i; } @@ -239,7 +222,7 @@ public class TileEnginePeat extends TileEngine implements ISidedInventory { return null; } - return new InventoryMapper(inventory, SLOT_WASTE_1, SLOT_WASTE_COUNT); + return new InventoryMapper(inventory, InventoryEnginePeat.SLOT_WASTE_1, InventoryEnginePeat.SLOT_WASTE_COUNT); } private void dumpStash() { @@ -353,20 +336,4 @@ public class TileEnginePeat extends TileEngine implements ISidedInventory { res.add(FactoryTriggers.lowFuel10); return res; } - - private static class EngineCopperInventoryAdapter extends TileInventoryAdapter { - public EngineCopperInventoryAdapter(TileEnginePeat engineCopper) { - super(engineCopper, 5, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return slotIndex == SLOT_FUEL && FuelManager.copperEngineFuel.containsKey(itemStack); - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_WASTE_1, SLOT_WASTE_COUNT); - } - } } diff --git a/src/main/java/forestry/energy/tiles/TileGenerator.java b/src/main/java/forestry/energy/tiles/TileGenerator.java index 4274357ad..0e67ca4a8 100644 --- a/src/main/java/forestry/energy/tiles/TileGenerator.java +++ b/src/main/java/forestry/energy/tiles/TileGenerator.java @@ -12,11 +12,9 @@ package forestry.energy.tiles; import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; @@ -25,17 +23,14 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.fuels.FuelManager; import forestry.api.fuels.GeneratorFuel; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; @@ -43,17 +38,14 @@ import forestry.core.render.TankRenderInfo; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.IRenderableTile; import forestry.core.tiles.TileBase; +import forestry.energy.inventory.InventoryGenerator; import forestry.plugins.PluginIC2; import ic2.api.energy.prefab.BasicSource; public class TileGenerator extends TileBase implements ISidedInventory, ILiquidTankTile, IFluidHandler, IRenderableTile { - - // / CONSTANTS private static final int maxEnergy = 30000; - public static final short SLOT_CAN = 0; - private final TankManager tankManager; private final FilteredTank resourceTank; @@ -62,9 +54,9 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT private BasicSource ic2EnergySource; public TileGenerator() { - setHints(Config.hints.get("generator")); + super(GuiId.GeneratorGUI, "generator"); - setInternalInventory(new GeneratorInventoryAdapter(this)); + setInternalInventory(new InventoryGenerator(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FuelManager.generatorFuel.keySet()); tankManager = new TankManager(this, resourceTank); @@ -74,11 +66,6 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT } } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.GeneratorGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); @@ -134,7 +121,7 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT @Override public void updateServerSide() { if (updateOnInterval(20)) { - FluidHelper.drainContainers(tankManager, this, SLOT_CAN); + FluidHelper.drainContainers(tankManager, this, InventoryGenerator.SLOT_CAN); } IErrorLogic errorLogic = getErrorLogic(); @@ -240,20 +227,4 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - - private static class GeneratorInventoryAdapter extends TileInventoryAdapter { - public GeneratorInventoryAdapter(TileGenerator generator) { - super(generator, 1, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_CAN) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.tankManager.accepts(fluid); - } - - return false; - } - } } diff --git a/src/main/java/forestry/factory/gui/ContainerBottler.java b/src/main/java/forestry/factory/gui/ContainerBottler.java index bb4848b62..a04323ad7 100755 --- a/src/main/java/forestry/factory/gui/ContainerBottler.java +++ b/src/main/java/forestry/factory/gui/ContainerBottler.java @@ -15,6 +15,7 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.factory.inventory.InventoryBottler; import forestry.factory.tiles.TileBottler; public class ContainerBottler extends ContainerLiquidTanks { @@ -22,8 +23,8 @@ public class ContainerBottler extends ContainerLiquidTanks { public ContainerBottler(InventoryPlayer player, TileBottler tile) { super(tile, player, 8, 84); - this.addSlotToContainer(new SlotFiltered(tile, TileBottler.SLOT_INPUT_EMPTY_CAN, 116, 19)); - this.addSlotToContainer(new SlotOutput(tile, TileBottler.SLOT_OUTPUT, 116, 55)); - this.addSlotToContainer(new SlotFiltered(tile, TileBottler.SLOT_INPUT_FULL_CAN, 26, 38)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryBottler.SLOT_INPUT_EMPTY_CAN, 116, 19)); + this.addSlotToContainer(new SlotOutput(tile, InventoryBottler.SLOT_OUTPUT, 116, 55)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryBottler.SLOT_INPUT_FULL_CAN, 26, 38)); } } diff --git a/src/main/java/forestry/factory/gui/ContainerCarpenter.java b/src/main/java/forestry/factory/gui/ContainerCarpenter.java index fe1038393..4fa18041a 100755 --- a/src/main/java/forestry/factory/gui/ContainerCarpenter.java +++ b/src/main/java/forestry/factory/gui/ContainerCarpenter.java @@ -22,6 +22,7 @@ import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotLocked; import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketItemStackDisplay; +import forestry.factory.inventory.InventoryCarpenter; import forestry.factory.tiles.TileCarpenter; public class ContainerCarpenter extends ContainerLiquidTanks implements IContainerCrafting { @@ -32,16 +33,16 @@ public class ContainerCarpenter extends ContainerLiquidTanks impl // Internal inventory for (int i = 0; i < 2; i++) { for (int k = 0; k < 9; k++) { - addSlotToContainer(new Slot(tile, TileCarpenter.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); + addSlotToContainer(new Slot(tile, InventoryCarpenter.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); } } // Liquid Input - this.addSlotToContainer(new SlotFiltered(tile, TileCarpenter.SLOT_CAN_INPUT, 120, 20)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryCarpenter.SLOT_CAN_INPUT, 120, 20)); // Boxes - this.addSlotToContainer(new SlotFiltered(tile, TileCarpenter.SLOT_BOX, 83, 20)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryCarpenter.SLOT_BOX, 83, 20)); // Product - this.addSlotToContainer(new SlotOutput(tile, TileCarpenter.SLOT_PRODUCT, 120, 56)); + this.addSlotToContainer(new SlotOutput(tile, InventoryCarpenter.SLOT_PRODUCT, 120, 56)); // Craft Preview display addSlotToContainer(new SlotLocked(tile.getCraftPreviewInventory(), 0, 80, 51)); diff --git a/src/main/java/forestry/factory/gui/ContainerFabricator.java b/src/main/java/forestry/factory/gui/ContainerFabricator.java index 5330cba58..47fd9e679 100755 --- a/src/main/java/forestry/factory/gui/ContainerFabricator.java +++ b/src/main/java/forestry/factory/gui/ContainerFabricator.java @@ -20,6 +20,7 @@ import forestry.core.gui.IContainerCrafting; import forestry.core.gui.slots.SlotCraftMatrix; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.factory.inventory.InventoryFabricator; import forestry.factory.tiles.TileFabricator; public class ContainerFabricator extends ContainerLiquidTanks implements IContainerCrafting { @@ -30,23 +31,23 @@ public class ContainerFabricator extends ContainerLiquidTanks im // Internal inventory for (int i = 0; i < 2; i++) { for (int k = 0; k < 9; k++) { - addSlotToContainer(new Slot(tile, TileFabricator.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 84 + i * 18)); + addSlotToContainer(new Slot(tile, InventoryFabricator.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 84 + i * 18)); } } // Molten resource - this.addSlotToContainer(new SlotFiltered(tile, TileFabricator.SLOT_METAL, 26, 21)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryFabricator.SLOT_METAL, 26, 21)); // Plan - this.addSlotToContainer(new SlotFiltered(tile, TileFabricator.SLOT_PLAN, 139, 17)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryFabricator.SLOT_PLAN, 139, 17)); // Result - this.addSlotToContainer(new SlotOutput(tile, TileFabricator.SLOT_RESULT, 139, 53)); + this.addSlotToContainer(new SlotOutput(tile, InventoryFabricator.SLOT_RESULT, 139, 53)); // Crafting matrix for (int l = 0; l < 3; l++) { for (int k = 0; k < 3; k++) { - addSlotToContainer(new SlotCraftMatrix(this, tile.getCraftingInventory(), TileFabricator.SLOT_CRAFTING_1 + k + l * 3, 67 + k * 18, 17 + l * 18)); + addSlotToContainer(new SlotCraftMatrix(this, tile.getCraftingInventory(), InventoryFabricator.SLOT_CRAFTING_1 + k + l * 3, 67 + k * 18, 17 + l * 18)); } } } diff --git a/src/main/java/forestry/factory/gui/ContainerFermenter.java b/src/main/java/forestry/factory/gui/ContainerFermenter.java index 61190dc30..98398f4f6 100755 --- a/src/main/java/forestry/factory/gui/ContainerFermenter.java +++ b/src/main/java/forestry/factory/gui/ContainerFermenter.java @@ -16,6 +16,7 @@ import net.minecraft.inventory.ICrafting; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.factory.inventory.InventoryFermenter; import forestry.factory.tiles.TileFermenter; public class ContainerFermenter extends ContainerLiquidTanks { @@ -23,11 +24,11 @@ public class ContainerFermenter extends ContainerLiquidTanks { public ContainerFermenter(InventoryPlayer player, TileFermenter fermenter) { super(fermenter, player, 8, 84); - this.addSlotToContainer(new SlotFiltered(fermenter, TileFermenter.SLOT_RESOURCE, 85, 23)); - this.addSlotToContainer(new SlotFiltered(fermenter, TileFermenter.SLOT_FUEL, 75, 57)); - this.addSlotToContainer(new SlotOutput(fermenter, TileFermenter.SLOT_CAN_OUTPUT, 150, 58)); - this.addSlotToContainer(new SlotFiltered(fermenter, TileFermenter.SLOT_CAN_INPUT, 150, 22)); - this.addSlotToContainer(new SlotFiltered(fermenter, TileFermenter.SLOT_INPUT, 10, 40)); + this.addSlotToContainer(new SlotFiltered(fermenter, InventoryFermenter.SLOT_RESOURCE, 85, 23)); + this.addSlotToContainer(new SlotFiltered(fermenter, InventoryFermenter.SLOT_FUEL, 75, 57)); + this.addSlotToContainer(new SlotOutput(fermenter, InventoryFermenter.SLOT_CAN_OUTPUT, 150, 58)); + this.addSlotToContainer(new SlotFiltered(fermenter, InventoryFermenter.SLOT_CAN_INPUT, 150, 22)); + this.addSlotToContainer(new SlotFiltered(fermenter, InventoryFermenter.SLOT_INPUT, 10, 40)); } @Override diff --git a/src/main/java/forestry/factory/gui/ContainerRaintank.java b/src/main/java/forestry/factory/gui/ContainerRaintank.java index 71ba86810..3e613fc55 100755 --- a/src/main/java/forestry/factory/gui/ContainerRaintank.java +++ b/src/main/java/forestry/factory/gui/ContainerRaintank.java @@ -16,6 +16,7 @@ import net.minecraft.inventory.ICrafting; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.factory.inventory.InventoryRaintank; import forestry.factory.tiles.TileRaintank; public class ContainerRaintank extends ContainerLiquidTanks { @@ -23,8 +24,8 @@ public class ContainerRaintank extends ContainerLiquidTanks { public ContainerRaintank(InventoryPlayer player, TileRaintank tile) { super(tile, player, 8, 84); - this.addSlotToContainer(new SlotFiltered(tile, TileRaintank.SLOT_RESOURCE, 116, 19)); - this.addSlotToContainer(new SlotOutput(tile, TileRaintank.SLOT_PRODUCT, 116, 55)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryRaintank.SLOT_RESOURCE, 116, 19)); + this.addSlotToContainer(new SlotOutput(tile, InventoryRaintank.SLOT_PRODUCT, 116, 55)); } @Override diff --git a/src/main/java/forestry/factory/gui/ContainerSqueezer.java b/src/main/java/forestry/factory/gui/ContainerSqueezer.java index dbf39fae4..1ff7180e8 100755 --- a/src/main/java/forestry/factory/gui/ContainerSqueezer.java +++ b/src/main/java/forestry/factory/gui/ContainerSqueezer.java @@ -15,6 +15,7 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.ContainerLiquidTanksSocketed; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.factory.inventory.InventorySqueezer; import forestry.factory.tiles.TileSqueezer; public class ContainerSqueezer extends ContainerLiquidTanksSocketed { @@ -30,11 +31,11 @@ public class ContainerSqueezer extends ContainerLiquidTanksSocketed { @@ -22,8 +23,8 @@ public class ContainerStill extends ContainerLiquidTanks { public ContainerStill(InventoryPlayer player, TileStill tile) { super(tile, player, 8, 84); - this.addSlotToContainer(new SlotOutput(tile, TileStill.SLOT_PRODUCT, 150, 54)); - this.addSlotToContainer(new SlotFiltered(tile, TileStill.SLOT_RESOURCE, 150, 18)); - this.addSlotToContainer(new SlotFiltered(tile, TileStill.SLOT_CAN, 10, 36)); + this.addSlotToContainer(new SlotOutput(tile, InventoryStill.SLOT_PRODUCT, 150, 54)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryStill.SLOT_RESOURCE, 150, 18)); + this.addSlotToContainer(new SlotFiltered(tile, InventoryStill.SLOT_CAN, 10, 36)); } } diff --git a/src/main/java/forestry/factory/gui/ContainerWorktable.java b/src/main/java/forestry/factory/gui/ContainerWorktable.java index 7abe6dfa5..e8823a458 100755 --- a/src/main/java/forestry/factory/gui/ContainerWorktable.java +++ b/src/main/java/forestry/factory/gui/ContainerWorktable.java @@ -25,6 +25,7 @@ import forestry.core.gui.slots.SlotCrafter; import forestry.core.network.PacketGuiSelectRequest; import forestry.core.proxy.Proxies; import forestry.core.utils.ItemStackUtil; +import forestry.factory.inventory.InventoryWorktable; import forestry.factory.network.PacketWorktableMemoryUpdate; import forestry.factory.recipes.RecipeMemory; import forestry.factory.tiles.TileWorktable; @@ -43,7 +44,7 @@ public class ContainerWorktable extends ContainerTile implements // Internal inventory for (int i = 0; i < 2; i++) { for (int k = 0; k < 9; k++) { - addSlotToContainer(new Slot(internalInventory, TileWorktable.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); + addSlotToContainer(new Slot(internalInventory, InventoryWorktable.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); } } @@ -55,7 +56,7 @@ public class ContainerWorktable extends ContainerTile implements } // CraftResult display - addSlotToContainer(new SlotCrafter(player, craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38)); + addSlotToContainer(new SlotCrafter(player, craftingInventory, tile, InventoryWorktable.SLOT_CRAFTING_RESULT, 77, 38)); // Update crafting matrix with current contents of tileentity. updateMatrix(); diff --git a/src/main/java/forestry/factory/inventory/InventoryBottler.java b/src/main/java/forestry/factory/inventory/InventoryBottler.java new file mode 100644 index 000000000..6540b0226 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryBottler.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.factory.tiles.TileBottler; + +public class InventoryBottler extends InventoryAdapterTile { + public static final short SLOT_INPUT_EMPTY_CAN = 0; + public static final short SLOT_OUTPUT = 1; + public static final short SLOT_INPUT_FULL_CAN = 2; + + public InventoryBottler(TileBottler tileBottler) { + super(tileBottler, 3, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_INPUT_EMPTY_CAN) { + return FluidHelper.isFillableContainer(itemStack); + } else if (slotIndex == SLOT_INPUT_FULL_CAN) { + FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemStack); + return fluidStack != null && FluidRegistry.isFluidRegistered(fluidStack.getFluid()); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_OUTPUT; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryCarpenter.java b/src/main/java/forestry/factory/inventory/InventoryCarpenter.java new file mode 100644 index 000000000..d5cb85ed6 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryCarpenter.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.factory.recipes.CarpenterRecipeManager; +import forestry.factory.tiles.TileCarpenter; + +public class InventoryCarpenter extends InventoryAdapterTile { + public final static int SLOT_CRAFTING_1 = 0; + public final static int SLOT_CRAFTING_COUNT = 9; + public final static int SLOT_BOX = 9; + public final static int SLOT_PRODUCT = 10; + public final static int SLOT_PRODUCT_COUNT = 1; + public final static int SLOT_CAN_INPUT = 11; + public final static short SLOT_INVENTORY_1 = 12; + public final static short SLOT_INVENTORY_COUNT = 18; + + public InventoryCarpenter(TileCarpenter carpenter) { + super(carpenter, 30, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN_INPUT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } else if (slotIndex == SLOT_BOX) { + return CarpenterRecipeManager.isBox(itemStack); + } else if (canSlotAccept(SLOT_CAN_INPUT, itemStack) || canSlotAccept(SLOT_BOX, itemStack)) { + return false; + } + + return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryCentrifuge.java b/src/main/java/forestry/factory/inventory/InventoryCentrifuge.java new file mode 100644 index 000000000..e011ecaec --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryCentrifuge.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.factory.recipes.CentrifugeRecipeManager; +import forestry.factory.tiles.TileCentrifuge; + +public class InventoryCentrifuge extends InventoryAdapterTile { + public static final int SLOT_RESOURCE = 0; + public static final int SLOT_PRODUCT_1 = 1; + public static final int SLOT_PRODUCT_COUNT = 9; + + public InventoryCentrifuge(TileCentrifuge centrifuge) { + super(centrifuge, 10, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return slotIndex == SLOT_RESOURCE && CentrifugeRecipeManager.findMatchingRecipe(itemStack) != null; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return SlotUtil.isSlotInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT); + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryFabricator.java b/src/main/java/forestry/factory/inventory/InventoryFabricator.java new file mode 100644 index 000000000..de7db4b47 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryFabricator.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.factory.recipes.FabricatorRecipeManager; +import forestry.factory.recipes.FabricatorSmeltingRecipeManager; +import forestry.factory.tiles.TileFabricator; + +public class InventoryFabricator extends InventoryAdapterTile { + public static final short SLOT_METAL = 0; + public static final short SLOT_PLAN = 1; + public static final short SLOT_RESULT = 2; + // FIXME 1.8: change indexes and use correct SLOT_COUNT of 21 + // left this way for now to avoid losing items in existing fabricators + public static final short SLOT_CRAFTING_LEGACY_1 = 3; + public static final short SLOT_CRAFTING_LEGACY_COUNT = 9; + public static final short SLOT_INVENTORY_1 = 12; + public static final short SLOT_INVENTORY_COUNT = 18; + public static final short SLOT_COUNT = 30; + public static final short SLOT_CRAFTING_1 = 0; + public static final short SLOT_CRAFTING_COUNT = 9; + + public InventoryFabricator(TileFabricator fabricator) { + super(fabricator, SLOT_COUNT, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_METAL) { + return FabricatorSmeltingRecipeManager.findMatchingSmelting(itemStack) != null; + } else if (slotIndex == SLOT_PLAN) { + return FabricatorRecipeManager.isPlan(itemStack); + } else if (SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT)) { + if (FabricatorRecipeManager.isPlan(itemStack)) { + return false; + } else if (FabricatorSmeltingRecipeManager.findMatchingSmelting(itemStack) != null) { + return false; + } + } + return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return slotIndex == SLOT_RESULT; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryFermenter.java b/src/main/java/forestry/factory/inventory/InventoryFermenter.java new file mode 100644 index 000000000..2dfeb7052 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryFermenter.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.api.fuels.FuelManager; +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.factory.recipes.FermenterRecipeManager; +import forestry.factory.tiles.TileFermenter; + +public class InventoryFermenter extends InventoryAdapterTile { + public static final short SLOT_RESOURCE = 0; + public static final short SLOT_FUEL = 1; + public static final short SLOT_CAN_OUTPUT = 2; + public static final short SLOT_CAN_INPUT = 3; + public static final short SLOT_INPUT = 4; + + public InventoryFermenter(TileFermenter fermenter) { + super(fermenter, 5, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return FermenterRecipeManager.isResource(itemStack); + } else if (slotIndex == SLOT_INPUT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } else if (slotIndex == SLOT_CAN_INPUT) { + return FluidHelper.isFillableContainer(itemStack); + } else if (slotIndex == SLOT_FUEL) { + return FuelManager.fermenterFuel.containsKey(itemStack); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_CAN_OUTPUT; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryMoistener.java b/src/main/java/forestry/factory/inventory/InventoryMoistener.java new file mode 100644 index 000000000..238665ca3 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryMoistener.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.api.fuels.FuelManager; +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.factory.recipes.MoistenerRecipeManager; +import forestry.factory.tiles.TileMoistener; + +public class InventoryMoistener extends InventoryAdapterTile { + public static final short SLOT_STASH_1 = 0; + public static final short SLOT_STASH_COUNT = 6; + public static final short SLOT_RESERVOIR_1 = 6; + public static final short SLOT_RESERVOIR_COUNT = 3; + public static final short SLOT_WORKING = 9; + public static final short SLOT_PRODUCT = 10; + public static final short SLOT_RESOURCE = 11; + + public InventoryMoistener(TileMoistener moistener) { + super(moistener, 12, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return MoistenerRecipeManager.isResource(itemStack); + } + + if (SlotUtil.isSlotInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) { + return FuelManager.moistenerResource.containsKey(itemStack); + } + + if (slotIndex == SLOT_PRODUCT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + if (slotIndex == SLOT_PRODUCT) { + return true; + } + + if (SlotUtil.isSlotInRange(slotIndex, SLOT_STASH_1, (SLOT_STASH_COUNT + SLOT_RESERVOIR_COUNT))) { + return !FuelManager.moistenerResource.containsKey(itemstack); + } + + return false; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryRainmaker.java b/src/main/java/forestry/factory/inventory/InventoryRainmaker.java new file mode 100644 index 000000000..40258f2d6 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryRainmaker.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.RainSubstrate; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.factory.tiles.TileMillRainmaker; + +public class InventoryRainmaker extends InventoryAdapterTile { + private static final int SLOT_SUBSTRATE = 0; + + public InventoryRainmaker(TileMillRainmaker tile) { + super(tile, 1, "items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_SUBSTRATE) { + if (FuelManager.rainSubstrate.containsKey(itemStack) && tile.charge == 0 && tile.progress == 0) { + RainSubstrate substrate = FuelManager.rainSubstrate.get(itemStack); + if (tile.getWorld().isRaining() && substrate.reverse) { + return true; + } else if (!tile.getWorld().isRaining() && !substrate.reverse) { + return true; + } + } + } + + return false; + } + + @Override + public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_SUBSTRATE) { + RainSubstrate substrate = FuelManager.rainSubstrate.get(itemStack); + if (substrate != null && substrate.item.isItemEqual(itemStack)) { + tile.addCharge(substrate); + } + } + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryRaintank.java b/src/main/java/forestry/factory/inventory/InventoryRaintank.java new file mode 100644 index 000000000..95cc99c55 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryRaintank.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.factory.tiles.TileRaintank; + +public class InventoryRaintank extends InventoryAdapterTile { + public static final short SLOT_RESOURCE = 0; + public static final short SLOT_PRODUCT = 1; + + public InventoryRaintank(TileRaintank raintank) { + super(raintank, 3, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return FluidHelper.getFilledContainer(Fluids.WATER.getFluid(1000), itemStack) != null; + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventorySqueezer.java b/src/main/java/forestry/factory/inventory/InventorySqueezer.java new file mode 100644 index 000000000..ff704745d --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventorySqueezer.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.inventory.wrappers.InventoryMapper; +import forestry.core.utils.InventoryUtil; +import forestry.factory.recipes.SqueezerRecipeManager; +import forestry.factory.tiles.TileSqueezer; + +public class InventorySqueezer extends InventoryAdapterTile { + public static final short SLOT_RESOURCE_1 = 0; + public static final short SLOTS_RESOURCE_COUNT = 9; + public static final short SLOT_REMNANT = 9; + public static final short SLOT_REMNANT_COUNT = 1; + public static final short SLOT_CAN_INPUT = 10; + public static final short SLOT_CAN_OUTPUT = 11; + + public InventorySqueezer(TileSqueezer squeezer) { + super(squeezer, 12, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN_INPUT) { + return FluidHelper.isEmptyContainer(itemStack); + } + + if (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) { + if (FluidHelper.isEmptyContainer(itemStack)) { + return false; + } + + if (SqueezerRecipeManager.canUse(itemStack)) { + return true; + } + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT; + } + + public boolean hasResources() { + return !InventoryUtil.isEmpty(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); + } + + public ItemStack[] getResources() { + return InventoryUtil.getStacks(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); + } + + public boolean removeResources(ItemStack[] stacks, EntityPlayer player) { + IInventory inventory = new InventoryMapper(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); + return InventoryUtil.removeSets(inventory, 1, stacks, player, false, true, false, true); + } + + public boolean addRemnant(ItemStack remnant, boolean doAdd) { + return InventoryUtil.tryAddStack(this, remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true, doAdd); + } + + public void fillContainers(FluidStack fluidStack, TankManager tankManager) { + if (getStackInSlot(SLOT_CAN_INPUT) == null || fluidStack == null) { + return; + } + FluidHelper.fillContainers(tankManager, this, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryStill.java b/src/main/java/forestry/factory/inventory/InventoryStill.java new file mode 100644 index 000000000..f3aecd28c --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryStill.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.factory.tiles.TileStill; + +public class InventoryStill extends InventoryAdapterTile { + public static final short SLOT_PRODUCT = 0; + public static final short SLOT_RESOURCE = 1; + public static final short SLOT_CAN = 2; + + public InventoryStill(TileStill still) { + super(still, 3, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return FluidHelper.isEmptyContainer(itemStack); + } else if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryWorktable.java b/src/main/java/forestry/factory/inventory/InventoryWorktable.java new file mode 100644 index 000000000..9f26316e7 --- /dev/null +++ b/src/main/java/forestry/factory/inventory/InventoryWorktable.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.factory.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.factory.tiles.TileWorktable; + +public class InventoryWorktable extends InventoryAdapterTile { + public final static int SLOT_CRAFTING_1 = 0; + public final static int SLOT_CRAFTING_COUNT = 9; + public final static int SLOT_CRAFTING_RESULT = 9; + public final static short SLOT_INVENTORY_1 = 0; + public final static short SLOT_INVENTORY_COUNT = 18; + + public InventoryWorktable(TileWorktable worktable) { + super(worktable, 18, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + } +} diff --git a/src/main/java/forestry/factory/recipes/BottlerRecipe.java b/src/main/java/forestry/factory/recipes/BottlerRecipe.java new file mode 100644 index 000000000..0a32c9e31 --- /dev/null +++ b/src/main/java/forestry/factory/recipes/BottlerRecipe.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.factory.recipes; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; + +import forestry.core.config.Constants; +import forestry.core.fluids.FluidHelper; + +public class BottlerRecipe { + public final FluidStack input; + public final ItemStack empty; + public final ItemStack filled; + + private BottlerRecipe(ItemStack empty, FluidStack input, ItemStack filled) { + this.input = input; + if (empty.getItem() instanceof IFluidContainerItem) { + FluidStack emptyFluid = FluidHelper.getFluidStackInContainer(empty); + if (emptyFluid != null) { + this.input.amount -= emptyFluid.amount; + } + if (this.input.amount > Constants.BUCKET_VOLUME) { + this.input.amount = Constants.BUCKET_VOLUME; + } + } + this.empty = empty; + this.filled = filled; + } + + public boolean matches(ItemStack emptyCan, FluidStack resource) { + if (emptyCan == null || resource == null || !emptyCan.isItemEqual(empty)) { + return false; + } + + if (empty.getItem() instanceof IFluidContainerItem) { + return true; + } else { + return resource.containsFluid(input); + } + } + + public static BottlerRecipe getRecipe(FluidStack res, ItemStack empty) { + if (res == null || empty == null) { + return null; + } + + ItemStack filled = FluidHelper.getFilledContainer(res.getFluid(), empty); + if (filled == null) { + return null; + } + + FluidStack input = FluidHelper.getFluidStackInContainer(filled); + if (input == null) { + return null; + } + + return new BottlerRecipe(empty, input, filled); + } +} diff --git a/src/main/java/forestry/factory/recipes/craftguide/CraftGuideBottler.java b/src/main/java/forestry/factory/recipes/craftguide/CraftGuideBottler.java index 8675341e4..aa4dad1b0 100644 --- a/src/main/java/forestry/factory/recipes/craftguide/CraftGuideBottler.java +++ b/src/main/java/forestry/factory/recipes/craftguide/CraftGuideBottler.java @@ -16,7 +16,7 @@ import net.minecraftforge.fluids.FluidContainerRegistry; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; -import forestry.factory.tiles.TileBottler; +import forestry.factory.recipes.BottlerRecipe; import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; @@ -48,7 +48,7 @@ public class CraftGuideBottler implements RecipeProvider { RecipeTemplate template = generator.createRecipeTemplate(slots, machine); for (FluidContainerRegistry.FluidContainerData container : FluidContainerRegistry.getRegisteredFluidContainerData()) { - TileBottler.BottlerRecipe recipe = TileBottler.BottlerRecipe.getRecipe(container.fluid, container.emptyContainer); + BottlerRecipe recipe = BottlerRecipe.getRecipe(container.fluid, container.emptyContainer); if (recipe != null) { Object[] array = new Object[4]; diff --git a/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java b/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java index ceaa2b917..3a2e69395 100644 --- a/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java +++ b/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java @@ -27,7 +27,7 @@ import forestry.core.recipes.nei.NEIUtils; import forestry.core.recipes.nei.PositionedFluidTank; import forestry.core.recipes.nei.RecipeHandlerBase; import forestry.factory.gui.GuiBottler; -import forestry.factory.tiles.TileBottler; +import forestry.factory.recipes.BottlerRecipe; import codechicken.lib.gui.GuiDraw; import codechicken.nei.NEIServerUtils; @@ -35,12 +35,12 @@ import codechicken.nei.PositionedStack; public class NEIHandlerBottler extends RecipeHandlerBase { - private static final List recipes = new ArrayList<>(); + private static final List recipes = new ArrayList<>(); @Override public void prepare() { for (FluidContainerData container : FluidContainerRegistry.getRegisteredFluidContainerData()) { - TileBottler.BottlerRecipe recipe = TileBottler.BottlerRecipe.getRecipe(container.fluid, container.emptyContainer); + BottlerRecipe recipe = BottlerRecipe.getRecipe(container.fluid, container.emptyContainer); if (recipe != null) { recipes.add(recipe); } @@ -53,7 +53,7 @@ public class NEIHandlerBottler extends RecipeHandlerBase { public PositionedStack input; public PositionedStack output; - public CachedBottlerRecipe(TileBottler.BottlerRecipe recipe) { + public CachedBottlerRecipe(BottlerRecipe recipe) { if (recipe.input != null) { this.fluid = new PositionedFluidTank(recipe.input, 10000, new Rectangle(48, 6, 16, 58), NEIHandlerBottler.this.getGuiTexture(), new Point(176, 0)); } @@ -120,14 +120,14 @@ public class NEIHandlerBottler extends RecipeHandlerBase { @Override public void loadAllRecipes() { - for (TileBottler.BottlerRecipe recipe : recipes) { + for (BottlerRecipe recipe : recipes) { this.arecipes.add(new CachedBottlerRecipe(recipe)); } } @Override public void loadCraftingRecipes(ItemStack result) { - for (TileBottler.BottlerRecipe recipe : recipes) { + for (BottlerRecipe recipe : recipes) { if (NEIServerUtils.areStacksSameTypeCrafting(recipe.filled, result)) { this.arecipes.add(new CachedBottlerRecipe(recipe)); } @@ -136,7 +136,7 @@ public class NEIHandlerBottler extends RecipeHandlerBase { @Override public void loadUsageRecipes(ItemStack ingred) { - for (TileBottler.BottlerRecipe recipe : recipes) { + for (BottlerRecipe recipe : recipes) { if (NEIServerUtils.areStacksSameTypeCrafting(recipe.empty, ingred)) { this.arecipes.add(new CachedBottlerRecipe(recipe)); } @@ -145,7 +145,7 @@ public class NEIHandlerBottler extends RecipeHandlerBase { @Override public void loadUsageRecipes(FluidStack ingred) { - for (TileBottler.BottlerRecipe recipe : recipes) { + for (BottlerRecipe recipe : recipes) { if (NEIUtils.areFluidsSameType(recipe.input, ingred)) { this.arecipes.add(new CachedBottlerRecipe(recipe)); } diff --git a/src/main/java/forestry/factory/tiles/TileBottler.java b/src/main/java/forestry/factory/tiles/TileBottler.java index 500d565b1..b3367d53b 100644 --- a/src/main/java/forestry/factory/tiles/TileBottler.java +++ b/src/main/java/forestry/factory/tiles/TileBottler.java @@ -10,13 +10,10 @@ ******************************************************************************/ package forestry.factory.tiles; -import com.google.common.base.Objects; - import java.io.IOException; import java.util.Collection; import java.util.LinkedList; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -24,30 +21,27 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; import cpw.mods.fml.common.Optional; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.StandardTank; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.render.TankRenderInfo; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; +import forestry.factory.inventory.InventoryBottler; +import forestry.factory.recipes.BottlerRecipe; import forestry.factory.triggers.FactoryTriggers; import buildcraft.api.statements.ITriggerExternal; @@ -56,30 +50,20 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid private static final int TICKS_PER_RECIPE_TIME = 5; private static final int ENERGY_PER_RECIPE_TIME = 1000; - public static final short SLOT_INPUT_EMPTY_CAN = 0; - public static final short SLOT_OUTPUT = 1; - public static final short SLOT_INPUT_FULL_CAN = 2; - private final StandardTank resourceTank; private final TankManager tankManager; private BottlerRecipe currentRecipe; public TileBottler() { - super(1100, 4000, 200); + super(GuiId.BottlerGUI, "bottler", 1100, 4000); - setInternalInventory(new BottlerInventoryAdapter(this)); + setInternalInventory(new InventoryBottler(this)); - setHints(Config.hints.get("bottler")); resourceTank = new StandardTank(Constants.PROCESSOR_TANK_CAPACITY); tankManager = new TankManager(this, resourceTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.BottlerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - /* SAVING & LOADING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { @@ -111,18 +95,18 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid super.updateServerSide(); if (updateOnInterval(20)) { - FluidHelper.drainContainers(tankManager, this, SLOT_INPUT_FULL_CAN); + FluidHelper.drainContainers(tankManager, this, InventoryBottler.SLOT_INPUT_FULL_CAN); } } @Override public boolean workCycle() { - FluidHelper.FillStatus status = FluidHelper.fillContainers(tankManager, this, SLOT_INPUT_EMPTY_CAN, SLOT_OUTPUT, currentRecipe.input.getFluid()); + FluidHelper.FillStatus status = FluidHelper.fillContainers(tankManager, this, InventoryBottler.SLOT_INPUT_EMPTY_CAN, InventoryBottler.SLOT_OUTPUT, currentRecipe.input.getFluid()); return status == FluidHelper.FillStatus.SUCCESS; } private void checkRecipe() { - ItemStack emptyCan = getStackInSlot(SLOT_INPUT_EMPTY_CAN); + ItemStack emptyCan = getStackInSlot(InventoryBottler.SLOT_INPUT_EMPTY_CAN); FluidStack resource = resourceTank.getFluid(); if (currentRecipe == null || !currentRecipe.matches(emptyCan, resource)) { @@ -144,11 +128,11 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid @Override public boolean hasResourcesMin(float percentage) { IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_INPUT_EMPTY_CAN) == null) { + if (inventory.getStackInSlot(InventoryBottler.SLOT_INPUT_EMPTY_CAN) == null) { return false; } - return ((float) inventory.getStackInSlot(SLOT_INPUT_EMPTY_CAN).stackSize / (float) inventory.getStackInSlot(SLOT_INPUT_EMPTY_CAN).getMaxStackSize()) > percentage; + return ((float) inventory.getStackInSlot(InventoryBottler.SLOT_INPUT_EMPTY_CAN).stackSize / (float) inventory.getStackInSlot(InventoryBottler.SLOT_INPUT_EMPTY_CAN).getMaxStackSize()) > percentage; } @Override @@ -162,7 +146,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid if (errorLogic.setCondition(currentRecipe == null, EnumErrorCode.NORECIPE)) { status = FluidHelper.FillStatus.SUCCESS; } else { - status = FluidHelper.fillContainers(tankManager, this, SLOT_INPUT_EMPTY_CAN, SLOT_OUTPUT, currentRecipe.input.getFluid(), false); + status = FluidHelper.fillContainers(tankManager, this, InventoryBottler.SLOT_INPUT_EMPTY_CAN, InventoryBottler.SLOT_OUTPUT, currentRecipe.input.getFluid(), false); } errorLogic.setCondition(status == FluidHelper.FillStatus.NO_FLUID, EnumErrorCode.NORESOURCE); @@ -221,86 +205,4 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid return res; } - private static class BottlerInventoryAdapter extends TileInventoryAdapter { - public BottlerInventoryAdapter(TileBottler tileBottler) { - super(tileBottler, 3, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_INPUT_EMPTY_CAN) { - return FluidHelper.isFillableContainer(itemStack); - } else if (slotIndex == SLOT_INPUT_FULL_CAN) { - FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemStack); - return fluidStack != null && FluidRegistry.isFluidRegistered(fluidStack.getFluid()); - } - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_OUTPUT; - } - } - - public static class BottlerRecipe { - public final FluidStack input; - public final ItemStack empty; - public final ItemStack filled; - - private BottlerRecipe(ItemStack empty, FluidStack input, ItemStack filled) { - this.input = input; - if (empty.getItem() instanceof IFluidContainerItem) { - FluidStack emptyFluid = FluidHelper.getFluidStackInContainer(empty); - if (emptyFluid != null) { - this.input.amount -= emptyFluid.amount; - } - if (this.input.amount > Constants.BUCKET_VOLUME) { - this.input.amount = Constants.BUCKET_VOLUME; - } - } - this.empty = empty; - this.filled = filled; - } - - public boolean matches(ItemStack emptyCan, FluidStack resource) { - if (emptyCan == null || resource == null || !emptyCan.isItemEqual(empty)) { - return false; - } - - if (empty.getItem() instanceof IFluidContainerItem) { - return true; - } else { - return resource.containsFluid(input); - } - } - - public static BottlerRecipe getRecipe(FluidStack res, ItemStack empty) { - if (res == null || empty == null) { - return null; - } - - ItemStack filled = FluidHelper.getFilledContainer(res.getFluid(), empty); - if (filled == null) { - return null; - } - - FluidStack input = FluidHelper.getFluidStackInContainer(filled); - if (input == null) { - return null; - } - - return new BottlerRecipe(empty, input, filled); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .addValue(input.amount).addValue(input.getLocalizedName()) - .add("empty", empty) - .add("filled", filled) - .toString(); - } - } - } diff --git a/src/main/java/forestry/factory/tiles/TileCarpenter.java b/src/main/java/forestry/factory/tiles/TileCarpenter.java index bc5840112..9faab704e 100644 --- a/src/main/java/forestry/factory/tiles/TileCarpenter.java +++ b/src/main/java/forestry/factory/tiles/TileCarpenter.java @@ -26,16 +26,14 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.recipes.ICarpenterRecipe; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.InventoryAdapterTile; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; @@ -46,7 +44,7 @@ import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; import forestry.core.utils.InventoryUtil; import forestry.core.utils.PlayerUtil; -import forestry.core.utils.SlotUtil; +import forestry.factory.inventory.InventoryCarpenter; import forestry.factory.recipes.CarpenterRecipeManager; public class TileCarpenter extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler, IItemStackDisplay { @@ -54,45 +52,30 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu private static final int ENERGY_PER_WORK_CYCLE = 2040; private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 10; - public final static int SLOT_CRAFTING_1 = 0; - public final static int SLOT_CRAFTING_COUNT = 9; - public final static int SLOT_BOX = 9; - public final static int SLOT_PRODUCT = 10; - public final static int SLOT_PRODUCT_COUNT = 1; - public final static int SLOT_CAN_INPUT = 11; - public final static short SLOT_INVENTORY_1 = 12; - public final static short SLOT_INVENTORY_COUNT = 18; - - /* MEMBER */ private final FilteredTank resourceTank; private final TankManager tankManager; - private final TileInventoryAdapter craftingInventory; + private final InventoryAdapterTile craftingInventory; private final InventoryCraftResult craftPreviewInventory; @Nullable private ICarpenterRecipe currentRecipe; private ItemStack getBoxStack() { - return getInternalInventory().getStackInSlot(SLOT_BOX); + return getInternalInventory().getStackInSlot(InventoryCarpenter.SLOT_BOX); } public TileCarpenter() { - super(1100, 4000, ENERGY_PER_WORK_CYCLE); - setHints(Config.hints.get("carpenter")); + super(GuiId.CarpenterGUI, "carpenter", 1100, 4000); + setEnergyPerWorkCycle(ENERGY_PER_WORK_CYCLE); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, CarpenterRecipeManager.recipeFluids); - craftingInventory = new TileInventoryAdapter<>(this, 10, "CraftItems"); + craftingInventory = new InventoryAdapterTile<>(this, 10, "CraftItems"); craftPreviewInventory = new InventoryCraftResult(); - setInternalInventory(new CarpenterInventoryAdapter(this)); + setInternalInventory(new InventoryCarpenter(this)); tankManager = new TankManager(this, resourceTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.CarpenterGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - /* LOADING & SAVING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { @@ -147,7 +130,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu super.updateServerSide(); if (updateOnInterval(20)) { - FluidHelper.drainContainers(tankManager, this, SLOT_CAN_INPUT); + FluidHelper.drainContainers(tankManager, this, InventoryCarpenter.SLOT_CAN_INPUT); } } @@ -158,7 +141,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu } ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getRecipeOutput(); - InventoryUtil.tryAddStack(this, pendingProduct, SLOT_PRODUCT, SLOT_PRODUCT_COUNT, true); + InventoryUtil.tryAddStack(this, pendingProduct, InventoryCarpenter.SLOT_PRODUCT, InventoryCarpenter.SLOT_PRODUCT_COUNT, true); return true; } @@ -179,18 +162,18 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu } if (currentRecipe.getBox() != null) { - ItemStack box = getStackInSlot(SLOT_BOX); + ItemStack box = getStackInSlot(InventoryCarpenter.SLOT_BOX); if (box == null || box.stackSize == 0) { return false; } if (doRemove) { - decrStackSize(SLOT_BOX, 1); + decrStackSize(InventoryCarpenter.SLOT_BOX, 1); } } EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner()); - ItemStack[] craftingSets = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); - IInventory inventory = new InventoryMapper(getInternalInventory(), SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + ItemStack[] craftingSets = InventoryUtil.getStacks(craftingInventory, InventoryCarpenter.SLOT_CRAFTING_1, InventoryCarpenter.SLOT_CRAFTING_COUNT); + IInventory inventory = new InventoryMapper(getInternalInventory(), InventoryCarpenter.SLOT_INVENTORY_1, InventoryCarpenter.SLOT_INVENTORY_COUNT); return InventoryUtil.removeSets(inventory, 1, craftingSets, player, true, true, false, doRemove); } @@ -209,7 +192,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu hasResources = removeResources(false); ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getRecipeOutput(); - canAdd = InventoryUtil.tryAddStack(this, pendingProduct, SLOT_PRODUCT, SLOT_PRODUCT_COUNT, true, false); + canAdd = InventoryUtil.tryAddStack(this, pendingProduct, InventoryCarpenter.SLOT_PRODUCT, InventoryCarpenter.SLOT_PRODUCT_COUNT, true, false); } IErrorLogic errorLogic = getErrorLogic(); @@ -276,30 +259,4 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - - private static class CarpenterInventoryAdapter extends TileInventoryAdapter { - public CarpenterInventoryAdapter(TileCarpenter carpenter) { - super(carpenter, 30, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_CAN_INPUT) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.tankManager.accepts(fluid); - } else if (slotIndex == SLOT_BOX) { - return CarpenterRecipeManager.isBox(itemStack); - } else if (canSlotAccept(SLOT_CAN_INPUT, itemStack) || canSlotAccept(SLOT_BOX, itemStack)) { - return false; - } - - return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_PRODUCT; - } - } - } diff --git a/src/main/java/forestry/factory/tiles/TileCentrifuge.java b/src/main/java/forestry/factory/tiles/TileCentrifuge.java index 9a83c8b24..771817b10 100644 --- a/src/main/java/forestry/factory/tiles/TileCentrifuge.java +++ b/src/main/java/forestry/factory/tiles/TileCentrifuge.java @@ -15,7 +15,6 @@ import java.util.Collection; import java.util.LinkedList; import java.util.Stack; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -30,54 +29,38 @@ import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitBoard; import forestry.api.circuits.ICircuitSocketType; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.recipes.ICentrifugeRecipe; import forestry.core.circuits.ISocketable; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.tiles.TilePowered; import forestry.core.utils.InventoryUtil; -import forestry.core.utils.SlotUtil; +import forestry.factory.inventory.InventoryCentrifuge; import forestry.factory.recipes.CentrifugeRecipeManager; import forestry.factory.triggers.FactoryTriggers; import buildcraft.api.statements.ITriggerExternal; public class TileCentrifuge extends TilePowered implements ISocketable, ISidedInventory { - private static final int TICKS_PER_RECIPE_TIME = 1; private static final int ENERGY_PER_WORK_CYCLE = 3200; private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 20; private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); - /* CONSTANTS */ - public static final int SLOT_RESOURCE = 0; - public static final int SLOT_PRODUCT_1 = 1; - public static final int SLOT_PRODUCT_COUNT = 9; - - /* MEMBER */ private ICentrifugeRecipe currentRecipe; private final Stack pendingProducts = new Stack<>(); public TileCentrifuge() { - super(800, Constants.MACHINE_MAX_ENERGY, ENERGY_PER_WORK_CYCLE); - setInternalInventory(new CentrifugeInventoryAdapter(this)); - setHints(Config.hints.get("centrifuge")); - } - - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.CentrifugeGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + super(GuiId.CentrifugeGUI, "centrifuge", 800, Constants.MACHINE_MAX_ENERGY); + setInternalInventory(new InventoryCentrifuge(this)); } /* LOADING & SAVING */ @@ -152,14 +135,14 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn Collection products = currentRecipe.getProducts(worldObj.rand); pendingProducts.addAll(products); - getInternalInventory().decrStackSize(SLOT_RESOURCE, 1); + getInternalInventory().decrStackSize(InventoryCentrifuge.SLOT_RESOURCE, 1); tryAddPending(); return true; } private void checkRecipe() { - ItemStack resource = getStackInSlot(SLOT_RESOURCE); + ItemStack resource = getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE); ICentrifugeRecipe matchingRecipe = CentrifugeRecipeManager.findMatchingRecipe(resource); if (currentRecipe != matchingRecipe) { @@ -179,7 +162,7 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn ItemStack next = pendingProducts.peek(); - boolean added = InventoryUtil.tryAddStack(this, next, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, true); + boolean added = InventoryUtil.tryAddStack(this, next, InventoryCentrifuge.SLOT_PRODUCT_1, InventoryCentrifuge.SLOT_PRODUCT_COUNT, true); if (added) { pendingProducts.pop(); @@ -192,18 +175,18 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn @Override public boolean hasResourcesMin(float percentage) { IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_RESOURCE) == null) { + if (inventory.getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE) == null) { return false; } - return ((float) inventory.getStackInSlot(SLOT_RESOURCE).stackSize / (float) inventory.getStackInSlot(SLOT_RESOURCE).getMaxStackSize()) > percentage; + return ((float) inventory.getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE).stackSize / (float) inventory.getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE).getMaxStackSize()) > percentage; } @Override public boolean hasWork() { checkRecipe(); - boolean hasResource = getStackInSlot(SLOT_RESOURCE) != null; + boolean hasResource = getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE) != null; IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasResource, EnumErrorCode.NORESOURCE); @@ -221,22 +204,6 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn return res; } - private static class CentrifugeInventoryAdapter extends TileInventoryAdapter { - public CentrifugeInventoryAdapter(TileCentrifuge centrifuge) { - super(centrifuge, 10, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return slotIndex == SLOT_RESOURCE && CentrifugeRecipeManager.findMatchingRecipe(itemStack) != null; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT); - } - } - /* ISocketable */ @Override public int getSocketCount() { diff --git a/src/main/java/forestry/factory/tiles/TileFabricator.java b/src/main/java/forestry/factory/tiles/TileFabricator.java index 4e7dbc59b..af6388ad4 100644 --- a/src/main/java/forestry/factory/tiles/TileFabricator.java +++ b/src/main/java/forestry/factory/tiles/TileFabricator.java @@ -27,7 +27,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import forestry.api.core.ForestryAPI; import forestry.api.recipes.IFabricatorRecipe; import forestry.api.recipes.IFabricatorSmeltingRecipe; import forestry.core.config.Constants; @@ -37,7 +36,7 @@ import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.tanks.StandardTank; import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.InventoryAdapterTile; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.items.ICraftingPlan; import forestry.core.network.DataInputStreamForestry; @@ -48,60 +47,36 @@ import forestry.core.tiles.ICrafter; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; import forestry.core.utils.InventoryUtil; -import forestry.core.utils.SlotUtil; +import forestry.factory.inventory.InventoryFabricator; import forestry.factory.recipes.FabricatorRecipeManager; import forestry.factory.recipes.FabricatorSmeltingRecipeManager; public class TileFabricator extends TilePowered implements ICrafter, ILiquidTankTile, IFluidHandler, ISidedInventory { - - /* CONSTANTS */ private static final int MAX_HEAT = 5000; - public static final short SLOT_METAL = 0; - public static final short SLOT_PLAN = 1; - public static final short SLOT_RESULT = 2; - // FIXME 1.8: change indexes and use correct SLOT_COUNT of 21 - // left this way for now to avoid losing items in existing fabricators - public static final short SLOT_CRAFTING_LEGACY_1 = 3; - public static final short SLOT_CRAFTING_LEGACY_COUNT = 9; - public static final short SLOT_INVENTORY_1 = 12; - public static final short SLOT_INVENTORY_COUNT = 18; - public static final short SLOT_COUNT = 30; - - public static final short SLOT_CRAFTING_1 = 0; - public static final short SLOT_CRAFTING_COUNT = 9; - - /* MEMBER */ - private final TileInventoryAdapter craftingInventory; + private final InventoryAdapterTile craftingInventory; private final TankManager tankManager; private final FilteredTank moltenTank; private int heat = 0; private int meltingPoint = 0; public TileFabricator() { - super(1100, 3300, 200); - craftingInventory = new TileInventoryAdapter<>(this, SLOT_CRAFTING_COUNT, "CraftItems"); - setInternalInventory(new FabricatorInventoryAdapter(this)); + super(GuiId.FabricatorGUI, "fabricator", 1100, 3300); + setEnergyPerWorkCycle(200); + craftingInventory = new InventoryAdapterTile<>(this, InventoryFabricator.SLOT_CRAFTING_COUNT, "CraftItems"); + setInternalInventory(new InventoryFabricator(this)); moltenTank = new FilteredTank(2 * Constants.BUCKET_VOLUME, Fluids.GLASS.getFluid()); moltenTank.tankMode = StandardTank.TankMode.INTERNAL; tankManager = new TankManager(this, moltenTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.FabricatorGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - /* SAVING & LOADING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setInteger("Heat", heat); - - // Tank tankManager.writeToNBT(nbttagcompound); - craftingInventory.writeToNBT(nbttagcompound); } @@ -110,21 +85,18 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank super.readFromNBT(nbttagcompound); heat = nbttagcompound.getInteger("Heat"); - - // Tank tankManager.readFromNBT(nbttagcompound); - craftingInventory.readFromNBT(nbttagcompound); // FIXME 1.8: wont need this // move items from legacy crafting area to the new one IInventory inventory = getInternalInventory(); - for (int slot = SLOT_CRAFTING_LEGACY_1; slot < SLOT_CRAFTING_LEGACY_1 + SLOT_CRAFTING_LEGACY_COUNT; slot++) { + for (int slot = InventoryFabricator.SLOT_CRAFTING_LEGACY_1; slot < InventoryFabricator.SLOT_CRAFTING_LEGACY_1 + InventoryFabricator.SLOT_CRAFTING_LEGACY_COUNT; slot++) { ItemStack stack = inventory.getStackInSlot(slot); if (stack != null) { inventory.setInventorySlotContents(slot, null); - int newSlot = slot - SLOT_CRAFTING_LEGACY_1; + int newSlot = slot - InventoryFabricator.SLOT_CRAFTING_LEGACY_1; craftingInventory.setInventorySlotContents(newSlot, stack); } } @@ -164,7 +136,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank private void trySmelting() { IInventoryAdapter inventory = getInternalInventory(); - ItemStack smeltResource = inventory.getStackInSlot(SLOT_METAL); + ItemStack smeltResource = inventory.getStackInSlot(InventoryFabricator.SLOT_METAL); if (smeltResource == null) { return; } @@ -176,7 +148,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank FluidStack smeltFluid = smelt.getProduct(); if (moltenTank.canFill(smeltFluid)) { - this.decrStackSize(SLOT_METAL, 1); + this.decrStackSize(InventoryFabricator.SLOT_METAL, 1); moltenTank.fill(smeltFluid, true); meltingPoint = smelt.getMeltingPoint(); } @@ -211,18 +183,11 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank private IFabricatorRecipe getRecipe() { IInventoryAdapter inventory = getInternalInventory(); - ItemStack plan = inventory.getStackInSlot(SLOT_PLAN); - ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN); + ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT); return FabricatorRecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting); } - /* ICRAFTER */ - @Override - public boolean canTakeStack(int slotIndex) { - return true; - } - - @Override public ItemStack getResult() { IFabricatorRecipe myRecipe = getRecipe(); @@ -233,13 +198,14 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank return RecipeUtil.getCraftingResult(myRecipe.getRecipeOutput(), myRecipe.preservesNbt(), craftingInventory); } + /* ICrafter */ @Override public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { - if (slotIndex != SLOT_RESULT) { + if (slotIndex != InventoryFabricator.SLOT_RESULT) { return null; } - return getInternalInventory().decrStackSize(SLOT_RESULT, 1); + return getInternalInventory().decrStackSize(InventoryFabricator.SLOT_RESULT, 1); } private void craftResult(EntityPlayer player) { @@ -255,14 +221,14 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_RESULT) != null) { + if (inventory.getStackInSlot(InventoryFabricator.SLOT_RESULT) != null) { return; } FluidStack liquid = myRecipe.getLiquid(); // Remove resources - ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT); if (!removeFromInventory(crafting, player, false)) { return; } @@ -275,32 +241,32 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank moltenTank.drain(liquid.amount, true); // Damage plan - if (inventory.getStackInSlot(SLOT_PLAN) != null) { - Item planItem = inventory.getStackInSlot(SLOT_PLAN).getItem(); + if (inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN) != null) { + Item planItem = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN).getItem(); if (planItem instanceof ICraftingPlan) { - inventory.setInventorySlotContents(SLOT_PLAN, ((ICraftingPlan) planItem).planUsed(inventory.getStackInSlot(SLOT_PLAN), result)); + inventory.setInventorySlotContents(InventoryFabricator.SLOT_PLAN, ((ICraftingPlan) planItem).planUsed(inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN), result)); } } - inventory.setInventorySlotContents(SLOT_RESULT, result); + inventory.setInventorySlotContents(InventoryFabricator.SLOT_RESULT, result); } private boolean removeFromInventory(ItemStack[] set, EntityPlayer player, boolean doRemove) { - IInventory inventory = new InventoryMapper(this, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + IInventory inventory = new InventoryMapper(this, InventoryFabricator.SLOT_INVENTORY_1, InventoryFabricator.SLOT_INVENTORY_COUNT); return InventoryUtil.removeSets(inventory, 1, set, player, true, true, false, doRemove); } @Override public boolean hasWork() { IInventoryAdapter inventory = getInternalInventory(); - ItemStack itemToMelt = inventory.getStackInSlot(SLOT_METAL); + ItemStack itemToMelt = inventory.getStackInSlot(InventoryFabricator.SLOT_METAL); IFabricatorSmeltingRecipe smelting = FabricatorSmeltingRecipeManager.findMatchingSmelting(itemToMelt); if (smelting != null && moltenTank.fill(smelting.getProduct(), false) > 0) { return true; } - ItemStack plan = inventory.getStackInSlot(SLOT_PLAN); - ItemStack[] resources = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN); + ItemStack[] resources = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT); return FabricatorRecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), resources) != null; } @@ -310,8 +276,8 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank } private int getMeltingPoint() { - if (this.getStackInSlot(SLOT_METAL) != null) { - IFabricatorSmeltingRecipe smelt = FabricatorSmeltingRecipeManager.findMatchingSmelting(this.getStackInSlot(SLOT_METAL)); + if (this.getStackInSlot(InventoryFabricator.SLOT_METAL) != null) { + IFabricatorSmeltingRecipe smelt = FabricatorSmeltingRecipeManager.findMatchingSmelting(this.getStackInSlot(InventoryFabricator.SLOT_METAL)); if (smelt != null) { return smelt.getMeltingPoint(); } @@ -388,32 +354,4 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - - private static class FabricatorInventoryAdapter extends TileInventoryAdapter { - public FabricatorInventoryAdapter(TileFabricator fabricator) { - super(fabricator, TileFabricator.SLOT_COUNT, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_METAL) { - return FabricatorSmeltingRecipeManager.findMatchingSmelting(itemStack) != null; - } else if (slotIndex == SLOT_PLAN) { - return FabricatorRecipeManager.isPlan(itemStack); - } else if (SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT)) { - if (FabricatorRecipeManager.isPlan(itemStack)) { - return false; - } else if (FabricatorSmeltingRecipeManager.findMatchingSmelting(itemStack) != null) { - return false; - } - } - return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { - return slotIndex == SLOT_RESULT; - } - } - } diff --git a/src/main/java/forestry/factory/tiles/TileFermenter.java b/src/main/java/forestry/factory/tiles/TileFermenter.java index 47e0d0c6f..46aa4ec2b 100644 --- a/src/main/java/forestry/factory/tiles/TileFermenter.java +++ b/src/main/java/forestry/factory/tiles/TileFermenter.java @@ -14,7 +14,6 @@ import java.io.IOException; import java.util.Collection; import java.util.LinkedList; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; @@ -30,42 +29,32 @@ import net.minecraftforge.fluids.IFluidHandler; import cpw.mods.fml.common.Optional; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.fuels.FermenterFuel; import forestry.api.fuels.FuelManager; import forestry.api.recipes.IFermenterRecipe; import forestry.api.recipes.IVariableFermentable; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.tanks.StandardTank; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.render.TankRenderInfo; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; +import forestry.factory.inventory.InventoryFermenter; import forestry.factory.recipes.FermenterRecipeManager; import forestry.factory.triggers.FactoryTriggers; import buildcraft.api.statements.ITriggerExternal; public class TileFermenter extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler { - - public static final short SLOT_RESOURCE = 0; - public static final short SLOT_FUEL = 1; - public static final short SLOT_CAN_OUTPUT = 2; - public static final short SLOT_CAN_INPUT = 3; - public static final short SLOT_INPUT = 4; - private final FilteredTank resourceTank; private final FilteredTank productTank; - private final TankManager tankManager; private IFermenterRecipe currentRecipe; @@ -77,9 +66,9 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu private int fuelCurrentFerment = 0; public TileFermenter() { - super(2000, 8000, 4200); - setInternalInventory(new FermenterInventoryAdapter(this)); - setHints(Config.hints.get("fermenter")); + super(GuiId.FermenterGUI, "fermenter", 2000, 8000); + setEnergyPerWorkCycle(4200); + setInternalInventory(new InventoryFermenter(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FermenterRecipeManager.recipeFluidInputs); resourceTank.tankMode = StandardTank.TankMode.INPUT; productTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FermenterRecipeManager.recipeFluidOutputs); @@ -87,11 +76,6 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu tankManager = new TankManager(this, resourceTank, productTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.FermenterGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); @@ -103,7 +87,6 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu nbttagcompound.setInteger("FuelCurrentFerment", fuelCurrentFerment); tankManager.writeToNBT(nbttagcompound); - } @Override @@ -136,11 +119,11 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu super.updateServerSide(); if (updateOnInterval(20)) { - FluidHelper.drainContainers(tankManager, this, SLOT_INPUT); + FluidHelper.drainContainers(tankManager, this, InventoryFermenter.SLOT_INPUT); FluidStack fluidStack = productTank.getFluid(); if (fluidStack != null) { - FluidHelper.fillContainers(tankManager, this, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); + FluidHelper.fillContainers(tankManager, this, InventoryFermenter.SLOT_CAN_INPUT, InventoryFermenter.SLOT_CAN_OUTPUT, fluidStack.getFluid()); } } } @@ -169,7 +152,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu return; } - ItemStack resource = getStackInSlot(SLOT_RESOURCE); + ItemStack resource = getStackInSlot(InventoryFermenter.SLOT_RESOURCE); FluidStack fluid = resourceTank.getFluid(); currentRecipe = FermenterRecipeManager.findMatchingRecipe(resource, fluid); @@ -178,7 +161,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu if (currentRecipe != null) { currentResourceModifier = determineResourceMod(resource); - decrStackSize(SLOT_RESOURCE, 1); + decrStackSize(InventoryFermenter.SLOT_RESOURCE, 1); } } @@ -187,7 +170,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu return; } - ItemStack fuel = getStackInSlot(SLOT_FUEL); + ItemStack fuel = getStackInSlot(InventoryFermenter.SLOT_FUEL); if (fuel == null) { return; } @@ -200,7 +183,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu fuelBurnTime = fuelTotalTime = fermenterFuel.burnDuration; fuelCurrentFerment = fermenterFuel.fermentPerCycle; - decrStackSize(SLOT_FUEL, 1); + decrStackSize(InventoryFermenter.SLOT_FUEL, 1); } private static float determineResourceMod(ItemStack itemstack) { @@ -214,7 +197,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu @Override public boolean hasResourcesMin(float percentage) { - ItemStack fermentationStack = getStackInSlot(SLOT_RESOURCE); + ItemStack fermentationStack = getStackInSlot(InventoryFermenter.SLOT_RESOURCE); if (fermentationStack == null) { return false; } @@ -224,7 +207,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu @Override public boolean hasFuelMin(float percentage) { - ItemStack fuelStack = getStackInSlot(SLOT_FUEL); + ItemStack fuelStack = getStackInSlot(InventoryFermenter.SLOT_FUEL); if (fuelStack == null) { return false; } @@ -239,7 +222,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu boolean hasRecipe = (currentRecipe != null); boolean hasFuel = fuelBurnTime > 0; - boolean hasResource = fermentationTime > 0 || getStackInSlot(SLOT_RESOURCE) != null; + boolean hasResource = fermentationTime > 0 || getStackInSlot(InventoryFermenter.SLOT_RESOURCE) != null; boolean hasFluidResource = resourceTank.canDrain(fuelCurrentFerment); boolean hasFluidSpace = true; @@ -354,30 +337,4 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu res.add(FactoryTriggers.lowResource10); return res; } - - private static class FermenterInventoryAdapter extends TileInventoryAdapter { - public FermenterInventoryAdapter(TileFermenter fermenter) { - super(fermenter, 5, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_RESOURCE) { - return FermenterRecipeManager.isResource(itemStack); - } else if (slotIndex == SLOT_INPUT) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.resourceTank.accepts(fluid); - } else if (slotIndex == SLOT_CAN_INPUT) { - return FluidHelper.isFillableContainer(itemStack); - } else if (slotIndex == SLOT_FUEL) { - return FuelManager.fermenterFuel.containsKey(itemStack); - } - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_CAN_OUTPUT; - } - } } diff --git a/src/main/java/forestry/factory/tiles/TileMillRainmaker.java b/src/main/java/forestry/factory/tiles/TileMillRainmaker.java index 0e06a06b1..39f1125d3 100644 --- a/src/main/java/forestry/factory/tiles/TileMillRainmaker.java +++ b/src/main/java/forestry/factory/tiles/TileMillRainmaker.java @@ -11,21 +11,20 @@ package forestry.factory.tiles; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import forestry.api.fuels.FuelManager; import forestry.api.fuels.RainSubstrate; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.proxy.Proxies; import forestry.core.tiles.TileMill; +import forestry.factory.inventory.InventoryRainmaker; public class TileMillRainmaker extends TileMill { - private int duration; private boolean reverse; public TileMillRainmaker() { + super(null, null); speed = 0.01f; setInternalInventory(new InventoryRainmaker(this)); } @@ -73,11 +72,12 @@ public class TileMillRainmaker extends TileMill { nbttagcompound.setBoolean("Reverse", reverse); } - private void addCharge(RainSubstrate substrate) { + public void addCharge(RainSubstrate substrate) { charge = 1; speed = substrate.speed; duration = substrate.duration; reverse = substrate.reverse; + sendNetworkUpdate(); } @Override @@ -112,39 +112,4 @@ public class TileMillRainmaker extends TileMill { } } - private static class InventoryRainmaker extends TileInventoryAdapter { - private static final int SLOT_SUBSTRATE = 0; - - public InventoryRainmaker(TileMillRainmaker tile) { - super(tile, 1, "items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_SUBSTRATE) { - if (FuelManager.rainSubstrate.containsKey(itemStack) && tile.charge == 0 && tile.progress == 0) { - RainSubstrate substrate = FuelManager.rainSubstrate.get(itemStack); - if (tile.worldObj.isRaining() && substrate.reverse) { - return true; - } else if (!tile.worldObj.isRaining() && !substrate.reverse) { - return true; - } - } - } - - return false; - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_SUBSTRATE) { - RainSubstrate substrate = FuelManager.rainSubstrate.get(itemStack); - if (substrate != null && substrate.item.isItemEqual(itemStack)) { - tile.addCharge(substrate); - tile.sendNetworkUpdate(); - } - } - } - } - } diff --git a/src/main/java/forestry/factory/tiles/TileMoistener.java b/src/main/java/forestry/factory/tiles/TileMoistener.java index 7353749b2..3fa221a7c 100644 --- a/src/main/java/forestry/factory/tiles/TileMoistener.java +++ b/src/main/java/forestry/factory/tiles/TileMoistener.java @@ -13,7 +13,6 @@ package forestry.factory.tiles; import java.io.IOException; import java.util.ArrayList; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; @@ -27,19 +26,16 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.fuels.FuelManager; import forestry.api.fuels.MoistenerFuel; import forestry.api.recipes.IMoistenerRecipe; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; @@ -49,20 +45,10 @@ import forestry.core.tiles.IRenderableTile; import forestry.core.tiles.TileBase; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.SlotUtil; +import forestry.factory.inventory.InventoryMoistener; import forestry.factory.recipes.MoistenerRecipeManager; public class TileMoistener extends TileBase implements ISidedInventory, ILiquidTankTile, IFluidHandler, IRenderableTile { - - /* CONSTANTS */ - private static final short SLOT_STASH_1 = 0; - private static final short SLOT_STASH_COUNT = 6; - private static final short SLOT_RESERVOIR_1 = 6; - private static final short SLOT_RESERVOIR_COUNT = 3; - private static final short SLOT_WORKING = 9; - private static final short SLOT_PRODUCT = 10; - private static final short SLOT_RESOURCE = 11; - private final FilteredTank resourceTank; private final TankManager tankManager; private IMoistenerRecipe currentRecipe; @@ -75,17 +61,12 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT private ItemStack pendingProduct; public TileMoistener() { - setInternalInventory(new MoistenerInventoryAdapter(this)); - setHints(Config.hints.get("moistener")); + super(GuiId.MoistenerGUI, "moistener"); + setInternalInventory(new InventoryMoistener(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); tankManager = new TankManager(this, resourceTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.MoistenerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - /* LOADING & SAVING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { @@ -150,7 +131,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT if (updateOnInterval(20)) { // Check if we have suitable water container waiting in the item slot - FluidHelper.drainContainers(tankManager, this, SLOT_PRODUCT); + FluidHelper.drainContainers(tankManager, this, InventoryMoistener.SLOT_PRODUCT); } // Let's get to work @@ -196,7 +177,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT if (productionTime <= 0) { pendingProduct = currentProduct; - decrStackSize(SLOT_RESOURCE, 1); + decrStackSize(InventoryMoistener.SLOT_RESOURCE, 1); resetRecipe(); tryAddPending(); } @@ -210,12 +191,12 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT checkRecipe(); // Let's see if we have a valid resource in the working slot - if (getStackInSlot(SLOT_WORKING) == null) { + if (getStackInSlot(InventoryMoistener.SLOT_WORKING) == null) { return; } - if (FuelManager.moistenerResource.containsKey(getStackInSlot(SLOT_WORKING))) { - MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(SLOT_WORKING)); + if (FuelManager.moistenerResource.containsKey(getStackInSlot(InventoryMoistener.SLOT_WORKING))) { + MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(InventoryMoistener.SLOT_WORKING)); burnTime = totalTime = res.moistenerValue; } } else { @@ -231,7 +212,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT return false; } - boolean added = InventoryUtil.tryAddStack(this, pendingProduct, SLOT_PRODUCT, 1, true); + boolean added = InventoryUtil.tryAddStack(this, pendingProduct, InventoryMoistener.SLOT_PRODUCT, 1, true); getErrorLogic().setCondition(!added, EnumErrorCode.NOSPACE); if (added) { @@ -242,7 +223,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT } public void checkRecipe() { - IMoistenerRecipe sameRec = MoistenerRecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE)); + IMoistenerRecipe sameRec = MoistenerRecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(InventoryMoistener.SLOT_RESOURCE)); if (currentRecipe != sameRec) { currentRecipe = sameRec; resetRecipe(); @@ -292,11 +273,11 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT } private int getFreeStashSlot(ItemStack deposit, boolean emptyOnly) { - return getFreeSlot(deposit, 0, SLOT_RESERVOIR_1, emptyOnly); + return getFreeSlot(deposit, 0, InventoryMoistener.SLOT_RESERVOIR_1, emptyOnly); } private int getFreeReservoirSlot(ItemStack deposit) { - return getFreeSlot(deposit, SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOT_RESERVOIR_COUNT, false); + return getFreeSlot(deposit, InventoryMoistener.SLOT_RESERVOIR_1, InventoryMoistener.SLOT_RESERVOIR_1 + InventoryMoistener.SLOT_RESERVOIR_COUNT, false); } @@ -330,14 +311,14 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT IErrorLogic errorLogic = getErrorLogic(); // Put working slot contents into inventory if space is available - if (getStackInSlot(SLOT_WORKING) != null) { + if (getStackInSlot(InventoryMoistener.SLOT_WORKING) != null) { // Get the result of the consumed item in the working slot ItemStack deposit; - if (FuelManager.moistenerResource.containsKey(getStackInSlot(SLOT_WORKING))) { - MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(SLOT_WORKING)); + if (FuelManager.moistenerResource.containsKey(getStackInSlot(InventoryMoistener.SLOT_WORKING))) { + MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(InventoryMoistener.SLOT_WORKING)); deposit = res.product.copy(); } else { - deposit = getStackInSlot(SLOT_WORKING).copy(); + deposit = getStackInSlot(InventoryMoistener.SLOT_WORKING).copy(); } int targetSlot = getFreeReservoirSlot(deposit); @@ -352,28 +333,28 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT getStackInSlot(targetSlot).stackSize++; } - decrStackSize(SLOT_WORKING, 1); + decrStackSize(InventoryMoistener.SLOT_WORKING, 1); } - if (getStackInSlot(SLOT_WORKING) != null) { + if (getStackInSlot(InventoryMoistener.SLOT_WORKING) != null) { return true; } // Let's look for a new resource to put into the working slot. - int resourceSlot = getNextResourceSlot(SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOT_RESERVOIR_COUNT); + int resourceSlot = getNextResourceSlot(InventoryMoistener.SLOT_RESERVOIR_1, InventoryMoistener.SLOT_RESERVOIR_1 + InventoryMoistener.SLOT_RESERVOIR_COUNT); // Nothing found, stop. if (errorLogic.setCondition(resourceSlot < 0, EnumErrorCode.NORESOURCE)) { return false; } - setInventorySlotContents(SLOT_WORKING, decrStackSize(resourceSlot, 1)); + setInventorySlotContents(InventoryMoistener.SLOT_WORKING, decrStackSize(resourceSlot, 1)); return true; } private void rotateReservoir() { ArrayList slotsToShift = new ArrayList<>(); - for (int i = SLOT_RESERVOIR_1; i < SLOT_RESERVOIR_1 + SLOT_RESERVOIR_COUNT; i++) { + for (int i = InventoryMoistener.SLOT_RESERVOIR_1; i < InventoryMoistener.SLOT_RESERVOIR_1 + InventoryMoistener.SLOT_RESERVOIR_COUNT; i++) { if (getStackInSlot(i) == null) { continue; } @@ -399,7 +380,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT // Grab new items from stash for (int i = 0; i < (slotsToShift.size() > 0 ? shiftedSlots : 2); i++) { - int resourceSlot = getNextResourceSlot(0, SLOT_RESERVOIR_1); + int resourceSlot = getNextResourceSlot(0, InventoryMoistener.SLOT_RESERVOIR_1); // Stop if no resources are available if (resourceSlot < 0) { break; @@ -431,7 +412,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT int avail = 0; IInventoryAdapter inventory = getInternalInventory(); - for (int i = SLOT_STASH_1; i < SLOT_RESERVOIR_1; i++) { + for (int i = InventoryMoistener.SLOT_STASH_1; i < InventoryMoistener.SLOT_RESERVOIR_1; i++) { if (inventory.getStackInSlot(i) == null) { max += 64; continue; @@ -450,11 +431,11 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT public boolean hasResourcesMin(float percentage) { IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_RESOURCE) == null) { + if (inventory.getStackInSlot(InventoryMoistener.SLOT_RESOURCE) == null) { return false; } - return ((float) inventory.getStackInSlot(SLOT_RESOURCE).stackSize / (float) inventory.getStackInSlot(SLOT_RESOURCE).getMaxStackSize()) > percentage; + return ((float) inventory.getStackInSlot(InventoryMoistener.SLOT_RESOURCE).stackSize / (float) inventory.getStackInSlot(InventoryMoistener.SLOT_RESOURCE).getMaxStackSize()) > percentage; } public boolean isProducing() { @@ -484,7 +465,6 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT } /* IRenderableTile */ - @Override public TankRenderInfo getResourceTankInfo() { return new TankRenderInfo(resourceTank); @@ -555,42 +535,4 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT iCrafting.sendProgressBarUpdate(container, 2, productionTime); iCrafting.sendProgressBarUpdate(container, 3, timePerItem); } - - private static class MoistenerInventoryAdapter extends TileInventoryAdapter { - public MoistenerInventoryAdapter(TileMoistener moistener) { - super(moistener, 12, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_RESOURCE) { - return MoistenerRecipeManager.isResource(itemStack); - } - - if (SlotUtil.isSlotInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) { - return FuelManager.moistenerResource.containsKey(itemStack); - } - - if (slotIndex == SLOT_PRODUCT) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.resourceTank.accepts(fluid); - } - - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - if (slotIndex == SLOT_PRODUCT) { - return true; - } - - if (SlotUtil.isSlotInRange(slotIndex, SLOT_STASH_1, (SLOT_STASH_COUNT + SLOT_RESERVOIR_COUNT))) { - return !FuelManager.moistenerResource.containsKey(itemstack); - } - - return false; - } - } - } diff --git a/src/main/java/forestry/factory/tiles/TileRaintank.java b/src/main/java/forestry/factory/tiles/TileRaintank.java index bbaa66b0e..4af9e7113 100644 --- a/src/main/java/forestry/factory/tiles/TileRaintank.java +++ b/src/main/java/forestry/factory/tiles/TileRaintank.java @@ -12,7 +12,6 @@ package forestry.factory.tiles; import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; @@ -28,31 +27,24 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import forestry.api.core.BiomeHelper; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.Fluids; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TileBase; import forestry.core.utils.ItemStackUtil; +import forestry.factory.inventory.InventoryRaintank; public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTankTile, IFluidHandler { - - /* CONSTANTS */ - public static final short SLOT_RESOURCE = 0; - public static final short SLOT_PRODUCT = 1; private static final FluidStack STACK_WATER = Fluids.WATER.getFluid(Constants.RAINTANK_AMOUNT_PER_UPDATE); - /* MEMBER */ private final FilteredTank resourceTank; private final TankManager tankManager; private boolean isValidBiome = true; @@ -60,8 +52,8 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa private ItemStack usedEmpty; public TileRaintank() { - setInternalInventory(new RaintankInventoryAdapter(this)); - setHints(Config.hints.get("raintank")); + super(GuiId.RaintankGUI, "raintank"); + setInternalInventory(new InventoryRaintank(this)); resourceTank = new FilteredTank(Constants.RAINTANK_TANK_CAPACITY, FluidRegistry.WATER); tankManager = new TankManager(this, resourceTank); @@ -79,11 +71,6 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa super.validate(); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.RaintankGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); @@ -134,24 +121,24 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa resourceTank.fill(STACK_WATER, true); } - if (!ItemStackUtil.isIdenticalItem(usedEmpty, getStackInSlot(SLOT_RESOURCE))) { + if (!ItemStackUtil.isIdenticalItem(usedEmpty, getStackInSlot(InventoryRaintank.SLOT_RESOURCE))) { fillingTime = 0; usedEmpty = null; } if (usedEmpty == null) { - usedEmpty = getStackInSlot(SLOT_RESOURCE); + usedEmpty = getStackInSlot(InventoryRaintank.SLOT_RESOURCE); } if (!isFilling()) { - FluidHelper.FillStatus canFill = FluidHelper.fillContainers(tankManager, this, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.getFluid(), false); + FluidHelper.FillStatus canFill = FluidHelper.fillContainers(tankManager, this, InventoryRaintank.SLOT_RESOURCE, InventoryRaintank.SLOT_PRODUCT, Fluids.WATER.getFluid(), false); if (canFill == FluidHelper.FillStatus.SUCCESS) { fillingTime = Constants.RAINTANK_FILLING_TIME; } } else { fillingTime--; if (fillingTime <= 0) { - FluidHelper.FillStatus filled = FluidHelper.fillContainers(tankManager, this, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.getFluid()); + FluidHelper.FillStatus filled = FluidHelper.fillContainers(tankManager, this, InventoryRaintank.SLOT_RESOURCE, InventoryRaintank.SLOT_PRODUCT, Fluids.WATER.getFluid()); if (filled == FluidHelper.FillStatus.SUCCESS) { fillingTime = 0; } @@ -215,23 +202,4 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - - private static class RaintankInventoryAdapter extends TileInventoryAdapter { - public RaintankInventoryAdapter(TileRaintank raintank) { - super(raintank, 3, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_RESOURCE) { - return FluidHelper.getFilledContainer(Fluids.WATER.getFluid(1000), itemStack) != null; - } - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_PRODUCT; - } - } } diff --git a/src/main/java/forestry/factory/tiles/TileSqueezer.java b/src/main/java/forestry/factory/tiles/TileSqueezer.java index be1b3e2b9..bfc14c8a4 100644 --- a/src/main/java/forestry/factory/tiles/TileSqueezer.java +++ b/src/main/java/forestry/factory/tiles/TileSqueezer.java @@ -13,7 +13,6 @@ package forestry.factory.tiles; import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -28,61 +27,48 @@ import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitBoard; import forestry.api.circuits.ICircuitSocketType; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.recipes.ISqueezerRecipe; import forestry.core.circuits.ISocketable; import forestry.core.circuits.ISpeedUpgradable; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; -import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.StandardTank; import forestry.core.inventory.InventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; -import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.render.TankRenderInfo; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; -import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.PlayerUtil; +import forestry.factory.inventory.InventorySqueezer; import forestry.factory.recipes.SqueezerRecipeManager; public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, IFluidHandler, ISpeedUpgradable { - private static final int TICKS_PER_RECIPE_TIME = 1; private static final int ENERGY_PER_WORK_CYCLE = 2000; private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 10; private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); - /* MEMBER */ private final TankManager tankManager; private final StandardTank productTank; - private final SqueezerInventory inventory; + private final InventorySqueezer inventory; private ISqueezerRecipe currentRecipe; public TileSqueezer() { - super(1100, Constants.MACHINE_MAX_ENERGY, ENERGY_PER_WORK_CYCLE); - this.inventory = new SqueezerInventory(this); + super(GuiId.SqueezerGUI, "squeezer", 1100, Constants.MACHINE_MAX_ENERGY); + this.inventory = new InventorySqueezer(this); setInternalInventory(this.inventory); - setHints(Config.hints.get("squeezer")); this.productTank = new StandardTank(Constants.PROCESSOR_TANK_CAPACITY); this.productTank.tankMode = StandardTank.TankMode.OUTPUT; this.tankManager = new TankManager(this, productTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.SqueezerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - /* LOADING & SAVING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { @@ -297,66 +283,4 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve public ICircuitSocketType getSocketType() { return CircuitSocketType.MACHINE; } - - public static class SqueezerInventory extends TileInventoryAdapter { - public static final short SLOT_RESOURCE_1 = 0; - public static final short SLOTS_RESOURCE_COUNT = 9; - public static final short SLOT_REMNANT = 9; - public static final short SLOT_REMNANT_COUNT = 1; - public static final short SLOT_CAN_INPUT = 10; - public static final short SLOT_CAN_OUTPUT = 11; - - public SqueezerInventory(TileSqueezer squeezer) { - super(squeezer, 12, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_CAN_INPUT) { - return FluidHelper.isEmptyContainer(itemStack); - } - - if (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) { - if (FluidHelper.isEmptyContainer(itemStack)) { - return false; - } - - if (SqueezerRecipeManager.canUse(itemStack)) { - return true; - } - } - - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT; - } - - public boolean hasResources() { - return !InventoryUtil.isEmpty(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); - } - - public ItemStack[] getResources() { - return InventoryUtil.getStacks(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); - } - - public boolean removeResources(ItemStack[] stacks, EntityPlayer player) { - IInventory inventory = new InventoryMapper(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); - return InventoryUtil.removeSets(inventory, 1, stacks, player, false, true, false, true); - } - - public boolean addRemnant(ItemStack remnant, boolean doAdd) { - return InventoryUtil.tryAddStack(this, remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true, doAdd); - } - - public void fillContainers(FluidStack fluidStack, TankManager tankManager) { - if (getStackInSlot(SLOT_CAN_INPUT) == null || fluidStack == null) { - return; - } - FluidHelper.fillContainers(tankManager, this, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); - } - } - } diff --git a/src/main/java/forestry/factory/tiles/TileStill.java b/src/main/java/forestry/factory/tiles/TileStill.java index 0337630c5..87bafd646 100644 --- a/src/main/java/forestry/factory/tiles/TileStill.java +++ b/src/main/java/forestry/factory/tiles/TileStill.java @@ -12,9 +12,7 @@ package forestry.factory.tiles; import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; @@ -23,32 +21,26 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.recipes.IStillRecipe; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.tanks.StandardTank; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.render.TankRenderInfo; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; +import forestry.factory.inventory.InventoryStill; import forestry.factory.recipes.StillRecipeManager; public class TileStill extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler { private static final int ENERGY_PER_RECIPE_TIME = 200; - public static final short SLOT_PRODUCT = 0; - public static final short SLOT_RESOURCE = 1; - public static final short SLOT_CAN = 2; - private final FilteredTank resourceTank; private final FilteredTank productTank; private final TankManager tankManager; @@ -57,9 +49,8 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa private FluidStack bufferedLiquid; public TileStill() { - super(1100, 8000, 200); - setInternalInventory(new StillInventoryAdapter(this)); - setHints(Config.hints.get("still")); + super(GuiId.StillGUI, "still", 1100, 8000); + setInternalInventory(new InventoryStill(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, StillRecipeManager.recipeFluidInputs); resourceTank.tankMode = StandardTank.TankMode.INPUT; productTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, StillRecipeManager.recipeFluidOutputs); @@ -67,11 +58,6 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa tankManager = new TankManager(this, resourceTank, productTank); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.StillGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); @@ -113,11 +99,11 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa super.updateServerSide(); if (updateOnInterval(20)) { - FluidHelper.drainContainers(tankManager, this, SLOT_CAN); + FluidHelper.drainContainers(tankManager, this, InventoryStill.SLOT_CAN); FluidStack fluidStack = productTank.getFluid(); if (fluidStack != null) { - FluidHelper.fillContainers(tankManager, this, SLOT_RESOURCE, SLOT_PRODUCT, fluidStack.getFluid()); + FluidHelper.fillContainers(tankManager, this, InventoryStill.SLOT_RESOURCE, InventoryStill.SLOT_PRODUCT, fluidStack.getFluid()); } } } @@ -223,26 +209,4 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - - private static class StillInventoryAdapter extends TileInventoryAdapter { - public StillInventoryAdapter(TileStill still) { - super(still, 3, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_RESOURCE) { - return FluidHelper.isEmptyContainer(itemStack); - } else if (slotIndex == SLOT_CAN) { - Fluid fluid = FluidHelper.getFluidInContainer(itemStack); - return tile.resourceTank.accepts(fluid); - } - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_PRODUCT; - } - } } diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index 4c6e77583..ab58c4aed 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -22,8 +22,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; -import forestry.api.core.ForestryAPI; -import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.InventoryAdapterTile; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; @@ -32,36 +31,23 @@ import forestry.core.recipes.RecipeUtil; import forestry.core.tiles.TileBase; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.SlotUtil; +import forestry.factory.inventory.InventoryWorktable; import forestry.factory.recipes.RecipeMemory; public class TileWorktable extends TileBase implements ICrafterWorktable { - - /* CONSTANTS */ - public final static int SLOT_CRAFTING_1 = 0; - public final static int SLOT_CRAFTING_COUNT = 9; - public final static int SLOT_CRAFTING_RESULT = 9; - public final static short SLOT_INVENTORY_1 = 0; - public final static short SLOT_INVENTORY_COUNT = 18; - - /* MEMBERS */ private RecipeMemory.Recipe currentRecipe; private InventoryCrafting currentCrafting; private final RecipeMemory memorized; - private final TileInventoryAdapter craftingInventory; + private final InventoryAdapterTile craftingInventory; public TileWorktable() { - craftingInventory = new TileInventoryAdapter<>(this, 10, "CraftItems"); - setInternalInventory(new WorktableInventoryAdapter(this)); + super(GuiId.WorktableGUI, "worktable"); + craftingInventory = new InventoryAdapterTile<>(this, 10, "CraftItems"); + setInternalInventory(new InventoryWorktable(this)); memorized = new RecipeMemory(); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.WorktableGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - /* LOADING & SAVING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { @@ -143,12 +129,12 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { if (currentRecipe != null) { ItemStack result = currentRecipe.getRecipeOutput(worldObj); if (result != null) { - craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, result.copy()); + craftingInventory.setInventorySlotContents(InventoryWorktable.SLOT_CRAFTING_RESULT, result.copy()); return; } } - craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, null); + craftingInventory.setInventorySlotContents(InventoryWorktable.SLOT_CRAFTING_RESULT, null); } private boolean canCraftCurrentRecipe() { @@ -156,8 +142,8 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { return false; } - ItemStack[] recipeItems = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); - ItemStack[] inventory = InventoryUtil.getStacks(getInternalInventory(), SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + ItemStack[] recipeItems = InventoryUtil.getStacks(craftingInventory, InventoryWorktable.SLOT_CRAFTING_1, InventoryWorktable.SLOT_CRAFTING_COUNT); + ItemStack[] inventory = InventoryUtil.getStacks(getInternalInventory(), InventoryWorktable.SLOT_INVENTORY_1, InventoryWorktable.SLOT_INVENTORY_COUNT); ItemStack recipeOutput = currentRecipe.getRecipeOutput(worldObj); return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory); @@ -165,7 +151,7 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { @Override public boolean canTakeStack(int slotIndex) { - if (slotIndex == SLOT_CRAFTING_RESULT) { + if (slotIndex == InventoryWorktable.SLOT_CRAFTING_RESULT) { return canCraftCurrentRecipe(); } return true; @@ -175,7 +161,7 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { public boolean onCraftingStart(EntityPlayer player) { ItemStack[] set = InventoryUtil.getStacks(currentRecipe.getMatrix()); - IInventory inventory = new InventoryMapper(this, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + IInventory inventory = new InventoryMapper(this, InventoryWorktable.SLOT_INVENTORY_1, InventoryWorktable.SLOT_INVENTORY_COUNT); ItemStack[] removed = InventoryUtil.removeSets(inventory, 1, set, player, false, true, true); if (removed == null) { @@ -245,17 +231,6 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { * @return Inaccessible crafting inventory for the craft grid. */ public IInventory getCraftingInventory() { - return new InventoryMapper(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); - } - - private static class WorktableInventoryAdapter extends TileInventoryAdapter { - public WorktableInventoryAdapter(TileWorktable worktable) { - super(worktable, 18, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); - } + return new InventoryMapper(craftingInventory, InventoryWorktable.SLOT_CRAFTING_1, InventoryWorktable.SLOT_CRAFTING_COUNT); } } diff --git a/src/main/java/forestry/farming/gui/ContainerFarm.java b/src/main/java/forestry/farming/gui/ContainerFarm.java index 4db8af1c3..833be190e 100755 --- a/src/main/java/forestry/farming/gui/ContainerFarm.java +++ b/src/main/java/forestry/farming/gui/ContainerFarm.java @@ -18,7 +18,7 @@ import forestry.core.gui.ContainerSocketed; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketGuiUpdate; -import forestry.farming.multiblock.FarmInventory; +import forestry.farming.multiblock.InventoryFarm; import forestry.farming.tiles.TileFarm; public class ContainerFarm extends ContainerSocketed { @@ -29,35 +29,35 @@ public class ContainerFarm extends ContainerSocketed { // Resources for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_RESOURCES_1 + j + i * 2, 123 + j * 18, 22 + i * 18)); + addSlotToContainer(new SlotFiltered(tile, InventoryFarm.SLOT_RESOURCES_1 + j + i * 2, 123 + j * 18, 22 + i * 18)); } } // Germlings for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_GERMLINGS_1 + j + i * 2, 164 + j * 18, 22 + i * 18)); + addSlotToContainer(new SlotFiltered(tile, InventoryFarm.SLOT_GERMLINGS_1 + j + i * 2, 164 + j * 18, 22 + i * 18)); } } // Production 1 for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - addSlotToContainer(new SlotOutput(tile, FarmInventory.SLOT_PRODUCTION_1 + j + i * 2, 123 + j * 18, 86 + i * 18)); + addSlotToContainer(new SlotOutput(tile, InventoryFarm.SLOT_PRODUCTION_1 + j + i * 2, 123 + j * 18, 86 + i * 18)); } } // Production 2 for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - addSlotToContainer(new SlotOutput(tile, FarmInventory.SLOT_PRODUCTION_1 + 4 + j + i * 2, 164 + j * 18, 86 + i * 18)); + addSlotToContainer(new SlotOutput(tile, InventoryFarm.SLOT_PRODUCTION_1 + 4 + j + i * 2, 164 + j * 18, 86 + i * 18)); } } // Fertilizer - addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_FERTILIZER, 63, 95)); + addSlotToContainer(new SlotFiltered(tile, InventoryFarm.SLOT_FERTILIZER, 63, 95)); // Can Slot - addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_CAN, 15, 95)); + addSlotToContainer(new SlotFiltered(tile, InventoryFarm.SLOT_CAN, 15, 95)); } @Override diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index 3626e2fce..52aba86c9 100644 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -122,7 +122,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen private final Map farmLogics = new EnumMap<>(FarmDirection.class); private final InventoryAdapter sockets; - private final FarmInventory inventory; + private final InventoryFarm inventory; private final TankManager tankManager; private final StandardTank resourceTank; private final FarmHydrationManager hydrationManager; @@ -139,7 +139,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen this.resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); this.tankManager = new TankManager(this, resourceTank); - this.inventory = new FarmInventory(this); + this.inventory = new InventoryFarm(this); this.sockets = new InventoryAdapter(1, "sockets"); this.hydrationManager = new FarmHydrationManager(this); this.fertilizerManager = new FarmFertilizerManager(); diff --git a/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java b/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java index ed6dda7e0..f14a7c9c9 100644 --- a/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java +++ b/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java @@ -14,8 +14,8 @@ import java.io.IOException; import net.minecraft.nbt.NBTTagCompound; +import forestry.api.core.ForestryAPI; import forestry.api.core.INBTTagable; -import forestry.core.config.GameMode; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; @@ -27,7 +27,7 @@ public class FarmFertilizerManager implements INBTTagable, IStreamable { private int storedFertilizer; public FarmFertilizerManager() { - this.fertilizerValue = GameMode.getGameMode().getIntegerSetting("farms.fertilizer.value"); + this.fertilizerValue = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.value"); } public boolean hasFertilizer(int amount) { @@ -49,7 +49,7 @@ public class FarmFertilizerManager implements INBTTagable, IStreamable { } } - public boolean maintainFertilizer(FarmInventory inventory) { + public boolean maintainFertilizer(InventoryFarm inventory) { if (storedFertilizer <= BUFFER_FERTILIZER) { if (fertilizerValue < 0) { storedFertilizer += 2000; diff --git a/src/main/java/forestry/farming/multiblock/FarmInventory.java b/src/main/java/forestry/farming/multiblock/InventoryFarm.java similarity index 95% rename from src/main/java/forestry/farming/multiblock/FarmInventory.java rename to src/main/java/forestry/farming/multiblock/InventoryFarm.java index a152f75ff..8b96a834c 100644 --- a/src/main/java/forestry/farming/multiblock/FarmInventory.java +++ b/src/main/java/forestry/farming/multiblock/InventoryFarm.java @@ -32,7 +32,7 @@ import forestry.core.utils.PlayerUtil; import forestry.core.utils.SlotUtil; import forestry.plugins.PluginFarming; -public class FarmInventory extends InventoryAdapterRestricted implements IFarmInventory { +public class InventoryFarm extends InventoryAdapterRestricted implements IFarmInventory { public static final int SLOT_RESOURCES_1 = 0; public static final int SLOT_RESOURCES_COUNT = 6; public static final int SLOT_GERMLINGS_1 = 6; @@ -54,7 +54,7 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn private final IInventory productInventory; private final IInventory fertilizerInventory; - public FarmInventory(FarmController farmController) { + public InventoryFarm(FarmController farmController) { super(SLOT_COUNT, "Items", farmController.getAccessHandler()); this.farmController = farmController; diff --git a/src/main/java/forestry/farming/tiles/TileFarm.java b/src/main/java/forestry/farming/tiles/TileFarm.java index 4d2753909..774a8805f 100644 --- a/src/main/java/forestry/farming/tiles/TileFarm.java +++ b/src/main/java/forestry/farming/tiles/TileFarm.java @@ -11,6 +11,7 @@ package forestry.farming.tiles; import java.io.IOException; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -172,7 +173,7 @@ public abstract class TileFarm extends RectangularMultiblockTileEntityBase imple /* IHintSource */ @Override - public String[] getHints() { + public List getHints() { return Config.hints.get("farm"); } diff --git a/src/main/java/forestry/food/GuiHandlerFood.java b/src/main/java/forestry/food/GuiHandlerFood.java index a17e5708f..be0528cae 100755 --- a/src/main/java/forestry/food/GuiHandlerFood.java +++ b/src/main/java/forestry/food/GuiHandlerFood.java @@ -18,7 +18,7 @@ import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.food.gui.ContainerInfuser; import forestry.food.gui.GuiInfuser; -import forestry.food.items.ItemInfuser.InfuserInventory; +import forestry.food.inventory.ItemInventoryInfuser; public class GuiHandlerFood extends GuiHandlerBase { @Override @@ -35,7 +35,7 @@ public class GuiHandlerFood extends GuiHandlerBase { if (infuser == null) { return null; } - return new GuiInfuser(player.inventory, new InfuserInventory(player, infuser)); + return new GuiInfuser(player.inventory, new ItemInventoryInfuser(player, infuser)); default: return null; @@ -56,7 +56,7 @@ public class GuiHandlerFood extends GuiHandlerBase { if (infuser == null) { return null; } - return new ContainerInfuser(player.inventory, new InfuserInventory(player, infuser)); + return new ContainerInfuser(player.inventory, new ItemInventoryInfuser(player, infuser)); default: return null; diff --git a/src/main/java/forestry/core/config/deprecated/Property.java b/src/main/java/forestry/food/InfuserIngredient.java similarity index 56% rename from src/main/java/forestry/core/config/deprecated/Property.java rename to src/main/java/forestry/food/InfuserIngredient.java index dad45ec4d..b84d60f56 100644 --- a/src/main/java/forestry/core/config/deprecated/Property.java +++ b/src/main/java/forestry/food/InfuserIngredient.java @@ -1,23 +1,31 @@ -/******************************************************************************* - * 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.config.deprecated; - -@Deprecated -public class Property { - public final String key; - public String value; - public String comment; - - public Property(String key, String value) { - this.key = key; - this.value = value; - } -} +/******************************************************************************* + * 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.food; + +import net.minecraft.item.ItemStack; + +public class InfuserIngredient { + private final ItemStack ingredient; + private final String description; + + public InfuserIngredient(ItemStack ingredient, String description) { + this.ingredient = ingredient; + this.description = description; + } + + public ItemStack getIngredient() { + return ingredient; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/forestry/food/InfuserIngredientManager.java b/src/main/java/forestry/food/InfuserIngredientManager.java new file mode 100644 index 000000000..43edf4a02 --- /dev/null +++ b/src/main/java/forestry/food/InfuserIngredientManager.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.food; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; + +import forestry.api.food.IIngredientManager; + +public class InfuserIngredientManager implements IIngredientManager { + private final List ingredients = new ArrayList<>(); + + @Override + public void addIngredient(ItemStack ingredient, String description) { + this.ingredients.add(new InfuserIngredient(ingredient, description)); + } + + @Override + public String getDescription(ItemStack itemstack) { + if (itemstack == null) { + return null; + } + + for (InfuserIngredient ingredient : ingredients) { + if (ingredient.getIngredient().getItemDamage() < 0 && ingredient.getIngredient().getItem() == itemstack.getItem()) { + return ingredient.getDescription(); + } else if (ingredient.getIngredient().getItemDamage() >= 0 && ingredient.getIngredient().isItemEqual(itemstack)) { + return ingredient.getDescription(); + } + } + + return null; + } +} diff --git a/src/main/java/forestry/food/InfuserMixture.java b/src/main/java/forestry/food/InfuserMixture.java new file mode 100644 index 000000000..afb9834ea --- /dev/null +++ b/src/main/java/forestry/food/InfuserMixture.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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.food; + +import net.minecraft.item.ItemStack; + +import forestry.api.food.IBeverageEffect; + +/** + * describes the itemstacks required to achieve a certain effect. + */ +public class InfuserMixture { + private final int meta; + private final ItemStack[] ingredients; + private final IBeverageEffect effect; + + public InfuserMixture(int meta, ItemStack ingredient, IBeverageEffect effect) { + this(meta, new ItemStack[]{ingredient}, effect); + } + + public InfuserMixture(int meta, ItemStack ingredients[], IBeverageEffect effect) { + this.meta = meta; + this.ingredients = ingredients; + this.effect = effect; + } + + public ItemStack[] getIngredients() { + return ingredients; + } + + public boolean isIngredient(ItemStack itemstack) { + for (ItemStack ingredient : ingredients) { + if (ingredient.getItemDamage() < 0 && ingredient.getItem() == itemstack.getItem()) { + return true; + } else if (ingredient.getItemDamage() >= 0 && ingredient.isItemEqual(itemstack)) { + return true; + } + } + + return false; + } + + public boolean matches(ItemStack[] res) { + + // No recipe without resource! + if (res == null || res.length <= 0) { + return false; + } + + boolean matchedAll = true; + + for (ItemStack stack : ingredients) { + boolean matched = false; + for (ItemStack matchStack : res) { + if (matchStack == null) { + continue; + } + + // Check item matching + if (stack.getItemDamage() < 0 && stack.getItem() == matchStack.getItem()) { + if (stack.stackSize <= matchStack.stackSize) { + matched = true; + break; + } + } else if (stack.getItemDamage() >= 0 && stack.isItemEqual(matchStack)) { + if (stack.stackSize <= matchStack.stackSize) { + matched = true; + break; + } + } + } + if (!matched) { + matchedAll = false; + } + } + return matchedAll; + + } + + public IBeverageEffect getEffect() { + return this.effect; + } + + public int getMeta() { + return meta; + } + + public int getWeight() { + return ingredients.length; + } +} diff --git a/src/main/java/forestry/food/InfuserMixtureManager.java b/src/main/java/forestry/food/InfuserMixtureManager.java new file mode 100644 index 000000000..590326794 --- /dev/null +++ b/src/main/java/forestry/food/InfuserMixtureManager.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * 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.food; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.minecraft.item.ItemStack; + +import forestry.api.food.IBeverageEffect; +import forestry.api.food.IInfuserManager; +import forestry.food.items.ItemBeverage; + +/** + * contains the available mixtures. + */ +public class InfuserMixtureManager implements IInfuserManager { + + private final List mixtures = new ArrayList<>(); + + @Override + public void addMixture(int meta, ItemStack ingredient, IBeverageEffect effect) { + this.mixtures.add(new InfuserMixture(meta, ingredient, effect)); + } + + @Override + public void addMixture(int meta, ItemStack[] ingredients, IBeverageEffect effect) { + this.mixtures.add(new InfuserMixture(meta, ingredients, effect)); + } + + public boolean isIngredient(ItemStack itemstack) { + for (InfuserMixture ingredient : mixtures) { + if (ingredient.isIngredient(itemstack)) { + return true; + } + } + + return false; + } + + private InfuserMixture[] getMatchingMixtures(ItemStack[] ingredients) { + + ArrayList matches = new ArrayList<>(); + + for (InfuserMixture mixture : mixtures) { + if (mixture.matches(ingredients)) { + matches.add(mixture); + } + } + + return matches.toArray(new InfuserMixture[matches.size()]); + } + + @Override + public boolean hasMixtures(ItemStack[] ingredients) { + return getMatchingMixtures(ingredients).length > 0; + } + + @Override + public ItemStack[] getRequired(ItemStack[] ingredients) { + InfuserMixture[] mixtures = getMatchingMixtures(ingredients); + ArrayList required = new ArrayList<>(); + + for (InfuserMixture mixture : mixtures) { + required.addAll(Arrays.asList(mixture.getIngredients())); + } + + return required.toArray(new ItemStack[required.size()]); + } + + @Override + public ItemStack getSeasoned(ItemStack base, ItemStack[] ingredients) { + InfuserMixture[] mixtures = getMatchingMixtures(ingredients); + List effects = ItemBeverage.BeverageInfo.loadEffects(base); + + int weight = 0; + int meta = 0; + for (InfuserMixture mixture : mixtures) { + effects.add(mixture.getEffect()); + if (mixture.getWeight() > weight) { + weight = mixture.getWeight(); + meta = mixture.getMeta(); + } + } + + ItemStack seasoned = base.copy(); + seasoned.setItemDamage(meta); + ItemBeverage.BeverageInfo.saveEffects(seasoned, effects); + return seasoned; + } +} diff --git a/src/main/java/forestry/food/gui/ContainerInfuser.java b/src/main/java/forestry/food/gui/ContainerInfuser.java index 8f35d2de3..7cb029328 100755 --- a/src/main/java/forestry/food/gui/ContainerInfuser.java +++ b/src/main/java/forestry/food/gui/ContainerInfuser.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.food.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -import forestry.core.utils.InventoryUtil; -import forestry.food.items.ItemInfuser.InfuserInventory; +import forestry.food.inventory.ItemInventoryInfuser; -public class ContainerInfuser extends ContainerItemInventory { +public class ContainerInfuser extends ContainerItemInventory { - public ContainerInfuser(InventoryPlayer inventoryplayer, InfuserInventory inventory) { + public ContainerInfuser(InventoryPlayer inventoryplayer, ItemInventoryInfuser inventory) { super(inventory, inventoryplayer, 8, 103); // Input @@ -36,13 +34,4 @@ public class ContainerInfuser extends ContainerItemInventory { this.addSlotToContainer(new SlotFiltered(inventory, 4, 12, 52)); this.addSlotToContainer(new SlotFiltered(inventory, 5, 12, 72)); } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) { - if (entityplayer.worldObj.isRemote) { - return; - } - - InventoryUtil.dropInventory(inventory, entityplayer.worldObj, entityplayer.posX, entityplayer.posY, entityplayer.posZ); - } } diff --git a/src/main/java/forestry/food/gui/GuiInfuser.java b/src/main/java/forestry/food/gui/GuiInfuser.java index e847c66af..1b55047ea 100755 --- a/src/main/java/forestry/food/gui/GuiInfuser.java +++ b/src/main/java/forestry/food/gui/GuiInfuser.java @@ -15,14 +15,14 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.api.food.BeverageManager; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; -import forestry.food.items.ItemInfuser.InfuserInventory; +import forestry.food.inventory.ItemInventoryInfuser; -public class GuiInfuser extends GuiForestry { +public class GuiInfuser extends GuiForestry { private int startX; private int startY; - public GuiInfuser(InventoryPlayer inventoryplayer, InfuserInventory inventory) { + public GuiInfuser(InventoryPlayer inventoryplayer, ItemInventoryInfuser inventory) { super(Constants.TEXTURE_PATH_GUI + "/infuser.png", new ContainerInfuser(inventoryplayer, inventory), inventory); xSize = 176; diff --git a/src/main/java/forestry/food/inventory/ItemInventoryInfuser.java b/src/main/java/forestry/food/inventory/ItemInventoryInfuser.java new file mode 100644 index 000000000..b79bfef32 --- /dev/null +++ b/src/main/java/forestry/food/inventory/ItemInventoryInfuser.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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.food.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import forestry.api.food.BeverageManager; +import forestry.core.config.ForestryItem; +import forestry.core.inventory.ItemInventory; + +public class ItemInventoryInfuser extends ItemInventory { + private static final short inputSlot = 0; + private static final short outputSlot = 1; + private static final short ingredientSlot1 = 2; + private static final short ingredientSlotCount = 4; + + public ItemInventoryInfuser(EntityPlayer player, ItemStack itemStack) { + super(player, 6, itemStack); + } + + @Override + public void onSlotClick(EntityPlayer player) { + + // Need input + ItemStack input = getStackInSlot(inputSlot); + if (input == null) { + return; + } + + // Output slot may not be occupied + if (getStackInSlot(outputSlot) != null) { + return; + } + + // Need a valid base + if (!input.isItemEqual(ForestryItem.beverage.getItemStack())) { + return; + } + + // Create the seasoned item + ItemStack[] ingredients = new ItemStack[4]; + for (int i = 0; i < 4; i++) { + ingredients[i] = getStackInSlot(i + ingredientSlot1); + } + + // Only continue if there is anything to season + if (!BeverageManager.infuserManager.hasMixtures(ingredients)) { + return; + } + + ItemStack seasoned = BeverageManager.infuserManager.getSeasoned(input, ingredients); + if (seasoned == null) { + return; + } + + // Remove required ingredients. + ItemStack[] toRemove = BeverageManager.infuserManager.getRequired(ingredients); + for (ItemStack templ : toRemove) { + ItemStack ghost = templ.copy(); + + for (int i = ingredientSlot1; i < this.getSizeInventory(); i++) { + ItemStack ingredient = getStackInSlot(i); + if (ingredient == null) { + continue; + } + if (ghost.stackSize <= 0) { + break; + } + + if ((ghost.getItemDamage() >= 0 && ingredient.isItemEqual(ghost)) + || (ghost.getItemDamage() < 0 && ghost.getItem() == ingredient.getItem())) { + ItemStack removed = decrStackSize(i, 1); + ghost.stackSize -= removed.stackSize; + } + } + } + decrStackSize(inputSlot, 1); + setInventorySlotContents(outputSlot, seasoned); + } + + @Override + public String getInventoryName() { + return "Infuser"; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == inputSlot) { + return ForestryItem.beverage.isItemEqual(itemStack); + } else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) { + return BeverageManager.infuserManager.isIngredient(itemStack); + } + return false; + } +} diff --git a/src/main/java/forestry/food/items/ItemInfuser.java b/src/main/java/forestry/food/items/ItemInfuser.java deleted file mode 100755 index 4aeecee6e..000000000 --- a/src/main/java/forestry/food/items/ItemInfuser.java +++ /dev/null @@ -1,352 +0,0 @@ -/******************************************************************************* - * 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.food.items; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import forestry.api.core.ForestryAPI; -import forestry.api.food.BeverageManager; -import forestry.api.food.IBeverageEffect; -import forestry.api.food.IInfuserManager; -import forestry.api.food.IIngredientManager; -import forestry.core.CreativeTabForestry; -import forestry.core.config.ForestryItem; -import forestry.core.inventory.ItemInventory; -import forestry.core.items.ItemForestry; -import forestry.core.network.GuiId; -import forestry.food.BeverageEffect; -import forestry.plugins.PluginManager; - -public class ItemInfuser extends ItemForestry { - - // / RECIPE MANAGMENT - - /** - * Mixture describes the itemstacks required to achieve a certain effect. - */ - public static class Mixture { - - private final int meta; - private final ItemStack[] ingredients; - private final IBeverageEffect effect; - - public Mixture(int meta, ItemStack ingredient, IBeverageEffect effect) { - this(meta, new ItemStack[]{ingredient}, effect); - } - - public Mixture(int meta, ItemStack ingredients[], IBeverageEffect effect) { - this.meta = meta; - this.ingredients = ingredients; - this.effect = effect; - } - - public ItemStack[] getIngredients() { - return ingredients; - } - - public boolean isIngredient(ItemStack itemstack) { - for (ItemStack ingredient : ingredients) { - if (ingredient.getItemDamage() < 0 && ingredient.getItem() == itemstack.getItem()) { - return true; - } else if (ingredient.getItemDamage() >= 0 && ingredient.isItemEqual(itemstack)) { - return true; - } - } - - return false; - } - - public boolean matches(ItemStack[] res) { - - // No recipe without resource! - if (res == null || res.length <= 0) { - return false; - } - - boolean matchedAll = true; - - for (ItemStack stack : ingredients) { - boolean matched = false; - for (ItemStack matchStack : res) { - if (matchStack == null) { - continue; - } - - // Check item matching - if (stack.getItemDamage() < 0 && stack.getItem() == matchStack.getItem()) { - if (stack.stackSize <= matchStack.stackSize) { - matched = true; - break; - } - } else if (stack.getItemDamage() >= 0 && stack.isItemEqual(matchStack)) { - if (stack.stackSize <= matchStack.stackSize) { - matched = true; - break; - } - } - } - if (!matched) { - matchedAll = false; - } - } - return matchedAll; - - } - - public IBeverageEffect getEffect() { - return this.effect; - } - - public int getMeta() { - return meta; - } - - public int getWeight() { - return ingredients.length; - } - } - - /** - * MixtureManager contains the available mixtures. - */ - public static class MixtureManager implements IInfuserManager { - - private final ArrayList mixtures = new ArrayList<>(); - - @Override - public void addMixture(int meta, ItemStack ingredient, IBeverageEffect effect) { - this.mixtures.add(new Mixture(meta, ingredient, effect)); - } - - @Override - public void addMixture(int meta, ItemStack[] ingredients, IBeverageEffect effect) { - this.mixtures.add(new Mixture(meta, ingredients, effect)); - } - - public boolean isIngredient(ItemStack itemstack) { - for (Mixture ingredient : mixtures) { - if (ingredient.isIngredient(itemstack)) { - return true; - } - } - - return false; - } - - private Mixture[] getMatchingMixtures(ItemStack[] ingredients) { - - ArrayList matches = new ArrayList<>(); - - for (Mixture mixture : mixtures) { - if (mixture.matches(ingredients)) { - matches.add(mixture); - } - } - - return matches.toArray(new Mixture[matches.size()]); - } - - @Override - public boolean hasMixtures(ItemStack[] ingredients) { - return getMatchingMixtures(ingredients).length > 0; - } - - @Override - public ItemStack[] getRequired(ItemStack[] ingredients) { - Mixture[] mixtures = getMatchingMixtures(ingredients); - ArrayList required = new ArrayList<>(); - - for (Mixture mixture : mixtures) { - required.addAll(Arrays.asList(mixture.getIngredients())); - } - - return required.toArray(new ItemStack[required.size()]); - } - - @Override - public ItemStack getSeasoned(ItemStack base, ItemStack[] ingredients) { - Mixture[] mixtures = getMatchingMixtures(ingredients); - List effects = ItemBeverage.BeverageInfo.loadEffects(base); - - int weight = 0; - int meta = 0; - for (Mixture mixture : mixtures) { - effects.add(mixture.getEffect()); - if (mixture.getWeight() > weight) { - weight = mixture.getWeight(); - meta = mixture.getMeta(); - } - } - - ItemStack seasoned = base.copy(); - seasoned.setItemDamage(meta); - ItemBeverage.BeverageInfo.saveEffects(seasoned, effects); - return seasoned; - } - } - - public static class Ingredient { - - public final ItemStack ingredient; - public final String description; - - public Ingredient(ItemStack ingredient, String description) { - this.ingredient = ingredient; - this.description = description; - } - } - - public static class IngredientManager implements IIngredientManager { - - private final ArrayList ingredients = new ArrayList<>(); - - @Override - public void addIngredient(ItemStack ingredient, String description) { - this.ingredients.add(new Ingredient(ingredient, description)); - } - - @Override - public String getDescription(ItemStack itemstack) { - if (itemstack == null) { - return null; - } - - for (Ingredient ingredient : ingredients) { - if (ingredient.ingredient.getItemDamage() < 0 && ingredient.ingredient.getItem() == itemstack.getItem()) { - return ingredient.description; - } else if (ingredient.ingredient.getItemDamage() >= 0 && ingredient.ingredient.isItemEqual(itemstack)) { - return ingredient.description; - } - } - - return null; - } - } - - // / INVENTORY MANAGMENT - public static class InfuserInventory extends ItemInventory { - - private static final short inputSlot = 0; - private static final short outputSlot = 1; - private static final short ingredientSlot1 = 2; - private static final short ingredientSlotCount = 4; - - public InfuserInventory(EntityPlayer player, ItemStack itemStack) { - super(player, 6, itemStack); - } - - @Override - public void onSlotClick(EntityPlayer player) { - - // Need input - ItemStack input = getStackInSlot(inputSlot); - if (input == null) { - return; - } - - // Output slot may not be occupied - if (getStackInSlot(outputSlot) != null) { - return; - } - - // Need a valid base - if (!input.isItemEqual(ForestryItem.beverage.getItemStack())) { - return; - } - - // Create the seasoned item - ItemStack[] ingredients = new ItemStack[4]; - for (int i = 0; i < 4; i++) { - ingredients[i] = getStackInSlot(i + ingredientSlot1); - } - - // Only continue if there is anything to season - if (!BeverageManager.infuserManager.hasMixtures(ingredients)) { - return; - } - - ItemStack seasoned = BeverageManager.infuserManager.getSeasoned(input, ingredients); - if (seasoned == null) { - return; - } - - // Remove required ingredients. - ItemStack[] toRemove = BeverageManager.infuserManager.getRequired(ingredients); - for (ItemStack templ : toRemove) { - ItemStack ghost = templ.copy(); - - for (int i = ingredientSlot1; i < this.getSizeInventory(); i++) { - ItemStack ingredient = getStackInSlot(i); - if (ingredient == null) { - continue; - } - if (ghost.stackSize <= 0) { - break; - } - - if ((ghost.getItemDamage() >= 0 && ingredient.isItemEqual(ghost)) - || (ghost.getItemDamage() < 0 && ghost.getItem() == ingredient.getItem())) { - ItemStack removed = decrStackSize(i, 1); - ghost.stackSize -= removed.stackSize; - } - } - } - decrStackSize(inputSlot, 1); - setInventorySlotContents(outputSlot, seasoned); - } - - @Override - public String getInventoryName() { - return "Infuser"; - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == inputSlot) { - return ForestryItem.beverage.isItemEqual(itemStack); - } else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) { - return BeverageManager.infuserManager.isIngredient(itemStack); - } - return false; - } - } - - public ItemInfuser() { - super(); - setMaxStackSize(1); - setCreativeTab(CreativeTabForestry.tabForestry); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.InfuserGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } - - return itemstack; - } - - public static void initialize() { - if (PluginManager.Module.APICULTURE.isEnabled()) { - BeverageManager.ingredientManager.addIngredient(ForestryItem.pollenCluster.getItemStack(1, 0), "Strong Curative"); - BeverageManager.ingredientManager.addIngredient(ForestryItem.pollenCluster.getItemStack(1, 1), "Weak Curative"); - BeverageManager.infuserManager.addMixture(1, ForestryItem.pollenCluster.getItemStack(1, 0), BeverageEffect.strongAntidote); - BeverageManager.infuserManager.addMixture(1, ForestryItem.pollenCluster.getItemStack(1, 1), BeverageEffect.weakAntidote); - } - } -} diff --git a/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java b/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java index 496fbc823..2087d8b16 100755 --- a/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java +++ b/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java @@ -19,7 +19,7 @@ import forestry.core.GuiHandlerBase; import forestry.core.gui.ContainerAlyzer; import forestry.core.network.GuiId; import forestry.lepidopterology.gui.GuiFlutterlyzer; -import forestry.lepidopterology.items.ItemFlutterlyzer.FlutterlyzerInventory; +import forestry.lepidopterology.inventory.ItemInventoryFlutterlyzer; public class GuiHandlerLepidopterology extends GuiHandlerBase { @@ -39,7 +39,7 @@ public class GuiHandlerLepidopterology extends GuiHandlerBase { return null; } - return new ContainerAlyzer(new FlutterlyzerInventory(player, equipped), player); + return new ContainerAlyzer(new ItemInventoryFlutterlyzer(player, equipped), player); case LepidopteristChestGUI: return getNaturalistChestContainer(ButterflyManager.butterflyRoot, player, world, x, y, z, guiData); @@ -66,7 +66,7 @@ public class GuiHandlerLepidopterology extends GuiHandlerBase { return null; } - return new GuiFlutterlyzer(player, new FlutterlyzerInventory(player, equipped)); + return new GuiFlutterlyzer(player, new ItemInventoryFlutterlyzer(player, equipped)); case LepidopteristChestGUI: return getNaturalistChestGui(ButterflyManager.butterflyRoot, player, world, x, y, z, guiData); diff --git a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java index 373e03f0b..2b9bb16c3 100755 --- a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java @@ -30,13 +30,13 @@ import forestry.core.gui.ContainerAlyzer; import forestry.core.gui.GuiAlyzer; import forestry.core.utils.StringUtil; import forestry.lepidopterology.genetics.ButterflyGenome; +import forestry.lepidopterology.inventory.ItemInventoryFlutterlyzer; import forestry.lepidopterology.items.ItemButterflyGE; -import forestry.lepidopterology.items.ItemFlutterlyzer.FlutterlyzerInventory; public class GuiFlutterlyzer extends GuiAlyzer { - public GuiFlutterlyzer(EntityPlayer player, FlutterlyzerInventory inventory) { - super("rootButterflies", player, new ContainerAlyzer(inventory, player), inventory, "gui.flutterlyzer"); + public GuiFlutterlyzer(EntityPlayer player, ItemInventoryFlutterlyzer inventory) { + super(ButterflyManager.butterflyRoot, player, new ContainerAlyzer(inventory, player), inventory, "gui.flutterlyzer"); ArrayList butterflyList = new ArrayList<>(); ((ItemButterflyGE) ForestryItem.butterflyGE.item()).addCreativeItems(butterflyList, false); @@ -54,8 +54,8 @@ public class GuiFlutterlyzer extends GuiAlyzer { int page = 0; IButterfly butterfly = null; - for (int k = 1; k < FlutterlyzerInventory.SLOT_ANALYZE_5 + 1; k++) { - if (k == FlutterlyzerInventory.SLOT_ENERGY) { + for (int k = 1; k < ItemInventoryFlutterlyzer.SLOT_ANALYZE_5 + 1; k++) { + if (k == ItemInventoryFlutterlyzer.SLOT_ENERGY) { continue; } diff --git a/src/main/java/forestry/lepidopterology/inventory/ItemInventoryFlutterlyzer.java b/src/main/java/forestry/lepidopterology/inventory/ItemInventoryFlutterlyzer.java new file mode 100644 index 000000000..1b9d3d6fe --- /dev/null +++ b/src/main/java/forestry/lepidopterology/inventory/ItemInventoryFlutterlyzer.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.lepidopterology.inventory; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import forestry.api.lepidopterology.ButterflyManager; +import forestry.core.config.Config; +import forestry.core.gui.IHintSource; +import forestry.core.inventory.ItemInventoryAlyzer; + +public class ItemInventoryFlutterlyzer extends ItemInventoryAlyzer implements IHintSource { + + public ItemInventoryFlutterlyzer(EntityPlayer player, ItemStack itemStack) { + super(ButterflyManager.butterflyRoot, player, itemStack); + } + + /* IHintSource */ + @Override + public List getHints() { + return Config.hints.get("flutterlyzer"); + } +} diff --git a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java deleted file mode 100755 index ca106546d..000000000 --- a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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.lepidopterology.items; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import forestry.api.core.ForestryAPI; -import forestry.api.core.Tabs; -import forestry.api.genetics.ISpeciesRoot; -import forestry.api.lepidopterology.ButterflyManager; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; -import forestry.core.items.ItemAlyzer; -import forestry.core.network.GuiId; - -public class ItemFlutterlyzer extends ItemAlyzer { - - public static class FlutterlyzerInventory extends AlyzerInventory implements IHintSource { - - public FlutterlyzerInventory(EntityPlayer player, ItemStack itemStack) { - super(player, 7, itemStack); - } - - @Override - protected ISpeciesRoot getSpeciesRoot() { - return ButterflyManager.butterflyRoot; - } - - /* IHINTSOURCE */ - @Override - public String[] getHints() { - return Config.hints.get("flutterlyzer"); - } - } - - public ItemFlutterlyzer() { - super(); - setMaxStackSize(1); - setCreativeTab(Tabs.tabLepidopterology); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (!world.isRemote) { - entityplayer.openGui(ForestryAPI.instance, GuiId.FlutterlyzerGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } - - return itemstack; - } -} diff --git a/src/main/java/forestry/lepidopterology/tiles/TileLepidopteristChest.java b/src/main/java/forestry/lepidopterology/tiles/TileLepidopteristChest.java index 62c14240c..2fc10e458 100644 --- a/src/main/java/forestry/lepidopterology/tiles/TileLepidopteristChest.java +++ b/src/main/java/forestry/lepidopterology/tiles/TileLepidopteristChest.java @@ -10,14 +10,12 @@ ******************************************************************************/ package forestry.lepidopterology.tiles; -import forestry.api.genetics.AlleleManager; +import forestry.api.lepidopterology.ButterflyManager; import forestry.core.network.GuiId; import forestry.core.tiles.TileNaturalistChest; public class TileLepidopteristChest extends TileNaturalistChest { - public TileLepidopteristChest() { - super(AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"), GuiId.LepidopteristChestGUI.ordinal()); + super(ButterflyManager.butterflyRoot, GuiId.LepidopteristChestGUI); } - } diff --git a/src/main/java/forestry/mail/GuiHandlerMail.java b/src/main/java/forestry/mail/GuiHandlerMail.java index 5e3f6afd1..bfbbbadf4 100755 --- a/src/main/java/forestry/mail/GuiHandlerMail.java +++ b/src/main/java/forestry/mail/GuiHandlerMail.java @@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.core.GuiHandlerBase; +import forestry.core.config.ForestryItem; import forestry.core.network.GuiId; import forestry.core.tiles.TileUtil; import forestry.mail.gui.ContainerCatalogue; @@ -29,9 +30,8 @@ import forestry.mail.gui.GuiMailbox; import forestry.mail.gui.GuiPhilatelist; import forestry.mail.gui.GuiTradeName; import forestry.mail.gui.GuiTrader; -import forestry.mail.items.ItemCatalogue; +import forestry.mail.inventory.ItemInventoryLetter; import forestry.mail.items.ItemLetter; -import forestry.mail.items.ItemLetter.LetterInventory; import forestry.mail.tiles.TileMailbox; import forestry.mail.tiles.TilePhilatelist; import forestry.mail.tiles.TileTrader; @@ -52,7 +52,7 @@ public class GuiHandlerMail extends GuiHandlerBase { return null; } - if (cata.getItem() instanceof ItemCatalogue) { + if (ForestryItem.catalogue.isItemEqual(cata)) { return new GuiCatalogue(player); } else { return null; @@ -65,7 +65,7 @@ public class GuiHandlerMail extends GuiHandlerBase { } if (equipped.getItem() instanceof ItemLetter) { - return new GuiLetter(player, new LetterInventory(player, equipped)); + return new GuiLetter(player, new ItemInventoryLetter(player, equipped)); } else { return null; } @@ -98,7 +98,7 @@ public class GuiHandlerMail extends GuiHandlerBase { return null; } - if (cata.getItem() instanceof ItemCatalogue) { + if (ForestryItem.catalogue.isItemEqual(cata)) { return new ContainerCatalogue(player); } else { return null; @@ -111,7 +111,7 @@ public class GuiHandlerMail extends GuiHandlerBase { } if (equipped.getItem() instanceof ItemLetter) { - return new ContainerLetter(player, new LetterInventory(player, equipped)); + return new ContainerLetter(player, new ItemInventoryLetter(player, equipped)); } else { return null; } diff --git a/src/main/java/forestry/mail/Letter.java b/src/main/java/forestry/mail/Letter.java index 53cb39004..9b6863d51 100755 --- a/src/main/java/forestry/mail/Letter.java +++ b/src/main/java/forestry/mail/Letter.java @@ -18,7 +18,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import forestry.api.core.INBTTagable; import forestry.api.mail.ILetter; import forestry.api.mail.IMailAddress; import forestry.api.mail.IStamps; @@ -26,9 +25,7 @@ import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.InventoryUtil; import forestry.core.utils.StringUtil; -public class Letter implements ILetter, INBTTagable { - - // CONSTANTS +public class Letter implements ILetter { public static final short SLOT_ATTACHMENT_1 = 0; public static final short SLOT_ATTACHMENT_COUNT = 18; public static final short SLOT_POSTAGE_1 = 18; @@ -68,7 +65,6 @@ public class Letter implements ILetter, INBTTagable { this.text = nbttagcompound.getString("TXT"); this.inventory.readFromNBT(nbttagcompound); - } @Override @@ -104,7 +100,6 @@ public class Letter implements ILetter, INBTTagable { @Override public int countAttachments() { - int count = 0; for (ItemStack stack : getAttachments()) { if (stack != null) { @@ -113,7 +108,6 @@ public class Letter implements ILetter, INBTTagable { } return count; - } @Override @@ -200,11 +194,7 @@ public class Letter implements ILetter, INBTTagable { return false; } - if (StringUtils.isBlank(recipient.getName())) { - return false; - } - - return true; + return !StringUtils.isBlank(recipient.getName()); } @Override @@ -217,10 +207,6 @@ public class Letter implements ILetter, INBTTagable { return sender; } - public void setRecipients(IMailAddress[] recipients) { - this.recipient = recipients; - } - @Override public void setRecipient(IMailAddress address) { if (address == null) { diff --git a/src/main/java/forestry/mail/LetterProperties.java b/src/main/java/forestry/mail/LetterProperties.java new file mode 100644 index 000000000..90cc04bdd --- /dev/null +++ b/src/main/java/forestry/mail/LetterProperties.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * 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.mail; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.api.mail.ILetter; +import forestry.core.config.ForestryItem; +import forestry.core.render.TextureManager; + +public class LetterProperties { + private enum State { + FRESH, STAMPED, OPENED, EMPTIED + } + + private enum Size { + EMPTY, SMALL, BIG + } + + public static ItemStack createStampedLetterStack(ILetter letter) { + Size size = getSize(letter); + int meta = encodeMeta(State.STAMPED, size); + return ForestryItem.letters.getItemStack(1, meta); + } + + public static void closeLetter(ItemStack parent, ILetter letter) { + State state = getState(parent.getItemDamage()); + Size size = getSize(parent.getItemDamage()); + + switch (state) { + case OPENED: + if (letter.countAttachments() <= 0) { + state = State.EMPTIED; + } + break; + case FRESH: + case STAMPED: + if (letter.isMailable() && letter.isPostPaid()) { + state = State.STAMPED; + } else { + state = State.FRESH; + } + size = getSize(letter); + break; + case EMPTIED: + } + + int meta = encodeMeta(state, size); + parent.setItemDamage(meta); + + letter.writeToNBT(parent.getTagCompound()); + } + + public static void openLetter(ItemStack parent) { + int oldMeta = parent.getItemDamage(); + State state = getState(oldMeta); + if (state == State.FRESH || state == State.STAMPED) { + Size size = getSize(oldMeta); + int newMeta = encodeMeta(State.OPENED, size); + parent.setItemDamage(newMeta); + } + } + + /* ICONS */ + @SideOnly(Side.CLIENT) + private static IIcon[][] icons; + + @SideOnly(Side.CLIENT) + public static void registerIcons(IIconRegister register) { + icons = new IIcon[3][4]; + for (int i = 0; i < 3; i++) { + icons[i][0] = TextureManager.registerTex(register, "mail/letter." + i + ".fresh"); + icons[i][1] = TextureManager.registerTex(register, "mail/letter." + i + ".stamped"); + icons[i][2] = TextureManager.registerTex(register, "mail/letter." + i + ".opened"); + icons[i][3] = TextureManager.registerTex(register, "mail/letter." + i + ".emptied"); + } + } + + @SideOnly(Side.CLIENT) + public static IIcon getIconFromDamage(int damage) { + State state = getState(damage); + Size size = getSize(damage); + + return icons[size.ordinal()][state.ordinal()]; + } + + private static State getState(int meta) { + int ordinal = meta & 0x0f; + State[] values = State.values(); + if (ordinal >= values.length) { + ordinal = 0; + } + return values[ordinal]; + } + + private static Size getSize(int meta) { + int ordinal = meta >> 4; + Size[] values = Size.values(); + if (ordinal >= values.length) { + ordinal = 0; + } + return values[ordinal]; + } + + private static int encodeMeta(State state, Size size) { + int meta = size.ordinal() << 4; + meta |= state.ordinal(); + return meta; + } + + private static Size getSize(ILetter letter) { + int count = letter.countAttachments(); + + if (count > 5) { + return Size.BIG; + } else if (count > 1) { + return Size.SMALL; + } else { + return Size.EMPTY; + } + } +} diff --git a/src/main/java/forestry/mail/PostRegistry.java b/src/main/java/forestry/mail/PostRegistry.java index 3db5f6a5f..7655bd388 100755 --- a/src/main/java/forestry/mail/PostRegistry.java +++ b/src/main/java/forestry/mail/PostRegistry.java @@ -33,7 +33,6 @@ import forestry.api.mail.PostManager; import forestry.core.config.ForestryItem; import forestry.core.proxy.Proxies; import forestry.core.utils.PlayerUtil; -import forestry.mail.items.ItemLetter; import forestry.mail.network.PacketPOBoxInfoResponse; public class PostRegistry implements IPostRegistry { @@ -214,7 +213,7 @@ public class PostRegistry implements IPostRegistry { NBTTagCompound nbttagcompound = new NBTTagCompound(); letter.writeToNBT(nbttagcompound); - ItemStack letterStack = ItemLetter.createStampedLetterStack(letter); + ItemStack letterStack = LetterProperties.createStampedLetterStack(letter); letterStack.setTagCompound(nbttagcompound); return letterStack; diff --git a/src/main/java/forestry/mail/TickHandlerMailClient.java b/src/main/java/forestry/mail/TickHandlerMailClient.java index 7027120a8..d0585f820 100755 --- a/src/main/java/forestry/mail/TickHandlerMailClient.java +++ b/src/main/java/forestry/mail/TickHandlerMailClient.java @@ -10,22 +10,20 @@ ******************************************************************************/ package forestry.mail; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; -import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; import forestry.core.proxy.Proxies; import forestry.mail.gui.GuiMailboxInfo; import forestry.mail.network.PacketPOBoxInfoRequest; public class TickHandlerMailClient { - public TickHandlerMailClient() { - FMLCommonHandler.instance().bus().register(this); - } + private static final int THROTTLE_TIME_MS = 10000; + private long lastInfoRequestTime; @SubscribeEvent - public void onRenderTick(RenderTickEvent event) { + public void onRenderTick(TickEvent.RenderTickEvent event) { if (event.phase != Phase.END) { return; } @@ -33,7 +31,11 @@ public class TickHandlerMailClient { if (GuiMailboxInfo.instance.hasPOBoxInfo()) { GuiMailboxInfo.instance.render(0, 0); } else { - Proxies.net.sendToServer(new PacketPOBoxInfoRequest()); + long time = System.currentTimeMillis(); + if (time - lastInfoRequestTime > THROTTLE_TIME_MS) { + Proxies.net.sendToServer(new PacketPOBoxInfoRequest()); + lastInfoRequestTime = time; + } } } } diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index 30846e767..a023bb6af 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTUtil; @@ -36,75 +35,9 @@ import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.SlotUtil; -import forestry.mail.items.ItemLetter; +import forestry.mail.inventory.InventoryTradeStation; public class TradeStation extends WorldSavedData implements ITradeStation, IInventoryAdapter { - - public static class TradeStationInventory extends InventoryAdapter { - - public TradeStationInventory() { - super(TradeStation.SLOT_SIZE, "INV"); - } - - @Override - public int[] getAccessibleSlotsFromSide(int side) { - - ArrayList slots = new ArrayList<>(); - - for (int i = SLOT_LETTERS_1; i < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT; i++) { - slots.add(i); - } - for (int i = SLOT_STAMPS_1; i < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; i++) { - slots.add(i); - } - for (int i = SLOT_RECEIVE_BUFFER; i < SLOT_RECEIVE_BUFFER + SLOT_RECEIVE_BUFFER_COUNT; i++) { - slots.add(i); - } - for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) { - slots.add(i); - } - - int[] slotsInt = new int[slots.size()]; - for (int i = 0; i < slots.size(); i++) { - slotsInt[i] = slots.get(i); - } - - return slotsInt; - } - - @Override - public boolean canExtractItem(int slot, ItemStack itemStack, int side) { - return SlotUtil.isSlotInRange(slot, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (SlotUtil.isSlotInRange(slotIndex, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) { - for (int i = 0; i < SLOT_TRADEGOOD_COUNT; i++) { - ItemStack tradeGood = getStackInSlot(SLOT_TRADEGOOD + i); - if (ItemStackUtil.isIdenticalItem(tradeGood, itemStack)) { - return true; - } - } - return false; - } else if (SlotUtil.isSlotInRange(slotIndex, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) { - Item item = itemStack.getItem(); - return item == Items.paper; - } else if (SlotUtil.isSlotInRange(slotIndex, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) { - Item item = itemStack.getItem(); - return item instanceof IStamps; - } - - return false; - } - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return canSlotAccept(i, itemstack); - } - } - - // / CONSTANTS public static final String SAVE_NAME = "TradePO_"; public static final short SLOT_TRADEGOOD = 0; public static final short SLOT_TRADEGOOD_COUNT = 1; @@ -120,14 +53,12 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve public static final short SLOT_SEND_BUFFER_COUNT = 10; public static final int SLOT_SIZE = SLOT_TRADEGOOD_COUNT + SLOT_EXCHANGE_COUNT + SLOT_LETTERS_COUNT + SLOT_STAMPS_COUNT + SLOT_RECEIVE_BUFFER_COUNT + SLOT_SEND_BUFFER_COUNT; - // / MEMBER private GameProfile owner; private IMailAddress address; private boolean isVirtual = false; private boolean isInvalid = false; - private final InventoryAdapter inventory = new TradeStationInventory(); + private final InventoryAdapter inventory = new InventoryTradeStation(); - // / CONSTRUCTORS public TradeStation(GameProfile owner, IMailAddress address) { super(SAVE_NAME + address); if (!address.isTrader()) { @@ -137,6 +68,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve this.address = address; } + @SuppressWarnings("unused") // required for WorldSavedData public TradeStation(String savename) { super(savename); } @@ -301,7 +233,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve NBTTagCompound nbttagcompound = new NBTTagCompound(); mail.writeToNBT(nbttagcompound); - ItemStack mailstack = ItemLetter.createStampedLetterStack(mail); + ItemStack mailstack = LetterProperties.createStampedLetterStack(mail); mailstack.setTagCompound(nbttagcompound); IPostalState responseState = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, mailstack, doLodge); @@ -335,7 +267,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve confirm.addStamps(ForestryItem.stamps.getItemStack(1, EnumPostage.P_1.ordinal() - 1)); confirm.writeToNBT(nbttagcompound); - ItemStack confirmstack = ItemLetter.createStampedLetterStack(confirm); + ItemStack confirmstack = LetterProperties.createStampedLetterStack(confirm); confirmstack.setTagCompound(nbttagcompound); PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, confirmstack, doLodge); diff --git a/src/main/java/forestry/mail/gui/ContainerLetter.java b/src/main/java/forestry/mail/gui/ContainerLetter.java index 0848c10f6..2a67032f3 100755 --- a/src/main/java/forestry/mail/gui/ContainerLetter.java +++ b/src/main/java/forestry/mail/gui/ContainerLetter.java @@ -31,16 +31,16 @@ import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketString; import forestry.core.proxy.Proxies; import forestry.mail.Letter; -import forestry.mail.items.ItemLetter.LetterInventory; +import forestry.mail.inventory.ItemInventoryLetter; import forestry.mail.network.PacketLetterInfoResponse; import forestry.mail.network.PacketLetterTextSet; -public class ContainerLetter extends ContainerItemInventory implements ILetterInfoReceiver { +public class ContainerLetter extends ContainerItemInventory implements ILetterInfoReceiver { private EnumAddressee carrierType = EnumAddressee.PLAYER; private TradeStationInfo tradeInfo = null; - public ContainerLetter(EntityPlayer player, LetterInventory inventory) { + public ContainerLetter(EntityPlayer player, ItemInventoryLetter inventory) { super(inventory, player.inventory, 17, 145); // Init slots @@ -85,7 +85,7 @@ public class ContainerLetter extends ContainerItemInventory imp } } - inventory.onContainerClosed(); + inventory.onLetterClosed(); super.onContainerClosed(entityplayer); } diff --git a/src/main/java/forestry/mail/gui/ContainerPhilatelist.java b/src/main/java/forestry/mail/gui/ContainerPhilatelist.java index 000f645cc..fae01680f 100755 --- a/src/main/java/forestry/mail/gui/ContainerPhilatelist.java +++ b/src/main/java/forestry/mail/gui/ContainerPhilatelist.java @@ -15,6 +15,7 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.mail.inventory.InventoryPhilatelist; import forestry.mail.tiles.TilePhilatelist; public class ContainerPhilatelist extends ContainerTile { @@ -23,12 +24,12 @@ public class ContainerPhilatelist extends ContainerTile { super(tile, player, 8, 111); // Filter - addSlotToContainer(new SlotFiltered(tile, TilePhilatelist.SLOT_FILTER, 80, 19)); + addSlotToContainer(new SlotFiltered(tile, InventoryPhilatelist.SLOT_FILTER, 80, 19)); // Collected Stamps for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { - addSlotToContainer(new SlotOutput(tile, j + i * 9 + TilePhilatelist.SLOT_BUFFER_1, 8 + j * 18, 46 + i * 18)); + addSlotToContainer(new SlotOutput(tile, j + i * 9 + InventoryPhilatelist.SLOT_BUFFER_1, 8 + j * 18, 46 + i * 18)); } } } diff --git a/src/main/java/forestry/mail/gui/GuiCatalogue.java b/src/main/java/forestry/mail/gui/GuiCatalogue.java index 0de84b2a9..a20ba86f5 100755 --- a/src/main/java/forestry/mail/gui/GuiCatalogue.java +++ b/src/main/java/forestry/mail/gui/GuiCatalogue.java @@ -55,9 +55,11 @@ public class GuiCatalogue extends GuiForestry { buttonList.add(new GuiButton(2, width / 2 + 44, guiTop + 150, 12, 20, ">")); buttonList.add(new GuiButton(3, width / 2 - 58, guiTop + 150, 12, 20, "<")); - buttonList.add(buttonFilter = new GuiButton(4, (width / 2) - 44, guiTop + 150, 42, 20, StringUtil.localize("gui.mail.filter.all"))); + buttonFilter = new GuiButton(4, (width / 2) - 44, guiTop + 150, 42, 20, StringUtil.localize("gui.mail.filter.all")); + buttonList.add(buttonFilter); - buttonList.add(buttonUse = new GuiButton(5, width / 2, guiTop + 150, 42, 20, StringUtil.localize("gui.mail.address.copy"))); + buttonUse = new GuiButton(5, width / 2, guiTop + 150, 42, 20, StringUtil.localize("gui.mail.address.copy")); + buttonList.add(buttonUse); } @Override diff --git a/src/main/java/forestry/mail/gui/GuiLetter.java b/src/main/java/forestry/mail/gui/GuiLetter.java index c821c0bcf..ff8ba91d1 100755 --- a/src/main/java/forestry/mail/gui/GuiLetter.java +++ b/src/main/java/forestry/mail/gui/GuiLetter.java @@ -32,10 +32,10 @@ import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; -import forestry.mail.items.ItemLetter.LetterInventory; +import forestry.mail.inventory.ItemInventoryLetter; import forestry.mail.network.PacketLetterInfoRequest; -public class GuiLetter extends GuiForestry { +public class GuiLetter extends GuiForestry { private final boolean isProcessedLetter; private boolean checkedSessionVars; @@ -48,7 +48,7 @@ public class GuiLetter extends GuiForestry { private final ArrayList tradeInfoWidgets; - public GuiLetter(EntityPlayer player, LetterInventory inventory) { + public GuiLetter(EntityPlayer player, ItemInventoryLetter inventory) { super(Constants.TEXTURE_PATH_GUI + "/letter.png", new ContainerLetter(player, inventory), inventory); this.xSize = 194; this.ySize = 227; diff --git a/src/main/java/forestry/mail/inventory/InventoryPhilatelist.java b/src/main/java/forestry/mail/inventory/InventoryPhilatelist.java new file mode 100644 index 000000000..1ae7f73f3 --- /dev/null +++ b/src/main/java/forestry/mail/inventory/InventoryPhilatelist.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.mail.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.api.mail.IStamps; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.mail.tiles.TilePhilatelist; + +public class InventoryPhilatelist extends InventoryAdapterTile { + public static final short SLOT_FILTER = 0; + public static final short SLOT_BUFFER_1 = 1; + public static final short SLOT_BUFFER_COUNT = 27; + + public InventoryPhilatelist(TilePhilatelist tile) { + super(tile, 28, "INV"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return itemStack.getItem() instanceof IStamps; + } +} diff --git a/src/main/java/forestry/mail/inventory/InventoryTradeStation.java b/src/main/java/forestry/mail/inventory/InventoryTradeStation.java new file mode 100644 index 000000000..efc6fb33a --- /dev/null +++ b/src/main/java/forestry/mail/inventory/InventoryTradeStation.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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.mail.inventory; + +import java.util.ArrayList; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import forestry.api.mail.IStamps; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.SlotUtil; +import forestry.mail.TradeStation; + +public class InventoryTradeStation extends InventoryAdapter { + + public InventoryTradeStation() { + super(TradeStation.SLOT_SIZE, "INV"); + } + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + + ArrayList slots = new ArrayList<>(); + + for (int i = TradeStation.SLOT_LETTERS_1; i < TradeStation.SLOT_LETTERS_1 + TradeStation.SLOT_LETTERS_COUNT; i++) { + slots.add(i); + } + for (int i = TradeStation.SLOT_STAMPS_1; i < TradeStation.SLOT_STAMPS_1 + TradeStation.SLOT_STAMPS_COUNT; i++) { + slots.add(i); + } + for (int i = TradeStation.SLOT_RECEIVE_BUFFER; i < TradeStation.SLOT_RECEIVE_BUFFER + TradeStation.SLOT_RECEIVE_BUFFER_COUNT; i++) { + slots.add(i); + } + for (int i = TradeStation.SLOT_SEND_BUFFER; i < TradeStation.SLOT_SEND_BUFFER + TradeStation.SLOT_SEND_BUFFER_COUNT; i++) { + slots.add(i); + } + + int[] slotsInt = new int[slots.size()]; + for (int i = 0; i < slots.size(); i++) { + slotsInt[i] = slots.get(i); + } + + return slotsInt; + } + + @Override + public boolean canExtractItem(int slot, ItemStack itemStack, int side) { + return SlotUtil.isSlotInRange(slot, TradeStation.SLOT_RECEIVE_BUFFER, TradeStation.SLOT_RECEIVE_BUFFER_COUNT); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (SlotUtil.isSlotInRange(slotIndex, TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT)) { + for (int i = 0; i < TradeStation.SLOT_TRADEGOOD_COUNT; i++) { + ItemStack tradeGood = getStackInSlot(TradeStation.SLOT_TRADEGOOD + i); + if (ItemStackUtil.isIdenticalItem(tradeGood, itemStack)) { + return true; + } + } + return false; + } else if (SlotUtil.isSlotInRange(slotIndex, TradeStation.SLOT_LETTERS_1, TradeStation.SLOT_LETTERS_COUNT)) { + Item item = itemStack.getItem(); + return item == Items.paper; + } else if (SlotUtil.isSlotInRange(slotIndex, TradeStation.SLOT_STAMPS_1, TradeStation.SLOT_STAMPS_COUNT)) { + Item item = itemStack.getItem(); + return item instanceof IStamps; + } + + return false; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return canSlotAccept(i, itemstack); + } +} diff --git a/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java b/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java new file mode 100644 index 000000000..d33ec9f26 --- /dev/null +++ b/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * 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.mail.inventory; + +import com.google.common.collect.ImmutableSet; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import forestry.api.core.IErrorSource; +import forestry.api.core.IErrorState; +import forestry.api.mail.ILetter; +import forestry.core.config.Config; +import forestry.core.config.ForestryItem; +import forestry.core.errors.EnumErrorCode; +import forestry.core.gui.IHintSource; +import forestry.core.inventory.ItemInventory; +import forestry.core.utils.SlotUtil; +import forestry.mail.Letter; +import forestry.mail.LetterProperties; +import forestry.mail.items.ItemStamps; + +public class ItemInventoryLetter extends ItemInventory implements IErrorSource, IHintSource { + private ILetter letter; + + public ItemInventoryLetter(EntityPlayer player, ItemStack itemstack) { + super(player, 0, itemstack); + } + + public ILetter getLetter() { + return letter; + } + + public void onLetterClosed() { + ItemStack parent = getParent(); + if (parent == null) { + return; + } + + LetterProperties.closeLetter(parent, letter); + } + + public void onLetterOpened() { + ItemStack parent = getParent(); + if (parent == null) { + return; + } + + LetterProperties.openLetter(parent); + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + if (nbttagcompound == null) { + return; + } + + letter = new Letter(nbttagcompound); + } + + @Override + public ItemStack decrStackSize(int i, int j) { + ItemStack result = letter.decrStackSize(i, j); + letter.writeToNBT(getParent().getTagCompound()); + return result; + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) { + letter.setInventorySlotContents(i, itemstack); + letter.writeToNBT(getParent().getTagCompound()); + } + + @Override + public ItemStack getStackInSlot(int i) { + return letter.getStackInSlot(i); + } + + @Override + public int getSizeInventory() { + return letter.getSizeInventory(); + } + + @Override + public String getInventoryName() { + return letter.getInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + return letter.getInventoryStackLimit(); + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + return letter.isUseableByPlayer(entityplayer); + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return letter.getStackInSlotOnClosing(slot); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (letter.isProcessed()) { + return false; + } else if (SlotUtil.isSlotInRange(slotIndex, Letter.SLOT_POSTAGE_1, Letter.SLOT_POSTAGE_COUNT)) { + Item item = itemStack.getItem(); + return item instanceof ItemStamps; + } else if (SlotUtil.isSlotInRange(slotIndex, Letter.SLOT_ATTACHMENT_1, Letter.SLOT_ATTACHMENT_COUNT)) { + return !ForestryItem.letters.isItemEqual(itemStack); + } + return false; + } + + /* IErrorSource */ + @Override + public ImmutableSet getErrorStates() { + + ImmutableSet.Builder errorStates = ImmutableSet.builder(); + + if (!letter.hasRecipient()) { + errorStates.add(EnumErrorCode.NORECIPIENT); + } + + if (!letter.isProcessed() && !letter.isPostPaid()) { + errorStates.add(EnumErrorCode.NOTPOSTPAID); + } + + return errorStates.build(); + } + + /* IHintSource */ + @Override + public List getHints() { + return Config.hints.get("letter"); + } + +} diff --git a/src/main/java/forestry/mail/items/ItemLetter.java b/src/main/java/forestry/mail/items/ItemLetter.java index d655f8625..6c08efdc4 100755 --- a/src/main/java/forestry/mail/items/ItemLetter.java +++ b/src/main/java/forestry/mail/items/ItemLetter.java @@ -10,13 +10,10 @@ ******************************************************************************/ package forestry.mail.items; -import com.google.common.collect.ImmutableSet; - import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentTranslation; @@ -26,43 +23,24 @@ import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.core.ForestryAPI; -import forestry.api.core.IErrorSource; -import forestry.api.core.IErrorState; import forestry.api.mail.ILetter; -import forestry.core.config.Config; -import forestry.core.config.ForestryItem; -import forestry.core.errors.EnumErrorCode; -import forestry.core.gui.IHintSource; -import forestry.core.inventory.ItemInventory; -import forestry.core.items.ItemInventoried; +import forestry.core.items.ItemWithGui; import forestry.core.network.GuiId; -import forestry.core.render.TextureManager; -import forestry.core.utils.SlotUtil; import forestry.core.utils.StringUtil; import forestry.mail.Letter; +import forestry.mail.LetterProperties; -public class ItemLetter extends ItemInventoried { - - private enum LetterState { - FRESH, STAMPED, OPENED, EMPTIED - } - - private enum LetterSize { - EMPTY, SMALL, BIG - } - - public static ItemStack createStampedLetterStack(ILetter letter) { - LetterSize size = getSize(letter); - int meta = encodeMeta(LetterState.STAMPED, size); - return ForestryItem.letters.getItemStack(1, meta); +public class ItemLetter extends ItemWithGui { + public ItemLetter() { + super(GuiId.LetterGUI); + setMaxStackSize(64); } @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { if (!world.isRemote) { if (itemstack.stackSize == 1) { - entityplayer.openGui(ForestryAPI.instance, GuiId.LetterGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ); + openGui(world, entityplayer); } else { entityplayer.addChatMessage(new ChatComponentTranslation("for.chat.mail.wrongstacksize")); } @@ -77,65 +55,16 @@ public class ItemLetter extends ItemInventoried { } /* ICONS */ - @SideOnly(Side.CLIENT) - private IIcon[][] icons; - @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister register) { - icons = new IIcon[3][4]; - for (int i = 0; i < 3; i++) { - icons[i][0] = TextureManager.registerTex(register, "mail/letter." + i + ".fresh"); - icons[i][1] = TextureManager.registerTex(register, "mail/letter." + i + ".stamped"); - icons[i][2] = TextureManager.registerTex(register, "mail/letter." + i + ".opened"); - icons[i][3] = TextureManager.registerTex(register, "mail/letter." + i + ".emptied"); - } + LetterProperties.registerIcons(register); } @SideOnly(Side.CLIENT) @Override public IIcon getIconFromDamage(int damage) { - - LetterState state = getState(damage); - LetterSize size = getSize(damage); - - return icons[size.ordinal()][state.ordinal()]; - } - - private static int encodeMeta(LetterState state, LetterSize size) { - int meta = size.ordinal() << 4; - meta |= state.ordinal(); - return meta; - } - - private static LetterState getState(int meta) { - int ordinal = meta & 0x0f; - LetterState[] values = LetterState.values(); - if (ordinal >= values.length) { - ordinal = 0; - } - return values[ordinal]; - } - - private static LetterSize getSize(int meta) { - int ordinal = meta >> 4; - LetterSize[] values = LetterSize.values(); - if (ordinal >= values.length) { - ordinal = 0; - } - return values[ordinal]; - } - - private static LetterSize getSize(ILetter letter) { - int count = letter.countAttachments(); - - if (count > 5) { - return LetterSize.BIG; - } else if (count > 1) { - return LetterSize.SMALL; - } else { - return LetterSize.EMPTY; - } + return LetterProperties.getIconFromDamage(damage); } @SuppressWarnings({"unchecked", "rawtypes"}) @@ -150,153 +79,4 @@ public class ItemLetter extends ItemInventoried { ILetter letter = new Letter(nbttagcompound); letter.addTooltip(list); } - - public static class LetterInventory extends ItemInventory implements IErrorSource, IHintSource { - private ILetter letter; - - public LetterInventory(EntityPlayer player, ItemStack itemstack) { - super(player, 0, itemstack); - } - - public ILetter getLetter() { - return letter; - } - - public void onContainerClosed() { - ItemStack parent = getParent(); - if (parent == null) { - return; - } - - LetterState state = getState(parent.getItemDamage()); - LetterSize size = getSize(parent.getItemDamage()); - - switch (state) { - case OPENED: - if (letter.countAttachments() <= 0) { - state = LetterState.EMPTIED; - } - break; - case FRESH: - case STAMPED: - if (letter.isMailable() && letter.isPostPaid()) { - state = LetterState.STAMPED; - } else { - state = LetterState.FRESH; - } - size = getSize(letter); - break; - case EMPTIED: - } - - int meta = encodeMeta(state, size); - parent.setItemDamage(meta); - - letter.writeToNBT(parent.getTagCompound()); - } - - public void onLetterOpened() { - ItemStack parent = getParent(); - if (parent != null) { - int oldMeta = parent.getItemDamage(); - LetterState state = getState(oldMeta); - if (state == LetterState.FRESH || state == LetterState.STAMPED) { - LetterSize size = ItemLetter.getSize(oldMeta); - int newMeta = ItemLetter.encodeMeta(LetterState.OPENED, size); - parent.setItemDamage(newMeta); - } - } - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - - if (nbttagcompound == null) { - return; - } - - letter = new Letter(nbttagcompound); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - ItemStack result = letter.decrStackSize(i, j); - letter.writeToNBT(getParent().getTagCompound()); - return result; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - letter.setInventorySlotContents(i, itemstack); - letter.writeToNBT(getParent().getTagCompound()); - } - - @Override - public ItemStack getStackInSlot(int i) { - return letter.getStackInSlot(i); - } - - @Override - public int getSizeInventory() { - return letter.getSizeInventory(); - } - - @Override - public String getInventoryName() { - return letter.getInventoryName(); - } - - @Override - public int getInventoryStackLimit() { - return letter.getInventoryStackLimit(); - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return letter.isUseableByPlayer(entityplayer); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return letter.getStackInSlotOnClosing(slot); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (letter.isProcessed()) { - return false; - } else if (SlotUtil.isSlotInRange(slotIndex, Letter.SLOT_POSTAGE_1, Letter.SLOT_POSTAGE_COUNT)) { - Item item = itemStack.getItem(); - return item instanceof ItemStamps; - } else if (SlotUtil.isSlotInRange(slotIndex, Letter.SLOT_ATTACHMENT_1, Letter.SLOT_ATTACHMENT_COUNT)) { - return !ForestryItem.letters.isItemEqual(itemStack); - } - return false; - } - - // / IERRORSOURCE - @Override - public ImmutableSet getErrorStates() { - - ImmutableSet.Builder errorStates = ImmutableSet.builder(); - - if (!letter.hasRecipient()) { - errorStates.add(EnumErrorCode.NORECIPIENT); - } - - if (!letter.isProcessed() && !letter.isPostPaid()) { - errorStates.add(EnumErrorCode.NOTPOSTPAID); - } - - return errorStates.build(); - } - - /* IHINTSOURCE */ - @Override - public String[] getHints() { - return Config.hints.get("letter"); - } - - } - } diff --git a/src/main/java/forestry/mail/tiles/TileMailbox.java b/src/main/java/forestry/mail/tiles/TileMailbox.java index 6b9ed508f..e44409893 100644 --- a/src/main/java/forestry/mail/tiles/TileMailbox.java +++ b/src/main/java/forestry/mail/tiles/TileMailbox.java @@ -26,12 +26,10 @@ import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional; -import forestry.api.core.ForestryAPI; import forestry.api.mail.ILetter; import forestry.api.mail.IMailAddress; import forestry.api.mail.IPostalState; import forestry.api.mail.PostManager; -import forestry.core.config.Config; import forestry.core.inventory.InventoryAdapter; import forestry.core.network.GuiId; import forestry.core.tiles.TileBase; @@ -47,14 +45,13 @@ public class TileMailbox extends TileBase implements IMailContainer { private boolean isLinked = false; public TileMailbox() { - setHints(Config.hints.get("mailbox")); + super(GuiId.MailboxGUI, "mailbox"); setInternalInventory(new InventoryAdapter(POBox.SLOT_SIZE, "Letters").disableAutomation()); } /* GUI */ @Override public void openGui(EntityPlayer player) { - if (worldObj.isRemote) { return; } @@ -70,7 +67,7 @@ public class TileMailbox extends TileBase implements IMailContainer { held.stackSize--; } } else { - player.openGui(ForestryAPI.instance, GuiId.MailboxGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + super.openGui(player); } } diff --git a/src/main/java/forestry/mail/tiles/TilePhilatelist.java b/src/main/java/forestry/mail/tiles/TilePhilatelist.java index 2aa759172..d3321a937 100644 --- a/src/main/java/forestry/mail/tiles/TilePhilatelist.java +++ b/src/main/java/forestry/mail/tiles/TilePhilatelist.java @@ -10,36 +10,23 @@ ******************************************************************************/ package forestry.mail.tiles; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import forestry.api.core.ForestryAPI; import forestry.api.mail.IStamps; import forestry.api.mail.PostManager; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.tiles.TileBase; import forestry.core.utils.InventoryUtil; +import forestry.mail.inventory.InventoryPhilatelist; public class TilePhilatelist extends TileBase implements IInventory { - - // / CONSTANTS - public static final short SLOT_FILTER = 0; - public static final short SLOT_BUFFER_1 = 1; - public static final short SLOT_BUFFER_COUNT = 27; - public TilePhilatelist() { - setInternalInventory(new PhilatelistInventoryAdapter(this)); + super(GuiId.PhilatelistGUI, "philatelist"); + setInternalInventory(new InventoryPhilatelist(this)); } - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.PhilatelistGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); - } - - // / UPDATING @Override public void updateServerSide() { if (!updateOnInterval(20)) { @@ -49,10 +36,10 @@ public class TilePhilatelist extends TileBase implements IInventory { ItemStack stamp = null; IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_FILTER) == null) { + if (inventory.getStackInSlot(InventoryPhilatelist.SLOT_FILTER) == null) { stamp = PostManager.postRegistry.getPostOffice(worldObj).getAnyStamp(1); } else { - ItemStack filter = inventory.getStackInSlot(SLOT_FILTER); + ItemStack filter = inventory.getStackInSlot(InventoryPhilatelist.SLOT_FILTER); if (filter.getItem() instanceof IStamps) { stamp = PostManager.postRegistry.getPostOffice(worldObj).getAnyStamp(((IStamps) filter.getItem()).getPostage(filter), 1); } @@ -63,17 +50,6 @@ public class TilePhilatelist extends TileBase implements IInventory { } // Store it. - InventoryUtil.stowInInventory(stamp, inventory, true, SLOT_BUFFER_1, SLOT_BUFFER_COUNT); - } - - private static class PhilatelistInventoryAdapter extends TileInventoryAdapter { - public PhilatelistInventoryAdapter(TilePhilatelist tile) { - super(tile, 28, "INV"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return itemStack.getItem() instanceof IStamps; - } + InventoryUtil.stowInInventory(stamp, inventory, true, InventoryPhilatelist.SLOT_BUFFER_1, InventoryPhilatelist.SLOT_BUFFER_COUNT); } } diff --git a/src/main/java/forestry/mail/tiles/TileTrader.java b/src/main/java/forestry/mail/tiles/TileTrader.java index a20f64b9b..35ae26c94 100644 --- a/src/main/java/forestry/mail/tiles/TileTrader.java +++ b/src/main/java/forestry/mail/tiles/TileTrader.java @@ -40,6 +40,7 @@ import forestry.core.tiles.TileBase; import forestry.core.utils.ItemStackUtil; import forestry.mail.MailAddress; import forestry.mail.TradeStation; +import forestry.mail.inventory.InventoryTradeStation; import forestry.mail.network.PacketTraderAddressResponse; import forestry.mail.triggers.MailTriggers; @@ -50,14 +51,15 @@ public class TileTrader extends TileBase { private IMailAddress address; public TileTrader() { + super(GuiId.TraderGUI, "trade.station"); address = new MailAddress(); - setInternalInventory(new TradeStation.TradeStationInventory()); + setInternalInventory(new InventoryTradeStation()); } @Override public void openGui(EntityPlayer player) { if (isLinked()) { - player.openGui(ForestryAPI.instance, GuiId.TraderGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); + super.openGui(player); } else { player.openGui(ForestryAPI.instance, GuiId.TraderNameGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); } diff --git a/src/main/java/forestry/plugins/ForestryPlugin.java b/src/main/java/forestry/plugins/ForestryPlugin.java index bd8d7ae07..4a174d64b 100755 --- a/src/main/java/forestry/plugins/ForestryPlugin.java +++ b/src/main/java/forestry/plugins/ForestryPlugin.java @@ -46,12 +46,27 @@ public abstract class ForestryPlugin { protected void disabledSetupAPI() { } + protected void registerItemsAndBlocks() { + } + protected void preInit() { } + protected void registerTriggers() { + } + + protected void registerBackpackItems() { + } + + protected void registerCrates() { + } + protected void doInit() { } + protected void registerRecipes() { + } + protected void postInit() { } @@ -113,21 +128,6 @@ public abstract class ForestryPlugin { return null; } - protected void registerItems() { - } - - protected void registerTriggers() { - } - - protected void registerBackpackItems() { - } - - protected void registerCrates() { - } - - protected void registerRecipes() { - } - @Override public String toString() { Plugin info = getClass().getAnnotation(Plugin.class); diff --git a/src/main/java/forestry/plugins/PluginAgriCraft.java b/src/main/java/forestry/plugins/PluginAgriCraft.java index f87366cde..48b878bc3 100644 --- a/src/main/java/forestry/plugins/PluginAgriCraft.java +++ b/src/main/java/forestry/plugins/PluginAgriCraft.java @@ -17,10 +17,10 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.utils.ModUtil; import forestry.farming.logic.FarmableBasicAgricraft; @@ -79,7 +79,7 @@ public class PluginAgriCraft extends ForestryPlugin { ); - int seedamount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int seedamount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); for (String seedName : seeds) { ItemStack seed = GameRegistry.findItemStack(AgriCraft, "seed" + seedName, 1); if (seed != null) { diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index 5b95834c2..0ca7f1050 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -24,6 +24,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; @@ -55,6 +56,7 @@ import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.FlowerManager; import forestry.api.apiculture.IBeekeepingMode; import forestry.api.apiculture.hives.HiveManager; +import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IClassification; @@ -86,12 +88,10 @@ import forestry.apiculture.genetics.JubilanceFactory; import forestry.apiculture.genetics.alleles.AlleleEffect; import forestry.apiculture.items.ItemArmorApiarist; import forestry.apiculture.items.ItemBeeGE; -import forestry.apiculture.items.ItemBeealyzer; import forestry.apiculture.items.ItemBlockCandle; import forestry.apiculture.items.ItemHabitatLocator; import forestry.apiculture.items.ItemHiveFrame; import forestry.apiculture.items.ItemHoneycomb; -import forestry.apiculture.items.ItemImprinter; import forestry.apiculture.items.ItemMinecartBeehouse; import forestry.apiculture.items.ItemWaxCast; import forestry.apiculture.multiblock.TileAlveary; @@ -126,7 +126,6 @@ import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.config.LocalizedConfiguration; import forestry.core.entities.EntityFXSnow; import forestry.core.fluids.Fluids; @@ -135,6 +134,8 @@ import forestry.core.items.ItemForestry; import forestry.core.items.ItemOverlay; import forestry.core.items.ItemOverlay.OverlayInfo; import forestry.core.items.ItemScoop; +import forestry.core.items.ItemWithGui; +import forestry.core.network.GuiId; import forestry.core.network.PacketIdClient; import forestry.core.network.PacketIdServer; import forestry.core.proxy.Proxies; @@ -200,10 +201,68 @@ public class PluginApiculture extends ForestryPlugin { } @Override - public void preInit() { - super.preInit(); + protected void registerItemsAndBlocks() { - MinecraftForge.EVENT_BUS.register(this); + // / BEES + ForestryItem.beeQueenGE.registerItem(new ItemBeeGE(EnumBeeType.QUEEN), "beeQueenGE"); + ForestryItem.beeDroneGE.registerItem(new ItemBeeGE(EnumBeeType.DRONE), "beeDroneGE"); + ForestryItem.beePrincessGE.registerItem(new ItemBeeGE(EnumBeeType.PRINCESS), "beePrincessGE"); + ForestryItem.beeLarvaeGE.registerItem(new ItemBeeGE(EnumBeeType.LARVAE), "beeLarvaeGE"); + + Item beealyzer = new ItemWithGui(GuiId.BeealyzerGUI).setCreativeTab(Tabs.tabApiculture); + ForestryItem.beealyzer.registerItem(beealyzer, "beealyzer"); + ForestryItem.habitatLocator.registerItem(new ItemHabitatLocator(), "habitatLocator"); + Item imprinter = new ItemWithGui(GuiId.ImprinterGUI).setCreativeTab(Tabs.tabApiculture).setMaxStackSize(1); + ForestryItem.imprinter.registerItem(imprinter, "imprinter"); + + ForestryItem.minecartBeehouse.registerItem(new ItemMinecartBeehouse(), "cart.beehouse"); + + // / COMB FRAMES + ForestryItem.frameUntreated.registerItem(new ItemHiveFrame(80, 0.9f), "frameUntreated"); + ForestryItem.frameImpregnated.registerItem(new ItemHiveFrame(240, 0.4f), "frameImpregnated"); + ForestryItem.frameProven.registerItem(new ItemHiveFrame(720, 0.3f), "frameProven"); + + // / BEE RESOURCES + ForestryItem.honeyDrop.registerItem(new ItemOverlay(Tabs.tabApiculture, + new OverlayInfo("honey", 0xecb42d, 0xe8c814), + new OverlayInfo("charged", 0x800505, 0x9c0707).setIsSecret(), + new OverlayInfo("omega", 0x191919, 0x4a8ca7).setIsSecret()), "honeyDrop"); + OreDictionary.registerOre("dropHoney", ForestryItem.honeyDrop.getItemStack()); + + ForestryItem.pollenCluster.registerItem(new ItemOverlay(Tabs.tabApiculture, + new OverlayInfo("normal", 0xa28a25, 0xa28a25), + new OverlayInfo("crystalline", 0xffffff, 0xc5feff)), + "pollen"); + OreDictionary.registerOre("itemPollen", ForestryItem.pollenCluster.getItemStack()); + + ForestryItem.propolis.registerItem(new ItemOverlay(Tabs.tabApiculture, + new OverlayInfo("normal", 0xc5b24e), + new OverlayInfo("sticky", 0xc68e57), + new OverlayInfo("pulsating", 0x2ccdb1).setIsSecret(), + new OverlayInfo("silky", 0xddff00)), + "propolis"); + + ForestryItem.honeydew.registerItem(new ItemForestry().setCreativeTab(Tabs.tabApiculture), "honeydew"); + OreDictionary.registerOre("dropHoneydew", ForestryItem.honeydew.getItemStack()); + + ForestryItem.royalJelly.registerItem(new ItemForestry().setCreativeTab(Tabs.tabApiculture), "royalJelly"); + OreDictionary.registerOre("dropRoyalJelly", ForestryItem.royalJelly.getItemStack()); + + ForestryItem.waxCast.registerItem(new ItemWaxCast().setCreativeTab(Tabs.tabApiculture), "waxCast"); + + // / BEE COMBS + ForestryItem.beeComb.registerItem(new ItemHoneycomb(), "beeCombs"); + OreDictionary.registerOre("beeComb", ForestryItem.beeComb.getWildcard()); + + // / APIARIST'S CLOTHES + ForestryItem.apiaristHat.registerItem(new ItemArmorApiarist(0), "apiaristHelmet"); + ForestryItem.apiaristChest.registerItem(new ItemArmorApiarist(1), "apiaristChest"); + ForestryItem.apiaristLegs.registerItem(new ItemArmorApiarist(2), "apiaristLegs"); + ForestryItem.apiaristBoots.registerItem(new ItemArmorApiarist(3), "apiaristBoots"); + + // TOOLS + ForestryItem.scoop.registerItem(new ItemScoop(), "scoop"); + ForestryItem.scoop.item().setHarvestLevel("scoop", 3); ForestryBlock.apiculture.registerBlock(new BlockBase(Material.iron), ItemBlockForestry.class, "apiculture"); ForestryBlock.apiculture.block().setCreativeTab(Tabs.tabApiculture); @@ -213,6 +272,23 @@ public class PluginApiculture extends ForestryPlugin { ForestryBlock.apicultureChest.block().setCreativeTab(Tabs.tabApiculture); ForestryBlock.apicultureChest.block().setHarvestLevel("axe", 0); + ForestryBlock.beehives.registerBlock(new BlockBeehives(), ItemBlockForestry.class, "beehives"); + + // Candles + ForestryBlock.candle.registerBlock(new BlockCandle(), ItemBlockCandle.class, "candle"); + ForestryBlock.stump.registerBlock(new BlockStump(), ItemBlockForestry.class, "stump"); + + // Alveary and Components + ForestryBlock.alveary.registerBlock(new BlockAlveary(), ItemBlockForestry.class, "alveary"); + ForestryBlock.alveary.block().setHarvestLevel("axe", 0); + } + + @Override + public void preInit() { + super.preInit(); + + MinecraftForge.EVENT_BUS.register(this); + definitionApiary = ((BlockBase) ForestryBlock.apiculture.block()).addDefinition(new MachineDefinition(Constants.DEFINITION_APIARY_META, "forestry.Apiary", TileApiary.class, ShapedRecipeCustom.createShapedRecipe(ForestryBlock.apiculture.getItemStack(1, Constants.DEFINITION_APIARY_META), "XXX", @@ -248,16 +324,6 @@ public class PluginApiculture extends ForestryPlugin { definitionAnalyzer = ((BlockBase) ForestryBlock.core.block()).addDefinition(new MachineDefinition(Constants.DEFINITION_ANALYZER_META, "forestry.Analyzer", TileAnalyzer.class, PluginApiculture.proxy.getRendererAnalyzer(Constants.TEXTURE_PATH_BLOCKS + "/analyzer_"))); - ForestryBlock.beehives.registerBlock(new BlockBeehives(), ItemBlockForestry.class, "beehives"); - - // Candles - ForestryBlock.candle.registerBlock(new BlockCandle(), ItemBlockCandle.class, "candle"); - ForestryBlock.stump.registerBlock(new BlockStump(), ItemBlockForestry.class, "stump"); - - // Alveary and Components - ForestryBlock.alveary.registerBlock(new BlockAlveary(), ItemBlockForestry.class, "alveary"); - ForestryBlock.alveary.block().setHarvestLevel("axe", 0); - // Add triggers if (PluginManager.Module.BUILDCRAFT_STATEMENTS.isEnabled()) { ApicultureTriggers.initialize(); @@ -274,25 +340,11 @@ public class PluginApiculture extends ForestryPlugin { @Override public void doInit() { - final String oldConfig = CONFIG_CATEGORY + ".conf"; - final String newConfig = CONFIG_CATEGORY + ".cfg"; - - File configFile = new File(Forestry.instance.getConfigFolder(), newConfig); + File configFile = new File(Forestry.instance.getConfigFolder(), CONFIG_CATEGORY + ".cfg"); if (!configFile.exists()) { setDefaultsForConfig(); } - File oldConfigFile = new File(Forestry.instance.getConfigFolder(), oldConfig); - if (oldConfigFile.exists()) { - loadOldConfig(); - - final String oldConfigRenamed = CONFIG_CATEGORY + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigFile.renameTo(oldConfigFileRenamed)) { - Log.info("Migrated " + CONFIG_CATEGORY + " settings to the new file '" + newConfig + "' and renamed '" + oldConfig + "' to '" + oldConfigRenamed + "'."); - } - } - LocalizedConfiguration config = new LocalizedConfiguration(configFile, "2.0.0"); if (!config.getLoadedConfigVersion().equals(config.getDefinedConfigVersion())) { boolean deleted = configFile.delete(); @@ -460,28 +512,6 @@ public class PluginApiculture extends ForestryPlugin { } } - private static void loadOldConfig() { - // Config - forestry.core.config.deprecated.Configuration apicultureConfig = new forestry.core.config.deprecated.Configuration(); - - forestry.core.config.deprecated.Property property = apicultureConfig.get("render.bees.fancy", CONFIG_CATEGORY, fancyRenderedBees); - property.comment = "set to true to enable a fancy butterfly-like renderer for bees. (experimental!)"; - fancyRenderedBees = Boolean.parseBoolean(property.value); - - property = apicultureConfig.get("beekeeping.mode", CONFIG_CATEGORY, "NORMAL"); - property.comment = "change beekeeping modes here. possible values EASY, NORMAL, HARD, HARDCORE, INSANE. mods may add additional modes."; - beekeepingMode = property.value.trim(); - Log.finer("Beekeeping mode read from config: " + beekeepingMode); - - property = apicultureConfig.get("beekeeping.secondprincess", CONFIG_CATEGORY, secondPrincessChance); - property.comment = "percent chance of second princess drop, for limited/skyblock maps. Acceptable values up to 2 decimals."; - secondPrincessChance = Float.parseFloat(property.value); - - property = apicultureConfig.get("species.blacklist", CONFIG_CATEGORY, ""); - property.comment = "add species to blacklist identified by their uid and seperated with ';'."; - parseBeeBlacklist(property.value); - } - @Override public IGuiHandler getGuiHandler() { return new GuiHandlerApiculture(); @@ -499,69 +529,6 @@ public class PluginApiculture extends ForestryPlugin { PacketIdServer.BEE_LOGIC_ACTIVE_ENTITY_REQUEST.setPacketHandler(new PacketBeeLogicEntityRequest()); } - @Override - protected void registerItems() { - - // / BEES - ForestryItem.beeQueenGE.registerItem((new ItemBeeGE(EnumBeeType.QUEEN)), "beeQueenGE"); - ForestryItem.beeDroneGE.registerItem((new ItemBeeGE(EnumBeeType.DRONE)), "beeDroneGE"); - ForestryItem.beePrincessGE.registerItem((new ItemBeeGE(EnumBeeType.PRINCESS)), "beePrincessGE"); - ForestryItem.beeLarvaeGE.registerItem((new ItemBeeGE(EnumBeeType.LARVAE)), "beeLarvaeGE"); - - ForestryItem.beealyzer.registerItem((new ItemBeealyzer()), "beealyzer"); - ForestryItem.habitatLocator.registerItem(new ItemHabitatLocator(), "habitatLocator"); - ForestryItem.imprinter.registerItem((new ItemImprinter()), "imprinter"); - - ForestryItem.minecartBeehouse.registerItem(new ItemMinecartBeehouse(), "cart.beehouse"); - - // / COMB FRAMES - ForestryItem.frameUntreated.registerItem(new ItemHiveFrame(80, 0.9f), "frameUntreated"); - ForestryItem.frameImpregnated.registerItem(new ItemHiveFrame(240, 0.4f), "frameImpregnated"); - ForestryItem.frameProven.registerItem(new ItemHiveFrame(720, 0.3f), "frameProven"); - - // / BEE RESOURCES - ForestryItem.honeyDrop.registerItem(new ItemOverlay(Tabs.tabApiculture, - new OverlayInfo("honey", 0xecb42d, 0xe8c814), - new OverlayInfo("charged", 0x800505, 0x9c0707).setIsSecret(), - new OverlayInfo("omega", 0x191919, 0x4a8ca7).setIsSecret()), "honeyDrop"); - OreDictionary.registerOre("dropHoney", ForestryItem.honeyDrop.getItemStack()); - - ForestryItem.pollenCluster.registerItem(new ItemOverlay(Tabs.tabApiculture, - new OverlayInfo("normal", 0xa28a25, 0xa28a25), - new OverlayInfo("crystalline", 0xffffff, 0xc5feff)), - "pollen"); - OreDictionary.registerOre("itemPollen", ForestryItem.pollenCluster.getItemStack()); - - ForestryItem.propolis.registerItem(new ItemOverlay(Tabs.tabApiculture, - new OverlayInfo("normal", 0xc5b24e), - new OverlayInfo("sticky", 0xc68e57), - new OverlayInfo("pulsating", 0x2ccdb1).setIsSecret(), - new OverlayInfo("silky", 0xddff00)), - "propolis"); - - ForestryItem.honeydew.registerItem(new ItemForestry().setCreativeTab(Tabs.tabApiculture), "honeydew"); - OreDictionary.registerOre("dropHoneydew", ForestryItem.honeydew.getItemStack()); - - ForestryItem.royalJelly.registerItem(new ItemForestry().setCreativeTab(Tabs.tabApiculture), "royalJelly"); - OreDictionary.registerOre("dropRoyalJelly", ForestryItem.royalJelly.getItemStack()); - - ForestryItem.waxCast.registerItem(new ItemWaxCast().setCreativeTab(Tabs.tabApiculture), "waxCast"); - - // / BEE COMBS - ForestryItem.beeComb.registerItem(new ItemHoneycomb(), "beeCombs"); - OreDictionary.registerOre("beeComb", ForestryItem.beeComb.getWildcard()); - - // / APIARIST'S CLOTHES - ForestryItem.apiaristHat.registerItem(new ItemArmorApiarist(0), "apiaristHelmet"); - ForestryItem.apiaristChest.registerItem(new ItemArmorApiarist(1), "apiaristChest"); - ForestryItem.apiaristLegs.registerItem(new ItemArmorApiarist(2), "apiaristLegs"); - ForestryItem.apiaristBoots.registerItem(new ItemArmorApiarist(3), "apiaristBoots"); - - // TOOLS - ForestryItem.scoop.registerItem(new ItemScoop(), "scoop"); - ForestryItem.scoop.item().setHarvestLevel("scoop", 3); - } - @Override protected void registerCrates() { ICrateRegistry crateRegistry = StorageManager.crateRegistry; @@ -662,8 +629,8 @@ public class PluginApiculture extends ForestryPlugin { } // / CAPSULES - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.capsule"), "###", '#', ForestryItem.beeswax); - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.refractory"), "###", '#', ForestryItem.refractoryWax); + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.capsule"), "###", '#', ForestryItem.beeswax); + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.refractory"), "###", '#', ForestryItem.refractoryWax); // / BITUMINOUS PEAT RecipeUtil.addRecipe(ForestryItem.bituminousPeat.getItemStack(), diff --git a/src/main/java/forestry/plugins/PluginArboriculture.java b/src/main/java/forestry/plugins/PluginArboriculture.java index 77eeee17d..207c74a44 100644 --- a/src/main/java/forestry/plugins/PluginArboriculture.java +++ b/src/main/java/forestry/plugins/PluginArboriculture.java @@ -17,6 +17,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandomChestContent; @@ -34,6 +35,7 @@ import cpw.mods.fml.common.registry.VillagerRegistry; import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumWoodType; import forestry.api.arboriculture.TreeManager; +import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; import forestry.api.recipes.RecipeManagers; @@ -64,7 +66,6 @@ import forestry.arboriculture.items.ItemBlockLeaves; import forestry.arboriculture.items.ItemBlockWood; import forestry.arboriculture.items.ItemGermlingGE; import forestry.arboriculture.items.ItemGrafter; -import forestry.arboriculture.items.ItemTreealyzer; import forestry.arboriculture.network.PacketRipeningUpdate; import forestry.arboriculture.proxy.ProxyArboriculture; import forestry.arboriculture.tiles.TileArboristChest; @@ -77,11 +78,12 @@ import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.genetics.alleles.AllelePlantType; import forestry.core.items.ItemBlockForestry; import forestry.core.items.ItemFruit.EnumFruit; +import forestry.core.items.ItemWithGui; +import forestry.core.network.GuiId; import forestry.core.network.PacketIdClient; import forestry.core.proxy.Proxies; import forestry.core.recipes.RecipeUtil; @@ -126,8 +128,19 @@ public class PluginArboriculture extends ForestryPlugin { } @Override - public void preInit() { - super.preInit(); + protected void registerItemsAndBlocks() { + + ForestryItem.sapling.registerItem(new ItemGermlingGE(EnumGermlingType.SAPLING), "sapling"); + OreDictionary.registerOre("treeSapling", ForestryItem.sapling.getWildcard()); + + if (PluginManager.Module.APICULTURE.isEnabled()) { + ForestryItem.pollenFertile.registerItem(new ItemGermlingGE(EnumGermlingType.POLLEN), "pollenFertile"); + Item treealyzer = new ItemWithGui(GuiId.TreealyzerGUI).setCreativeTab(Tabs.tabArboriculture); + ForestryItem.treealyzer.registerItem(treealyzer, "treealyzer"); + } + + ForestryItem.grafter.registerItem(new ItemGrafter(4), "grafter"); + ForestryItem.grafterProven.registerItem(new ItemGrafter(149), "grafterProven"); // Wood blocks ForestryBlock.logs.registerBlock(new BlockLog(false), ItemBlockWood.class, "logs"); @@ -160,20 +173,6 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.stairsFireproof.registerBlock(new BlockArbStairs(ForestryBlock.planksFireproof.block(), true), ItemBlockWood.class, "stairsFireproof"); OreDictionary.registerOre("stairWood", ForestryBlock.stairsFireproof.getWildcard()); - for (EnumWoodType woodType : EnumWoodType.VALUES) { - WoodItemAccess.registerLog(ForestryBlock.logs.block(), woodType, false); - WoodItemAccess.registerPlanks(ForestryBlock.planks.block(), woodType, false); - WoodItemAccess.registerSlab(ForestryBlock.slabs.block(), woodType, false); - WoodItemAccess.registerFence(ForestryBlock.fences.block(), woodType, false); - WoodItemAccess.registerStairs(ForestryBlock.stairs.block(), woodType, false); - - WoodItemAccess.registerLog(ForestryBlock.logsFireproof.block(), woodType, true); - WoodItemAccess.registerPlanks(ForestryBlock.planksFireproof.block(), woodType, true); - WoodItemAccess.registerSlab(ForestryBlock.slabsFireproof.block(), woodType, true); - WoodItemAccess.registerFence(ForestryBlock.fencesFireproof.block(), woodType, true); - WoodItemAccess.registerStairs(ForestryBlock.stairsFireproof.block(), woodType, true); - } - // Saplings ForestryBlock.saplingGE.registerBlock(new BlockSapling(), ItemBlockForestry.class, "saplingGE"); OreDictionary.registerOre("treeSapling", ForestryBlock.saplingGE.getWildcard()); @@ -188,6 +187,25 @@ public class PluginArboriculture extends ForestryPlugin { // Machines ForestryBlock.arboriculture.registerBlock(new BlockBase(Material.iron, true), ItemBlockForestry.class, "arboriculture"); ForestryBlock.arboriculture.block().setCreativeTab(Tabs.tabArboriculture); + } + + @Override + public void preInit() { + super.preInit(); + + for (EnumWoodType woodType : EnumWoodType.VALUES) { + WoodItemAccess.registerLog(ForestryBlock.logs.block(), woodType, false); + WoodItemAccess.registerPlanks(ForestryBlock.planks.block(), woodType, false); + WoodItemAccess.registerSlab(ForestryBlock.slabs.block(), woodType, false); + WoodItemAccess.registerFence(ForestryBlock.fences.block(), woodType, false); + WoodItemAccess.registerStairs(ForestryBlock.stairs.block(), woodType, false); + + WoodItemAccess.registerLog(ForestryBlock.logsFireproof.block(), woodType, true); + WoodItemAccess.registerPlanks(ForestryBlock.planksFireproof.block(), woodType, true); + WoodItemAccess.registerSlab(ForestryBlock.slabsFireproof.block(), woodType, true); + WoodItemAccess.registerFence(ForestryBlock.fencesFireproof.block(), woodType, true); + WoodItemAccess.registerStairs(ForestryBlock.stairsFireproof.block(), woodType, true); + } definitionChest = ((BlockBase) ForestryBlock.arboriculture.block()).addDefinition(new MachineDefinition(Constants.DEFINITION_ARBCHEST_META, "forestry.ArbChest", TileArboristChest.class, Proxies.render.getRenderChest("arbchest"), @@ -240,23 +258,6 @@ public class PluginArboriculture extends ForestryPlugin { public void postInit() { super.postInit(); registerDungeonLoot(); - - } - - @Override - protected void registerItems() { - - ForestryItem.sapling.registerItem(new ItemGermlingGE(EnumGermlingType.SAPLING), "sapling"); - OreDictionary.registerOre("treeSapling", ForestryItem.sapling.getWildcard()); - - if (PluginManager.Module.APICULTURE.isEnabled()) { - ForestryItem.pollenFertile.registerItem(new ItemGermlingGE(EnumGermlingType.POLLEN), "pollenFertile"); - ForestryItem.treealyzer.registerItem(new ItemTreealyzer(), "treealyzer"); - } - - ForestryItem.grafter.registerItem(new ItemGrafter(4), "grafter"); - ForestryItem.grafterProven.registerItem(new ItemGrafter(149), "grafterProven"); - } @Override @@ -314,9 +315,9 @@ public class PluginArboriculture extends ForestryPlugin { 'D', "gemDiamond"); // SQUEEZER RECIPES - int seedOilMultiplier = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); - int juiceMultiplier = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); - int mulchMultiplier = GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple"); + int seedOilMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + int juiceMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); + int mulchMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple"); RecipeManagers.squeezerManager.addRecipe(20, new ItemStack[]{EnumFruit.CHERRY.getStack()}, Fluids.SEEDOIL.getFluid(5 * seedOilMultiplier), ForestryItem.mulch.getItemStack(), 5); RecipeManagers.squeezerManager.addRecipe(60, new ItemStack[]{EnumFruit.WALNUT.getStack()}, Fluids.SEEDOIL.getFluid(18 * seedOilMultiplier), ForestryItem.mulch.getItemStack(), 5); RecipeManagers.squeezerManager.addRecipe(70, new ItemStack[]{EnumFruit.CHESTNUT.getStack()}, Fluids.SEEDOIL.getFluid(22 * seedOilMultiplier), ForestryItem.mulch.getItemStack(), 2); @@ -325,7 +326,7 @@ public class PluginArboriculture extends ForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.PAPAYA.getStack()}, Fluids.JUICE.getFluid(juiceMultiplier * 3), ForestryItem.mulch.getItemStack(), (int) Math.floor(mulchMultiplier * 0.5f)); RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.DATES.getStack()}, Fluids.JUICE.getFluid((int) Math.floor(juiceMultiplier * 0.25)), ForestryItem.mulch.getItemStack(), mulchMultiplier); - RecipeUtil.addFermenterRecipes(ForestryItem.sapling.getItemStack(), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(ForestryItem.sapling.getItemStack(), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); } // Stairs diff --git a/src/main/java/forestry/plugins/PluginBiomesOPlenty.java b/src/main/java/forestry/plugins/PluginBiomesOPlenty.java index e81f4647b..61c3f9b06 100644 --- a/src/main/java/forestry/plugins/PluginBiomesOPlenty.java +++ b/src/main/java/forestry/plugins/PluginBiomesOPlenty.java @@ -24,12 +24,12 @@ import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; import forestry.api.apiculture.FlowerManager; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.Log; @@ -71,6 +71,12 @@ public class PluginBiomesOPlenty extends ForestryPlugin { addFlowers(); addFarmCrops(); + } + + @Override + protected void registerRecipes() { + super.registerRecipes(); + addFermenterRecipes(); addSqueezerRecipes(); } @@ -107,7 +113,7 @@ public class PluginBiomesOPlenty extends ForestryPlugin { } private static void addFermenterRecipes() { - int saplingYield = GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"); + int saplingYield = ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"); if (saplings != null) { RecipeUtil.addFermenterRecipes(new ItemStack(saplings, 1, OreDictionary.WILDCARD_VALUE), saplingYield, Fluids.BIOMASS); diff --git a/src/main/java/forestry/plugins/PluginBuildCraftFuels.java b/src/main/java/forestry/plugins/PluginBuildCraftFuels.java index 902a83b07..f25d4abc3 100644 --- a/src/main/java/forestry/plugins/PluginBuildCraftFuels.java +++ b/src/main/java/forestry/plugins/PluginBuildCraftFuels.java @@ -14,8 +14,8 @@ import net.minecraftforge.fluids.Fluid; import cpw.mods.fml.common.Optional; +import forestry.api.core.ForestryAPI; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.utils.ModUtil; @@ -48,7 +48,7 @@ public class PluginBuildCraftFuels extends ForestryPlugin { Fluid ethanol = Fluids.ETHANOL.getFluid(); if (ethanol != null) { int ethanolPower = 40; - int ethanolBurnTime = Math.round(Constants.ENGINE_CYCLE_DURATION_ETHANOL * GameMode.getGameMode().getFloatSetting("fuel.ethanol.combustion")); + int ethanolBurnTime = Math.round(Constants.ENGINE_CYCLE_DURATION_ETHANOL * ForestryAPI.activeMode.getFloatSetting("fuel.ethanol.combustion")); BuildcraftFuelRegistry.fuel.addFuel(ethanol, ethanolPower, ethanolBurnTime); } } diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index 2965a5bef..fb4157cda 100644 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -17,6 +17,7 @@ import net.minecraft.block.material.Material; import net.minecraft.command.ICommand; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; @@ -27,6 +28,7 @@ import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.circuits.ChipsetManager; +import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; import forestry.api.storage.ICrateRegistry; @@ -42,7 +44,7 @@ import forestry.core.blocks.BlockResourceStorage; import forestry.core.blocks.BlockSoil; import forestry.core.circuits.CircuitRegistry; import forestry.core.circuits.ItemCircuitBoard; -import forestry.core.circuits.ItemSolderingIron; +import forestry.core.circuits.SolderManager; import forestry.core.commands.CommandPlugins; import forestry.core.commands.CommandVersion; import forestry.core.commands.RootCommand; @@ -50,7 +52,6 @@ import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.genetics.ItemResearchNote; import forestry.core.genetics.alleles.AlleleFactory; import forestry.core.genetics.alleles.AlleleHelper; @@ -61,13 +62,16 @@ import forestry.core.items.ItemBlockForestry; import forestry.core.items.ItemBlockTyped; import forestry.core.items.ItemElectronTube; import forestry.core.items.ItemForestry; +import forestry.core.items.ItemForestryBonemeal; import forestry.core.items.ItemForestryPickaxe; import forestry.core.items.ItemForestryShovel; import forestry.core.items.ItemFruit; import forestry.core.items.ItemMisc; import forestry.core.items.ItemOverlay.OverlayInfo; import forestry.core.items.ItemPipette; +import forestry.core.items.ItemWithGui; import forestry.core.items.ItemWrench; +import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.recipes.RecipeUtil; import forestry.core.recipes.ShapedRecipeCustom; @@ -88,7 +92,7 @@ public class PluginCore extends ForestryPlugin { protected void setupAPI() { super.setupAPI(); - ChipsetManager.solderManager = new ItemSolderingIron.SolderManager(); + ChipsetManager.solderManager = new SolderManager(); ChipsetManager.circuitRegistry = new CircuitRegistry(); @@ -97,80 +101,18 @@ public class PluginCore extends ForestryPlugin { AlleleManager.climateHelper = new ClimateUtil(); AlleleManager.alleleFactory = new AlleleFactory(); alleleRegistry.initialize(); - } - - @Override - public void preInit() { - super.preInit(); - - rootCommand.addChildCommand(new CommandVersion()); - rootCommand.addChildCommand(new CommandPlugins()); AlleleHelper.instance = new AlleleHelper(); - - ForestryBlock.core.registerBlock(new BlockBase(Material.iron, true), ItemBlockForestry.class, "core"); - - definitionEscritoire = ((BlockBase) ForestryBlock.core.block()).addDefinition(new MachineDefinition(Constants.DEFINITION_ESCRITOIRE_META, "forestry.Escritoire", TileEscritoire.class, - Proxies.render.getRenderEscritoire())); - - ForestryBlock.soil.registerBlock(new BlockSoil(), ItemBlockTyped.class, "soil"); - ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 0); - ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 1); - - ForestryBlock.resources.registerBlock(new BlockResourceOre(), ItemBlockForestry.class, "resources"); - ForestryBlock.resources.block().setHarvestLevel("pickaxe", 1); - - OreDictionary.registerOre("oreApatite", ForestryBlock.resources.getItemStack(1, 0)); - OreDictionary.registerOre("oreCopper", ForestryBlock.resources.getItemStack(1, 1)); - OreDictionary.registerOre("oreTin", ForestryBlock.resources.getItemStack(1, 2)); - - ForestryBlock.resourceStorage.registerBlock(new BlockResourceStorage(), ItemBlockForestry.class, "resourceStorage"); - ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0); - - OreDictionary.registerOre("blockApatite", ForestryBlock.resourceStorage.getItemStack(1, 0)); - OreDictionary.registerOre("blockCopper", ForestryBlock.resourceStorage.getItemStack(1, 1)); - OreDictionary.registerOre("blockTin", ForestryBlock.resourceStorage.getItemStack(1, 2)); - OreDictionary.registerOre("blockBronze", ForestryBlock.resourceStorage.getItemStack(1, 3)); - OreDictionary.registerOre("chestWood", Blocks.chest); - OreDictionary.registerOre("craftingTableWood", Blocks.crafting_table); } @Override - public void doInit() { - super.doInit(); - - definitionEscritoire.register(); - ForestryModEnvWarningCallable.register(); - - AlleleHelper.instance.init(); - - RecipeSorter.register("forestry:shapedrecipecustom", ShapedRecipeCustom.class, RecipeSorter.Category.SHAPED, "before:minecraft:shaped"); - RecipeSorter.register("forestry:shapelessrecipecustom", ShapelessRecipeCustom.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless"); - } - - @Override - public boolean isAvailable() { - return true; - } - - @Override - public IGuiHandler getGuiHandler() { - return null; - } - - @Override - public ISaveEventHandler getSaveEventHandler() { - return new SaveEventHandlerCore(); - } - - @Override - protected void registerItems() { + protected void registerItemsAndBlocks() { // / FERTILIZERS - ForestryItem.fertilizerBio.registerItem((new ItemForestry()), "fertilizerBio"); - ForestryItem.fertilizerCompound.registerItem((new ItemForestry()).setBonemeal(), "fertilizerCompound"); + ForestryItem.fertilizerBio.registerItem(new ItemForestry(), "fertilizerBio"); + ForestryItem.fertilizerCompound.registerItem(new ItemForestryBonemeal(), "fertilizerCompound"); // / GEMS - ForestryItem.apatite.registerItem((new ItemForestry()), "apatite"); + ForestryItem.apatite.registerItem(new ItemForestry(), "apatite"); OreDictionary.registerOre("gemApatite", ForestryItem.apatite.getItemStack()); ForestryItem.researchNote.registerItem(new ItemResearchNote(), "researchNote"); @@ -218,7 +160,8 @@ public class PluginCore extends ForestryPlugin { // / CIRCUIT BOARDS ForestryItem.circuitboards.registerItem(new ItemCircuitBoard(), "chipsets"); - ForestryItem.solderingIron.registerItem(new ItemSolderingIron(), "solderingIron"); + Item solderingIron = new ItemWithGui(GuiId.SolderingIronGUI).setMaxDamage(5).setFull3D(); + ForestryItem.solderingIron.registerItem(solderingIron, "solderingIron"); Color tubeCoverNormal = Color.WHITE; Color tubeCoverGold = new Color(0xFFF87E); @@ -285,6 +228,69 @@ public class PluginCore extends ForestryPlugin { for (ItemFruit.EnumFruit def : ItemFruit.EnumFruit.values()) { OreDictionary.registerOre(def.getOreDict(), def.getStack()); } + + ForestryBlock.core.registerBlock(new BlockBase(Material.iron, true), ItemBlockForestry.class, "core"); + + ForestryBlock.soil.registerBlock(new BlockSoil(), ItemBlockTyped.class, "soil"); + ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 0); + ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 1); + + ForestryBlock.resources.registerBlock(new BlockResourceOre(), ItemBlockForestry.class, "resources"); + ForestryBlock.resources.block().setHarvestLevel("pickaxe", 1); + OreDictionary.registerOre("oreApatite", ForestryBlock.resources.getItemStack(1, 0)); + OreDictionary.registerOre("oreCopper", ForestryBlock.resources.getItemStack(1, 1)); + OreDictionary.registerOre("oreTin", ForestryBlock.resources.getItemStack(1, 2)); + + ForestryBlock.resourceStorage.registerBlock(new BlockResourceStorage(), ItemBlockForestry.class, "resourceStorage"); + ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0); + OreDictionary.registerOre("blockApatite", ForestryBlock.resourceStorage.getItemStack(1, 0)); + OreDictionary.registerOre("blockCopper", ForestryBlock.resourceStorage.getItemStack(1, 1)); + OreDictionary.registerOre("blockTin", ForestryBlock.resourceStorage.getItemStack(1, 2)); + OreDictionary.registerOre("blockBronze", ForestryBlock.resourceStorage.getItemStack(1, 3)); + + OreDictionary.registerOre("chestWood", Blocks.chest); + OreDictionary.registerOre("craftingTableWood", Blocks.crafting_table); + } + + @Override + public void preInit() { + super.preInit(); + + rootCommand.addChildCommand(new CommandVersion()); + rootCommand.addChildCommand(new CommandPlugins()); + + definitionEscritoire = ((BlockBase) ForestryBlock.core.block()).addDefinition(new MachineDefinition(Constants.DEFINITION_ESCRITOIRE_META, "forestry.Escritoire", TileEscritoire.class, + Proxies.render.getRenderEscritoire())); + } + + @Override + public void doInit() { + super.doInit(); + + Proxies.render.init(); + + definitionEscritoire.register(); + ForestryModEnvWarningCallable.register(); + + AlleleHelper.instance.init(); + + RecipeSorter.register("forestry:shapedrecipecustom", ShapedRecipeCustom.class, RecipeSorter.Category.SHAPED, "before:minecraft:shaped"); + RecipeSorter.register("forestry:shapelessrecipecustom", ShapelessRecipeCustom.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless"); + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public IGuiHandler getGuiHandler() { + return null; + } + + @Override + public ISaveEventHandler getSaveEventHandler() { + return new SaveEventHandlerCore(); } @Override @@ -362,7 +368,7 @@ public class PluginCore extends ForestryPlugin { RecipeUtil.addRecipe(ForestryItem.sturdyCasing.getItemStack(), "###", "# #", "###", '#', "ingotBronze"); // / EMPTY CANS - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.can"), " # ", "# #", '#', "ingotTin"); + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.can"), " # ", "# #", '#', "ingotTin"); // / GEARS ArrayList stoneGear = OreDictionary.getOres("gearStone"); @@ -389,36 +395,36 @@ public class PluginCore extends ForestryPlugin { RecipeUtil.addRecipe(ForestryItem.wrench.getItemStack(), "# #", " # ", " # ", '#', "ingotBronze"); // Manure and Fertilizer - if (GameMode.getGameMode().getStackSetting("recipe.output.compost.wheat").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.compost.wheat"), " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "cropWheat"); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat"), " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "cropWheat"); } - if (GameMode.getGameMode().getStackSetting("recipe.output.compost.ash").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.compost.ash"), " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "dustAsh"); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.compost.ash").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.compost.ash"), " X ", "X#X", " X ", '#', Blocks.dirt, 'X', "dustAsh"); } - if (GameMode.getGameMode().getStackSetting("recipe.output.fertilizer.apatite").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.fertilizer.apatite"), " # ", " X ", " # ", '#', "sand", 'X', "gemApatite"); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.apatite").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.apatite"), " # ", " X ", " # ", '#', "sand", 'X', "gemApatite"); } - if (GameMode.getGameMode().getStackSetting("recipe.output.fertilizer.ash").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.fertilizer.ash"), "###", "#X#", "###", '#', "dustAsh", 'X', "gemApatite"); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.ash").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.fertilizer.ash"), "###", "#X#", "###", '#', "dustAsh", 'X', "gemApatite"); } // Humus - if (GameMode.getGameMode().getStackSetting("recipe.output.humus.compost").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.humus.compost"), "###", "#X#", "###", '#', Blocks.dirt, 'X', ForestryItem.fertilizerBio); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.humus.compost").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.humus.compost"), "###", "#X#", "###", '#', Blocks.dirt, 'X', ForestryItem.fertilizerBio); } - if (GameMode.getGameMode().getStackSetting("recipe.output.humus.fertilizer").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.humus.fertilizer"), "###", "#X#", "###", '#', Blocks.dirt, 'X', ForestryItem.fertilizerCompound); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.humus.fertilizer").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.humus.fertilizer"), "###", "#X#", "###", '#', Blocks.dirt, 'X', ForestryItem.fertilizerCompound); } // Bog earth - if (GameMode.getGameMode().getStackSetting("recipe.output.bogearth.bucket").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.bucket"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', Items.water_bucket, 'Y', "sand"); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.bucket").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.bucket"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', Items.water_bucket, 'Y', "sand"); } - if (GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can").stackSize > 0) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.canWater, 'Y', "sand"); - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.waxCapsuleWater, 'Y', "sand"); - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.refractoryWater, 'Y', "sand"); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can").stackSize > 0) { + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.canWater, 'Y', "sand"); + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.waxCapsuleWater, 'Y', "sand"); + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.refractoryWater, 'Y', "sand"); } // Crafting Material diff --git a/src/main/java/forestry/plugins/PluginEnderIO.java b/src/main/java/forestry/plugins/PluginEnderIO.java index 85ad279c5..53714bc25 100644 --- a/src/main/java/forestry/plugins/PluginEnderIO.java +++ b/src/main/java/forestry/plugins/PluginEnderIO.java @@ -6,8 +6,8 @@ import net.minecraftforge.fluids.Fluid; import cpw.mods.fml.common.event.FMLInterModComms; +import forestry.api.core.ForestryAPI; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.utils.ModUtil; @@ -40,7 +40,7 @@ public class PluginEnderIO extends ForestryPlugin { public void doInit() { Fluid ethanol = Fluids.ETHANOL.getFluid(); if (ethanol != null) { - int ethanolBurnTime = Math.round(Constants.ENGINE_CYCLE_DURATION_ETHANOL * GameMode.getGameMode().getFloatSetting("fuel.ethanol.combustion")); + int ethanolBurnTime = Math.round(Constants.ENGINE_CYCLE_DURATION_ETHANOL * ForestryAPI.activeMode.getFloatSetting("fuel.ethanol.combustion")); addFuel(ethanol, 40, ethanolBurnTime); } diff --git a/src/main/java/forestry/plugins/PluginEnergy.java b/src/main/java/forestry/plugins/PluginEnergy.java index d691162fa..ff85ce0a6 100755 --- a/src/main/java/forestry/plugins/PluginEnergy.java +++ b/src/main/java/forestry/plugins/PluginEnergy.java @@ -17,10 +17,10 @@ import net.minecraft.init.Items; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.network.IGuiHandler; +import forestry.api.core.ForestryAPI; import forestry.core.blocks.BlockBase; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; -import forestry.core.config.GameMode; import forestry.core.items.ItemBlockForestry; import forestry.core.recipes.ShapedRecipeCustom; import forestry.core.tiles.MachineDefinition; @@ -42,10 +42,15 @@ public class PluginEnergy extends ForestryPlugin { private static MachineDefinition definitionEngineClockwork; @Override - public void preInit() { - super.preInit(); + protected void registerItemsAndBlocks() { + super.registerItemsAndBlocks(); ForestryBlock.engine.registerBlock(new BlockEngine(Material.iron), ItemBlockForestry.class, "engine"); + } + + @Override + public void preInit() { + super.preInit(); definitionEnginePeat = ((BlockBase) ForestryBlock.engine.block()).addDefinition(new EngineDefinition(Constants.DEFINITION_ENGINE_PEAT_META, "forestry.EngineCopper", TileEnginePeat.class, PluginEnergy.proxy.getRenderDefaultEngine(Constants.TEXTURE_PATH_BLOCKS + "/engine_copper_"), ShapedRecipeCustom.createShapedRecipe( @@ -69,7 +74,7 @@ public class PluginEnergy extends ForestryPlugin { 'V', Blocks.piston))); ShapedRecipeCustom clockworkRecipe = null; - if (GameMode.getGameMode().getBooleanSetting("energy.engine.clockwork")) { + if (ForestryAPI.activeMode.getBooleanSetting("energy.engine.clockwork")) { clockworkRecipe = ShapedRecipeCustom.createShapedRecipe( ForestryBlock.engine.getItemStack(1, Constants.DEFINITION_ENGINE_CLOCKWORK_META), "###", diff --git a/src/main/java/forestry/plugins/PluginFactory.java b/src/main/java/forestry/plugins/PluginFactory.java index e46684b8b..1565f1f61 100644 --- a/src/main/java/forestry/plugins/PluginFactory.java +++ b/src/main/java/forestry/plugins/PluginFactory.java @@ -26,6 +26,13 @@ import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitLayout; +import forestry.api.core.ForestryAPI; +import forestry.api.fuels.EngineBronzeFuel; +import forestry.api.fuels.EngineCopperFuel; +import forestry.api.fuels.FermenterFuel; +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.MoistenerFuel; +import forestry.api.fuels.RainSubstrate; import forestry.api.recipes.ICraftingProvider; import forestry.api.recipes.RecipeManagers; import forestry.core.blocks.BlockBase; @@ -34,7 +41,6 @@ import forestry.core.circuits.CircuitLayout; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.items.ItemBlockForestry; import forestry.core.items.ItemBlockNBT; @@ -48,6 +54,8 @@ import forestry.core.recipes.nei.PacketWorktableNEISelect; import forestry.core.tiles.MachineDefinition; import forestry.core.utils.Log; import forestry.core.utils.ModUtil; +import forestry.core.utils.datastructures.FluidMap; +import forestry.core.utils.datastructures.ItemStackMap; import forestry.factory.DummyManagers; import forestry.factory.GuiHandlerFactory; import forestry.factory.circuits.CircuitSpeedUpgrade; @@ -102,13 +110,8 @@ public class PluginFactory extends ForestryPlugin { RecipeManagers.squeezerManager = new SqueezerRecipeManager(), RecipeManagers.stillManager = new StillRecipeManager() ); - } - @Override - public void registerPacketHandlers() { - PacketIdServer.WORKTABLE_NEI_SELECT.setPacketHandler(new PacketWorktableNEISelect()); - - PacketIdClient.WORKTABLE_MEMORY_UPDATE.setPacketHandler(new PacketWorktableMemoryUpdate()); + setupFuelManager(); } @Override @@ -125,13 +128,75 @@ public class PluginFactory extends ForestryPlugin { RecipeManagers.squeezerManager = new DummyManagers.DummySqueezerManager(), RecipeManagers.stillManager = new DummyManagers.DummyStillManager() ); + + setupFuelManager(); + } + + private static void setupFuelManager() { + FuelManager.fermenterFuel = new ItemStackMap<>(); + FuelManager.moistenerResource = new ItemStackMap<>(); + FuelManager.rainSubstrate = new ItemStackMap<>(); + FuelManager.bronzeEngineFuel = new FluidMap<>(); + FuelManager.copperEngineFuel = new ItemStackMap<>(); + FuelManager.generatorFuel = new FluidMap<>(); + } + + @Override + protected void registerItemsAndBlocks() { + super.registerItemsAndBlocks(); + + ForestryBlock.factoryTESR.registerBlock(new BlockBase(Material.iron, true), ItemBlockForestry.class, "factory"); + ForestryBlock.factoryPlain.registerBlock(new BlockBase(Material.iron), ItemBlockNBT.class, "factory2"); + } + + @Override + public void registerPacketHandlers() { + PacketIdServer.WORKTABLE_NEI_SELECT.setPacketHandler(new PacketWorktableNEISelect()); + + PacketIdClient.WORKTABLE_MEMORY_UPDATE.setPacketHandler(new PacketWorktableMemoryUpdate()); } @Override public void preInit() { super.preInit(); - ForestryBlock.factoryTESR.registerBlock(new BlockBase(Material.iron, true), ItemBlockForestry.class, "factory"); + // Set fuels and resources for the fermenter + FuelManager.fermenterFuel.put(ForestryItem.fertilizerCompound.getItemStack(), new FermenterFuel(ForestryItem.fertilizerCompound.getItemStack(), + ForestryAPI.activeMode.getIntegerSetting("fermenter.value.fertilizer"), ForestryAPI.activeMode.getIntegerSetting("fermenter.cycles.fertilizer"))); + FuelManager.fermenterFuel.put(ForestryItem.fertilizerBio.getItemStack(), new FermenterFuel(ForestryItem.fertilizerBio.getItemStack(), ForestryAPI.activeMode.getIntegerSetting("fermenter.value.compost"), ForestryAPI.activeMode.getIntegerSetting("fermenter.cycles.compost"))); + FuelManager.fermenterFuel.put(ForestryItem.mulch.getItemStack(), new FermenterFuel(ForestryItem.mulch.getItemStack(), ForestryAPI.activeMode + .getIntegerSetting("fermenter.value.compost"), ForestryAPI.activeMode.getIntegerSetting("fermenter.cycles.compost"))); + + // Add moistener resources + FuelManager.moistenerResource.put(new ItemStack(Items.wheat), new MoistenerFuel(new ItemStack(Items.wheat), ForestryItem.mouldyWheat.getItemStack(), 0, + 300)); + FuelManager.moistenerResource.put(ForestryItem.mouldyWheat.getItemStack(), new MoistenerFuel(ForestryItem.mouldyWheat.getItemStack(), ForestryItem.decayingWheat.getItemStack(), 1, 600)); + FuelManager.moistenerResource.put(ForestryItem.decayingWheat.getItemStack(), new MoistenerFuel(ForestryItem.decayingWheat.getItemStack(), + ForestryItem.mulch.getItemStack(), 2, 900)); + + // Set fuels for our own engines + FuelManager.copperEngineFuel.put(ForestryItem.peat.getItemStack(), new EngineCopperFuel(ForestryItem.peat.getItemStack(), + Constants.ENGINE_COPPER_FUEL_VALUE_PEAT, Constants.ENGINE_COPPER_CYCLE_DURATION_PEAT)); + FuelManager.copperEngineFuel.put(ForestryItem.bituminousPeat.getItemStack(), new EngineCopperFuel(ForestryItem.bituminousPeat.getItemStack(), + Constants.ENGINE_COPPER_FUEL_VALUE_BITUMINOUS_PEAT, Constants.ENGINE_COPPER_CYCLE_DURATION_BITUMINOUS_PEAT)); + + FuelManager.bronzeEngineFuel.put(Fluids.BIOMASS.getFluid(), new EngineBronzeFuel(Fluids.BIOMASS.getFluid(), + Constants.ENGINE_FUEL_VALUE_BIOMASS, (int) (Constants.ENGINE_CYCLE_DURATION_BIOMASS * ForestryAPI.activeMode.getFloatSetting("fuel.biomass.biogas")), 1)); + FuelManager.bronzeEngineFuel.put(Fluids.WATER.getFluid(), new EngineBronzeFuel(Fluids.WATER.getFluid(), + Constants.ENGINE_FUEL_VALUE_WATER, Constants.ENGINE_CYCLE_DURATION_WATER, 3)); + FuelManager.bronzeEngineFuel.put(Fluids.MILK.getFluid(), new EngineBronzeFuel(Fluids.MILK.getFluid(), + Constants.ENGINE_FUEL_VALUE_MILK, Constants.ENGINE_CYCLE_DURATION_MILK, 3)); + FuelManager.bronzeEngineFuel.put(Fluids.SEEDOIL.getFluid(), new EngineBronzeFuel(Fluids.SEEDOIL.getFluid(), + Constants.ENGINE_FUEL_VALUE_SEED_OIL, Constants.ENGINE_CYCLE_DURATION_SEED_OIL, 1)); + FuelManager.bronzeEngineFuel.put(Fluids.HONEY.getFluid(), new EngineBronzeFuel(Fluids.HONEY.getFluid(), + Constants.ENGINE_FUEL_VALUE_HONEY, Constants.ENGINE_CYCLE_DURATION_HONEY, 1)); + FuelManager.bronzeEngineFuel.put(Fluids.JUICE.getFluid(), new EngineBronzeFuel(Fluids.JUICE.getFluid(), + Constants.ENGINE_FUEL_VALUE_JUICE, Constants.ENGINE_CYCLE_DURATION_JUICE, 1)); + + // Set rain substrates + FuelManager.rainSubstrate.put(ForestryItem.iodineCharge.getItemStack(), new RainSubstrate(ForestryItem.iodineCharge.getItemStack(), + Constants.RAINMAKER_RAIN_DURATION_IODINE, 0.01f)); + FuelManager.rainSubstrate.put(ForestryItem.craftingMaterial.getItemStack(1, 4), new RainSubstrate(ForestryItem.craftingMaterial.getItemStack(1, 4), 0.075f)); BlockBase factoryTESR = ((BlockBase) ForestryBlock.factoryTESR.block()); @@ -215,8 +280,6 @@ public class PluginFactory extends ForestryPlugin { 'X', "gearTin", 'Y', ForestryItem.hardenedCasing))); - ForestryBlock.factoryPlain.registerBlock(new BlockBase(Material.iron), ItemBlockNBT.class, "factory2"); - BlockBase factoryPlain = ((BlockBase) ForestryBlock.factoryPlain.block()); definitionFabricator = factoryPlain.addDefinition(new MachineDefinition(Constants.DEFINITION_FABRICATOR_META, "forestry.Fabricator", TileFabricator.class, @@ -335,12 +398,12 @@ public class PluginFactory extends ForestryPlugin { } // / SQUEEZER - int appleMulchAmount = GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple"); - int appleJuiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); + int appleMulchAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple"); + int appleJuiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.apple)}, Fluids.JUICE.getFluid(appleJuiceAmount), ForestryItem.mulch.getItemStack(), appleMulchAmount); - int seedOilAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int seedOilAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); FluidStack seedOil = Fluids.SEEDOIL.getFluid(seedOilAmount); RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.wheat_seeds)}, seedOil); RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.pumpkin_seeds)}, seedOil); @@ -365,14 +428,14 @@ public class PluginFactory extends ForestryPlugin { // FERMENTER for (int i = 0; i < 6; i++) { - RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.sapling, 1, i), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.sapling, 1, i), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); } - RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.cactus), GameMode.getGameMode().getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Items.wheat), GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Items.reeds), GameMode.getGameMode().getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.brown_mushroom), GameMode.getGameMode().getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.red_mushroom), GameMode.getGameMode().getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.cactus), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(new ItemStack(Items.wheat), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(new ItemStack(Items.reeds), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.brown_mushroom), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.red_mushroom), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); // FABRICATOR @@ -440,7 +503,6 @@ public class PluginFactory extends ForestryPlugin { "R#R", "R#R", "R#R", '#', "ingotGold", 'R', "dustRedstone"); RecipeManagers.carpenterManager.addRecipe(40, Fluids.WATER.getFluid(1000), null, ForestryItem.solderingIron.getItemStack(), " # ", "# #", " B", '#', "ingotIron", 'B', "ingotBronze"); - // ForestryCore.oreHandler.registerCarpenterRecipe(solderingIron); // RAIN SUBSTRATES if (PluginManager.Module.APICULTURE.isEnabled()) { @@ -452,7 +514,6 @@ public class PluginFactory extends ForestryPlugin { 'X', Items.gunpowder, 'Y', ForestryItem.canEmpty, 'Z', ForestryItem.honeyDrop); - // ForestryCore.oreHandler.registerCarpenterRecipe(iodineCapsule); RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null, ForestryItem.craftingMaterial.getItemStack(1, 4), "Z#Z", "#Y#", @@ -461,7 +522,6 @@ public class PluginFactory extends ForestryPlugin { 'X', Items.gunpowder, 'Y', ForestryItem.canEmpty, 'Z', ForestryItem.honeydew); - // ForestryCore.oreHandler.registerCarpenterRecipe(dissipationCharge); } // Ender pearl diff --git a/src/main/java/forestry/plugins/PluginFarming.java b/src/main/java/forestry/plugins/PluginFarming.java index 8ff48a9a0..24e397566 100644 --- a/src/main/java/forestry/plugins/PluginFarming.java +++ b/src/main/java/forestry/plugins/PluginFarming.java @@ -87,11 +87,19 @@ public class PluginFarming extends ForestryPlugin { public static ItemStack farmFertilizer; @Override - public void preInit() { - super.preInit(); + protected void registerItemsAndBlocks() { + super.registerItemsAndBlocks(); ForestryBlock.mushroom.registerBlock(new BlockMushroom(), ItemBlockTyped.class, "mushroom"); + ForestryBlock.farm.registerBlock(new BlockFarm(), ItemBlockFarm.class, "ffarm"); + ForestryBlock.farm.block().setHarvestLevel("pickaxe", 0); + } + + @Override + public void preInit() { + super.preInit(); + Farmables.farmables.put("farmArboreal", new ArrayList()); Farmables.farmables.get("farmArboreal").add(new FarmableVanillaSapling()); if (PluginManager.Module.ARBORICULTURE.isEnabled()) { @@ -128,11 +136,6 @@ public class PluginFarming extends ForestryPlugin { Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(Items.potato), Blocks.potatoes, 7)); Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(Items.carrot), Blocks.carrots, 7)); - ForestryBlock.farm.registerBlock(new BlockFarm(), ItemBlockFarm.class, "ffarm"); - /*Item.itemsList[ForestryBlock.farm] = null; - Item.itemsList[ForestryBlock.farm] = (new ItemBlockFarm(ForestryBlock.farm - 256, "ffarm"));*/ - ForestryBlock.farm.block().setHarvestLevel("pickaxe", 0); - proxy.initializeRendering(); // Layouts @@ -151,6 +154,8 @@ public class PluginFarming extends ForestryPlugin { public void doInit() { super.doInit(); + farmFertilizer = ForestryItem.fertilizerCompound.getItemStack(); + GameRegistry.registerTileEntity(TileFarmPlain.class, "forestry.Farm"); GameRegistry.registerTileEntity(TileGearbox.class, "forestry.FarmGearbox"); GameRegistry.registerTileEntity(TileHatch.class, "forestry.FarmHatch"); @@ -178,12 +183,6 @@ public class PluginFarming extends ForestryPlugin { MinecraftForge.EVENT_BUS.register(new EventHandlerFarming()); } - @Override - public void postInit() { - super.postInit(); - farmFertilizer = ForestryItem.fertilizerCompound.getItemStack(); - } - @Override public boolean processIMCMessage(IMCMessage message) { diff --git a/src/main/java/forestry/plugins/PluginFluids.java b/src/main/java/forestry/plugins/PluginFluids.java index 5291734ac..9bd596271 100644 --- a/src/main/java/forestry/plugins/PluginFluids.java +++ b/src/main/java/forestry/plugins/PluginFluids.java @@ -33,13 +33,13 @@ import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.ForestryAPI; import forestry.api.fuels.FuelManager; import forestry.api.fuels.GeneratorFuel; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.BlockForestryFluid; import forestry.core.fluids.Fluids; import forestry.core.fluids.LiquidRegistryHelper; @@ -87,16 +87,11 @@ public class PluginFluids extends ForestryPlugin { } @Override - public void preInit() { + public void registerItemsAndBlocks() { for (Fluids fluidType : Fluids.forestryFluids) { createFluid(fluidType); } - MinecraftForge.EVENT_BUS.register(getTextureHook()); - MinecraftForge.EVENT_BUS.register(getFillBucketHook()); - } - @Override - public void registerItems() { for (EnumContainerType type : EnumContainerType.values()) { Item emptyContainer = new ItemLiquidContainer(type, Blocks.air, null); switch (type) { @@ -124,6 +119,12 @@ public class PluginFluids extends ForestryPlugin { } } + @Override + public void preInit() { + MinecraftForge.EVENT_BUS.register(getTextureHook()); + MinecraftForge.EVENT_BUS.register(getFillBucketHook()); + } + @Override public void doInit() { for (Fluids fluidType : Fluids.values()) { @@ -152,11 +153,11 @@ public class PluginFluids extends ForestryPlugin { } FluidStack ethanol = Fluids.ETHANOL.getFluid(1); - GeneratorFuel ethanolFuel = new GeneratorFuel(ethanol, (int) (32 * GameMode.getGameMode().getFloatSetting("fuel.ethanol.generator")), 4); + GeneratorFuel ethanolFuel = new GeneratorFuel(ethanol, (int) (32 * ForestryAPI.activeMode.getFloatSetting("fuel.ethanol.generator")), 4); FuelManager.generatorFuel.put(ethanol.getFluid(), ethanolFuel); FluidStack biomass = Fluids.BIOMASS.getFluid(1); - GeneratorFuel biomassFuel = new GeneratorFuel(biomass, (int) (8 * GameMode.getGameMode().getFloatSetting("fuel.biomass.generator")), 1); + GeneratorFuel biomassFuel = new GeneratorFuel(biomass, (int) (8 * ForestryAPI.activeMode.getFloatSetting("fuel.biomass.generator")), 1); FuelManager.generatorFuel.put(biomass.getFluid(), biomassFuel); } diff --git a/src/main/java/forestry/plugins/PluginFood.java b/src/main/java/forestry/plugins/PluginFood.java index 50fecf027..1b6c60b6b 100755 --- a/src/main/java/forestry/plugins/PluginFood.java +++ b/src/main/java/forestry/plugins/PluginFood.java @@ -13,6 +13,7 @@ package forestry.plugins; import java.util.Collections; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.network.IGuiHandler; @@ -23,13 +24,16 @@ import forestry.core.config.ForestryItem; import forestry.core.fluids.Fluids; import forestry.core.fluids.LiquidRegistryHelper; import forestry.core.items.ItemForestryFood; +import forestry.core.items.ItemWithGui; +import forestry.core.network.GuiId; import forestry.core.recipes.RecipeUtil; import forestry.food.BeverageEffect; import forestry.food.GuiHandlerFood; +import forestry.food.InfuserIngredientManager; +import forestry.food.InfuserMixtureManager; import forestry.food.items.ItemAmbrosia; import forestry.food.items.ItemBeverage; import forestry.food.items.ItemBeverage.BeverageInfo; -import forestry.food.items.ItemInfuser; @Plugin(pluginID = "Food", name = "Food", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.food.description") public class PluginFood extends ForestryPlugin { @@ -39,19 +43,12 @@ public class PluginFood extends ForestryPlugin { super.setupAPI(); // Init seasoner - BeverageManager.infuserManager = new ItemInfuser.MixtureManager(); - BeverageManager.ingredientManager = new ItemInfuser.IngredientManager(); + BeverageManager.infuserManager = new InfuserMixtureManager(); + BeverageManager.ingredientManager = new InfuserIngredientManager(); } @Override - public void postInit() { - super.postInit(); - - ItemInfuser.initialize(); - } - - @Override - protected void registerItems() { + protected void registerItemsAndBlocks() { // / FOOD ITEMS ForestryItem.honeyedSlice.registerItem(new ItemForestryFood(8, 0.6f), "honeyedSlice"); ForestryItem.beverage.registerItem(new ItemBeverage( @@ -62,13 +59,26 @@ public class PluginFood extends ForestryPlugin { ForestryItem.honeyPot.registerItem(new ItemForestryFood(2, 0.2f).setIsDrink(), "honeyPot"); // / SEASONER - ForestryItem.infuser.registerItem(new ItemInfuser(), "infuser"); + Item infuser = new ItemWithGui(GuiId.InfuserGUI); + ForestryItem.infuser.registerItem(infuser, "infuser"); // Mead ItemStack meadBottle = ForestryItem.beverage.getItemStack(); BeverageInfo.saveEffects(meadBottle, Collections.singletonList(BeverageEffect.weakAlcoholic)); + } - LiquidRegistryHelper.registerLiquidContainer(Fluids.SHORT_MEAD, Constants.BUCKET_VOLUME, meadBottle, new ItemStack(Items.glass_bottle)); + @Override + protected void preInit() { + super.preInit(); + + LiquidRegistryHelper.registerLiquidContainer(Fluids.SHORT_MEAD, Constants.BUCKET_VOLUME, ForestryItem.beverage.getItemStack(), new ItemStack(Items.glass_bottle)); + + if (PluginManager.Module.APICULTURE.isEnabled()) { + BeverageManager.ingredientManager.addIngredient(ForestryItem.pollenCluster.getItemStack(1, 0), "Strong Curative"); + BeverageManager.ingredientManager.addIngredient(ForestryItem.pollenCluster.getItemStack(1, 1), "Weak Curative"); + BeverageManager.infuserManager.addMixture(1, ForestryItem.pollenCluster.getItemStack(1, 0), BeverageEffect.strongAntidote); + BeverageManager.infuserManager.addMixture(1, ForestryItem.pollenCluster.getItemStack(1, 1), BeverageEffect.weakAntidote); + } } @Override diff --git a/src/main/java/forestry/plugins/PluginGrowthCraft.java b/src/main/java/forestry/plugins/PluginGrowthCraft.java index bf39c9c55..e7d587fc1 100644 --- a/src/main/java/forestry/plugins/PluginGrowthCraft.java +++ b/src/main/java/forestry/plugins/PluginGrowthCraft.java @@ -17,12 +17,12 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; @@ -43,11 +43,12 @@ public class PluginGrowthCraft extends ForestryPlugin { return "GrowthCraft not found"; } + @Override protected void registerRecipes() { - int saplingYield = GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"); - int juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); - int seedamount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int saplingYield = ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"); + int juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); + int seedamount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); ItemStack appleSeed = GameRegistry.findItemStack("Growthcraft|Apples", "grc.appleSeeds", 1); ItemStack grapeSeed = GameRegistry.findItemStack("Growthcraft|Grapes", "grc.grapeSeeds", 1); diff --git a/src/main/java/forestry/plugins/PluginHarvestCraft.java b/src/main/java/forestry/plugins/PluginHarvestCraft.java index 1d9df692e..7150a40f6 100644 --- a/src/main/java/forestry/plugins/PluginHarvestCraft.java +++ b/src/main/java/forestry/plugins/PluginHarvestCraft.java @@ -18,13 +18,13 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.fuels.FuelManager; import forestry.api.fuels.MoistenerFuel; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; @@ -184,9 +184,9 @@ public class PluginHarvestCraft extends ForestryPlugin { ImmutableList.Builder plants = ImmutableList.builder(); - int juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") / 25; - int seedamount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); - ItemStack wheatamount = GameMode.getGameMode().getStackSetting("recipe.output.compost.wheat"); + int juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25; + int seedamount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + ItemStack wheatamount = ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat"); juiceAmount = Math.max(juiceAmount, 1); // Produce at least 1 mb of juice. for (String berryName : berries) { @@ -206,7 +206,7 @@ public class PluginHarvestCraft extends ForestryPlugin { plants.add(berryName); } - juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); + juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); for (String fruitName : fruits) { ItemStack fruit = GameRegistry.findItemStack(HC, fruitName + "Item", 1); ItemStack fruitSeed = GameRegistry.findItemStack(HC, fruitName + "seedItem", 1); @@ -224,7 +224,7 @@ public class PluginHarvestCraft extends ForestryPlugin { plants.add(fruitName); } - juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") / 2; // vegetables produce less juice + juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 2; // vegetables produce less juice juiceAmount = Math.max(juiceAmount, 1); // Produce at least 1 mb of juice. for (String vegetableName : vegetables) { ItemStack vegetable = GameRegistry.findItemStack(HC, vegetableName + "Item", 1); @@ -312,13 +312,13 @@ public class PluginHarvestCraft extends ForestryPlugin { Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(mustardCropBlock, 7)); } if (mustardFruit != null) { - RecipeUtil.addFermenterRecipes(mustardFruit, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(mustardFruit, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); } for (String plantName : plants.build()) { ItemStack plant = GameRegistry.findItemStack(HC, plantName + "Item", 1); if (plant != null) { - RecipeUtil.addFermenterRecipes(plant, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(plant, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); } } @@ -356,7 +356,7 @@ public class PluginHarvestCraft extends ForestryPlugin { ItemStack hcBeeswaxItem = GameRegistry.findItemStack(HC, "beeswaxItem", 1); if (hcBeeswaxItem != null) { - RecipeUtil.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.capsule"), "XXX ", 'X', hcBeeswaxItem); + RecipeUtil.addRecipe(ForestryAPI.activeMode.getStackSetting("recipe.output.capsule"), "XXX ", 'X', hcBeeswaxItem); } } diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index 18c1f3d96..2562921ed 100644 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -27,6 +27,7 @@ import cpw.mods.fml.common.registry.GameData; import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitLayout; +import forestry.api.core.ForestryAPI; import forestry.api.fuels.EngineBronzeFuel; import forestry.api.fuels.FuelManager; import forestry.api.recipes.RecipeManagers; @@ -40,7 +41,6 @@ import forestry.core.circuits.CircuitLayout; import forestry.core.config.Constants; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.proxy.Proxies; import forestry.core.recipes.RecipeUtil; @@ -52,7 +52,6 @@ import forestry.core.utils.ModUtil; import forestry.energy.circuits.CircuitElectricBoost; import forestry.energy.circuits.CircuitElectricChoke; import forestry.energy.circuits.CircuitElectricEfficiency; -import forestry.energy.circuits.CircuitFireDampener; import forestry.energy.tiles.EngineDefinition; import forestry.energy.tiles.TileEngineElectric; import forestry.energy.tiles.TileGenerator; @@ -194,7 +193,6 @@ public class PluginIC2 extends ForestryPlugin { definitionGenerator.register(); Circuit.energyElectricChoke1 = new CircuitElectricChoke("electric.choke.1"); - Circuit.energyFireDampener1 = new CircuitFireDampener("dampener.1"); Circuit.energyElectricEfficiency1 = new CircuitElectricEfficiency("electric.efficiency.1"); Circuit.energyElectricBoost1 = new CircuitElectricBoost("electric.boost.1", 2, 7, 20); Circuit.energyElectricBoost2 = new CircuitElectricBoost("electric.boost.2", 2, 15, 40); @@ -263,10 +261,10 @@ public class PluginIC2 extends ForestryPlugin { } if (plantBall != null) { - RecipeUtil.addFermenterRecipes(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(plantBall, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS); } if (compressedPlantBall != null) { - RecipeUtil.addFermenterRecipes(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(compressedPlantBall, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS); } if (resin != null) { @@ -276,7 +274,7 @@ public class PluginIC2 extends ForestryPlugin { } if (rubbersapling != null) { - RecipeUtil.addFermenterRecipes(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(rubbersapling, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); } else { Log.fine("Missing IC2 rubber sapling, skipping fermenter recipe for converting rubber sapling to biomass."); } @@ -294,11 +292,11 @@ public class PluginIC2 extends ForestryPlugin { FluidStack biogas = FluidRegistry.getFluidStack("ic2biogas", 1000); if (biogas != null && PluginManager.Module.ENERGY.isEnabled()) { FuelManager.bronzeEngineFuel.put(biogas.getFluid(), new EngineBronzeFuel(Fluids.BIOMASS.getFluid(), - Constants.ENGINE_FUEL_VALUE_BIOMASS, (int) ((Constants.ENGINE_CYCLE_DURATION_BIOMASS * GameMode.getGameMode().getFloatSetting("fuel.biomass.biogas"))), 1)); + Constants.ENGINE_FUEL_VALUE_BIOMASS, (int) ((Constants.ENGINE_CYCLE_DURATION_BIOMASS * ForestryAPI.activeMode.getFloatSetting("fuel.biomass.biogas"))), 1)); } if (waterCell != null) { - ItemStack bogEarthCan = GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"); + ItemStack bogEarthCan = ForestryAPI.activeMode.getStackSetting("recipe.output.bogearth.can"); if (bogEarthCan.stackSize > 0) { RecipeUtil.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', "sand"); } diff --git a/src/main/java/forestry/plugins/PluginImmersiveEngineering.java b/src/main/java/forestry/plugins/PluginImmersiveEngineering.java index 58d1a1dd1..76c8b8a43 100644 --- a/src/main/java/forestry/plugins/PluginImmersiveEngineering.java +++ b/src/main/java/forestry/plugins/PluginImmersiveEngineering.java @@ -15,10 +15,10 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.utils.ModUtil; import forestry.farming.logic.FarmableGenericCrop; @@ -44,7 +44,7 @@ public class PluginImmersiveEngineering extends ForestryPlugin { ItemStack hempSeed = GameRegistry.findItemStack(ImEng, "seed", 1); Block hempCrop = GameRegistry.findBlock(ImEng, "hemp"); ItemStack hempFiber = new ItemStack(GameRegistry.findItem(ImEng, "material"), 1, 3); - int seedAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); if (hempSeed != null && hempCrop != null) { RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{hempSeed}, Fluids.SEEDOIL.getFluid(seedAmount)); Farmables.farmables.get("farmWheat").add(new FarmableGenericCrop(hempSeed, hempCrop, 4, hempFiber)); diff --git a/src/main/java/forestry/plugins/PluginLepidopterology.java b/src/main/java/forestry/plugins/PluginLepidopterology.java index ccaa11863..395ac11dd 100755 --- a/src/main/java/forestry/plugins/PluginLepidopterology.java +++ b/src/main/java/forestry/plugins/PluginLepidopterology.java @@ -14,6 +14,7 @@ import java.io.File; import java.util.EnumSet; import net.minecraft.block.material.Material; +import net.minecraft.item.Item; import net.minecraft.item.crafting.CraftingManager; import net.minecraftforge.oredict.OreDictionary; @@ -36,11 +37,12 @@ import forestry.core.config.ForestryItem; import forestry.core.config.LocalizedConfiguration; import forestry.core.fluids.Fluids; import forestry.core.items.ItemBlockForestry; +import forestry.core.items.ItemWithGui; +import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.recipes.ShapedRecipeCustom; import forestry.core.tiles.MachineDefinition; import forestry.core.utils.EntityUtil; -import forestry.core.utils.Log; import forestry.lepidopterology.ButterflySpawner; import forestry.lepidopterology.GuiHandlerLepidopterology; import forestry.lepidopterology.commands.CommandButterfly; @@ -52,7 +54,6 @@ import forestry.lepidopterology.genetics.ButterflyFactory; import forestry.lepidopterology.genetics.ButterflyHelper; import forestry.lepidopterology.genetics.MothDefinition; import forestry.lepidopterology.items.ItemButterflyGE; -import forestry.lepidopterology.items.ItemFlutterlyzer; import forestry.lepidopterology.proxy.ProxyLepidopterology; import forestry.lepidopterology.recipes.MatingRecipe; import forestry.lepidopterology.tiles.TileLepidopteristChest; @@ -78,10 +79,19 @@ public class PluginLepidopterology extends ForestryPlugin { } @Override - public void preInit() { + protected void registerItemsAndBlocks() { + Item flutterlyzer = new ItemWithGui(GuiId.FlutterlyzerGUI).setCreativeTab(Tabs.tabLepidopterology); + ForestryItem.flutterlyzer.registerItem(flutterlyzer, "flutterlyzer"); + ForestryItem.butterflyGE.registerItem(new ItemButterflyGE(EnumFlutterType.BUTTERFLY), "butterflyGE"); + ForestryItem.serumGE.registerItem(new ItemButterflyGE(EnumFlutterType.SERUM), "serumGE"); + ForestryItem.caterpillarGE.registerItem(new ItemButterflyGE(EnumFlutterType.CATERPILLAR), "caterpillarGE"); + ForestryBlock.lepidopterology.registerBlock(new BlockBase(Material.iron, true), ItemBlockForestry.class, "lepidopterology"); ForestryBlock.lepidopterology.block().setCreativeTab(Tabs.tabLepidopterology); + } + @Override + public void preInit() { ButterflyBranchDefinition.createAlleles(); AlleleButterflyEffect.createAlleles(); } @@ -95,22 +105,8 @@ public class PluginLepidopterology extends ForestryPlugin { @Override public void doInit() { - final String oldConfig = CONFIG_CATEGORY + ".conf"; - final String newConfig = CONFIG_CATEGORY + ".cfg"; - - File configFile = new File(Forestry.instance.getConfigFolder(), newConfig); - File oldConfigFile = new File(Forestry.instance.getConfigFolder(), oldConfig); - if (oldConfigFile.exists()) { - loadOldConfig(); - - final String oldConfigRenamed = CONFIG_CATEGORY + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigFile.renameTo(oldConfigFileRenamed)) { - Log.info("Migrated " + CONFIG_CATEGORY + " settings to the new file '" + newConfig + "' and renamed '" + oldConfig + "' to '" + oldConfigRenamed + "'."); - } - } - - loadNewConfig(configFile); + File configFile = new File(Forestry.instance.getConfigFolder(), CONFIG_CATEGORY + ".cfg"); + loadConfig(configFile); PluginCore.rootCommand.addChildCommand(new CommandButterfly()); @@ -138,7 +134,7 @@ public class PluginLepidopterology extends ForestryPlugin { RecipeSorter.register("forestry:lepidopterologymating", MatingRecipe.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless"); } - private static void loadNewConfig(File configFile) { + private static void loadConfig(File configFile) { LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0"); spawnConstraint = config.getIntLocalized("butterfly.entities", "spawn.limit", spawnConstraint, 0, 500); @@ -148,30 +144,6 @@ public class PluginLepidopterology extends ForestryPlugin { config.save(); } - private static void loadOldConfig() { - forestry.core.config.deprecated.Configuration config = new forestry.core.config.deprecated.Configuration(); - - forestry.core.config.deprecated.Property property = config.get("entities.spawn.limit", CONFIG_CATEGORY, spawnConstraint); - property.comment = "determines the global butterfly entity count above which natural spawning of butterflies ceases."; - spawnConstraint = Integer.parseInt(property.value); - - property = config.get("entities.maximum.allowed", CONFIG_CATEGORY, entityConstraint); - property.comment = "determines the global butterfly entity count above which butterflies will stay in item form and will not take flight anymore."; - entityConstraint = Integer.parseInt(property.value); - - property = config.get("entities.pollination.allowed", CONFIG_CATEGORY, allowPollination); - property.comment = "determines whether butterflies can pollinate leaves."; - allowPollination = Boolean.parseBoolean(property.value); - } - - @Override - protected void registerItems() { - ForestryItem.flutterlyzer.registerItem(new ItemFlutterlyzer(), "flutterlyzer"); - ForestryItem.butterflyGE.registerItem(new ItemButterflyGE(EnumFlutterType.BUTTERFLY), "butterflyGE"); - ForestryItem.serumGE.registerItem(new ItemButterflyGE(EnumFlutterType.SERUM), "serumGE"); - ForestryItem.caterpillarGE.registerItem(new ItemButterflyGE(EnumFlutterType.CATERPILLAR), "caterpillarGE"); - } - @SuppressWarnings("unchecked") @Override protected void registerRecipes() { diff --git a/src/main/java/forestry/plugins/PluginMagicalCrops.java b/src/main/java/forestry/plugins/PluginMagicalCrops.java index d01546e9c..e9935a47b 100644 --- a/src/main/java/forestry/plugins/PluginMagicalCrops.java +++ b/src/main/java/forestry/plugins/PluginMagicalCrops.java @@ -20,11 +20,11 @@ import net.minecraftforge.oredict.OreDictionary; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Config; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; @@ -220,7 +220,7 @@ public class PluginMagicalCrops extends ForestryPlugin { "Yellorite" ); - int seedAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); for (String magicSeedName : magicSeeds) { addRecipes("_MagicSeeds", "_MagicCrop", magicSeedName, seedAmount); @@ -252,9 +252,9 @@ public class PluginMagicalCrops extends ForestryPlugin { Item cropProduce = GameRegistry.findItem(MagCrop, MagCrop + "_CropProduce"); if (cropProduce != null) { - int juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); + int juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); ItemStack produce = new ItemStack(GameRegistry.findItem(MagCrop, MagCrop + "_CropProduce"), 1, OreDictionary.WILDCARD_VALUE); - RecipeUtil.addFermenterRecipes(produce, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(produce, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{produce}, Fluids.JUICE.getFluid(juiceAmount)); } } diff --git a/src/main/java/forestry/plugins/PluginMail.java b/src/main/java/forestry/plugins/PluginMail.java index a15950a0a..dee87dd6c 100755 --- a/src/main/java/forestry/plugins/PluginMail.java +++ b/src/main/java/forestry/plugins/PluginMail.java @@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.mail.EnumAddressee; @@ -31,6 +32,8 @@ import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.fluids.Fluids; import forestry.core.items.ItemBlockForestry; +import forestry.core.items.ItemWithGui; +import forestry.core.network.GuiId; import forestry.core.network.PacketIdClient; import forestry.core.network.PacketIdServer; import forestry.core.recipes.RecipeUtil; @@ -42,7 +45,6 @@ import forestry.mail.PostalCarrier; import forestry.mail.SaveEventHandlerMail; import forestry.mail.TickHandlerMailClient; import forestry.mail.commands.CommandMail; -import forestry.mail.items.ItemCatalogue; import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemStamps; import forestry.mail.items.ItemStamps.StampInfo; @@ -75,15 +77,41 @@ public class PluginMail extends ForestryPlugin { PostManager.postRegistry.registerCarrier(new PostalCarrier(EnumAddressee.TRADER)); } + @Override + protected void registerItemsAndBlocks() { + + stampDefinitions = new StampInfo[]{ + new StampInfo("1n", EnumPostage.P_1, ForestryItem.apatite, 0x4a8ca7, 0xffffff), + new StampInfo("2n", EnumPostage.P_2, "ingotCopper", 0xe8c814, 0xffffff), + new StampInfo("5n", EnumPostage.P_5, "ingotTin", 0x9c0707, 0xffffff), + new StampInfo("10n", EnumPostage.P_10, Items.gold_ingot, 0x7bd1b8, 0xffffff), + new StampInfo("20n", EnumPostage.P_20, Items.diamond, 0xff9031, 0xfff7dd), + new StampInfo("50n", EnumPostage.P_50, Items.emerald, 0x6431d7, 0xfff7dd), + new StampInfo("100n", EnumPostage.P_100, Items.nether_star, 0xd731ba, 0xfff7dd)}; //new StampInfo("200n", EnumPostage.P_200, Item.netherStar, 0xcd9831, 0xfff7dd)}; + + /* STAMPS */ + ForestryItem.stamps.registerItem(new ItemStamps(stampDefinitions), "stamps"); + + /* LETTER */ + ForestryItem.letters.registerItem(new ItemLetter(), "letters"); + + /* CATALOGUE */ + Item itemCatalogue = new ItemWithGui(GuiId.CatalogueGUI).setMaxStackSize(1); + ForestryItem.catalogue.registerItem(itemCatalogue, "catalogue"); + + ForestryBlock.mail.registerBlock(new BlockBase(Material.iron), ItemBlockForestry.class, "mail"); + + } + @Override public void preInit() { super.preInit(); PluginCore.rootCommand.addChildCommand(new CommandMail()); - new TickHandlerMailClient(); - - ForestryBlock.mail.registerBlock(new BlockBase(Material.iron), ItemBlockForestry.class, "mail"); + if (Config.mailAlertEnabled) { + FMLCommonHandler.instance().bus().register(new TickHandlerMailClient()); + } ShapedRecipeCustom recipe = ShapedRecipeCustom.createShapedRecipe(ForestryBlock.mail.getItemStack(1, Constants.DEFINITION_MAILBOX_META), " # ", "#Y#", "XXX", @@ -142,28 +170,6 @@ public class PluginMail extends ForestryPlugin { PacketIdClient.POBOX_INFO_RESPONSE.setPacketHandler(new PacketPOBoxInfoResponse()); } - @Override - protected void registerItems() { - - stampDefinitions = new StampInfo[]{ - new StampInfo("1n", EnumPostage.P_1, ForestryItem.apatite, 0x4a8ca7, 0xffffff), - new StampInfo("2n", EnumPostage.P_2, "ingotCopper", 0xe8c814, 0xffffff), - new StampInfo("5n", EnumPostage.P_5, "ingotTin", 0x9c0707, 0xffffff), - new StampInfo("10n", EnumPostage.P_10, Items.gold_ingot, 0x7bd1b8, 0xffffff), - new StampInfo("20n", EnumPostage.P_20, Items.diamond, 0xff9031, 0xfff7dd), - new StampInfo("50n", EnumPostage.P_50, Items.emerald, 0x6431d7, 0xfff7dd), - new StampInfo("100n", EnumPostage.P_100, Items.nether_star, 0xd731ba, 0xfff7dd)}; //new StampInfo("200n", EnumPostage.P_200, Item.netherStar, 0xcd9831, 0xfff7dd)}; - - /* STAMPS */ - ForestryItem.stamps.registerItem(new ItemStamps(stampDefinitions), "stamps"); - - /* LETTER */ - ForestryItem.letters.registerItem(new ItemLetter(), "letters"); - - /* CATALOGUE */ - ForestryItem.catalogue.registerItem(new ItemCatalogue(), "catalogue"); - } - @Override protected void registerRecipes() { // Letters diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index c653ccae7..7896aaf8d 100644 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -59,7 +59,12 @@ public class PluginManager { private static Stage stage = Stage.SETUP; public enum Stage { - SETUP, SETUP_DISABLED, PRE_INIT, INIT, POST_INIT, FINISHED + SETUP, // setup API to make it functional, register basic blocks and items. GameMode Configs are not yet accessible + SETUP_DISABLED, // setup fallback API to avoid crashes + PRE_INIT, // register handlers, triggers, definitions, backpacks, crates, and anything that depends on basic items + INIT, // anything that depends on PreInit stages, recipe registration + POST_INIT, // stubborn mod integration, dungeon loot, and finalization of things that take input from mods + FINISHED } public enum Module { @@ -240,6 +245,7 @@ public class PluginManager { ForestryPlugin plugin = m.instance; Log.fine("Setup Start: {0}", plugin); plugin.setupAPI(); + plugin.registerItemsAndBlocks(); Log.fine("Setup Complete: {0}", plugin); } @@ -259,7 +265,6 @@ public class PluginManager { Log.fine("Pre-Init Start: {0}", plugin); registerHandlers(plugin); plugin.preInit(); - plugin.registerItems(); if (Module.BUILDCRAFT_STATEMENTS.isEnabled()) { plugin.registerTriggers(); } diff --git a/src/main/java/forestry/plugins/PluginNatura.java b/src/main/java/forestry/plugins/PluginNatura.java index 262ba99d2..ff232a8c5 100755 --- a/src/main/java/forestry/plugins/PluginNatura.java +++ b/src/main/java/forestry/plugins/PluginNatura.java @@ -24,6 +24,7 @@ import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.fuels.FuelManager; import forestry.api.fuels.MoistenerFuel; @@ -32,7 +33,6 @@ import forestry.api.storage.ICrateRegistry; import forestry.api.storage.StorageManager; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; @@ -92,7 +92,7 @@ public class PluginNatura extends ForestryPlugin { Item saplingItem = GameRegistry.findItem(NATURA, key); ItemStack saplingWild = new ItemStack(saplingItem, 1, OreDictionary.WILDCARD_VALUE); - RecipeUtil.addFermenterRecipes(saplingWild, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(saplingWild, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); String saplingName = GameData.getItemRegistry().getNameForObject(saplingItem); FMLInterModComms.sendMessage(Constants.MOD, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName)); @@ -210,7 +210,7 @@ public class PluginNatura extends ForestryPlugin { seedList.add(seedCotton); } - int amount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); for (ItemStack aSeedList : seedList) { RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{aSeedList}, Fluids.SEEDOIL.getFluid(amount)); } @@ -245,11 +245,11 @@ public class PluginNatura extends ForestryPlugin { berries.add(berryMalo); } - amount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") / 2; + amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 2; amount = Math.max(amount, 1); // Produce at least 1 mb of juice. - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(GameRegistry.findItem(NATURA, "Natura.netherfood"), 1, 0)}, Fluids.JUICE.getFluid(amount), ForestryItem.mulch.getItemStack(), GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple")); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(GameRegistry.findItem(NATURA, "Natura.netherfood"), 1, 0)}, Fluids.JUICE.getFluid(amount), ForestryItem.mulch.getItemStack(), ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple")); - amount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") / 25; + amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25; amount = Math.max(amount, 1); // Produce at least 1 mb of juice. for (ItemStack berry : berries) { @@ -257,9 +257,9 @@ public class PluginNatura extends ForestryPlugin { } if (itemBarley != null) { - RecipeUtil.addFermenterRecipes(itemBarley, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); - if (GameMode.getGameMode().getStackSetting("recipe.output.compost.wheat").stackSize > 0) { - ItemStack compostWheat = GameMode.getGameMode().getStackSetting("recipe.output.compost.wheat"); + RecipeUtil.addFermenterRecipes(itemBarley, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + if (ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat").stackSize > 0) { + ItemStack compostWheat = ForestryAPI.activeMode.getStackSetting("recipe.output.compost.wheat"); RecipeUtil.addRecipe(compostWheat, " X ", "X#X", " X ", '#', Blocks.dirt, 'X', itemBarley); } FuelManager.moistenerResource.put(itemBarley, new MoistenerFuel(itemBarley, ForestryItem.mouldyWheat.getItemStack(), 0, 300)); diff --git a/src/main/java/forestry/plugins/PluginPlantMegaPack.java b/src/main/java/forestry/plugins/PluginPlantMegaPack.java index 7d1998f7e..58ddcfb68 100644 --- a/src/main/java/forestry/plugins/PluginPlantMegaPack.java +++ b/src/main/java/forestry/plugins/PluginPlantMegaPack.java @@ -21,10 +21,10 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.common.registry.GameRegistry; import forestry.api.apiculture.FlowerManager; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; @@ -355,14 +355,14 @@ public class PluginPlantMegaPack extends ForestryPlugin { .put("jungleShellflower", FlowerManager.FlowerTypeJungle) .build(); - int seedamount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); - int juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); + int seedamount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + int juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); for (String reedLike : reedLikePlant) { Block reedBlock = GameRegistry.findBlock(PlantMP, reedLike); ItemStack reedStack = GameRegistry.findItemStack(PlantMP, reedLike, 1); if (reedBlock != null && reedStack != null) { - RecipeUtil.addFermenterRecipes(reedStack, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(reedStack, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); Farmables.farmables.get("farmPoales").add(new FarmableStacked(reedBlock, 14, 4)); } } @@ -399,7 +399,7 @@ public class PluginPlantMegaPack extends ForestryPlugin { } } - juiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") / 25; + juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25; juiceAmount = Math.max(juiceAmount, 1); // Produce at least 1 mb of juice. for (Map.Entry berryBushCrop : berryBushPlant.entrySet()) { @@ -433,7 +433,7 @@ public class PluginPlantMegaPack extends ForestryPlugin { for (String wPlant : waterPlant) { ItemStack waterPlantStack = GameRegistry.findItemStack(PlantMP, wPlant, 1); if (waterPlantStack != null) { - RecipeUtil.addFermenterRecipes(waterPlantStack, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(waterPlantStack, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); } } } diff --git a/src/main/java/forestry/plugins/PluginStorage.java b/src/main/java/forestry/plugins/PluginStorage.java index 9a9b5fb51..049ac2bd3 100755 --- a/src/main/java/forestry/plugins/PluginStorage.java +++ b/src/main/java/forestry/plugins/PluginStorage.java @@ -72,14 +72,14 @@ import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Log; import forestry.core.utils.StringUtil; import forestry.storage.BackpackDefinition; +import forestry.storage.BackpackDefinition.BackpackDefinitionApiarist; +import forestry.storage.BackpackDefinition.BackpackDefinitionLepidopterist; import forestry.storage.BackpackInterface; import forestry.storage.CrateRegistry; import forestry.storage.GuiHandlerStorage; import forestry.storage.PickupHandlerStorage; import forestry.storage.ResupplyHandler; -import forestry.storage.items.ItemNaturalistBackpack; -import forestry.storage.items.ItemNaturalistBackpack.BackpackDefinitionApiarist; -import forestry.storage.items.ItemNaturalistBackpack.BackpackDefinitionLepidopterist; +import forestry.storage.items.ItemBackpack; import forestry.storage.proxy.ProxyStorage; @Plugin(pluginID = "Storage", name = "Storage", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.storage.description") @@ -146,9 +146,53 @@ public class PluginStorage extends ForestryPlugin { BackpackManager.definitions.put(definition.getKey(), definition); } + @Override + protected void registerItemsAndBlocks() { + // CRATE + ForestryItem.crate.registerItem((new ItemCrated(null, false)), "crate"); + + // BACKPACKS + IBackpackDefinition definition; + + if (PluginManager.Module.APICULTURE.isEnabled()) { + definition = BackpackManager.definitions.get("apiarist"); + Item backpack = new ItemBackpack(GuiId.ApiaristBackpackGUI, definition, EnumBackpackType.APIARIST).setCreativeTab(Tabs.tabApiculture); + ForestryItem.apiaristBackpack.registerItem(backpack, "apiaristBag"); + } + + if (PluginManager.Module.LEPIDOPTEROLOGY.isEnabled()) { + definition = BackpackManager.definitions.get("lepidopterist"); + Item backpack = new ItemBackpack(GuiId.LepidopteristBackpackGUI, definition, EnumBackpackType.APIARIST).setCreativeTab(Tabs.tabLepidopterology); + ForestryItem.lepidopteristBackpack.registerItem(backpack, "lepidopteristBag"); + } + + definition = BackpackManager.definitions.get("miner"); + ForestryItem.minerBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "minerBag"); + ForestryItem.minerBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "minerBagT2"); + + definition = BackpackManager.definitions.get("digger"); + ForestryItem.diggerBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "diggerBag"); + ForestryItem.diggerBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "diggerBagT2"); + + definition = BackpackManager.definitions.get("forester"); + ForestryItem.foresterBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "foresterBag"); + ForestryItem.foresterBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "foresterBagT2"); + + definition = BackpackManager.definitions.get("hunter"); + ForestryItem.hunterBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "hunterBag"); + ForestryItem.hunterBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "hunterBagT2"); + + definition = BackpackManager.definitions.get("adventurer"); + ForestryItem.adventurerBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "adventurerBag"); + ForestryItem.adventurerBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "adventurerBagT2"); + + definition = BackpackManager.definitions.get("builder"); + ForestryItem.builderBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "builderBag"); + ForestryItem.builderBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "builderBagT2"); + } + @Override public void postInit() { - final String oldConfig = CONFIG_CATEGORY + ".conf"; final String newConfig = CONFIG_CATEGORY + ".cfg"; File configFile = new File(Forestry.instance.getConfigFolder(), newConfig); @@ -156,17 +200,6 @@ public class PluginStorage extends ForestryPlugin { setDefaultsForConfig(); } - File oldConfigFile = new File(Forestry.instance.getConfigFolder(), oldConfig); - if (oldConfigFile.exists()) { - loadOldConfig(); - - final String oldConfigRenamed = CONFIG_CATEGORY + ".conf.old"; - File oldConfigFileRenamed = new File(Forestry.instance.getConfigFolder(), oldConfigRenamed); - if (oldConfigFile.renameTo(oldConfigFileRenamed)) { - Log.info("Migrated " + CONFIG_CATEGORY + " settings to the new file '" + newConfig + "' and renamed '" + oldConfig + "' to '" + oldConfigRenamed + "'."); - } - } - LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0"); handleBackpackConfig(config, "miner"); @@ -211,35 +244,6 @@ public class PluginStorage extends ForestryPlugin { builder.addValidItemClass(ItemDoor.class); } - private static void loadOldConfig() { - - final forestry.core.config.deprecated.Configuration config = new forestry.core.config.deprecated.Configuration(); - - forestry.core.config.deprecated.Property backpackConf = config.get("backpacks.miner.items", CONFIG_CATEGORY, ""); - backpackConf.comment = "add additional blocks and items for the miner's backpack here in the format modid:name:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - old_parseBackpackItems(backpackConf.value, BackpackManager.definitions.get("miner")); - backpackConf = config.get("backpacks.digger.items", CONFIG_CATEGORY, ""); - backpackConf.comment = "add additional blocks and items for the digger's backpack here in the format modid:name:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - old_parseBackpackItems(backpackConf.value, BackpackManager.definitions.get("digger")); - backpackConf = config.get("backpacks.forester.items", CONFIG_CATEGORY, ""); - backpackConf.comment = "add additional blocks and items for the forester's backpack here in the format modid:name:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - old_parseBackpackItems(backpackConf.value, BackpackManager.definitions.get("forester")); - backpackConf = config.get("backpacks.hunter.items", CONFIG_CATEGORY, ""); - backpackConf.comment = "add additional blocks and items for the hunter's backpack here in the format modid:name:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - old_parseBackpackItems(backpackConf.value, BackpackManager.definitions.get("hunter")); - backpackConf = config.get("backpacks.adventurer.items", CONFIG_CATEGORY, ""); - backpackConf.comment = "add blocks and items for the adventurer's backpack here in the format modid:name:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - old_parseBackpackItems(backpackConf.value, BackpackManager.definitions.get("adventurer")); - backpackConf = config.get("backpacks.builder.items", CONFIG_CATEGORY, ""); - backpackConf.comment = "add blocks and items for the builder's backpack here in the format modid:name:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - old_parseBackpackItems(backpackConf.value, BackpackManager.definitions.get("builder")); - } - - private static void old_parseBackpackItems(String list, IBackpackDefinition backpackDefinition) { - List backpackItems = ItemStackUtil.parseItemStackStrings(list, 0); - backpackDefinition.addValidItems(backpackItems); - } - private void setDefaultsForConfig() { final BackpackDefinition miner = (BackpackDefinition) BackpackManager.definitions.get("miner"); @@ -531,51 +535,6 @@ public class PluginStorage extends ForestryPlugin { return new ResupplyHandler(); } - @Override - protected void registerItems() { - // CRATE - ForestryItem.crate.registerItem((new ItemCrated(null, false)), "crate"); - - // BACKPACKS - IBackpackDefinition definition; - - if (PluginManager.Module.APICULTURE.isEnabled()) { - definition = BackpackManager.definitions.get("apiarist"); - Item backpack = new ItemNaturalistBackpack(GuiId.ApiaristBackpackGUI.ordinal(), definition).setCreativeTab(Tabs.tabApiculture); - ForestryItem.apiaristBackpack.registerItem(backpack, "apiaristBag"); - } - - if (PluginManager.Module.LEPIDOPTEROLOGY.isEnabled()) { - definition = BackpackManager.definitions.get("lepidopterist"); - Item backpack = new ItemNaturalistBackpack(GuiId.LepidopteristBackpackGUI.ordinal(), definition).setCreativeTab(Tabs.tabLepidopterology); - ForestryItem.lepidopteristBackpack.registerItem(backpack, "lepidopteristBag"); - } - - definition = BackpackManager.definitions.get("miner"); - ForestryItem.minerBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "minerBag"); - ForestryItem.minerBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "minerBagT2"); - - definition = BackpackManager.definitions.get("digger"); - ForestryItem.diggerBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "diggerBag"); - ForestryItem.diggerBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "diggerBagT2"); - - definition = BackpackManager.definitions.get("forester"); - ForestryItem.foresterBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "foresterBag"); - ForestryItem.foresterBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "foresterBagT2"); - - definition = BackpackManager.definitions.get("hunter"); - ForestryItem.hunterBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "hunterBag"); - ForestryItem.hunterBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "hunterBagT2"); - - definition = BackpackManager.definitions.get("adventurer"); - ForestryItem.adventurerBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "adventurerBag"); - ForestryItem.adventurerBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "adventurerBagT2"); - - definition = BackpackManager.definitions.get("builder"); - ForestryItem.builderBackpack.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T1), "builderBag"); - ForestryItem.builderBackpackT2.registerItem(BackpackManager.backpackInterface.addBackpack(definition, EnumBackpackType.T2), "builderBagT2"); - } - @Override protected void registerRecipes() { diff --git a/src/main/java/forestry/plugins/PluginWitchery.java b/src/main/java/forestry/plugins/PluginWitchery.java index 1b33adb53..b0f0ea11e 100644 --- a/src/main/java/forestry/plugins/PluginWitchery.java +++ b/src/main/java/forestry/plugins/PluginWitchery.java @@ -26,10 +26,10 @@ import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; import forestry.api.apiculture.FlowerManager; +import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; -import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; @@ -71,11 +71,11 @@ public class PluginWitchery extends ForestryPlugin { ImmutableList cropDirect = ImmutableList.of( "garlic" //meta 5 ); - int seedamount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int seedamount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); Item saplingItem = GameRegistry.findItem(Witch, "witchsapling"); ItemStack saplingStack = new ItemStack(saplingItem, 1, OreDictionary.WILDCARD_VALUE); - RecipeUtil.addFermenterRecipes(saplingStack, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(saplingStack, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); String saplingName = GameData.getItemRegistry().getNameForObject(saplingItem); FMLInterModComms.sendMessage(Constants.MOD, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName)); diff --git a/src/main/java/forestry/storage/BackpackDefinition.java b/src/main/java/forestry/storage/BackpackDefinition.java index 54d13b350..e5a7fe6b8 100755 --- a/src/main/java/forestry/storage/BackpackDefinition.java +++ b/src/main/java/forestry/storage/BackpackDefinition.java @@ -24,6 +24,8 @@ import net.minecraftforge.oredict.OreDictionary; import cpw.mods.fml.common.registry.GameData; +import forestry.api.apiculture.BeeManager; +import forestry.api.lepidopterology.ButterflyManager; import forestry.api.storage.IBackpackDefinition; public class BackpackDefinition implements IBackpackDefinition { @@ -217,4 +219,27 @@ public class BackpackDefinition implements IBackpackDefinition { return false; } + public static class BackpackDefinitionApiarist extends BackpackDefinition { + + public BackpackDefinitionApiarist(int primaryColor) { + super("apiarist", primaryColor); + } + + @Override + public boolean isValidItem(ItemStack itemStack) { + return BeeManager.beeRoot.isMember(itemStack); + } + } + + public static class BackpackDefinitionLepidopterist extends BackpackDefinition { + + public BackpackDefinitionLepidopterist(int primaryColor) { + super("lepidopterist", primaryColor); + } + + @Override + public boolean isValidItem(ItemStack itemStack) { + return ButterflyManager.butterflyRoot.isMember(itemStack); + } + } } diff --git a/src/main/java/forestry/storage/BackpackInterface.java b/src/main/java/forestry/storage/BackpackInterface.java index 4d9aea410..4b46e9008 100644 --- a/src/main/java/forestry/storage/BackpackInterface.java +++ b/src/main/java/forestry/storage/BackpackInterface.java @@ -10,20 +10,30 @@ ******************************************************************************/ package forestry.storage; +import java.util.EnumMap; + import net.minecraft.item.Item; import forestry.api.storage.BackpackManager; import forestry.api.storage.EnumBackpackType; import forestry.api.storage.IBackpackDefinition; import forestry.api.storage.IBackpackInterface; +import forestry.core.network.GuiId; import forestry.storage.items.ItemBackpack; public class BackpackInterface implements IBackpackInterface { + private static final EnumMap guiIds = new EnumMap<>(EnumBackpackType.class); + + static { + guiIds.put(EnumBackpackType.T1, GuiId.BackpackGUI); + guiIds.put(EnumBackpackType.T2, GuiId.BackpackT2GUI); + guiIds.put(EnumBackpackType.APIARIST, GuiId.ApiaristBackpackGUI); + } + @Override public Item addBackpack(IBackpackDefinition definition, EnumBackpackType type) { BackpackManager.definitions.put(definition.getKey(), definition); - return new ItemBackpack(definition, type); + return new ItemBackpack(guiIds.get(type), definition, type); } - } diff --git a/src/main/java/forestry/storage/GuiHandlerStorage.java b/src/main/java/forestry/storage/GuiHandlerStorage.java index 4b3e90c5a..77be9e801 100755 --- a/src/main/java/forestry/storage/GuiHandlerStorage.java +++ b/src/main/java/forestry/storage/GuiHandlerStorage.java @@ -10,44 +10,30 @@ ******************************************************************************/ package forestry.storage; +import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.api.core.ForestryAPI; -import forestry.api.genetics.AlleleManager; +import forestry.api.apiculture.BeeManager; import forestry.api.genetics.ISpeciesRoot; +import forestry.api.lepidopterology.ButterflyManager; import forestry.core.GuiHandlerBase; import forestry.core.config.Constants; import forestry.core.gui.GuiNaturalistInventory; -import forestry.core.gui.IPagedInventory; -import forestry.core.inventory.ItemInventoryBackpack; import forestry.core.network.GuiId; import forestry.storage.gui.ContainerBackpack; import forestry.storage.gui.ContainerNaturalistBackpack; import forestry.storage.gui.GuiBackpack; import forestry.storage.gui.GuiBackpackT2; +import forestry.storage.inventory.ItemInventoryBackpackPaged; import forestry.storage.items.ItemBackpack; public class GuiHandlerStorage extends GuiHandlerBase { - public static class PagedBackpackInventory extends ItemInventoryBackpack implements IPagedInventory { - - private final int guiId; - - public PagedBackpackInventory(EntityPlayer player, int size, ItemStack itemstack, int guiId) { - super(player, size, itemstack); - this.guiId = guiId; - } - - @Override - public void flipPage(EntityPlayer player, int page) { - player.openGui(ForestryAPI.instance, encodeGuiData(guiId, page), player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); - } - } - @Override - public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { + public Gui getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { int cleanId = decodeGuiID(id); int guiData = decodeGuiData(id); @@ -55,17 +41,15 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } - ItemStack equipped; - switch (GuiId.values()[cleanId]) { + GuiId guiId = GuiId.values()[cleanId]; + ItemStack equipped; + switch (guiId) { case ApiaristBackpackGUI: - equipped = getBackpackItem(player); - if (equipped == null) { - return null; - } - ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); - PagedBackpackInventory inventory = new PagedBackpackInventory(player, Constants.SLOTS_BACKPACK_APIARIST, equipped, cleanId); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player, inventory, guiData), inventory, guiData, 5); + return getNaturalistGui(BeeManager.beeRoot, player, guiId, guiData); + + case LepidopteristBackpackGUI: + return getNaturalistGui(ButterflyManager.butterflyRoot, player, guiId, guiData); case BackpackGUI: equipped = getBackpackItem(player); @@ -81,21 +65,22 @@ public class GuiHandlerStorage extends GuiHandlerBase { } return new GuiBackpackT2(new ContainerBackpack(player, ContainerBackpack.Size.T2, equipped)); - case LepidopteristBackpackGUI: - equipped = getBackpackItem(player); - if (equipped == null) { - return null; - } - speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"); - inventory = new PagedBackpackInventory(player, Constants.SLOTS_BACKPACK_APIARIST, equipped, id); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player, inventory, guiData), inventory, guiData, 5); - default: return null; } } + private static Gui getNaturalistGui(ISpeciesRoot root, EntityPlayer player, GuiId guiId, int guiData) { + ItemStack equipped = getBackpackItem(player); + if (equipped == null) { + return null; + } + ItemInventoryBackpackPaged inventory = new ItemInventoryBackpackPaged(player, Constants.SLOTS_BACKPACK_APIARIST, equipped, guiId); + ContainerNaturalistBackpack container = new ContainerNaturalistBackpack(player, inventory, guiData); + return new GuiNaturalistInventory(root, player, container, inventory, guiData, 5); + } + private static ItemStack getBackpackItem(EntityPlayer player) { ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) { @@ -108,24 +93,26 @@ public class GuiHandlerStorage extends GuiHandlerBase { } @Override - public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { + public Container getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { int cleanId = decodeGuiID(id); int guiData = decodeGuiData(id); + GuiId guiId = GuiId.values()[cleanId]; if (cleanId >= GuiId.values().length) { return null; } ItemStack equipped; - switch (GuiId.values()[cleanId]) { - + switch (guiId) { case ApiaristBackpackGUI: + case LepidopteristBackpackGUI: equipped = getBackpackItem(player); if (equipped == null) { return null; } - return new ContainerNaturalistBackpack(player, new PagedBackpackInventory(player, Constants.SLOTS_BACKPACK_APIARIST, equipped, cleanId), guiData); + ItemInventoryBackpackPaged inventory = new ItemInventoryBackpackPaged(player, Constants.SLOTS_BACKPACK_APIARIST, equipped, guiId); + return new ContainerNaturalistBackpack(player, inventory, guiData); case BackpackGUI: equipped = getBackpackItem(player); @@ -143,17 +130,8 @@ public class GuiHandlerStorage extends GuiHandlerBase { return new ContainerBackpack(player, ContainerBackpack.Size.T2, equipped); - case LepidopteristBackpackGUI: - equipped = getBackpackItem(player); - if (equipped == null) { - return null; - } - - return new ContainerNaturalistBackpack(player, new PagedBackpackInventory(player, Constants.SLOTS_BACKPACK_APIARIST, equipped, cleanId), guiData); - default: return null; - } } } diff --git a/src/main/java/forestry/storage/ResupplyHandler.java b/src/main/java/forestry/storage/ResupplyHandler.java index 90890f847..70988e6b4 100755 --- a/src/main/java/forestry/storage/ResupplyHandler.java +++ b/src/main/java/forestry/storage/ResupplyHandler.java @@ -25,7 +25,7 @@ import cpw.mods.fml.common.eventhandler.Event; import forestry.api.storage.BackpackResupplyEvent; import forestry.core.IResupplyHandler; import forestry.core.inventory.ItemInventory; -import forestry.core.inventory.ItemInventoryBackpack; +import forestry.storage.inventory.ItemInventoryBackpack; import forestry.storage.items.ItemBackpack; public class ResupplyHandler implements IResupplyHandler { diff --git a/src/main/java/forestry/storage/gui/ContainerBackpack.java b/src/main/java/forestry/storage/gui/ContainerBackpack.java index 0f7bc93d6..7c12b4f40 100755 --- a/src/main/java/forestry/storage/gui/ContainerBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerBackpack.java @@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotFiltered; -import forestry.core.inventory.ItemInventoryBackpack; +import forestry.storage.inventory.ItemInventoryBackpack; public class ContainerBackpack extends ContainerItemInventory { diff --git a/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java b/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java index 44c5358e7..6496c276e 100755 --- a/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java @@ -17,11 +17,11 @@ import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.IGuiSelectable; import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketGuiSelectRequest; -import forestry.storage.GuiHandlerStorage.PagedBackpackInventory; +import forestry.storage.inventory.ItemInventoryBackpackPaged; -public class ContainerNaturalistBackpack extends ContainerItemInventory implements IGuiSelectable { +public class ContainerNaturalistBackpack extends ContainerItemInventory implements IGuiSelectable { - public ContainerNaturalistBackpack(EntityPlayer player, PagedBackpackInventory inventory, int page) { + public ContainerNaturalistBackpack(EntityPlayer player, ItemInventoryBackpackPaged inventory, int page) { super(inventory, player.inventory, 18, 120); // Inventory diff --git a/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java b/src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java similarity index 89% rename from src/main/java/forestry/core/inventory/ItemInventoryBackpack.java rename to src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java index 7b5d65001..b90fa600b 100644 --- a/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java +++ b/src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java @@ -1,10 +1,11 @@ -package forestry.core.inventory; +package forestry.storage.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import forestry.api.storage.IBackpackDefinition; +import forestry.core.inventory.ItemInventory; import forestry.storage.items.ItemBackpack; public class ItemInventoryBackpack extends ItemInventory { diff --git a/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java b/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java new file mode 100644 index 000000000..6e3a1ae34 --- /dev/null +++ b/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.storage.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import forestry.api.core.ForestryAPI; +import forestry.core.GuiHandlerBase; +import forestry.core.gui.IPagedInventory; +import forestry.core.network.GuiId; + +public class ItemInventoryBackpackPaged extends ItemInventoryBackpack implements IPagedInventory { + private final GuiId guiId; + + public ItemInventoryBackpackPaged(EntityPlayer player, int size, ItemStack itemstack, GuiId guiId) { + super(player, size, itemstack); + this.guiId = guiId; + } + + @Override + public void flipPage(EntityPlayer player, int page) { + player.openGui(ForestryAPI.instance, GuiHandlerBase.encodeGuiData(guiId, page), player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); + } +} diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index 2becc750e..9c32d14f6 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -28,34 +28,31 @@ import cpw.mods.fml.common.eventhandler.Event; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.core.ForestryAPI; import forestry.api.storage.BackpackStowEvent; import forestry.api.storage.EnumBackpackType; import forestry.api.storage.IBackpackDefinition; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.inventory.ItemInventory; -import forestry.core.inventory.ItemInventoryBackpack; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; -import forestry.core.items.ItemInventoried; +import forestry.core.items.ItemWithGui; import forestry.core.network.GuiId; import forestry.core.render.TextureManager; import forestry.core.tiles.TileUtil; import forestry.core.utils.InventoryUtil; import forestry.core.utils.StringUtil; import forestry.storage.BackpackMode; +import forestry.storage.inventory.ItemInventoryBackpack; -public class ItemBackpack extends ItemInventoried { - +public class ItemBackpack extends ItemWithGui { private final IBackpackDefinition definition; private final EnumBackpackType type; - public ItemBackpack(IBackpackDefinition definition, EnumBackpackType type) { - super(); + public ItemBackpack(GuiId guiId, IBackpackDefinition definition, EnumBackpackType type) { + super(guiId); this.definition = definition; this.type = type; - setMaxStackSize(1); } public IBackpackDefinition getDefinition() { @@ -73,18 +70,15 @@ public class ItemBackpack extends ItemInventoried { @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) { - - if (world.isRemote) { - return itemstack; + if (!world.isRemote) { + if (!player.isSneaking()) { + openGui(world, player); + } else { + switchMode(itemstack); + } } - if (!player.isSneaking()) { - openGui(player); - } else { - switchMode(itemstack); - } return itemstack; - } @Override @@ -202,17 +196,6 @@ public class ItemBackpack extends ItemInventoried { ItemStack remaining = InventoryUtil.moveItemStack(targetStack, backpackInventory); slot.setStackInSlot(remaining); } - - } - - protected void openGui(EntityPlayer entityplayer) { - if (getBackpackSize() == Constants.SLOTS_BACKPACK_DEFAULT) { - entityplayer.openGui(ForestryAPI.instance, GuiId.BackpackGUI.ordinal(), entityplayer.worldObj, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } else if (getBackpackSize() == Constants.SLOTS_BACKPACK_T2) { - entityplayer.openGui(ForestryAPI.instance, GuiId.BackpackT2GUI.ordinal(), entityplayer.worldObj, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - } } public int getBackpackSize() { diff --git a/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java b/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java deleted file mode 100755 index 39a76013b..000000000 --- a/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * 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.storage.items; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - -import forestry.api.apiculture.BeeManager; -import forestry.api.core.ForestryAPI; -import forestry.api.lepidopterology.ButterflyManager; -import forestry.api.storage.EnumBackpackType; -import forestry.api.storage.IBackpackDefinition; -import forestry.storage.BackpackDefinition; - -public class ItemNaturalistBackpack extends ItemBackpack { - - public static class BackpackDefinitionApiarist extends BackpackDefinition { - - public BackpackDefinitionApiarist(int primaryColor) { - super("apiarist", primaryColor); - } - - @Override - public boolean isValidItem(ItemStack itemStack) { - return BeeManager.beeRoot.isMember(itemStack); - } - } - - public static class BackpackDefinitionLepidopterist extends BackpackDefinition { - - public BackpackDefinitionLepidopterist(int primaryColor) { - super("lepidopterist", primaryColor); - } - - @Override - public boolean isValidItem(ItemStack itemStack) { - return ButterflyManager.butterflyRoot.isMember(itemStack); - } - } - - private final int guiId; - - public ItemNaturalistBackpack(int guiId, IBackpackDefinition definition) { - super(definition, EnumBackpackType.APIARIST); - this.guiId = guiId; - } - - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, guiId, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); - } -} diff --git a/src/main/resources/config/forestry/hints.properties b/src/main/resources/config/forestry/hints.properties index d8820a379..f6e25fc2a 100755 --- a/src/main/resources/config/forestry/hints.properties +++ b/src/main/resources/config/forestry/hints.properties @@ -1,20 +1,34 @@ -analyzer=nopowerrequired;accesscontrol;accessrules;accesspipe;pipette;flowerjungle;flowernether;apiaristsuit;honeyfood -apiarist.chest= -apiary=accesscontrol;accessrules;accesspipe;beebiomes;beebreeding;beejubilance;beeflowers;nopowerrequired;flowerjungle;flowernether;apiaristsuit;honeyfood -beealyzer= -bottler=powerrequired;accesscontrol;accessrules;accesspipe;pipette -carpenter=powerrequired;accesscontrol;accessrules;accesspipe;pipette;crating -centrifuge=powerrequired;accesscontrol;accessrules;accesspipe -engine.bronze=accesscontrol;accessrules;accesspipe;energyunit;energybuffer;pipette;enginebronzefuels;enginebronzeheatloss;enginebronzeoutput;enginebronzewaste -engine.copper=accesscontrol;accessrules;accesspipe;energyunit;energybuffer;forcedcooldown;cooldownloss;enginecopperfuels;usesofash;enginecopperwaste;manualpeat;peatharvest -engine.tin=accesscontrol;accessrules;accesspipe;energyunit;energybuffer;forcedcooldown;cooldownloss;enginetinbatteries;enginetinchoke -farm=accesscontrol;accessrules;accesspipe;farmland;gearbox;valve;fertilizer;hatch;circuitboard;manualfarms;farmgui -fermenter=powerrequired;accesscontrol;accessrules;accesspipe;pipette;shortmead -generator=accesscontrol;accessrules;accesspipe;energyunit;pipette;generatorfuels -habitatlocator= -letter=postage -mailbox=nopowerrequired;accesscontrol;accessrules;accesspipe;postage -moistener=nopowerrequired;accesscontrol;accessrules;accesspipe;pipette;moistenerproducts -raintank=powerraintank;accesscontrol;accessrules;accesspipe -squeezer=powerrequired;accesscontrol;accessrules;accesspipe;pipette -still=powerrequired;accesscontrol;accessrules;accesspipe;pipette \ No newline at end of file +apiary=accesspipe;nopowerrequired;beebiomes;beebreeding;beejubilance;beeflowers;flowerjungle;flowernether;apiaristsuit;honeyfood; +bee.house=nopowerrequired;beebiomes;beebreeding;beejubilance;beeflowers;flowerjungle;flowernether;apiaristsuit;honeyfood; +beealyzer=beebiomes;beebreeding;beejubilance;beeflowers;flowerjungle;flowernether; +escritoire=beebiomes;beebreeding;beejubilance;beeflowers; +farm=farmland;gearbox;valve;fertilizer;hatch;circuitboard;manualfarms;farmgui; +flutterlyzer= +generator=accesscontrol;accessrules;accesspipe;energyunit;pipette;generatorfuels; +habitat.locator=beebiomes; +moistener=nopowerrequired;accesscontrol;accessrules;accesspipe;pipette;moistenerproducts; +naturalist.chest=accesscontrol;accessrules;accesspipe; +raintank=powerraintank; +soldering.iron=circuitboard; +treealyzer= +worktable= + +letter=postage; +mailbox=postage; +philatelist=postage; +trade.station=postage; + +powered.machine=powerrequired;accesscontrol;accessrules;accesspipe; +analyzer=pipette;flowerjungle;flowernether;apiaristsuit;honeyfood; +bottler=pipette; +carpenter=pipette;crating; +centrifuge= +fabricator= +fermenter=pipette;shortmead; +squeezer=pipette; +still=pipette; + +engine=accesscontrol;accessrules;accesspipe;energyunit;energybuffer; +engine.bronze=pipette;enginebronzefuels;enginebronzeheatloss;enginebronzeoutput;enginebronzewaste +engine.copper=forcedcooldown;cooldownloss;enginecopperfuels;usesofash;enginecopperwaste;manualpeat;peatharvest +engine.tin=forcedcooldown;cooldownloss;enginetinbatteries;enginetinchoke;