diff --git a/application.properties b/application.properties index 67cdae7af..fcd208741 100644 --- a/application.properties +++ b/application.properties @@ -1,5 +1,5 @@ mcversion=1.7.10 -forgeversion=10.13.0.1180 +forgeversion=10.13.0.1207 version_major=3 version_minor=0 version_patch=0 diff --git a/build.gradle b/build.gradle index 5755bf3c2..824fe2480 100755 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ apply plugin: 'maven' loadProperties() -version = "3.0.0.92-RF-" + System.getenv("DRONE_BUILD_NUMBER") +version = "3.0.0.131-RF-" + System.getenv("DRONE_BUILD_NUMBER") group= "net.sengir.forestry" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "forestry_" + mcversion @@ -73,7 +73,7 @@ configurations { dependencies { apis 'net.industrial-craft:industrialcraft-2:2.2.575-experimental:api' - apis 'com.mod-buildcraft:buildcraft:6.0.17:dev' + apis 'com.mod-buildcraft:buildcraft:6.0.18:dev' } processResources { diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 31b23ff2b..a48076d0b 100755 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -49,7 +49,7 @@ import net.minecraft.item.Item; modid = Defaults.MOD, name = "Forestry", version = Version.VERSION, - dependencies = "required-after:Forge@[10.13.0.1180,);" + dependencies = "required-after:Forge@[10.13.0.1207,);" + "after:Buildcraft|Core;" + "after:ExtrabiomesXL;" + "after:BiomesOPlenty;" @@ -119,18 +119,22 @@ public class Forestry { if (block != null) { mapping.remap(Item.getItemFromBlock(block)); Proxies.log.warning("Remapping item " + mapping.name + " to " + StringUtil.cleanBlockName(block)); - continue; - } - if (mapping.name.equals("builderBackpack")) + } else if (mapping.name.equals("Forestry:builderBackpack")) { mapping.remap(ForestryItem.builderBackpack.item()); - if (mapping.name.equals("builderBackpackT2")) + Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.builderBackpack.name()); + } else if (mapping.name.equals("Forestry:builderBackpackT2")) { mapping.remap(ForestryItem.builderBackpackT2.item()); - if (mapping.name.equals("adventurerBackpack")) + Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.builderBackpackT2.name()); + } else if (mapping.name.equals("Forestry:adventurerBackpack")) { mapping.remap(ForestryItem.adventurerBackpack.item()); - if (mapping.name.equals("adventurerBackpackT2")) + Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.adventurerBackpack.name()); + } else if (mapping.name.equals("Forestry:adventurerBackpackT2")) { mapping.remap(ForestryItem.adventurerBackpackT2.item()); - if (mapping.name.equals("shortMead")) + Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.adventurerBackpackT2.name()); + } else if (mapping.name.equals("Forestry:shortMead")) { mapping.remap(ForestryItem.beverage.item()); + Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.beverage.name()); + } } } } diff --git a/src/main/java/forestry/apiculture/CommandBeekeepingMode.java b/src/main/java/forestry/apiculture/CommandBeekeepingMode.java index b55eebc72..2125b5756 100755 --- a/src/main/java/forestry/apiculture/CommandBeekeepingMode.java +++ b/src/main/java/forestry/apiculture/CommandBeekeepingMode.java @@ -204,7 +204,10 @@ public class CommandBeekeepingMode extends CommandMC { private void listModes(ICommandSender sender, String[] arguments) { World world = getWorld(sender, arguments); - sendChatMessage(sender, StringUtil.localize("chat.bees.command.mode.current").replaceAll("%MODE", PluginApiculture.beeInterface.getBeekeepingMode(world).getName()).replaceAll("%WORLD", String.valueOf(world.getWorldInfo().getSaveVersion()))); + String message = StringUtil.localize("chat.bees.command.mode.current"); + message = message.replaceAll("%MODE", PluginApiculture.beeInterface.getBeekeepingMode(world).getName()); + message = message.replaceAll("%WORLD", String.valueOf(world.getWorldInfo().getSaveVersion())); + sendChatMessage(sender, message); String help = ""; for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes()) { diff --git a/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java b/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java index f0ad0afec..9b3013afb 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java @@ -147,6 +147,8 @@ public class BlockAlveary extends BlockStructure { return icons[BOTTOM]; switch (metadata) { + case TileAlvearyPlain.BLOCK_META: + return icons[PLAIN]; case 1: return icons[ENTRANCE]; case TileAlvearySwarmer.BLOCK_META: @@ -162,7 +164,7 @@ public class BlockAlveary extends BlockStructure { case TileAlvearySieve.BLOCK_META: return icons[SIEVE]; default: - return icons[PLAIN]; + return null; } } diff --git a/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java b/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java index 1bdf838ca..7d59381b4 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java @@ -155,6 +155,9 @@ public class BlockBeehives extends BlockContainer { @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int i, int j) { + if (j == 0 || j >= 8) + return null; + if (i == 0 || i == 1) { if (j * 2 < icons.length && icons[j * 2] != null) return icons[j * 2]; diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java index b9d31566d..75f3648fb 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java @@ -136,10 +136,6 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IPowe nbttagcompound.setInteger("Heating", transferTime); } - @Override - public String getInventoryName() { - return "tile.alveary.climatiser"; - } /* NETWORK */ @Override diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java index 325e2c70c..49d1764d2 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java @@ -77,7 +77,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public String getInventoryName() { - return "tile.alveary.5"; + return getUnlocalizedName(); } /* UPDATING */ diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java index 104284e46..35f2c398c 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java @@ -54,6 +54,8 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS public static final int SLOT_DRONE = 1; public static final int SLOT_PRODUCT_1 = 2; public static final int SLOT_PRODUCTION_COUNT = 7; + public static final int BLOCK_META = 0; + // / MEMBERS protected IBeekeepingLogic beekeepingLogic; protected int biomeId; @@ -582,7 +584,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS @Override public String getInventoryName() { - return "alveary.0"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java index 9c79627fc..59108854a 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java @@ -45,10 +45,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe player.openGui(ForestryAPI.instance, GuiId.AlvearySieveGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); } - @Override - public String getInventoryName() { - return "tile.alveary.7"; - } @Override public boolean hasFunction() { diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java index 1b0ff3200..a2da88c4c 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java @@ -46,10 +46,6 @@ public class TileAlvearyStabiliser extends TileAlveary implements IBeeModifier { ((IAlvearyComponent)getCentralTE()).registerBeeModifier(this); } - @Override - public String getInventoryName() { - return "tile.alveary.6"; - } @Override public boolean hasFunction() { diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java index b05f393fb..a7339d22f 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java @@ -267,7 +267,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public String getInventoryName() { - return "tile.alveary.2"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/apiculture/gadgets/TileApiary.java b/src/main/java/forestry/apiculture/gadgets/TileApiary.java index 9c0693ff8..ca2d2f098 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileApiary.java +++ b/src/main/java/forestry/apiculture/gadgets/TileApiary.java @@ -30,7 +30,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public String getInventoryName() { - return "apiculture.0"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java index 3e4f38665..74d68a435 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java +++ b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java @@ -68,11 +68,6 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { logic = PluginApiculture.beeInterface.createBeekeepingLogic(this); } - @Override - public String getInventoryName() { - return "apiculture.2"; - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.BeehouseGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); diff --git a/src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java b/src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java index 60b9b493c..e2d562dc8 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java +++ b/src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java @@ -10,74 +10,17 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - +import forestry.core.gui.ContainerAlyzer; +import forestry.core.config.ForestryItem; import forestry.apiculture.items.ItemBeeGE; import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory; -import forestry.core.config.ForestryItem; -import forestry.core.gui.ContainerItemInventory; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.proxy.Proxies; -public class ContainerBeealyzer extends ContainerItemInventory { +import net.minecraft.entity.player.InventoryPlayer; - BeealyzerInventory inventory; +public class ContainerBeealyzer extends ContainerAlyzer { public ContainerBeealyzer(InventoryPlayer inventoryplayer, BeealyzerInventory inventory) { - super(inventory, inventoryplayer.player); - - this.inventory = inventory; - - // Energy - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ENERGY, 172, 8, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop })); - - // Bee to analyze - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_SPECIMEN, 172, 26, new Object[] { ItemBeeGE.class })); - - // Analyzed bee - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_1, 172, 57, new Object[] { ItemBeeGE.class })); - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_2, 172, 75, new Object[] { ItemBeeGE.class })); - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_3, 172, 93, new Object[] { ItemBeeGE.class })); - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_4, 172, 111, new Object[] { ItemBeeGE.class })); - this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_5, 172, 129, new Object[] { ItemBeeGE.class })); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) - for (int l1 = 0; l1 < 9; l1++) - addSecuredSlot(inventoryplayer, l1 + i1 * 9 + 9, 18 + l1 * 18, 156 + i1 * 18); - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) - addSecuredSlot(inventoryplayer, j1, 18 + j1 * 18, 214); - - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) { - - if (!Proxies.common.isSimulating(entityplayer.worldObj)) - return; - - // Last slot is the energy slot, so we don't save that one. - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (i == BeealyzerInventory.SLOT_ENERGY) - continue; - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - Proxies.common.dropItemPlayer(entityplayer, stack); - inventory.setInventorySlotContents(i, null); - } - - inventory.onGuiSaved(entityplayer); - - } - - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return true; + super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, new Object[] { ItemBeeGE.class }); } } diff --git a/src/main/java/forestry/apiculture/gui/GuiAlveary.java b/src/main/java/forestry/apiculture/gui/GuiAlveary.java index 85da7f1d4..4285f6889 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlveary.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlveary.java @@ -14,12 +14,11 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.apiculture.gadgets.TileAlvearyPlain; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; -public class GuiAlveary extends GuiForestry { +public class GuiAlveary extends GuiForestryTitled { public GuiAlveary(InventoryPlayer inventory, TileAlvearyPlain tile) { super(Defaults.TEXTURE_PATH_GUI + "/alveary.png", new ContainerAlveary(inventory, tile), tile); @@ -27,13 +26,6 @@ public class GuiAlveary extends GuiForestry { ySize = 190; } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String title = StringUtil.localize("tile." + tile.getInventoryName()); - this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java index 3d5266c5d..6a7c16190 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java @@ -14,23 +14,15 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.apiculture.gadgets.TileAlvearyHygroregulator; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; -public class GuiAlvearyHygroregulator extends GuiForestry { +public class GuiAlvearyHygroregulator extends GuiForestryTitled { public GuiAlvearyHygroregulator(InventoryPlayer inventory, TileAlvearyHygroregulator tile) { - super(Defaults.TEXTURE_PATH_GUI + "/hygroregulator.png", new ContainerAlvearyHygroregulator(inventory, tile)); + super(Defaults.TEXTURE_PATH_GUI + "/hygroregulator.png", new ContainerAlvearyHygroregulator(inventory, tile), tile); widgetManager.add(new TankWidget(this.widgetManager, 104, 17, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.alveary.5"); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - } diff --git a/src/main/java/forestry/apiculture/gui/GuiApiary.java b/src/main/java/forestry/apiculture/gui/GuiApiary.java index c3cf7c821..1a73b16a3 100755 --- a/src/main/java/forestry/apiculture/gui/GuiApiary.java +++ b/src/main/java/forestry/apiculture/gui/GuiApiary.java @@ -15,12 +15,11 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.apiculture.gadgets.TileApiary; import forestry.apiculture.gadgets.TileBeehouse; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; -public class GuiApiary extends GuiForestry { +public class GuiApiary extends GuiForestryTitled { public GuiApiary(InventoryPlayer inventory, TileApiary tile) { super(Defaults.TEXTURE_PATH_GUI + "/apiary.png", new ContainerApiary(inventory, tile, true), tile); @@ -34,13 +33,6 @@ public class GuiApiary extends GuiForestry { ySize = 190; } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java index 1f38a8a3d..eee45d1fd 100755 --- a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java +++ b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java @@ -41,8 +41,7 @@ public class GuiBeealyzer extends GuiAlyzer { super(AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"), player, new ContainerBeealyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory()); - xSize = 196; - ySize = 238; + guiName = "gui.beealyzer"; ArrayList beeList = new ArrayList(); ((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false); @@ -96,45 +95,6 @@ public class GuiBeealyzer extends GuiAlyzer { } - private void drawAnalyticsOverview() { - - startPage(); - - newLine(); - String title = StringUtil.localize("gui.beealyzer").toUpperCase(); - drawCenteredLine(title, 8, 158); - newLine(); - - fontRendererObj.drawSplitString(StringUtil.localize("gui.beealyzer.help"), (int) ((guiLeft + COLUMN_0 + 4) * (1 / factor)), - (int) ((guiTop + 42) * (1 / factor)), (int) (158 * (1 / factor)), fontColor.get("gui.screen")); - newLine(); - newLine(); - newLine(); - newLine(); - - drawLine(StringUtil.localize("gui.beealyzer.overview") + ":", COLUMN_0 + 4); - newLine(); - drawLine("I : " + StringUtil.localize("gui.general"), COLUMN_0 + 4); - newLine(); - drawLine("II : " + StringUtil.localize("gui.environment"), COLUMN_0 + 4); - newLine(); - drawLine("III: " + StringUtil.localize("gui.produce"), COLUMN_0 + 4); - newLine(); - drawLine("IV : " + StringUtil.localize("gui.evolution"), COLUMN_0 + 4); - - newLine(); - - String mode = breedingTracker.getModeName(); - if (mode != null && !mode.isEmpty()) { - newLine(); - String rules = StringUtil.localize("gui.beealyzer.behaviour") + ": " + StringUtil.capitalize(mode); - drawLine(rules, 8 + getCenteredOffset(title, 158), fontColor.get("gui.beealyzer.binomial")); - } - - endPage(); - - } - private void drawAnalyticsPage1(IBee bee, EnumBeeType type) { startPage(COLUMN_0, COLUMN_1, COLUMN_2); @@ -268,16 +228,14 @@ public class GuiBeealyzer extends GuiAlyzer { if (!bee.isNatural()) displayText = "bees.stock.ignoble"; displayText = StringUtil.localize(displayText); - // int offset = (int)(((158 - fontRendererObj.getStringWidth(origin)) / 2)*(1/factor)); - drawCenteredLine(displayText, 8, 158, fontColor.get("gui.beealyzer.binomial"));; + drawCenteredLine(displayText, 8, 208, fontColor.get("gui.beealyzer.binomial")); } if (bee.getGeneration() >= 0) { newLine(); displayText = StringUtil.localizeAndFormat("gui.beealyzer.generations", bee.getGeneration()); - // offset = (int)(((158 - fontRendererObj.getStringWidth(origin)) / 2)*(1/factor)); - drawCenteredLine(displayText, 8, 158, fontColor.get("gui.beealyzer.binomial")); + drawCenteredLine(displayText, 8, 208, fontColor.get("gui.beealyzer.binomial")); } endPage(); diff --git a/src/main/java/forestry/apiculture/items/ItemBeeGE.java b/src/main/java/forestry/apiculture/items/ItemBeeGE.java index 90b484238..be2a1768c 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeeGE.java +++ b/src/main/java/forestry/apiculture/items/ItemBeeGE.java @@ -77,7 +77,10 @@ public class ItemBeeGE extends ItemGE { if(StatCollector.canTranslate("for." + customBeeKey)){ return StringUtil.localize(customBeeKey); } - return StringUtil.localize("bees.grammar." + type.getName()).replaceAll("%SPECIES", individual.getDisplayName()).replaceAll("%TYPE", StringUtil.localize("bees.grammar." + type.getName() + ".type")); + String beeGrammar = StringUtil.localize("bees.grammar." + type.getName()); + String beeSpecies = individual.getDisplayName(); + String beeType = StringUtil.localize("bees.grammar." + type.getName() + ".type"); + return beeGrammar.replaceAll("%SPECIES", beeSpecies).replaceAll("%TYPE", beeType); } @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java index 1fa0bcab4..fc74aa51b 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java +++ b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java @@ -10,10 +10,10 @@ ******************************************************************************/ package forestry.apiculture.items; +import forestry.core.utils.AlyzerInventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import forestry.api.apiculture.IBee; @@ -27,22 +27,11 @@ import forestry.core.interfaces.IHintSource; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; import forestry.plugins.PluginApiculture; public class ItemBeealyzer extends ItemInventoried { - public static class BeealyzerInventory extends ItemInventory implements IErrorSource, IHintSource { - - 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; - - EntityPlayer player; + public static class BeealyzerInventory extends AlyzerInventory implements IErrorSource, IHintSource { public BeealyzerInventory(EntityPlayer player) { super(ItemBeealyzer.class, 7); @@ -54,21 +43,6 @@ public class ItemBeealyzer extends ItemInventoried { this.player = player; } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - - NBTTagList nbttaglist = new NBTTagList(); - for (int i = SLOT_ENERGY; i < SLOT_ENERGY + 1; i++) - if (inventoryStacks[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - inventoryStacks[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - nbttagcompound.setTag("Items", nbttaglist); - - } - private boolean isEnergy(ItemStack itemstack) { if (itemstack == null || itemstack.stackSize <= 0) return false; diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockLog.java b/src/main/java/forestry/arboriculture/gadgets/BlockLog.java index 65e2b9802..2054ed499 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockLog.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockLog.java @@ -103,6 +103,7 @@ public class BlockLog extends Block implements IWoodTyped { @Override public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) { if(cat == LogCat.CAT6) { + itemList.add(new ItemStack(this, 1, 0)); return; } @@ -123,7 +124,10 @@ public class BlockLog extends Block implements IWoodTyped { int oriented = meta & 12; - WoodType type = getWoodType(getTypeFromMeta(meta)); + WoodType type = getWoodType(meta); + if (type == null) + return null; + switch (oriented) { case 4: if (side > 3) @@ -157,7 +161,7 @@ public class BlockLog extends Block implements IWoodTyped { /* PROPERTIES */ @Override public float getBlockHardness(World world, int x, int y, int z) { - return getWoodType(getTypeFromMeta(world.getBlockMetadata(x, y, z))).getHardness(); + return getWoodType(world.getBlockMetadata(x, y, z)).getHardness(); } @Override @@ -192,10 +196,11 @@ public class BlockLog extends Block implements IWoodTyped { @Override public WoodType getWoodType(int meta) { + meta = getTypeFromMeta(meta); if(meta + cat.ordinal() * 4 < WoodType.VALUES.length) return WoodType.VALUES[meta + cat.ordinal() * 4]; else - return WoodType.LARCH; + return null; } @Override diff --git a/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java b/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java index 742414e68..b0e1ec589 100755 --- a/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java +++ b/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java @@ -10,77 +10,19 @@ ******************************************************************************/ package forestry.arboriculture.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -import org.apache.commons.lang3.ArrayUtils; - -import forestry.api.genetics.AlleleManager; +import forestry.core.gui.ContainerAlyzer; +import forestry.core.config.ForestryItem; import forestry.arboriculture.items.ItemGermlingGE; import forestry.arboriculture.items.ItemTreealyzer.TreealyzerInventory; -import forestry.core.config.ForestryItem; -import forestry.core.gui.ContainerItemInventory; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.proxy.Proxies; -public class ContainerTreealyzer extends ContainerItemInventory { +import net.minecraft.entity.player.InventoryPlayer; + +public class ContainerTreealyzer extends ContainerAlyzer { TreealyzerInventory inventory; public ContainerTreealyzer(InventoryPlayer inventoryplayer, TreealyzerInventory inventory) { - super(inventory, inventoryplayer.player); - - this.inventory = inventory; - - // Energy - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_ENERGY, 172, 8, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop })); - - // Tree to analyze - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_SPECIMEN, 172, 26, ArrayUtils.addAll(AlleleManager.ersatzSaplings.keySet().toArray(new Object[0]), ItemGermlingGE.class))); - - // Analyzed tree - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_ANALYZE_1, 172, 57, new Object[] { ItemGermlingGE.class })); - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_ANALYZE_2, 172, 75, new Object[] { ItemGermlingGE.class })); - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_ANALYZE_3, 172, 93, new Object[] { ItemGermlingGE.class })); - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_ANALYZE_4, 172, 111, new Object[] { ItemGermlingGE.class })); - this.addSlot(new SlotCustom(inventory, TreealyzerInventory.SLOT_ANALYZE_5, 172, 129, new Object[] { ItemGermlingGE.class })); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) - for (int l1 = 0; l1 < 9; l1++) - addSecuredSlot(inventoryplayer, l1 + i1 * 9 + 9, 18 + l1 * 18, 156 + i1 * 18); - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) - addSecuredSlot(inventoryplayer, j1, 18 + j1 * 18, 214); - - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) { - - if (!Proxies.common.isSimulating(entityplayer.worldObj)) - return; - - // Last slot is the energy slot, so we don't save that one. - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (i == TreealyzerInventory.SLOT_ENERGY) - continue; - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - Proxies.common.dropItemPlayer(entityplayer, stack); - inventory.setInventorySlotContents(i, null); - } - - inventory.onGuiSaved(entityplayer); - - } - - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return true; + super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, new Object[] { ItemGermlingGE.class }); } } diff --git a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java index cc91b1848..6d55ed488 100755 --- a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java +++ b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java @@ -46,8 +46,7 @@ public class GuiTreealyzer extends GuiAlyzer { super(AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees"), player, new ContainerTreealyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory()); - xSize = 196; - ySize = 238; + guiName = "gui.treealyzer"; ArrayList treeList = new ArrayList(); ((ItemGermlingGE) ForestryItem.sapling.item()).addCreativeItems(treeList, false); @@ -99,35 +98,6 @@ public class GuiTreealyzer extends GuiAlyzer { } - private void drawAnalyticsOverview() { - - startPage(); - - newLine(); - String title = StringUtil.localize("gui.treealyzer").toUpperCase(); - drawCenteredLine(title, 8, 158); - newLine(); - - fontRendererObj.drawSplitString(StringUtil.localize("gui.treealyzer.help"), (int) ((guiLeft + COLUMN_0 + 4) * (1 / factor)), - (int) ((guiTop + 42) * (1 / factor)), (int) (158 * (1 / factor)), fontColor.get("gui.screen")); - newLine(); - newLine(); - newLine(); - newLine(); - - drawLine(StringUtil.localize("gui.treealyzer.overview") + ":", COLUMN_0 + 4); - newLine(); - drawLine("I : " + StringUtil.localize("gui.general"), COLUMN_0 + 4); - newLine(); - drawLine("II : " + StringUtil.localize("gui.environment"), COLUMN_0 + 4); - newLine(); - drawLine("III: " + StringUtil.localize("gui.produce"), COLUMN_0 + 4); - newLine(); - drawLine("IV : " + StringUtil.localize("gui.evolution"), COLUMN_0 + 4); - - endPage(); - } - private void drawAnalyticsPage1(ITree tree, EnumGermlingType type) { startPage(COLUMN_0, COLUMN_1, COLUMN_2); diff --git a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java index 95004f75e..15a63b279 100755 --- a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java +++ b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java @@ -13,9 +13,9 @@ package forestry.arboriculture.items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; +import forestry.core.utils.AlyzerInventory; import forestry.api.arboriculture.ITree; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; @@ -27,22 +27,12 @@ import forestry.core.interfaces.IHintSource; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; import forestry.core.utils.Utils; import forestry.plugins.PluginArboriculture; public class ItemTreealyzer extends ItemInventoried { - public static class TreealyzerInventory extends ItemInventory implements IErrorSource, IHintSource { - - public final static int SLOT_SPECIMEN = 0; - public final static int SLOT_ANALYZE_1 = 1; - public final static int SLOT_ANALYZE_2 = 2; - public final static int SLOT_ANALYZE_3 = 3; - public final static int SLOT_ANALYZE_4 = 4; - public final static int SLOT_ANALYZE_5 = 6; - public final static int SLOT_ENERGY = 5; - EntityPlayer player; + public static class TreealyzerInventory extends AlyzerInventory implements IErrorSource, IHintSource { public TreealyzerInventory(EntityPlayer player) { super(ItemTreealyzer.class, 7); @@ -54,22 +44,6 @@ public class ItemTreealyzer extends ItemInventoried { this.player = player; } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - - NBTTagList nbttaglist = new NBTTagList(); - for (int i = SLOT_ENERGY; i < SLOT_ENERGY + 1; i++) { - if (inventoryStacks[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - inventoryStacks[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - } - nbttagcompound.setTag("Items", nbttaglist); - - } - private boolean isEnergy(ItemStack itemstack) { if (itemstack == null || itemstack.stackSize <= 0) return false; diff --git a/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java b/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java index d7b4edb70..62387fae2 100755 --- a/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java +++ b/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java @@ -34,6 +34,8 @@ public class ItemWoodBlock extends ItemForestryBlock { IWoodTyped block = (IWoodTyped) getBlock(); int meta = itemstack.getItemDamage(); WoodType woodType = block.getWoodType(meta); + if (woodType == null) + return null; return "tile.for." + block.getBlockKind() + "." + woodType.ordinal(); } return super.getUnlocalizedName(itemstack); diff --git a/src/main/java/forestry/core/EnumErrorCode.java b/src/main/java/forestry/core/EnumErrorCode.java index 0efcfb27e..64d96143b 100755 --- a/src/main/java/forestry/core/EnumErrorCode.java +++ b/src/main/java/forestry/core/EnumErrorCode.java @@ -66,7 +66,7 @@ public enum EnumErrorCode { NOHONEY("noHoney", 22), - NOTPOSTPAID("notPostpaid", 23), + NOTPOSTPAID("notPostpaid", "noStamps", 23), NORECIPIENT("noRecipient", 24), @@ -86,14 +86,28 @@ public enum EnumErrorCode { CIRCUITMISMATCH("circuitMismatch", 26), - NOLIQUID("noLiquid", 29); + NOLIQUID("noLiquid", 29), + + NOPAPER("noPaper", 30), + + NOSTAMPSNOPAPER("noStampsNoPaper", "noStamps", 31), + + NOSUPPLIES("noSupplies", "noResource", 32), + + NOTRADE("noTrade", "noResource", 33); private String name; + private String iconName; @SideOnly(Side.CLIENT) private IIcon icon; private EnumErrorCode(String name, int iconIndex) { + this(name, name, iconIndex); + } + + private EnumErrorCode(String name, String iconName, int iconIndex) { this.name = name; + this.iconName = iconName; } public String getDescription() { @@ -106,7 +120,7 @@ public enum EnumErrorCode { @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister register) { - icon = TextureManager.getInstance().registerTex(register, "errors/" + name); + icon = TextureManager.getInstance().registerTex(register, "errors/" + iconName); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/core/IItemTyped.java b/src/main/java/forestry/core/IItemTyped.java new file mode 100644 index 000000000..c53101f1c --- /dev/null +++ b/src/main/java/forestry/core/IItemTyped.java @@ -0,0 +1,5 @@ +package forestry.core; + +public interface IItemTyped { + public Enum getTypeFromMeta(int meta); +} diff --git a/src/main/java/forestry/core/gadgets/BlockBase.java b/src/main/java/forestry/core/gadgets/BlockBase.java index 3ec79d988..dfc1dcd99 100755 --- a/src/main/java/forestry/core/gadgets/BlockBase.java +++ b/src/main/java/forestry/core/gadgets/BlockBase.java @@ -242,7 +242,7 @@ public class BlockBase extends BlockForestry { @Override public IIcon getIcon(int side, int metadata) { if (metadata >= definitions.size() || definitions.get(metadata) == null) - metadata = 0; + return null; return definitions.get(metadata).getBlockTextureFromSideAndMetadata(side, metadata); } diff --git a/src/main/java/forestry/core/gadgets/BlockResource.java b/src/main/java/forestry/core/gadgets/BlockResource.java index ef3897802..66fd7b3ff 100755 --- a/src/main/java/forestry/core/gadgets/BlockResource.java +++ b/src/main/java/forestry/core/gadgets/BlockResource.java @@ -101,8 +101,10 @@ public class BlockResource extends Block { return iconApatite; else if (j == 1) return iconCopper; - else + else if (j == 2) return iconTin; + else + return null; } } diff --git a/src/main/java/forestry/core/gadgets/BlockSoil.java b/src/main/java/forestry/core/gadgets/BlockSoil.java index 3eecb210f..e7cf3721e 100755 --- a/src/main/java/forestry/core/gadgets/BlockSoil.java +++ b/src/main/java/forestry/core/gadgets/BlockSoil.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import forestry.core.IItemTyped; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -45,9 +46,13 @@ import forestry.core.render.TextureManager; * @author * */ -public class BlockSoil extends Block { +public class BlockSoil extends Block implements IItemTyped { - private final int degradeDelimiter = 3; + public enum SoilType { + HUMUS, BOG_EARTH, PEAT; + } + + private static final int degradeDelimiter = 3; public BlockSoil() { super(Material.sand); @@ -66,16 +71,15 @@ public class BlockSoil extends Block { public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList ret = new ArrayList(); - int type = (metadata & 0x03); - int maturity = metadata >> 2; + SoilType type = getTypeFromMeta(metadata); - if (maturity >= this.degradeDelimiter && type == 1) { + if (type == SoilType.PEAT) { ret.add(ForestryItem.peat.getItemStack()); ret.add(new ItemStack(Blocks.dirt)); - } else if (type == 0) + } else if (type == SoilType.HUMUS) ret.add(new ItemStack(Blocks.dirt)); else - ret.add(new ItemStack(this, 1, type)); + ret.add(new ItemStack(this, 1, SoilType.BOG_EARTH.ordinal())); return ret; } @@ -91,14 +95,13 @@ public class BlockSoil extends Block { return; int meta = world.getBlockMetadata(i, j, k); - int type = (meta & 0x03); - if (type == 0) + SoilType type = getTypeFromMeta(meta); + + if (type == SoilType.HUMUS) updateTickHumus(world, i, j, k, random); - else if (type == 1) + else if (type == SoilType.BOG_EARTH) updateTickBogEarth(world, i, j, k, random); - else - Proxies.log.warning(this.getClass() + " with unknown type " + type + " encountered."); } private void updateTickHumus(World world, int i, int j, int k, Random random) { @@ -155,17 +158,17 @@ public class BlockSoil extends Block { int type = meta & 0x03; int grade = meta >> 2; - // Increment (de)gradation - grade++; + // Increment (de)gradation + grade++; - // Repackage in format TTGG - meta = (grade << 2 | type); + // Repackage in format TTGG + meta = (grade << 2 | type); - if (grade >= this.degradeDelimiter) - world.setBlock(i, j, k, Blocks.sand, 0, Defaults.FLAG_BLOCK_SYNCH); - else - world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); - world.markBlockForUpdate(i, j, k); + if (grade >= this.degradeDelimiter) + world.setBlock(i, j, k, Blocks.sand, 0, Defaults.FLAG_BLOCK_SYNCH); + else + world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); + world.markBlockForUpdate(i, j, k); } public static boolean isMoistened(World world, int x, int y, int z) { @@ -192,15 +195,15 @@ public class BlockSoil extends Block { int type = meta & 0x03; int maturity = meta >> 2; - if (maturity >= this.degradeDelimiter) - return; + if (maturity >= this.degradeDelimiter) + return; - // Increment (de)gradation - maturity++; + // Increment (de)gradation + maturity++; - meta = (maturity << 2 | type); - world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); - world.markBlockForUpdate(i, j, k); + meta = (maturity << 2 | type); + world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); + world.markBlockForUpdate(i, j, k); } @Override @@ -210,8 +213,9 @@ public class BlockSoil extends Block { return false; int meta = world.getBlockMetadata(x, y, z); + SoilType type = getTypeFromMeta(meta); - return (meta & 0x03) == 0; + return type == SoilType.HUMUS; } @Override @@ -219,6 +223,19 @@ public class BlockSoil extends Block { return false; } + public SoilType getTypeFromMeta(int meta) { + int type = meta & 0x03; + int maturity = meta >> 2; + + if (type == 1) + if (maturity < degradeDelimiter) + return SoilType.BOG_EARTH; + else + return SoilType.PEAT; + else + return SoilType.HUMUS; + } + // / CREATIVE INVENTORY @SuppressWarnings({ "rawtypes", "unchecked" }) @Override @@ -245,19 +262,16 @@ public class BlockSoil extends Block { @Override @SideOnly(Side.CLIENT) - public IIcon getIcon(int i, int j) { + public IIcon getIcon(int side, int meta) { - int meta = j; - int type = meta & 0x03; - int maturity = meta >> 2; + SoilType type = getTypeFromMeta(meta); - if (type == 1) - if (maturity < this.degradeDelimiter) - return iconBogEarth; - else - return iconPeat; - else - return iconHumus; + switch (type) { + case HUMUS: return iconHumus; + case BOG_EARTH: return iconBogEarth; + case PEAT: return iconPeat; + } + return null; } } diff --git a/src/main/java/forestry/core/gadgets/TileAnalyzer.java b/src/main/java/forestry/core/gadgets/TileAnalyzer.java index 514e82d40..03052832f 100755 --- a/src/main/java/forestry/core/gadgets/TileAnalyzer.java +++ b/src/main/java/forestry/core/gadgets/TileAnalyzer.java @@ -76,7 +76,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI @Override public String getInventoryName() { - return StringUtil.localize("core.0"); + return getUnlocalizedName(); } /* GUI */ diff --git a/src/main/java/forestry/core/gadgets/TileBase.java b/src/main/java/forestry/core/gadgets/TileBase.java index 2c169207a..142d83671 100755 --- a/src/main/java/forestry/core/gadgets/TileBase.java +++ b/src/main/java/forestry/core/gadgets/TileBase.java @@ -21,11 +21,6 @@ import forestry.core.utils.Utils; public abstract class TileBase extends TileForestry implements IHintSource { - @Override - public String getInventoryName() { - return null; - } - @Override public boolean isOwnable() { return true; diff --git a/src/main/java/forestry/core/gadgets/TileEscritoire.java b/src/main/java/forestry/core/gadgets/TileEscritoire.java index 735c59cd7..6fdde0480 100755 --- a/src/main/java/forestry/core/gadgets/TileEscritoire.java +++ b/src/main/java/forestry/core/gadgets/TileEscritoire.java @@ -47,7 +47,7 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender private final InventoryAdapter inventory; @Override public String getInventoryName() { - return StringUtil.localize("core.1"); + return getUnlocalizedName(); } public TileEscritoire() { diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index 516e81316..ffd3bc9d9 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -297,7 +297,14 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit } /* NAME */ - public abstract String getInventoryName(); + + /** + * Gets the tile's unlocalized name, based on the block at the location of this entity (client-only). + */ + public String getUnlocalizedName() { + String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.",""); + return blockUnlocalizedName + "." + getBlockMetadata() + ".name"; + } public boolean hasCustomInventoryName() { return true; diff --git a/src/main/java/forestry/core/gadgets/TileMachine.java b/src/main/java/forestry/core/gadgets/TileMachine.java index 3b0fb6e24..2cb47a929 100755 --- a/src/main/java/forestry/core/gadgets/TileMachine.java +++ b/src/main/java/forestry/core/gadgets/TileMachine.java @@ -42,7 +42,7 @@ import forestry.plugins.PluginEnergy; import forestry.plugins.PluginFactory; import forestry.plugins.PluginMail; -public class TileMachine extends TileForestry implements ISpecialInventory, IClimatised, IHintSource { +public abstract class TileMachine extends TileForestry implements ISpecialInventory, IClimatised, IHintSource { public TileMachine() { } @@ -301,7 +301,7 @@ public class TileMachine extends TileForestry implements ISpecialInventory, ICli @Override public String getInventoryName() { - return "[Unknown]"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/core/gadgets/TileNaturalistChest.java b/src/main/java/forestry/core/gadgets/TileNaturalistChest.java index ab4b1fe25..152f0fa8c 100755 --- a/src/main/java/forestry/core/gadgets/TileNaturalistChest.java +++ b/src/main/java/forestry/core/gadgets/TileNaturalistChest.java @@ -37,7 +37,7 @@ public abstract class TileNaturalistChest extends TileBase implements IInventory @Override public String getInventoryName() { - return StringUtil.localize("tile.mill.3"); + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/core/gui/ContainerAlyzer.java b/src/main/java/forestry/core/gui/ContainerAlyzer.java new file mode 100644 index 000000000..1b5af9f50 --- /dev/null +++ b/src/main/java/forestry/core/gui/ContainerAlyzer.java @@ -0,0 +1,83 @@ +package forestry.core.gui; + +import forestry.core.gui.slots.SlotCustom; +import forestry.core.proxy.Proxies; +import forestry.core.utils.AlyzerInventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; + +public class ContainerAlyzer extends ContainerItemInventory { + + private AlyzerInventory inventory; + + protected ContainerAlyzer(InventoryPlayer inventoryplayer, AlyzerInventory inventory, Object[] acceptedEnergy, Object[] acceptedSpecimens) { + super(inventory, inventoryplayer.player); + + this.inventory = inventory; + + final int xPosLeftSlots = 223; + + // Energy + this.addSlot(new SlotCustom(inventory, inventory.SLOT_ENERGY, xPosLeftSlots, 8, acceptedEnergy)); + + // Bee to analyze + this.addSlot(new SlotCustom(inventory, inventory.SLOT_SPECIMEN, xPosLeftSlots, 26, acceptedSpecimens)); + + // Analyzed bee + this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_1, xPosLeftSlots, 57, acceptedSpecimens)); + this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_2, xPosLeftSlots, 75, acceptedSpecimens)); + this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_3, xPosLeftSlots, 93, acceptedSpecimens)); + this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_4, xPosLeftSlots, 111, acceptedSpecimens)); + this.addSlot(new SlotCustom(inventory, inventory.SLOT_ANALYZE_5, xPosLeftSlots, 129, acceptedSpecimens)); + + final int xPosPlayerInv = 43; + final int xSpacePlayerInv = 18; + final int yPosPlayerInv= 156; + final int ySpacePlayerInv = 18; + + // Player inventory + for (int i1 = 0; i1 < 3; i1++) { + for (int l1 = 0; l1 < 9; l1++) { + int slot = l1 + i1 * 9 + 9; + int x = xPosPlayerInv + (l1 * xSpacePlayerInv); + int y = yPosPlayerInv + (i1 * ySpacePlayerInv); + addSecuredSlot(inventoryplayer, slot, x, y); + } + } + // Player hotbar + for (int j1 = 0; j1 < 9; j1++) { + int x = xPosPlayerInv + (j1 * xSpacePlayerInv); + addSecuredSlot(inventoryplayer, j1, x, 214); + } + + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) { + + if (!Proxies.common.isSimulating(entityplayer.worldObj)) + return; + + // Last slot is the energy slot, so we don't save that one. + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (i == inventory.SLOT_ENERGY) + continue; + ItemStack stack = inventory.getStackInSlot(i); + if (stack == null) + continue; + + Proxies.common.dropItemPlayer(entityplayer, stack); + inventory.setInventorySlotContents(i, null); + } + + inventory.onGuiSaved(entityplayer); + } + + @Override + protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { + return true; + } + +} diff --git a/src/main/java/forestry/core/gui/GuiAlyzer.java b/src/main/java/forestry/core/gui/GuiAlyzer.java index c828d1537..5ec00934f 100755 --- a/src/main/java/forestry/core/gui/GuiAlyzer.java +++ b/src/main/java/forestry/core/gui/GuiAlyzer.java @@ -21,6 +21,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +import org.apache.commons.lang3.StringUtils; import org.lwjgl.opengl.GL11; import forestry.api.apiculture.EnumBeeChromosome; @@ -43,18 +44,23 @@ import forestry.core.utils.StringUtil; public abstract class GuiAlyzer extends GuiForestry { protected static final int COLUMN_0 = 12; - protected static final int COLUMN_1 = 52; - protected static final int COLUMN_2 = 108; + protected static final int COLUMN_1 = 85; + protected static final int COLUMN_2 = 150; protected IInventory inventory; protected ISpeciesRoot speciesRoot; protected IBreedingTracker breedingTracker; + protected String guiName; + protected HashMap iconStacks = new HashMap(); public GuiAlyzer(ISpeciesRoot speciesRoot, EntityPlayer player, ContainerForestry container, IInventory inventory, int pageMax, int pageSize) { super(Defaults.TEXTURE_PATH_GUI + "/beealyzer.png", container); + xSize = 246; + ySize = 238; + this.inventory = inventory; this.speciesRoot = speciesRoot; this.breedingTracker = speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile()); @@ -94,8 +100,8 @@ public abstract class GuiAlyzer extends GuiForestry { int columnwidth = column2 - column1 - 16; RenderHelper.enableStandardItemLighting(); - drawItemStack(iconStacks.get(primary.getUID()), adjustToFactor(guiLeft + column1 + columnwidth + 2), adjustToFactor(guiTop + getLineY())); - drawItemStack(iconStacks.get(secondary.getUID()), adjustToFactor(guiLeft + column2 + columnwidth + 4), adjustToFactor(guiTop + getLineY())); + drawItemStack(iconStacks.get(primary.getUID()), adjustToFactor(guiLeft + column1 + columnwidth - 4), adjustToFactor(guiTop + getLineY())); + drawItemStack(iconStacks.get(secondary.getUID()), adjustToFactor(guiLeft + column2 + columnwidth - 2), adjustToFactor(guiTop + getLineY())); RenderHelper.disableStandardItemLighting(); String primaryName; @@ -124,6 +130,44 @@ public abstract class GuiAlyzer extends GuiForestry { } } + protected void drawAnalyticsOverview() { + + startPage(); + + newLine(); + String title = StringUtil.localize(guiName).toUpperCase(); + drawCenteredLine(title, 8, 208); + newLine(); + + fontRendererObj.drawSplitString(StringUtil.localize(guiName + ".help"), (int) ((guiLeft + COLUMN_0 + 4) * (1 / factor)), + (int) ((guiTop + 42) * (1 / factor)), (int) (195 * (1 / factor)), fontColor.get("gui.screen")); + newLine(); + newLine(); + newLine(); + newLine(); + + drawLine(StringUtil.localize("gui.alyzer.overview") + ":", COLUMN_0 + 4); + newLine(); + drawLine("I : " + StringUtil.localize("gui.general"), COLUMN_0 + 4); + newLine(); + drawLine("II : " + StringUtil.localize("gui.environment"), COLUMN_0 + 4); + newLine(); + drawLine("III: " + StringUtil.localize("gui.produce"), COLUMN_0 + 4); + newLine(); + drawLine("IV : " + StringUtil.localize("gui.evolution"), COLUMN_0 + 4); + + newLine(); + + String mode = breedingTracker.getModeName(); + if (mode != null && !mode.isEmpty()) { + newLine(); + String rules = StringUtil.localize(guiName + ".behaviour") + ": " + StringUtil.capitalize(mode); + drawCenteredLine(rules, 8, 208, fontColor.get(guiName + ".binomial")); + } + + endPage(); + } + protected final void drawAnalyticsPageClassification(IIndividual individual) { startPage(); @@ -151,9 +195,9 @@ public abstract class GuiAlyzer extends GuiForestry { continue; drawLine(group.getScientific(), x, group.getLevel().getColour()); - drawLine(group.getLevel().name(), 130, group.getLevel().getColour()); + drawLine(group.getLevel().name(), 155, group.getLevel().getColour()); newLine(); - x += 8; + x += 10; } // Add the species name @@ -162,26 +206,26 @@ public abstract class GuiAlyzer extends GuiForestry { binomial = group.getScientific().substring(0, 1) + ". " + binomial.toLowerCase(Locale.ENGLISH); drawLine(binomial, x, 0xebae85); - drawLine("SPECIES", 130, 0xebae85); + drawLine("SPECIES", 155, 0xebae85); newLine(); newLine(); drawLine(StringUtil.localize("gui.alyzer.authority") + ": " + individual.getGenome().getPrimary().getAuthority(), 12); if (AlleleManager.alleleRegistry.isBlacklisted(individual.getIdent())) { String extinct = ">> " + StringUtil.localize("gui.alyzer.extinct").toUpperCase() + " <<"; - fontRendererObj.drawStringWithShadow(extinct, adjustToFactor(guiLeft + 160) - fontRendererObj.getStringWidth(extinct), + fontRendererObj.drawStringWithShadow(extinct, adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth(extinct), adjustToFactor(guiTop + getLineY()), fontColor.get("gui.beealyzer.dominant")); } newLine(); String description = individual.getGenome().getPrimary().getDescription(); - if (description == null || description.isEmpty()) - drawSplitLine(StringUtil.localize("gui.alyzer.nodescription"), 12, 156, 0x666666); + if (StringUtils.isBlank(description) || description.startsWith("for.description.")) + drawSplitLine(StringUtil.localize("gui.alyzer.nodescription"), 12, 208, 0x666666); else { String tokens[] = description.split("\\|"); - drawSplitLine(tokens[0], 12, 152, 0x666666); + drawSplitLine(tokens[0], 12, 208, 0x666666); if (tokens.length > 1) - fontRendererObj.drawStringWithShadow("- " + tokens[1], adjustToFactor(guiLeft + 160) - fontRendererObj.getStringWidth("- " + tokens[1]), + fontRendererObj.drawStringWithShadow("- " + tokens[1], adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth("- " + tokens[1]), adjustToFactor(guiTop + 145 - 14), 0x99cc32); } @@ -222,7 +266,7 @@ public abstract class GuiAlyzer extends GuiForestry { } x += columnWidth; - if (x > 150) { + if (x > columnWidth * 4) { x = 0; newLine(); newLine(); @@ -254,30 +298,29 @@ public abstract class GuiAlyzer extends GuiForestry { adjustToFactor(guiTop) + getLineY()); */ - int line = 0; - int column = 196; + int line = 247; + int column = 100; switch (EnumMutateChance.rateChance(combination.getBaseChance())) { - case HIGHEST: - column = 226; - line = 9; - break; - case HIGHER: - column = 211; - line = 9; - break; - case HIGH: - line = 9; - break; - case NORMAL: - column = 226; - break; - case LOW: - column = 211; - break; - case LOWEST: - default: - break; + case HIGHEST: + column = 100; + break; + case HIGHER: + column = 100 + 15; + break; + case HIGH: + column = 100 + 15 * 2; + break; + case NORMAL: + column = 100 + 15 * 3; + break; + case LOW: + column = 100 + 15 * 4; + break; + case LOWEST: + column = 100 + 15 * 5; + default: + break; } Proxies.common.bindTexture(textureFile); @@ -289,35 +332,34 @@ public abstract class GuiAlyzer extends GuiForestry { // Question marks Proxies.common.bindTexture(textureFile); - drawTexturedModalRect(adjustToFactor(guiLeft) + x, adjustToFactor(guiTop) + getLineY(), 196, 18, 16, 16); + drawTexturedModalRect(adjustToFactor(guiLeft) + x, adjustToFactor(guiTop) + getLineY(), 78, 240, 16, 16); Proxies.common.bindTexture(textureFile); - drawTexturedModalRect(adjustToFactor(guiLeft) + x + 32, adjustToFactor(guiTop) + getLineY(), 196, 18, 16, 16); + drawTexturedModalRect(adjustToFactor(guiLeft) + x + 32, adjustToFactor(guiTop) + getLineY(), 78, 240, 16, 16); - int line = 0; - int column = 196; + int line = 247; + int column = 100; switch (EnumMutateChance.rateChance(combination.getBaseChance())) { - case HIGHEST: - column = 226; - line = 9; - break; - case HIGHER: - column = 211; - line = 9; - break; - case HIGH: - line = 9; - break; - case NORMAL: - column = 226; - break; - case LOW: - column = 211; - break; - case LOWEST: - default: - break; + case HIGHEST: + column = 100; + break; + case HIGHER: + column = 100 + 15; + break; + case HIGH: + column = 100 + 15 * 2; + break; + case NORMAL: + column = 100 + 15 * 3; + break; + case LOW: + column = 100 + 15 * 4; + break; + case LOWEST: + column = 100 + 15 * 5; + default: + break; } // Probability arrow @@ -367,22 +409,22 @@ public abstract class GuiAlyzer extends GuiForestry { private void drawDownSymbol(int x, int y) { Proxies.common.bindTexture(textureFile); - drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 196, 34, 15, 9); + drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 0, 247, 15, 9); } private void drawUpSymbol(int x, int y) { Proxies.common.bindTexture(textureFile); - drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 211, 34, 15, 9); + drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 15, 247, 15, 9); } private void drawBothSymbol(int x, int y) { Proxies.common.bindTexture(textureFile); - drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 226, 34, 15, 9); + drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 30, 247, 15, 9); } private void drawNoneSymbol(int x, int y) { Proxies.common.bindTexture(textureFile); - drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 241, 34, 15, 9); + drawTexturedModalRect((int) ((guiLeft + x) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 45, 247, 15, 9); } protected void drawFertilityInfo(int fertility, int x, int textColor, int texOffset) { @@ -390,7 +432,7 @@ public abstract class GuiAlyzer extends GuiForestry { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Proxies.common.bindTexture(textureFile); - drawTexturedModalRect((int) ((guiLeft + x + 19) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 196, 43 + texOffset, 12, 9); + drawTexturedModalRect((int) ((guiLeft + x + 14) * (1 / factor)), (int) ((guiTop + getLineY()) * (1 / factor)), 60, 240 + texOffset, 12, 8); drawLine(Integer.toString(fertility) + " x", x, textColor); } diff --git a/src/main/java/forestry/core/gui/GuiAnalyzer.java b/src/main/java/forestry/core/gui/GuiAnalyzer.java index 8c3775b5c..f03f2b9d4 100755 --- a/src/main/java/forestry/core/gui/GuiAnalyzer.java +++ b/src/main/java/forestry/core/gui/GuiAnalyzer.java @@ -16,10 +16,9 @@ import forestry.core.config.Defaults; import forestry.core.gadgets.TileAnalyzer; import forestry.core.gui.widgets.TankWidget; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; -public class GuiAnalyzer extends GuiForestry { +public class GuiAnalyzer extends GuiForestryTitled { public GuiAnalyzer(InventoryPlayer inventory, TileAnalyzer tile) { super(Defaults.TEXTURE_PATH_GUI + "/alyzer.png", new ContainerAnalyzer(inventory, tile), tile); @@ -27,13 +26,6 @@ public class GuiAnalyzer extends GuiForestry { widgetManager.add(new TankWidget(this.widgetManager, 95, 24, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String title = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index 2cbc6a857..874b0c391 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -53,10 +53,6 @@ public abstract class GuiForestry extends GuiContainer { public ResourceLocation textureFile; protected FontColour fontColor; - public GuiForestry(ContainerForestry container) { - this("", container); - } - public GuiForestry(String texture, ContainerForestry container) { this(new ResourceLocation("forestry", texture), container, null); } diff --git a/src/main/java/forestry/core/gui/GuiForestryTitled.java b/src/main/java/forestry/core/gui/GuiForestryTitled.java new file mode 100644 index 000000000..41d9e9df8 --- /dev/null +++ b/src/main/java/forestry/core/gui/GuiForestryTitled.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.core.gui; + +import net.minecraft.util.ResourceLocation; + +import forestry.core.gadgets.TileForestry; +import forestry.core.utils.StringUtil; + +public abstract class GuiForestryTitled extends GuiForestry { + + public GuiForestryTitled(String texture, ContainerForestry container, Object inventory) { + super(texture, container, inventory); + } + + public GuiForestryTitled(ResourceLocation texture, ContainerForestry container, Object inventory) { + super(texture, container, inventory); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + String name = StringUtil.localizeTile(tile.getUnlocalizedName()); + this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); + } +} diff --git a/src/main/java/forestry/core/gui/slots/SlotCustom.java b/src/main/java/forestry/core/gui/slots/SlotCustom.java index d0881973a..e7624ccd1 100755 --- a/src/main/java/forestry/core/gui/slots/SlotCustom.java +++ b/src/main/java/forestry/core/gui/slots/SlotCustom.java @@ -42,8 +42,8 @@ public class SlotCustom extends SlotForestry { private ICrafter crafter; private String blockedTexture = "slots/blocked"; - public SlotCustom(IInventory iinventory, int i, int j, int k, boolean exclusion) { - super(iinventory, i, j, k); + public SlotCustom(IInventory iinventory, int slotIndex, int xPos, int yPos, boolean exclusion) { + super(iinventory, slotIndex, xPos, yPos); items = new Object[0]; this.exclusion = exclusion; } @@ -52,17 +52,17 @@ public class SlotCustom extends SlotForestry { this(iinventory, i, j, k, items.toArray()); }*/ - public SlotCustom(IInventory iinventory, Collection items, int i, int j, int k) { - this(iinventory, i, j, k, items.toArray()); + public SlotCustom(IInventory iinventory, Collection items, int slotIndex, int xPos, int yPos) { + this(iinventory, slotIndex, xPos, yPos, items.toArray()); } - public SlotCustom(IInventory iinventory, int i, int j, int k, boolean exclusion, Object... items) { - this(iinventory, i, j, k, items); + public SlotCustom(IInventory iinventory, int slotIndex, int xPos, int yPos, boolean exclusion, Object... items) { + this(iinventory, slotIndex, xPos, yPos, items); this.exclusion = exclusion; } - public SlotCustom(IInventory iinventory, int i, int j, int k, Object... items) { - super(iinventory, i, j, k); + public SlotCustom(IInventory iinventory, int slotIndex, int xPos, int yPos, Object... items) { + super(iinventory, slotIndex, xPos, yPos); this.items = items; } diff --git a/src/main/java/forestry/core/items/ItemCrated.java b/src/main/java/forestry/core/items/ItemCrated.java index d244a7935..1a20d8510 100755 --- a/src/main/java/forestry/core/items/ItemCrated.java +++ b/src/main/java/forestry/core/items/ItemCrated.java @@ -81,13 +81,13 @@ public class ItemCrated extends Item implements IGenericCrate { return itemstack; } -// @Override -// public String getItemStackDisplayName(ItemStack itemstack) { -// if (contained != null) -// return StringUtil.localize("item.crated.adj") + " " + Proxies.common.getDisplayName(contained); -// else -// return StringUtil.localize("item.crated.unknown"); -// } + @Override + public String getItemStackDisplayName(ItemStack itemstack) { + if (contained != null) + return StringUtil.localize("item.crated.adj") + " " + Proxies.common.getDisplayName(contained); + else + return StringUtil.localize("item.crated.unknown"); + } @SideOnly(Side.CLIENT) @Override diff --git a/src/main/java/forestry/core/items/ItemForestryBlock.java b/src/main/java/forestry/core/items/ItemForestryBlock.java index 1a003bf76..9aba23515 100755 --- a/src/main/java/forestry/core/items/ItemForestryBlock.java +++ b/src/main/java/forestry/core/items/ItemForestryBlock.java @@ -10,9 +10,12 @@ ******************************************************************************/ package forestry.core.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; public class ItemForestryBlock extends ItemBlock { @@ -31,6 +34,12 @@ public class ItemForestryBlock extends ItemBlock { return field_150939_a; } + @SideOnly(Side.CLIENT) + @Override + public IIcon getIconFromDamage(int meta) { + return this.getBlock().getIcon(1, meta); + } + @Override public String getUnlocalizedName(ItemStack itemstack) { return getBlock().getUnlocalizedName() + "." + itemstack.getItemDamage(); diff --git a/src/main/java/forestry/core/items/ItemTypedBlock.java b/src/main/java/forestry/core/items/ItemTypedBlock.java new file mode 100644 index 000000000..556ee28b5 --- /dev/null +++ b/src/main/java/forestry/core/items/ItemTypedBlock.java @@ -0,0 +1,30 @@ +package forestry.core.items; + +import forestry.core.IItemTyped; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +/** + * For blocks whose type depends on metadata. + * This allows control over which localized name maps to which meta value. + */ +public class ItemTypedBlock extends ItemForestryBlock { + + public ItemTypedBlock(Block block) { + super(block); + } + + @Override + public String getUnlocalizedName(ItemStack itemstack) { + Block block = getBlock(); + if (block instanceof IItemTyped) { + IItemTyped blockTyped = (IItemTyped)block; + Enum type = blockTyped.getTypeFromMeta(itemstack.getItemDamage()); + if (type != null) + return getBlock().getUnlocalizedName() + "." + type.ordinal(); + else + return null; + } + return super.getUnlocalizedName(itemstack); + } +} diff --git a/src/main/java/forestry/core/network/ClassMap.java b/src/main/java/forestry/core/network/ClassMap.java index bac3e53c8..d22e4b926 100755 --- a/src/main/java/forestry/core/network/ClassMap.java +++ b/src/main/java/forestry/core/network/ClassMap.java @@ -76,10 +76,13 @@ public class ClassMap { } for (Field member : gameProfileMember) { GameProfile profile = (GameProfile) member.get(obj); - intPayload[index.intIndex] = (int) (profile.getId().getMostSignificantBits() >>> 32); - intPayload[index.intIndex + 1] = (int) profile.getId().getMostSignificantBits(); - intPayload[index.intIndex + 2] = (int) (profile.getId().getLeastSignificantBits() >>> 32); - intPayload[index.intIndex + 3] = (int) profile.getId().getLeastSignificantBits(); + UUID profileID = profile.getId(); + if (profileID == null) + profileID = new UUID(0,0); + intPayload[index.intIndex] = (int) profileID.getMostSignificantBits() >>> 32; + intPayload[index.intIndex + 1] = (int) profileID.getMostSignificantBits(); + intPayload[index.intIndex + 2] = (int) profileID.getLeastSignificantBits() >>> 32; + intPayload[index.intIndex + 3] = (int) profileID.getLeastSignificantBits(); index.intIndex += 4; stringPayload[index.stringIndex] = profile.getName(); index.stringIndex++; diff --git a/src/main/java/forestry/core/network/PacketIds.java b/src/main/java/forestry/core/network/PacketIds.java index 5139f513a..acc395720 100755 --- a/src/main/java/forestry/core/network/PacketIds.java +++ b/src/main/java/forestry/core/network/PacketIds.java @@ -42,7 +42,7 @@ public class PacketIds { public static final int LETTER_RECIPIENT = 80; public static final int LETTER_TEXT = 81; public static final int TRADING_ADDRESS_SET = 82; - public static final int TRADING_INFO = 83; + public static final int LETTER_INFO = 83; public static final int POBOX_INFO = 85; public static final int POBOX_INFO_REQUEST = 86; diff --git a/src/main/java/forestry/core/utils/AlyzerInventory.java b/src/main/java/forestry/core/utils/AlyzerInventory.java new file mode 100644 index 000000000..398ab4764 --- /dev/null +++ b/src/main/java/forestry/core/utils/AlyzerInventory.java @@ -0,0 +1,45 @@ +package forestry.core.utils; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class AlyzerInventory extends ItemInventory { + + 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; + + protected EntityPlayer player; + + public AlyzerInventory(Class itemClass, int slots) { + super(itemClass, slots); + } + + public AlyzerInventory(Class itemClass, int size, ItemStack itemstack) { + super(itemClass, size, itemstack); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + + NBTTagList nbttaglist = new NBTTagList(); + for (int i = SLOT_ENERGY; i < SLOT_ENERGY + 1; i++) { + if (inventoryStacks[i] != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte) i); + inventoryStacks[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } + nbttagcompound.setTag("Items", nbttaglist); + + } + +} diff --git a/src/main/java/forestry/core/utils/InventoryAdapter.java b/src/main/java/forestry/core/utils/InventoryAdapter.java index e037d953f..70737cc71 100755 --- a/src/main/java/forestry/core/utils/InventoryAdapter.java +++ b/src/main/java/forestry/core/utils/InventoryAdapter.java @@ -76,17 +76,20 @@ public class InventoryAdapter implements IInventory, INBTTagable { } public boolean tryAddStacksCopy(ItemStack[] stacks, boolean all) { + return tryAddStacksCopy(stacks, 0, this.getSizeInventory(), all); + } + + public boolean tryAddStacksCopy(ItemStack[] stacks, int startSlot, int slots, boolean all) { - boolean addedAll = true; for (ItemStack stack : stacks) { if (stack == null) continue; - if (!tryAddStack(stack.copy(), all)) - addedAll = false; + if (!tryAddStack(stack.copy(), startSlot, slots, all)) + return false; } - return addedAll; + return true; } public boolean tryAddStacks(ItemStack[] stacks, boolean all) { @@ -121,7 +124,11 @@ public class InventoryAdapter implements IInventory, INBTTagable { } public boolean tryAddStack(ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) { - return addStack(stack, startSlot, slots, all, doAdd) > 0; + int added = addStack(stack, startSlot, slots, all, doAdd); + if (all) + return added == stack.stackSize; + else + return added > 0; } public int addStack(ItemStack stack, boolean all, boolean doAdd) { @@ -193,7 +200,7 @@ public class InventoryAdapter implements IInventory, INBTTagable { if (stack == null) continue; - if (StackUtils.equals(Blocks.air, queried)) { + if (StackUtils.equals(Blocks.bedrock, queried)) { itemCount += stack.stackSize; continue; } diff --git a/src/main/java/forestry/core/utils/StackUtils.java b/src/main/java/forestry/core/utils/StackUtils.java index a46e2a1dc..b97d593a8 100755 --- a/src/main/java/forestry/core/utils/StackUtils.java +++ b/src/main/java/forestry/core/utils/StackUtils.java @@ -193,7 +193,7 @@ public class StackUtils { * without decreasing the source stack. * * @param stack - * @param i + * @param amount * @return */ public static ItemStack createSplitStack(ItemStack stack, int amount) { @@ -309,6 +309,9 @@ public class StackUtils { if (isIdenticalItem(base, comparison)) return true; + if (base == null || comparison == null) + return false; + if (oreDictionary) { int[] idsBase = OreDictionary.getOreIDs(base); for (int idBase : idsBase) { diff --git a/src/main/java/forestry/core/utils/StringUtil.java b/src/main/java/forestry/core/utils/StringUtil.java index f459b8af0..f8b44e465 100755 --- a/src/main/java/forestry/core/utils/StringUtil.java +++ b/src/main/java/forestry/core/utils/StringUtil.java @@ -22,14 +22,12 @@ public class StringUtil { return StatCollector.translateToLocal("for." + key).replace("\\n", "\n").replace("@", "%").replace("\\%", "@"); } - public static String localizeAndFormat(String key, Object... args) { - String text = StringUtil.localize(key); + public static String localizeTile(String key) { + return StatCollector.translateToLocal("tile.for." + key).replace("\\n", "\n").replace("@", "%").replace("\\%", "@"); + } - try { - return String.format(text, args); - } catch (IllegalFormatException ex) { - return "Format error: " + text; - } + public static String localizeAndFormat(String key, Object... args) { + return localizeAndFormatRaw("for." + key, args); } /** diff --git a/src/main/java/forestry/core/utils/Utils.java b/src/main/java/forestry/core/utils/Utils.java index 7aa851825..2a123d77d 100755 --- a/src/main/java/forestry/core/utils/Utils.java +++ b/src/main/java/forestry/core/utils/Utils.java @@ -320,7 +320,7 @@ public class Utils { public static int addRGBComponents(int colour, int r, int g, int b) { r = ((colour & 0xff0000) >> 16) + r; - g = ((colour & 0xff00) >> 8) + b; + g = ((colour & 0xff00) >> 8) + g; b = ((colour & 0xff)) + b; r = r <= 255 ? r : 255; diff --git a/src/main/java/forestry/energy/gadgets/EngineBronze.java b/src/main/java/forestry/energy/gadgets/EngineBronze.java index c8cdf1801..cb0728de6 100755 --- a/src/main/java/forestry/energy/gadgets/EngineBronze.java +++ b/src/main/java/forestry/energy/gadgets/EngineBronze.java @@ -405,12 +405,9 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa return super.isUseableByPlayer(player); } - /** - * TODO: just a specialsource workaround - */ @Override public String getInventoryName() { - return super.getInventoryName(); + return getUnlocalizedName(); } /** diff --git a/src/main/java/forestry/energy/gadgets/EngineCopper.java b/src/main/java/forestry/energy/gadgets/EngineCopper.java index 7a0e74f6c..eb371b303 100755 --- a/src/main/java/forestry/energy/gadgets/EngineCopper.java +++ b/src/main/java/forestry/energy/gadgets/EngineCopper.java @@ -397,12 +397,9 @@ public class EngineCopper extends Engine implements ISpecialInventory, ISidedInv return super.isUseableByPlayer(player); } - /** - * TODO: just a specialsource workaround - */ @Override public String getInventoryName() { - return super.getInventoryName(); + return getUnlocalizedName(); } /** diff --git a/src/main/java/forestry/energy/gadgets/EngineTin.java b/src/main/java/forestry/energy/gadgets/EngineTin.java index a1f74ec75..b138b889f 100755 --- a/src/main/java/forestry/energy/gadgets/EngineTin.java +++ b/src/main/java/forestry/energy/gadgets/EngineTin.java @@ -311,12 +311,9 @@ public class EngineTin extends Engine implements ISocketable, IInventory { return super.isUseableByPlayer(player); } - /** - * TODO: just a specialsource workaround - */ @Override public String getInventoryName() { - return super.getInventoryName(); + return getUnlocalizedName(); } /** diff --git a/src/main/java/forestry/energy/gadgets/MachineGenerator.java b/src/main/java/forestry/energy/gadgets/MachineGenerator.java index 77444dba4..bab24cd96 100755 --- a/src/main/java/forestry/energy/gadgets/MachineGenerator.java +++ b/src/main/java/forestry/energy/gadgets/MachineGenerator.java @@ -65,7 +65,7 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi @Override public String getInventoryName() { - return StringUtil.localize("engine.3"); + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/energy/gui/GuiEngine.java b/src/main/java/forestry/energy/gui/GuiEngine.java index 60e8dd175..5646a44a3 100755 --- a/src/main/java/forestry/energy/gui/GuiEngine.java +++ b/src/main/java/forestry/energy/gui/GuiEngine.java @@ -15,12 +15,12 @@ package forestry.energy.gui; import forestry.core.gadgets.Engine; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.Ledger; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; -public abstract class GuiEngine extends GuiForestry { +public abstract class GuiEngine extends GuiForestryTitled { protected class EngineLedger extends Ledger { diff --git a/src/main/java/forestry/energy/gui/GuiEngineBronze.java b/src/main/java/forestry/energy/gui/GuiEngineBronze.java index 5b0374c0a..c73d78556 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineBronze.java +++ b/src/main/java/forestry/energy/gui/GuiEngineBronze.java @@ -103,19 +103,15 @@ public class GuiEngineBronze extends GuiEngine { widgetManager.add(new BiogasSlot(this.widgetManager, 30, 47, tile)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for.engine.2"); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); + protected EngineBronze getEngine() { + return (EngineBronze)tile; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - EngineBronze engine = (EngineBronze) tile; - int temp = engine.getOperatingTemperatureScaled(16); + int temp = getEngine().getOperatingTemperatureScaled(16); if (temp > 16) temp = 16; if (temp > 0) diff --git a/src/main/java/forestry/energy/gui/GuiEngineCopper.java b/src/main/java/forestry/energy/gui/GuiEngineCopper.java index bea21fa42..df8193097 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineCopper.java +++ b/src/main/java/forestry/energy/gui/GuiEngineCopper.java @@ -22,19 +22,15 @@ public class GuiEngineCopper extends GuiEngine { super(Defaults.TEXTURE_PATH_GUI + "/peatengine.png", new ContainerEngineCopper(inventory, tile), tile); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for.engine.1"); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - this.fontRendererObj.drawString("Inventory", 8, this.ySize - 96 + 2, fontColor.get("gui.title")); + protected EngineCopper getEngine() { + return (EngineCopper)tile; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - EngineCopper engine = (EngineCopper) tile; + EngineCopper engine = getEngine(); int progress; if (engine.isBurning()) { progress = engine.getBurnTimeRemainingScaled(12); diff --git a/src/main/java/forestry/energy/gui/GuiEngineTin.java b/src/main/java/forestry/energy/gui/GuiEngineTin.java index 0a6d2035c..f1942c073 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineTin.java +++ b/src/main/java/forestry/energy/gui/GuiEngineTin.java @@ -25,19 +25,20 @@ public class GuiEngineTin extends GuiEngine { widgetManager.add(new SocketWidget(this.widgetManager, 30, 40, tile, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for.engine.0"); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); + protected EngineTin getEngine() { + return (EngineTin)tile; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - EngineTin engine = (EngineTin) tile; - drawHealthMeter(guiLeft + 74, guiTop + 25, engine.getStorageScaled(46), engine.rateLevel(engine.getStorageScaled(100))); + EngineTin engine = getEngine(); + int storageHeight = engine.getStorageScaled(46); + int storageMaxHeight = engine.getStorageScaled(100); + EnumTankLevel rated = engine.rateLevel(storageMaxHeight); + + drawHealthMeter(guiLeft + 74, guiTop + 25, storageHeight, rated); } private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) { diff --git a/src/main/java/forestry/energy/gui/GuiGenerator.java b/src/main/java/forestry/energy/gui/GuiGenerator.java index c2a4f01f4..673f10fd4 100755 --- a/src/main/java/forestry/energy/gui/GuiGenerator.java +++ b/src/main/java/forestry/energy/gui/GuiGenerator.java @@ -13,25 +13,17 @@ package forestry.energy.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.energy.gadgets.MachineGenerator; -public class GuiGenerator extends GuiForestry { +public class GuiGenerator extends GuiForestryTitled { public GuiGenerator(InventoryPlayer inventory, MachineGenerator tile) { super(Defaults.TEXTURE_PATH_GUI + "/generator.png", new ContainerGenerator(inventory, tile), tile); widgetManager.add(new TankWidget(this.widgetManager, 49, 17, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String title = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gadgets/MachineBottler.java b/src/main/java/forestry/factory/gadgets/MachineBottler.java index d8308a2ad..9541a6eb3 100755 --- a/src/main/java/forestry/factory/gadgets/MachineBottler.java +++ b/src/main/java/forestry/factory/gadgets/MachineBottler.java @@ -168,7 +168,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq @Override public String getInventoryName() { - return "factory.0"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java index dc93a50aa..eded391fe 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java @@ -239,7 +239,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL @Override public String getInventoryName() { - return "factory.1"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java index b96f17c20..44d37e105 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java +++ b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java @@ -148,7 +148,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I @Override public String getInventoryName() { - return "factory.2"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineFabricator.java b/src/main/java/forestry/factory/gadgets/MachineFabricator.java index 0e3e2da85..331a75a8a 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFabricator.java +++ b/src/main/java/forestry/factory/gadgets/MachineFabricator.java @@ -248,7 +248,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial @Override public String getInventoryName() { - return "factory2.0"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineFermenter.java b/src/main/java/forestry/factory/gadgets/MachineFermenter.java index e2e3ff7aa..464f8e758 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFermenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineFermenter.java @@ -200,7 +200,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL @Override public String getInventoryName() { - return "factory.3"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineMoistener.java b/src/main/java/forestry/factory/gadgets/MachineMoistener.java index 6ef2d0c4a..95fb05177 100755 --- a/src/main/java/forestry/factory/gadgets/MachineMoistener.java +++ b/src/main/java/forestry/factory/gadgets/MachineMoistener.java @@ -145,7 +145,7 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory, @Override public String getInventoryName() { - return "factory.4"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineRaintank.java b/src/main/java/forestry/factory/gadgets/MachineRaintank.java index b8b327b24..bd0612c9a 100755 --- a/src/main/java/forestry/factory/gadgets/MachineRaintank.java +++ b/src/main/java/forestry/factory/gadgets/MachineRaintank.java @@ -70,7 +70,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui @Override public String getInventoryName() { - return "factory2.1"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java index 4641e35cc..71e4758d8 100755 --- a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java +++ b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java @@ -156,7 +156,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I @Override public String getInventoryName() { - return "factory.5"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineStill.java b/src/main/java/forestry/factory/gadgets/MachineStill.java index 6de02b5c6..d39513063 100755 --- a/src/main/java/forestry/factory/gadgets/MachineStill.java +++ b/src/main/java/forestry/factory/gadgets/MachineStill.java @@ -135,7 +135,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid @Override public String getInventoryName() { - return "factory.6"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/MillRainmaker.java b/src/main/java/forestry/factory/gadgets/MillRainmaker.java index 75a349c33..3bbab49e7 100755 --- a/src/main/java/forestry/factory/gadgets/MillRainmaker.java +++ b/src/main/java/forestry/factory/gadgets/MillRainmaker.java @@ -34,7 +34,7 @@ public class MillRainmaker extends Mill implements ISpecialInventory { @Override public String getInventoryName() { - return "Rainmaker"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/factory/gadgets/TileWorktable.java b/src/main/java/forestry/factory/gadgets/TileWorktable.java index 693e93499..6ae55cde3 100755 --- a/src/main/java/forestry/factory/gadgets/TileWorktable.java +++ b/src/main/java/forestry/factory/gadgets/TileWorktable.java @@ -120,7 +120,7 @@ public class TileWorktable extends TileBase implements ICrafter { @Override public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) { if (updateCachedIRecipe()) - return cachedRecipe.getRecipeOutput(); + return cachedRecipe.getCraftingResult(inventorycrafting); return null; } @@ -193,29 +193,25 @@ public class TileWorktable extends TileBase implements ICrafter { private LinkedList recipes = new LinkedList(); private long lastUpdate; + public final int capacity = 9; public long getLastUpdate() { return lastUpdate; } - public Recipe getOrCreateRecipe(World world, InventoryCrafting crafting) { - - Recipe memory = getMemorized(crafting, world); - if (memory != null) { - return memory; - } - - return new Recipe(crafting); - } - - public void memorizeRecipe(World world, Recipe recipe) { + public void memorizeRecipe(World world, Recipe recipe, InventoryCrafting crafting) { lastUpdate = world.getTotalWorldTime(); recipe.updateLastUse(world); - if (recipes.contains(recipe)) + Recipe memory = getMemorized(crafting, world); + if (memory != null) { + int index = recipes.indexOf(memory); + recipes.set(index, recipe); return; - if (recipes.size() < 8) { + } + + if (recipes.size() < capacity) { recipes.add(recipe); return; } @@ -361,6 +357,7 @@ public class TileWorktable extends TileBase implements ICrafter { } /* MEMBERS */ private Recipe currentRecipe; + private InventoryCrafting currentCrafting; private final RecipeMemory memorized; private final TileInventoryAdapter craftingInventory; private final TileInventoryAdapter accessibleInventory; @@ -372,11 +369,6 @@ public class TileWorktable extends TileBase implements ICrafter { memorized = new RecipeMemory(); } - @Override - public String getInventoryName() { - return "factory2.2"; - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.WorktableGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -425,7 +417,7 @@ public class TileWorktable extends TileBase implements ICrafter { } public void chooseRecipe(int recipeIndex) { - if (recipeIndex == 9) { + if (recipeIndex >= memorized.capacity) { for (int slot = 0; slot < craftingInventory.getSizeInventory(); slot++) { craftingInventory.setInventorySlotContents(slot, null); } @@ -447,13 +439,19 @@ public class TileWorktable extends TileBase implements ICrafter { public void setRecipe(InventoryCrafting crafting) { IRecipe recipe = RECIPE_BRIDGE.getRecipe(crafting, worldObj); - currentRecipe = recipe != null ? memorized.getOrCreateRecipe(worldObj, crafting) : null; - updateCraftResult(); + if (recipe == null) { + currentRecipe = null; + currentCrafting = null; + } else { + currentRecipe = new Recipe(crafting); + currentCrafting = crafting; + } + updateCraftResult(currentCrafting); } - private void updateCraftResult() { + private void updateCraftResult(InventoryCrafting inventorycrafting) { if (currentRecipe != null) { - ItemStack result = currentRecipe.getCraftingResult(null); + ItemStack result = currentRecipe.getCraftingResult(inventorycrafting); if (result != null) { craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, result.copy()); return; @@ -467,7 +465,10 @@ public class TileWorktable extends TileBase implements ICrafter { // Need at least one matched set if (currentRecipe == null) return false; - return StackUtils.containsSets(currentRecipe.getMatrix().getStacks(SLOT_CRAFTING_1, 9), accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT), currentRecipe.getRecipeOutput(), true, true) > 0; + + ItemStack[] set = currentRecipe.getMatrix().getStacks(); + ItemStack[] stock = accessibleInventory.getStacks(); + return StackUtils.containsSets(set, stock, currentRecipe.getRecipeOutput(), true, true) > 0; } private void removeResources(EntityPlayer player) { @@ -511,9 +512,9 @@ public class TileWorktable extends TileBase implements ICrafter { return null; if (Proxies.common.isSimulating(worldObj)) - memorized.memorizeRecipe(worldObj, currentRecipe); + memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting); removeResources(player); - updateCraftResult(); + updateCraftResult(currentCrafting); return currentRecipe.getRecipeOutput().copy(); } diff --git a/src/main/java/forestry/factory/gui/ContainerWorktable.java b/src/main/java/forestry/factory/gui/ContainerWorktable.java index 9ffcab696..62a190aec 100755 --- a/src/main/java/forestry/factory/gui/ContainerWorktable.java +++ b/src/main/java/forestry/factory/gui/ContainerWorktable.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.factory.gui; +import forestry.core.utils.StackUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; @@ -25,6 +26,7 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.factory.gadgets.TileWorktable; +import net.minecraft.item.ItemStack; public class ContainerWorktable extends ContainerForestry implements IContainerCrafting, IGuiSelectable { @@ -91,10 +93,16 @@ public class ContainerWorktable extends ContainerForestry implements IContainerC @Override public void onCraftMatrixChanged(IInventory iinventory, int slot) { -// craftingInventory.setInventorySlotContents(slot, iinventory.getStackInSlot(slot)); - if (slot < craftMatrix.getSizeInventory()) - craftMatrix.setInventorySlotContents(slot, iinventory.getStackInSlot(slot)); - updateRecipe(); + if (slot >= craftMatrix.getSizeInventory()) + return; + + ItemStack stack = iinventory.getStackInSlot(slot); + ItemStack currentStack = craftMatrix.getStackInSlot(slot); + + if (!StackUtils.isIdenticalItem(stack, currentStack)) { + craftMatrix.setInventorySlotContents(slot, stack); + updateRecipe(); + } } private void updateMatrix() { @@ -107,6 +115,10 @@ public class ContainerWorktable extends ContainerForestry implements IContainerC tile.setRecipe(craftMatrix); } + public void clearRecipe() { + sendRecipeClick(0, tile.getMemory().capacity); + } + public void sendRecipeClick(int mouseButton, int recipeIndex) { PacketPayload payload = new PacketPayload(2, 0, 0); payload.intPayload[0] = mouseButton; diff --git a/src/main/java/forestry/factory/gui/GuiBottler.java b/src/main/java/forestry/factory/gui/GuiBottler.java index a2ff20397..fd24dc271 100755 --- a/src/main/java/forestry/factory/gui/GuiBottler.java +++ b/src/main/java/forestry/factory/gui/GuiBottler.java @@ -13,25 +13,17 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineBottler; -public class GuiBottler extends GuiForestry { +public class GuiBottler extends GuiForestryTitled { public GuiBottler(InventoryPlayer inventory, MachineBottler processor) { super(Defaults.TEXTURE_PATH_GUI + "/bottler.png", new ContainerBottler(inventory, processor), processor); widgetManager.add(new TankWidget(this.widgetManager, 53, 17, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiCarpenter.java b/src/main/java/forestry/factory/gui/GuiCarpenter.java index 102cf0666..655e8df89 100755 --- a/src/main/java/forestry/factory/gui/GuiCarpenter.java +++ b/src/main/java/forestry/factory/gui/GuiCarpenter.java @@ -13,12 +13,11 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineCarpenter; -public class GuiCarpenter extends GuiForestry { +public class GuiCarpenter extends GuiForestryTitled { public GuiCarpenter(InventoryPlayer inventory, MachineCarpenter tile) { super(Defaults.TEXTURE_PATH_GUI + "/carpenter.png", new ContainerCarpenter(inventory, tile), tile); @@ -33,13 +32,6 @@ public class GuiCarpenter extends GuiForestry { inventorySlots.onContainerClosed(mc.thePlayer); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiCentrifuge.java b/src/main/java/forestry/factory/gui/GuiCentrifuge.java index 254c8d720..dde1b62c8 100755 --- a/src/main/java/forestry/factory/gui/GuiCentrifuge.java +++ b/src/main/java/forestry/factory/gui/GuiCentrifuge.java @@ -13,23 +13,15 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; -import forestry.core.utils.StringUtil; +import forestry.core.gui.GuiForestryTitled; import forestry.factory.gadgets.MachineCentrifuge; -public class GuiCentrifuge extends GuiForestry { +public class GuiCentrifuge extends GuiForestryTitled { public GuiCentrifuge(InventoryPlayer inventory, MachineCentrifuge tile) { super(Defaults.TEXTURE_PATH_GUI + "/centrifuge.png", new ContainerCentrifuge(inventory, tile), tile); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiFabricator.java b/src/main/java/forestry/factory/gui/GuiFabricator.java index 626bd509f..e15044361 100755 --- a/src/main/java/forestry/factory/gui/GuiFabricator.java +++ b/src/main/java/forestry/factory/gui/GuiFabricator.java @@ -13,12 +13,11 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.ReservoirWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineFabricator; -public class GuiFabricator extends GuiForestry { +public class GuiFabricator extends GuiForestryTitled { public GuiFabricator(InventoryPlayer player, MachineFabricator tile) { super(Defaults.TEXTURE_PATH_GUI + "/fabricator.png", new ContainerFabricator(player, tile), tile); @@ -26,13 +25,6 @@ public class GuiFabricator extends GuiForestry { widgetManager.add(new ReservoirWidget(this.widgetManager, 26, 48, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiFermenter.java b/src/main/java/forestry/factory/gui/GuiFermenter.java index 23ca2d97f..1d51ba00b 100755 --- a/src/main/java/forestry/factory/gui/GuiFermenter.java +++ b/src/main/java/forestry/factory/gui/GuiFermenter.java @@ -13,12 +13,11 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineFermenter; -public class GuiFermenter extends GuiForestry { +public class GuiFermenter extends GuiForestryTitled { public GuiFermenter(InventoryPlayer inventory, MachineFermenter tile) { super(Defaults.TEXTURE_PATH_GUI + "/fermenter.png", new ContainerFermenter(inventory, tile), tile); @@ -26,13 +25,6 @@ public class GuiFermenter extends GuiForestry { widgetManager.add(new TankWidget(this.widgetManager, 125, 19, 1)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiMoistener.java b/src/main/java/forestry/factory/gui/GuiMoistener.java index 8b0b118dc..e4fbd864d 100755 --- a/src/main/java/forestry/factory/gui/GuiMoistener.java +++ b/src/main/java/forestry/factory/gui/GuiMoistener.java @@ -13,25 +13,17 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineMoistener; -public class GuiMoistener extends GuiForestry { +public class GuiMoistener extends GuiForestryTitled { public GuiMoistener(InventoryPlayer inventory, MachineMoistener tile) { super(Defaults.TEXTURE_PATH_GUI + "/moistener.png", new ContainerMoistener(inventory, tile), tile); widgetManager.add(new TankWidget(this.widgetManager, 16, 16, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiRaintank.java b/src/main/java/forestry/factory/gui/GuiRaintank.java index 044ed9a07..02a93a01c 100755 --- a/src/main/java/forestry/factory/gui/GuiRaintank.java +++ b/src/main/java/forestry/factory/gui/GuiRaintank.java @@ -13,25 +13,17 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineRaintank; -public class GuiRaintank extends GuiForestry { +public class GuiRaintank extends GuiForestryTitled { public GuiRaintank(InventoryPlayer inventory, MachineRaintank tile) { super(Defaults.TEXTURE_PATH_GUI + "/raintank.png", new ContainerRaintank(inventory, tile), tile); widgetManager.add(new TankWidget(this.widgetManager, 53, 17, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiSqueezer.java b/src/main/java/forestry/factory/gui/GuiSqueezer.java index c09c07dc1..93797d6ec 100755 --- a/src/main/java/forestry/factory/gui/GuiSqueezer.java +++ b/src/main/java/forestry/factory/gui/GuiSqueezer.java @@ -13,25 +13,17 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineSqueezer; -public class GuiSqueezer extends GuiForestry { +public class GuiSqueezer extends GuiForestryTitled { public GuiSqueezer(InventoryPlayer inventory, MachineSqueezer tile) { super(Defaults.TEXTURE_PATH_GUI + "/squeezer.png", new ContainerSqueezer(inventory, tile), tile); widgetManager.add(new TankWidget(this.widgetManager, 85, 15, 0)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiStill.java b/src/main/java/forestry/factory/gui/GuiStill.java index 74f8f437c..2fcb8cd1f 100755 --- a/src/main/java/forestry/factory/gui/GuiStill.java +++ b/src/main/java/forestry/factory/gui/GuiStill.java @@ -13,12 +13,11 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; -import forestry.core.utils.StringUtil; import forestry.factory.gadgets.MachineStill; -public class GuiStill extends GuiForestry { +public class GuiStill extends GuiForestryTitled { public GuiStill(InventoryPlayer inventory, MachineStill tile) { super(Defaults.TEXTURE_PATH_GUI + "/still.png", new ContainerStill(inventory, tile), tile); @@ -26,13 +25,6 @@ public class GuiStill extends GuiForestry { widgetManager.add(new TankWidget(this.widgetManager, 125, 15, 1)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } - @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); diff --git a/src/main/java/forestry/factory/gui/GuiWorktable.java b/src/main/java/forestry/factory/gui/GuiWorktable.java index a909d4913..b1b8495d7 100755 --- a/src/main/java/forestry/factory/gui/GuiWorktable.java +++ b/src/main/java/forestry/factory/gui/GuiWorktable.java @@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; import forestry.core.config.Defaults; -import forestry.core.gui.GuiForestry; +import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.WidgetManager; import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; @@ -28,7 +28,7 @@ import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; import forestry.factory.gadgets.TileWorktable; -public class GuiWorktable extends GuiForestry { +public class GuiWorktable extends GuiForestryTitled { private class MemorizedSlot extends Widget { @@ -58,6 +58,7 @@ public class GuiWorktable extends GuiForestry { //RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); if (worktable.getMemory().isLocked(slotNumber)) { manager.gui.setZLevel(110f); @@ -81,67 +82,46 @@ public class GuiWorktable extends GuiForestry { } } - private class BookSlot extends Widget { + private class ClearWorktable extends Widget { - private final ItemStack BOOK = new ItemStack(Items.book); - - public BookSlot(WidgetManager manager, int xPos, int yPos) { + public ClearWorktable(WidgetManager manager, int xPos, int yPos) { super(manager, xPos, yPos); + width = 7; + height = 7; } @Override public void draw(int startX, int startY) { - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - manager.gui.drawItemStack(BOOK, startX + xPos, startY + yPos); - - GL11.glPopAttrib(); - } - - @Override - protected String getLegacyTooltip(EntityPlayer player) { - return StringUtil.localize("gui.worktable.clear"); } @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - container.sendRecipeClick(mouseButton, 9); + container.clearRecipe(); } } private final TileWorktable worktable; protected ContainerWorktable container; public GuiWorktable(EntityPlayer player, TileWorktable tile) { - super(Defaults.TEXTURE_PATH_GUI + "/worktable.png", new ContainerWorktable(player, tile)); + super(Defaults.TEXTURE_PATH_GUI + "/worktable.png", new ContainerWorktable(player, tile), tile); ySize = 218; worktable = tile; this.tile = tile; container = (ContainerWorktable) inventorySlots; - widgetManager.add(new BookSlot(widgetManager, 128, 38)); + final int spacing = 18; + int slot = 0; + for (int y = 0; y < 3; y++) { + int yPos = 20 + (y * spacing); + for (int x = 0; x < 3; x++) { + int xPos = 110 + (x * spacing); + widgetManager.add(new MemorizedSlot(widgetManager, xPos, yPos, slot)); + slot += 1; + } + } - widgetManager.add(new MemorizedSlot(widgetManager, 146, 20, 0)); - widgetManager.add(new MemorizedSlot(widgetManager, 146, 38, 1)); - widgetManager.add(new MemorizedSlot(widgetManager, 146, 56, 2)); - - widgetManager.add(new MemorizedSlot(widgetManager, 128, 56, 3)); - widgetManager.add(new MemorizedSlot(widgetManager, 110, 56, 4)); - - widgetManager.add(new MemorizedSlot(widgetManager, 110, 38, 5)); - widgetManager.add(new MemorizedSlot(widgetManager, 110, 20, 6)); - widgetManager.add(new MemorizedSlot(widgetManager, 128, 20, 7)); + widgetManager.add(new ClearWorktable(widgetManager, 66, 19)); } - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); - this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title")); - } } diff --git a/src/main/java/forestry/farming/gadgets/BlockMushroom.java b/src/main/java/forestry/farming/gadgets/BlockMushroom.java index bb47886ae..366b6a6ce 100755 --- a/src/main/java/forestry/farming/gadgets/BlockMushroom.java +++ b/src/main/java/forestry/farming/gadgets/BlockMushroom.java @@ -11,12 +11,16 @@ package forestry.farming.gadgets; import java.util.ArrayList; +import java.util.List; import java.util.Random; +import forestry.core.IItemTyped; import net.minecraft.block.Block; import net.minecraft.block.BlockSapling; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; @@ -29,7 +33,11 @@ import forestry.core.config.Defaults; import forestry.core.proxy.Proxies; import forestry.farming.worldgen.WorldGenBigMushroom; -public class BlockMushroom extends BlockSapling { +public class BlockMushroom extends BlockSapling implements IItemTyped { + + public enum MushroomType { + BROWN, RED; + } private final WorldGenerator[] generators; private final ItemStack[] drops; @@ -53,8 +61,9 @@ public class BlockMushroom extends BlockSapling { public ArrayList getDrops(World world, int X, int Y, int Z, int metadata, int fortune) { ArrayList ret = new ArrayList(); - int type = metadata & 0x03; - ret.add(drops[type]); + MushroomType type = getTypeFromMeta(metadata); + + ret.add(drops[type.ordinal()]); return ret; } @@ -71,13 +80,13 @@ public class BlockMushroom extends BlockSapling { return; int meta = world.getBlockMetadata(i, j, k); - int type = meta & 0x03; + MushroomType type = getTypeFromMeta(meta); int maturity = meta >> 2; tickGermling(world, i, j, k, random, type, maturity); } - private void tickGermling(World world, int i, int j, int k, Random random, int type, int maturity) { + private void tickGermling(World world, int i, int j, int k, Random random, MushroomType type, int maturity) { int lightvalue = world.getBlockLightValue(i, j + 1, k); @@ -87,7 +96,7 @@ public class BlockMushroom extends BlockSapling { if (maturity != 3) { maturity = 3; int matX = maturity << 2; - int meta = (matX | type); + int meta = (matX | type.ordinal()); world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); } else if (lightvalue <= 7) func_149878_d(world, i, j, k, random); @@ -105,7 +114,22 @@ public class BlockMushroom extends BlockSapling { world.setBlock(i, j, k, this, type, 0); } + @Override + public MushroomType getTypeFromMeta(int meta) { + meta %= 3; + if (meta >= MushroomType.values().length) + return null; + return MushroomType.values()[meta]; + } + /* ICONS */ + @SideOnly(Side.CLIENT) + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + list.add(new ItemStack(item, 1, 0)); + list.add(new ItemStack(item, 1, 1)); + } + @SideOnly(Side.CLIENT) @Override public void registerBlockIcons(IIconRegister register) { @@ -114,11 +138,14 @@ public class BlockMushroom extends BlockSapling { @SideOnly(Side.CLIENT) @Override public IIcon getIcon(int side, int meta) { - int type = meta & 0x03; - if (type > 0) + MushroomType type = getTypeFromMeta(meta); + + if (type == MushroomType.BROWN) + return Blocks.brown_mushroom.getIcon(side, meta); + else if (type == MushroomType.RED) return Blocks.red_mushroom.getIcon(side, meta); else - return Blocks.brown_mushroom.getIcon(side, meta); + return null; } } diff --git a/src/main/java/forestry/farming/gadgets/TileFarm.java b/src/main/java/forestry/farming/gadgets/TileFarm.java index 82076a604..63f87ea2d 100755 --- a/src/main/java/forestry/farming/gadgets/TileFarm.java +++ b/src/main/java/forestry/farming/gadgets/TileFarm.java @@ -349,11 +349,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { public void removeListener(IFarmListener listener) { } - @Override - public String getInventoryName() { - return "Farm"; - } - /* INTERACTION */ @Override public boolean isUseableByPlayer(EntityPlayer player) { diff --git a/src/main/java/forestry/farming/gadgets/TileHatch.java b/src/main/java/forestry/farming/gadgets/TileHatch.java index 59a52c946..d8ba476f7 100755 --- a/src/main/java/forestry/farming/gadgets/TileHatch.java +++ b/src/main/java/forestry/farming/gadgets/TileHatch.java @@ -240,6 +240,11 @@ public class TileHatch extends TileFarm implements ISidedInventory { public void closeInventory() { } + @Override + public String getInventoryName() { + return getUnlocalizedName(); + } + /** * TODO: just a specialsource workaround */ diff --git a/src/main/java/forestry/farming/gui/GuiFarm.java b/src/main/java/forestry/farming/gui/GuiFarm.java index f79759599..4de688b67 100755 --- a/src/main/java/forestry/farming/gui/GuiFarm.java +++ b/src/main/java/forestry/farming/gui/GuiFarm.java @@ -148,7 +148,7 @@ public class GuiFarm extends GuiForestry { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String title = StringUtil.localize("Farm"); + String title = StringUtil.localize("gui.farm.title"); this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title")); } diff --git a/src/main/java/forestry/farming/triggers/TriggerLowSoil.java b/src/main/java/forestry/farming/triggers/TriggerLowSoil.java index 632475f96..80b2a91f6 100755 --- a/src/main/java/forestry/farming/triggers/TriggerLowSoil.java +++ b/src/main/java/forestry/farming/triggers/TriggerLowSoil.java @@ -56,9 +56,9 @@ public class TriggerLowSoil extends Trigger { return false; ItemStack filter; - if (parameter == null || parameter.getItemStack() == null) - filter = new ItemStack(Blocks.air, threshold, -1); - else { + if (parameter == null || parameter.getItemStack() == null) { + filter = new ItemStack(Blocks.bedrock, threshold); + } else { filter = parameter.getItemStack().copy(); filter.stackSize = threshold; } diff --git a/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java b/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java index 176de6ebb..d6d755837 100755 --- a/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java @@ -10,75 +10,19 @@ ******************************************************************************/ package forestry.lepidopterology.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; - +import forestry.core.gui.ContainerAlyzer; import forestry.core.config.ForestryItem; -import forestry.core.gui.ContainerItemInventory; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.proxy.Proxies; import forestry.lepidopterology.items.ItemButterflyGE; import forestry.lepidopterology.items.ItemFlutterlyzer.FlutterlyzerInventory; -public class ContainerFlutterlyzer extends ContainerItemInventory { +import net.minecraft.entity.player.InventoryPlayer; + +public class ContainerFlutterlyzer extends ContainerAlyzer { FlutterlyzerInventory inventory; public ContainerFlutterlyzer(InventoryPlayer inventoryplayer, FlutterlyzerInventory inventory) { - super(inventory, inventoryplayer.player); - - this.inventory = inventory; - - // Energy - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_ENERGY, 172, 8, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop })); - - // Bee to analyze - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_SPECIMEN, 172, 26, new Object[] { ItemButterflyGE.class, Blocks.sapling })); - - // Analyzed bee - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_ANALYZE_1, 172, 57, new Object[] { ItemButterflyGE.class })); - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_ANALYZE_2, 172, 75, new Object[] { ItemButterflyGE.class })); - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_ANALYZE_3, 172, 93, new Object[] { ItemButterflyGE.class })); - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_ANALYZE_4, 172, 111, new Object[] { ItemButterflyGE.class })); - this.addSlot(new SlotCustom(inventory, FlutterlyzerInventory.SLOT_ANALYZE_5, 172, 129, new Object[] { ItemButterflyGE.class })); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) - for (int l1 = 0; l1 < 9; l1++) - addSecuredSlot(inventoryplayer, l1 + i1 * 9 + 9, 18 + l1 * 18, 156 + i1 * 18); - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) - addSecuredSlot(inventoryplayer, j1, 18 + j1 * 18, 214); - - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) { - - if (!Proxies.common.isSimulating(entityplayer.worldObj)) - return; - - // Last slot is the energy slot, so we don't save that one. - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (i == FlutterlyzerInventory.SLOT_ENERGY) - continue; - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - Proxies.common.dropItemPlayer(entityplayer, stack); - inventory.setInventorySlotContents(i, null); - } - - inventory.onGuiSaved(entityplayer); - - } - - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return true; + super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, new Object[] { ItemButterflyGE.class }); } } diff --git a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java index b26f67053..fc117ca51 100755 --- a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java @@ -45,8 +45,7 @@ public class GuiFlutterlyzer extends GuiAlyzer { super(AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"), player, new ContainerFlutterlyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory()); - xSize = 196; - ySize = 238; + guiName = "gui.flutterlyzer"; ArrayList butterflyList = new ArrayList(); ((ItemButterflyGE) ForestryItem.butterflyGE.item()).addCreativeItems(butterflyList, false); @@ -97,35 +96,6 @@ public class GuiFlutterlyzer extends GuiAlyzer { } - private void drawAnalyticsOverview() { - - startPage(); - - newLine(); - String title = StringUtil.localize("gui.flutterlyzer").toUpperCase(); - drawCenteredLine(title, 8, 158); - newLine(); - - fontRendererObj.drawSplitString(StringUtil.localize("gui.flutterlyzer.help"), (int) ((guiLeft + COLUMN_0 + 4) * (1 / factor)), - (int) ((guiTop + 42) * (1 / factor)), (int) (158 * (1 / factor)), fontColor.get("gui.screen")); - newLine(); - newLine(); - newLine(); - newLine(); - - drawLine(StringUtil.localize("gui.beealyzer.overview") + ":", COLUMN_0 + 4); - newLine(); - drawLine("I : " + StringUtil.localize("gui.general"), COLUMN_0 + 4); - newLine(); - drawLine("II : " + StringUtil.localize("gui.environment"), COLUMN_0 + 4); - newLine(); - drawLine("III: " + StringUtil.localize("gui.produce"), COLUMN_0 + 4); - newLine(); - drawLine("IV : " + StringUtil.localize("gui.evolution"), COLUMN_0 + 4); - - endPage(); - } - private void drawAnalyticsPage1(IButterfly butterfly) { startPage(COLUMN_0, COLUMN_1, COLUMN_2); diff --git a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java index 9d56cfbd9..8d037ae50 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java @@ -13,9 +13,9 @@ package forestry.lepidopterology.items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; +import forestry.core.utils.AlyzerInventory; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.api.lepidopterology.IButterfly; @@ -27,21 +27,11 @@ import forestry.core.interfaces.IHintSource; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; import forestry.plugins.PluginLepidopterology; public class ItemFlutterlyzer extends ItemInventoried { - public static class FlutterlyzerInventory extends ItemInventory implements IErrorSource, IHintSource { - - public final static int SLOT_SPECIMEN = 0; - public final static int SLOT_ANALYZE_1 = 1; - public final static int SLOT_ANALYZE_2 = 2; - public final static int SLOT_ANALYZE_3 = 3; - public final static int SLOT_ANALYZE_4 = 4; - public final static int SLOT_ANALYZE_5 = 6; - public final static int SLOT_ENERGY = 5; - EntityPlayer player; + public static class FlutterlyzerInventory extends AlyzerInventory implements IErrorSource, IHintSource { public FlutterlyzerInventory(EntityPlayer player) { super(ItemFlutterlyzer.class, 7); @@ -53,22 +43,6 @@ public class ItemFlutterlyzer extends ItemInventoried { this.player = player; } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - - NBTTagList nbttaglist = new NBTTagList(); - for (int i = SLOT_ENERGY; i < SLOT_ENERGY + 1; i++) { - if (inventoryStacks[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - inventoryStacks[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - } - nbttagcompound.setTag("Items", nbttaglist); - - } - private boolean isEnergy(ItemStack itemstack) { if (itemstack == null || itemstack.stackSize <= 0) return false; diff --git a/src/main/java/forestry/mail/CommandMail.java b/src/main/java/forestry/mail/CommandMail.java index 0fb18a23c..d0cd4ed6b 100755 --- a/src/main/java/forestry/mail/CommandMail.java +++ b/src/main/java/forestry/mail/CommandMail.java @@ -12,7 +12,6 @@ package forestry.mail; import java.util.List; -import forestry.api.mail.MailAddress; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; diff --git a/src/main/java/forestry/mail/EnumAddressee.java b/src/main/java/forestry/mail/EnumAddressee.java deleted file mode 100755 index 30aa2b2d1..000000000 --- a/src/main/java/forestry/mail/EnumAddressee.java +++ /dev/null @@ -1,30 +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.mail; - -import java.util.Locale; - -public enum EnumAddressee { - PLAYER, TRADER; - - public static EnumAddressee fromString(String ident) { - for(EnumAddressee addr : values()) { - if(addr.toString().equals(ident)) - return addr; - } - - return null; - } - - public static String asString(EnumAddressee addressee) { - return addressee.toString().toLowerCase(Locale.ENGLISH); - } -} diff --git a/src/main/java/forestry/mail/Letter.java b/src/main/java/forestry/mail/Letter.java index 515cc3be9..62641f252 100755 --- a/src/main/java/forestry/mail/Letter.java +++ b/src/main/java/forestry/mail/Letter.java @@ -19,7 +19,7 @@ import net.minecraft.nbt.NBTTagCompound; import forestry.api.core.INBTTagable; import forestry.api.mail.ILetter; import forestry.api.mail.IStamps; -import forestry.api.mail.MailAddress; +import forestry.api.mail.IMailAddress; import forestry.core.utils.InventoryAdapter; import forestry.core.utils.StringUtil; import org.apache.commons.lang3.StringUtils; @@ -32,15 +32,15 @@ public class Letter implements ILetter, INBTTagable { private boolean isProcessed = false; - private MailAddress sender; - private MailAddress[] recipient; + private IMailAddress sender; + private IMailAddress[] recipient; private String text; private InventoryAdapter inventory = new InventoryAdapter(22, "INV"); - public Letter(MailAddress sender, MailAddress recipient) { + public Letter(IMailAddress sender, IMailAddress recipient) { this.sender = sender; - this.recipient = new MailAddress[] { recipient }; + this.recipient = new IMailAddress[] { recipient }; } public Letter(NBTTagCompound nbttagcompound) { @@ -191,7 +191,7 @@ public class Letter implements ILetter, INBTTagable { if (getRecipients().length <= 0) return false; - MailAddress recipient = getRecipients()[0]; + IMailAddress recipient = getRecipients()[0]; if (recipient == null) return false; @@ -202,36 +202,36 @@ public class Letter implements ILetter, INBTTagable { } @Override - public void setSender(MailAddress address) { + public void setSender(IMailAddress address) { this.sender = address; } @Override - public MailAddress getSender() { + public IMailAddress getSender() { return sender; } - public void setRecipients(MailAddress[] recipients) { + public void setRecipients(IMailAddress[] recipients) { this.recipient = recipients; } @Override - public void setRecipient(MailAddress address) { + public void setRecipient(IMailAddress address) { if (address == null) - this.recipient = new MailAddress[] {}; + this.recipient = new IMailAddress[] {}; else - this.recipient = new MailAddress[] { address }; + this.recipient = new IMailAddress[] { address }; } @Override - public MailAddress[] getRecipients() { + public IMailAddress[] getRecipients() { return recipient; } @Override public String getRecipientString() { String recipientString = ""; - for (MailAddress address : recipient) { + for (IMailAddress address : recipient) { if (recipientString.length() > 0) recipientString += ", "; recipientString += address.getName(); diff --git a/src/main/java/forestry/mail/MailAddress.java b/src/main/java/forestry/mail/MailAddress.java new file mode 100644 index 000000000..def51aada --- /dev/null +++ b/src/main/java/forestry/mail/MailAddress.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * 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 java.util.Locale; +import java.util.UUID; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.world.World; +import net.minecraft.entity.player.EntityPlayer; + +import com.mojang.authlib.GameProfile; + +import forestry.api.core.INBTTagable; +import forestry.core.proxy.Proxies; +import forestry.core.network.EntityNetData; +import forestry.api.mail.EnumAddressee; +import forestry.api.mail.IMailAddress; + +public class MailAddress implements INBTTagable, IMailAddress { + @EntityNetData + private EnumAddressee type; + @EntityNetData + private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players + + private static final MailAddress invalidAddress = new MailAddress(); + + public MailAddress() { + this.type = EnumAddressee.INVALID; + this.gameProfile = new GameProfile(new UUID(0,0), ""); + } + + public MailAddress(GameProfile gameProfile) { + if (gameProfile == null) + throw new IllegalArgumentException("gameProfile must not be null"); + + this.type = EnumAddressee.PLAYER; + this.gameProfile = gameProfile; + } + + public MailAddress(String name) { + if (name == null) + throw new IllegalArgumentException("name must not be null"); + + this.type = EnumAddressee.TRADER; + this.gameProfile = new GameProfile(new UUID(0,0), name); + } + + public MailAddress(IMailAddress address) { + this.type = address.getType(); + if (type == EnumAddressee.TRADER) { + String name = address.getName(); + this.gameProfile = new GameProfile(new UUID(0, 0), name); + } else if (type == EnumAddressee.PLAYER) { + this.gameProfile = address.getPlayerProfile(); + } + } + + public EnumAddressee getType() { + return type; + } + + public String getName() { + return gameProfile.getName(); + } + + @Override + public String toString() { + String name = getName().toLowerCase(Locale.ENGLISH); + if (isPlayer()) { + return type + "-" + name + "-" + gameProfile.getId(); + } else { + return type + "-" + name; + } + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof MailAddress)) + return false; + + MailAddress address = (MailAddress)o; + return address.gameProfile.equals(gameProfile); + } + + @Override + public int hashCode() { + return gameProfile.hashCode(); + } + + public boolean isPlayer() { + return type == EnumAddressee.PLAYER; + } + + public boolean isValid() { + return type != EnumAddressee.INVALID; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + type = EnumAddressee.INVALID; + if(nbttagcompound.hasKey("TP")) { + String typeName = nbttagcompound.getString("TP"); + type = EnumAddressee.fromString(typeName); + } + + if (!isValid()) { + gameProfile = invalidAddress.gameProfile; + } else if(nbttagcompound.hasKey("profile")) { + NBTTagCompound profileTag = nbttagcompound.getCompoundTag("profile"); + gameProfile = NBTUtil.func_152459_a(profileTag); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + nbttagcompound.setString("TP", type.toString()); + + if (gameProfile != null) { + NBTTagCompound profileNbt = new NBTTagCompound(); + NBTUtil.func_152460_a(profileNbt, gameProfile); + nbttagcompound.setTag("profile", profileNbt); + } + } + + public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) { + MailAddress address = new MailAddress(); + address.readFromNBT(nbttagcompound); + return address; + } + + public EntityPlayer getPlayer(World world) { + if (!this.isPlayer()) + return null; + + return world.getPlayerEntityByName(this.gameProfile.getName()); + } + + public boolean isClientPlayer(World world) { + if (!this.isPlayer()) + return false; + + EntityPlayer addressPlayer = this.getPlayer(world); + EntityPlayer clientPlayer = Proxies.common.getPlayer(); + + return addressPlayer != null && clientPlayer != null && clientPlayer.equals(addressPlayer); + } + + public GameProfile getPlayerProfile() { + if (!this.isPlayer()) + return null; + return gameProfile; + } +} diff --git a/src/main/java/forestry/mail/POBox.java b/src/main/java/forestry/mail/POBox.java index 261ce5e3e..5fbc694f2 100755 --- a/src/main/java/forestry/mail/POBox.java +++ b/src/main/java/forestry/mail/POBox.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.mail; -import forestry.api.mail.MailAddress; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -19,6 +18,7 @@ import net.minecraft.world.WorldSavedData; import forestry.api.mail.ILetter; import forestry.api.mail.PostManager; +import forestry.api.mail.IMailAddress; import forestry.core.utils.InventoryAdapter; public class POBox extends WorldSavedData implements IInventory { @@ -26,10 +26,10 @@ public class POBox extends WorldSavedData implements IInventory { public static final String SAVE_NAME = "POBox_"; public static final short SLOT_SIZE = 84; - private MailAddress address; + private IMailAddress address; private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters"); - public POBox(MailAddress address) { + public POBox(IMailAddress address) { super(SAVE_NAME + address); if (!address.isPlayer()) { throw new IllegalArgumentException("POBox address must be a player"); diff --git a/src/main/java/forestry/mail/PacketHandlerMail.java b/src/main/java/forestry/mail/PacketHandlerMail.java index 9678186cd..d971f9446 100755 --- a/src/main/java/forestry/mail/PacketHandlerMail.java +++ b/src/main/java/forestry/mail/PacketHandlerMail.java @@ -12,7 +12,6 @@ package forestry.mail; import java.io.DataInputStream; -import forestry.api.mail.MailAddress; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; @@ -24,7 +23,7 @@ import forestry.mail.gui.ContainerCatalogue; import forestry.mail.gui.ContainerLetter; import forestry.mail.gui.ContainerTradeName; import forestry.mail.network.PacketPOBoxInfo; -import forestry.mail.network.PacketTradeInfo; +import forestry.mail.network.PacketLetterInfo; import forestry.plugins.PluginMail; public class PacketHandlerMail implements IPacketHandler { @@ -36,10 +35,10 @@ public class PacketHandlerMail implements IPacketHandler { PacketUpdate packet; switch (packetID) { - case PacketIds.TRADING_INFO: - PacketTradeInfo packetT = new PacketTradeInfo(); + case PacketIds.LETTER_INFO: + PacketLetterInfo packetT = new PacketLetterInfo(); packetT.readData(data); - onTradeInfo(packetT); + onLetterInfo(packetT); break; case PacketIds.POBOX_INFO: PacketPOBoxInfo packetP = new PacketPOBoxInfo(); @@ -70,11 +69,11 @@ public class PacketHandlerMail implements IPacketHandler { } } - private void onTradeInfo(PacketTradeInfo packet) { + private void onLetterInfo(PacketLetterInfo packet) { Container container = Proxies.common.getClientInstance().thePlayer.openContainer; if (container instanceof ContainerLetter) { - ((ContainerLetter) container).handleTradeInfoUpdate(packet); + ((ContainerLetter) container).handleLetterInfoUpdate(packet); } else if(container instanceof ContainerCatalogue) { ((ContainerCatalogue) container).handleTradeInfoUpdate(packet); } diff --git a/src/main/java/forestry/mail/PostOffice.java b/src/main/java/forestry/mail/PostOffice.java index c75ffe303..422cfaed3 100755 --- a/src/main/java/forestry/mail/PostOffice.java +++ b/src/main/java/forestry/mail/PostOffice.java @@ -12,15 +12,12 @@ package forestry.mail; import java.io.File; import java.util.LinkedHashMap; -import java.util.UUID; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; -import com.mojang.authlib.GameProfile; - import forestry.api.mail.EnumPostage; import forestry.api.mail.ILetter; import forestry.api.mail.IPostOffice; @@ -28,8 +25,8 @@ import forestry.api.mail.IPostalCarrier; import forestry.api.mail.IPostalState; import forestry.api.mail.IStamps; import forestry.api.mail.ITradeStation; -import forestry.api.mail.MailAddress; import forestry.api.mail.PostManager; +import forestry.api.mail.IMailAddress; import forestry.core.config.ForestryItem; public class PostOffice extends WorldSavedData implements IPostOffice { @@ -47,6 +44,10 @@ public class PostOffice extends WorldSavedData implements IPostOffice { super(s); } + public void setWorld(World world) { + refreshActiveTradeStations(world); + } + @Override public void readFromNBT(NBTTagCompound nbttagcompound) { for (int i = 0; i < collectedPostage.length; i++) { @@ -63,18 +64,15 @@ public class PostOffice extends WorldSavedData implements IPostOffice { } /* TRADE STATION MANAGMENT */ - private LinkedHashMap activeTradeStations; + private LinkedHashMap activeTradeStations; @Override - public LinkedHashMap getActiveTradeStations(World world) { - if (activeTradeStations == null) - refreshActiveTradeStations(world); - + public LinkedHashMap getActiveTradeStations(World world) { return this.activeTradeStations; } private void refreshActiveTradeStations(World world) { - activeTradeStations = new LinkedHashMap(); + activeTradeStations = new LinkedHashMap(); if (world == null || world.getSaveHandler() == null) return; File worldSave = world.getSaveHandler().getMapFileFromName("dummy"); @@ -101,18 +99,12 @@ public class PostOffice extends WorldSavedData implements IPostOffice { @Override public void registerTradeStation(ITradeStation trade) { - if (activeTradeStations == null) - return; - if (!activeTradeStations.containsKey(trade.getAddress())) activeTradeStations.put(trade.getAddress(), trade); } @Override public void deregisterTradeStation(ITradeStation trade) { - if (activeTradeStations == null) - return; - activeTradeStations.remove(trade.getAddress()); } @@ -166,8 +158,8 @@ public class PostOffice extends WorldSavedData implements IPostOffice { return EnumDeliveryState.NOT_MAILABLE; IPostalState state = EnumDeliveryState.NOT_MAILABLE; - for (MailAddress address : letter.getRecipients()) { - IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType()); + for (IMailAddress address : letter.getRecipients()) { + IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType().toString()); if (carrier == null) continue; state = carrier.deliverLetter(world, this, address, itemstack, doLodge); diff --git a/src/main/java/forestry/mail/PostRegistry.java b/src/main/java/forestry/mail/PostRegistry.java index d9a5c9c04..6e9a730bf 100755 --- a/src/main/java/forestry/mail/PostRegistry.java +++ b/src/main/java/forestry/mail/PostRegistry.java @@ -25,8 +25,8 @@ import forestry.api.mail.IPostOffice; import forestry.api.mail.IPostRegistry; import forestry.api.mail.IPostalCarrier; import forestry.api.mail.ITradeStation; -import forestry.api.mail.MailAddress; import forestry.api.mail.PostManager; +import forestry.api.mail.IMailAddress; import forestry.core.config.ForestryItem; import forestry.mail.items.ItemLetter; import forestry.plugins.PluginMail; @@ -34,8 +34,8 @@ import forestry.plugins.PluginMail; public class PostRegistry implements IPostRegistry { public static PostOffice cachedPostOffice; - public static HashMap cachedPOBoxes = new HashMap(); - public static HashMap cachedTradeStations = new HashMap(); + public static HashMap cachedPOBoxes = new HashMap(); + public static HashMap cachedTradeStations = new HashMap(); /** * @param world the Minecraft world the PO box will be in @@ -43,11 +43,11 @@ public class PostRegistry implements IPostRegistry { * @return true if the passed address is valid for PO Boxes. */ @Override - public boolean isValidPOBox(World world, MailAddress address) { + public boolean isValidPOBox(World world, IMailAddress address) { return address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$"); } - public static POBox getPOBox(World world, MailAddress address) { + public static POBox getPOBox(World world, IMailAddress address) { if (cachedPOBoxes.containsKey(address)) return cachedPOBoxes.get(address); @@ -58,7 +58,7 @@ public class PostRegistry implements IPostRegistry { return pobox; } - public static POBox getOrCreatePOBox(World world, MailAddress address) { + public static POBox getOrCreatePOBox(World world, IMailAddress address) { POBox pobox = getPOBox(world, address); if (pobox == null) { @@ -78,7 +78,7 @@ public class PostRegistry implements IPostRegistry { * @return true if the passed address can be an address for a trade station */ @Override - public boolean isValidTradeAddress(World world, MailAddress address) { + public boolean isValidTradeAddress(World world, IMailAddress address) { return !address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$"); } @@ -88,12 +88,12 @@ public class PostRegistry implements IPostRegistry { * @return true if the trade address has not yet been used before. */ @Override - public boolean isAvailableTradeAddress(World world, MailAddress address) { + public boolean isAvailableTradeAddress(World world, IMailAddress address) { return getTradeStation(world, address) == null; } @Override - public TradeStation getTradeStation(World world, MailAddress address) { + public TradeStation getTradeStation(World world, IMailAddress address) { if (cachedTradeStations.containsKey(address)) return (TradeStation)cachedTradeStations.get(address); @@ -110,7 +110,7 @@ public class PostRegistry implements IPostRegistry { } @Override - public TradeStation getOrCreateTradeStation(World world, GameProfile owner, MailAddress address) { + public TradeStation getOrCreateTradeStation(World world, GameProfile owner, IMailAddress address) { TradeStation trade = getTradeStation(world, address); if (trade == null) { @@ -125,7 +125,7 @@ public class PostRegistry implements IPostRegistry { } @Override - public void deleteTradeStation(World world, MailAddress address) { + public void deleteTradeStation(World world, IMailAddress address) { TradeStation trade = getTradeStation(world, address); if (trade == null) return; @@ -151,10 +151,22 @@ public class PostRegistry implements IPostRegistry { world.setItemData(PostOffice.SAVE_NAME, office); } + office.setWorld(world); + cachedPostOffice = office; return office; } + @Override + public IMailAddress getMailAddress(GameProfile gameProfile) { + return new MailAddress(gameProfile); + } + + @Override + public IMailAddress getMailAddress(String traderName) { + return new MailAddress(traderName); + } + /* CARRIER */ private final HashMap carriers = new HashMap(); @@ -175,7 +187,7 @@ public class PostRegistry implements IPostRegistry { /* LETTERS */ @Override - public ILetter createLetter(MailAddress sender, MailAddress recipient) { + public ILetter createLetter(IMailAddress sender, IMailAddress recipient) { return new Letter(sender, recipient); } diff --git a/src/main/java/forestry/mail/PostalCarrier.java b/src/main/java/forestry/mail/PostalCarrier.java index c53b43740..fc68c13b9 100755 --- a/src/main/java/forestry/mail/PostalCarrier.java +++ b/src/main/java/forestry/mail/PostalCarrier.java @@ -20,8 +20,6 @@ import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import com.mojang.authlib.GameProfile; - import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; import forestry.plugins.PluginMail; @@ -55,14 +53,14 @@ public class PostalCarrier implements IPostalCarrier { } @Override - public IPostalState deliverLetter(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doDeliver) { + public IPostalState deliverLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doDeliver) { if(type == EnumAddressee.TRADER) return handleTradeLetter(world, office, recipient, letterstack, doDeliver); else return storeInPOBox(world, office, recipient, letterstack, doDeliver); } - private IPostalState handleTradeLetter(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doLodge) { + private IPostalState handleTradeLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { IPostalState state = EnumDeliveryState.NOT_MAILABLE; ITradeStation trade = PostManager.postRegistry.getTradeStation(world, recipient); @@ -74,7 +72,7 @@ public class PostalCarrier implements IPostalCarrier { return state; } - private EnumDeliveryState storeInPOBox(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doLodge) { + private EnumDeliveryState storeInPOBox(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { POBox pobox = PostRegistry.getPOBox(world, recipient); if (pobox == null) diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index bae1dd188..677ada2ec 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -28,9 +28,9 @@ import forestry.api.mail.ILetter; import forestry.api.mail.IPostalState; import forestry.api.mail.IStamps; import forestry.api.mail.ITradeStation; -import forestry.api.mail.MailAddress; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; +import forestry.api.mail.IMailAddress; import forestry.core.config.ForestryItem; import forestry.core.utils.InventoryAdapter; import forestry.core.utils.StackUtils; @@ -40,26 +40,29 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve // / CONSTANTS public static final String SAVE_NAME = "TradePO_"; - public static final short SLOT_SIZE = 39; public static final short SLOT_TRADEGOOD = 0; + public static final short SLOT_TRADEGOOD_COUNT = 1; public static final short SLOT_EXCHANGE_1 = 1; public static final short SLOT_EXCHANGE_COUNT = 4; public static final short SLOT_LETTERS_1 = 5; public static final short SLOT_LETTERS_COUNT = 6; public static final short SLOT_STAMPS_1 = 11; public static final short SLOT_STAMPS_COUNT = 4; - public static final short SLOT_INPUTBUF_1 = 15; - public static final short SLOT_OUTPUTBUF_1 = 27; - public static final short SLOT_BUFFER_COUNT = 12; + public static final short SLOT_RECEIVE_BUFFER = 15; + public static final short SLOT_RECEIVE_BUFFER_COUNT = 15; + public static final short SLOT_SEND_BUFFER = 30; + public static final short SLOT_SEND_BUFFER_COUNT = 10; + public static final short 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 MailAddress address; + private IMailAddress address; private boolean isVirtual = false; private boolean isInvalid = false; private final InventoryAdapter inventory = new InventoryAdapter(SLOT_SIZE, "INV"); // / CONSTRUCTORS - public TradeStation(GameProfile owner, MailAddress address) { + public TradeStation(GameProfile owner, IMailAddress address) { super(SAVE_NAME + address); if (address.isPlayer()) { throw new IllegalArgumentException("TradeStation address must not be a player"); @@ -73,7 +76,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve } @Override - public MailAddress getAddress() { + public IMailAddress getAddress() { return this.address; } @@ -160,7 +163,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve /* ILETTERHANDLER */ @Override - public IPostalState handleLetter(World world, MailAddress recipient, ItemStack letterstack, boolean doLodge) { + public IPostalState handleLetter(World world, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { boolean sendOwnerNotice = doLodge && owner != null; @@ -235,7 +238,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve if (stack == null) continue; - inventory.tryAddStack(stack.copy(), SLOT_OUTPUTBUF_1, SLOT_BUFFER_COUNT, false); + inventory.tryAddStack(stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false); } } @@ -275,7 +278,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve // How many orders are fillable? int itemCount = 0; - for (ItemStack stack : inventory.getStacks(SLOT_INPUTBUF_1, SLOT_BUFFER_COUNT)) { + for (ItemStack stack : inventory.getStacks(SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) { if (stack != null && stack.isItemEqual(tradegood) && ItemStack.areItemStackTagsEqual(stack, tradegood)) itemCount += stack.stackSize; } @@ -283,13 +286,20 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve return (int) Math.floor(itemCount / tradegood.stackSize); } + public boolean canReceivePayment() { + InventoryAdapter test = inventory.copy(); + ItemStack [] payment = inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT); + + return test.tryAddStacksCopy(payment, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true); + } + private int countStorablePayment(int max, ItemStack[] exchange) { InventoryAdapter test = inventory.copy(); int count = 0; for (int i = 0; i < max; i++) { - if (test.tryAddStacksCopy(exchange, true)) + if (test.tryAddStacksCopy(exchange, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true)) count++; else break; @@ -302,7 +312,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve for (int j = 0; j < filled; j++) { int toRemove = inventory.getStackInSlot(SLOT_TRADEGOOD).stackSize; - for (int i = SLOT_INPUTBUF_1; i < SLOT_INPUTBUF_1 + SLOT_BUFFER_COUNT; i++) { + for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) { ItemStack buffer = inventory.getStackInSlot(i); if (buffer == null) continue; diff --git a/src/main/java/forestry/mail/gadgets/MachineMailbox.java b/src/main/java/forestry/mail/gadgets/MachineMailbox.java index e289970e9..6e6645d13 100755 --- a/src/main/java/forestry/mail/gadgets/MachineMailbox.java +++ b/src/main/java/forestry/mail/gadgets/MachineMailbox.java @@ -12,6 +12,7 @@ package forestry.mail.gadgets; import java.util.LinkedList; +import com.mojang.authlib.GameProfile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; @@ -26,8 +27,8 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.ISpecialInventory; import forestry.api.mail.ILetter; import forestry.api.mail.IPostalState; -import forestry.api.mail.MailAddress; import forestry.api.mail.PostManager; +import forestry.api.mail.IMailAddress; import forestry.core.config.Config; import forestry.core.gadgets.TileBase; @@ -52,7 +53,7 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial @Override public String getInventoryName() { - return "mail.0"; + return getUnlocalizedName(); } /* GUI */ @@ -86,17 +87,21 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial /* MAIL HANDLING */ public IInventory getOrCreateMailInventory() { + return getOrCreateMailInventory(null); + } + public IInventory getOrCreateMailInventory(EntityPlayer player) { - // Handle client side - if (!Proxies.common.isSimulating(worldObj)) + GameProfile playerProfile; + if (player != null) { + playerProfile = player.getGameProfile(); + } else { + playerProfile = getOwnerProfile(); + } + + if (playerProfile == null) return new InventoryAdapter(POBox.SLOT_SIZE, "Letters"); - EntityPlayer player = Proxies.common.getPlayer(); - - if (player == null || player.getGameProfile() == null) - return new InventoryAdapter(POBox.SLOT_SIZE, "Letters"); - - MailAddress address = new MailAddress(player.getGameProfile()); + IMailAddress address = PostManager.postRegistry.getMailAddress(playerProfile); return PostRegistry.getOrCreatePOBox(worldObj, address); } diff --git a/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java b/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java index 27531aa05..5352cf720 100755 --- a/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java +++ b/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java @@ -37,7 +37,7 @@ public class MachinePhilatelist extends TileBase implements IInventory { @Override public String getInventoryName() { - return "mail.2"; + return getUnlocalizedName(); } @Override diff --git a/src/main/java/forestry/mail/gadgets/MachineTrader.java b/src/main/java/forestry/mail/gadgets/MachineTrader.java index 661d463f7..2b9812530 100755 --- a/src/main/java/forestry/mail/gadgets/MachineTrader.java +++ b/src/main/java/forestry/mail/gadgets/MachineTrader.java @@ -12,7 +12,6 @@ package forestry.mail.gadgets; import java.util.LinkedList; -import forestry.api.mail.MailAddress; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; @@ -28,6 +27,8 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.ISpecialInventory; import forestry.api.mail.IStamps; import forestry.api.mail.PostManager; +import forestry.api.mail.IMailAddress; +import forestry.mail.MailAddress; import forestry.core.EnumErrorCode; import forestry.core.gadgets.TileBase; import forestry.core.network.EntityNetData; @@ -41,7 +42,7 @@ import forestry.plugins.PluginMail; public class MachineTrader extends TileBase implements ISpecialInventory, ISidedInventory { @EntityNetData - public MailAddress address; + private MailAddress address; public MachineTrader() { address = new MailAddress(); @@ -49,7 +50,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided @Override public String getInventoryName() { - return "mail.1"; + return getUnlocalizedName(); } @Override @@ -89,21 +90,61 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided } /* UPDATING */ + + /** + * The trade station should show errors for missing stamps and paper first. + * Once it is able to send letters, it should display other error states. + */ @Override public void updateServerSide() { - if (worldObj.getTotalWorldTime() % 40 * 10 != 0) + if (!isLinked() || worldObj.getTotalWorldTime() % 4 != 0) return; - if (!hasPaperMin(0.0f) || !hasInputBufMin(0.0f)) { - setErrorState(EnumErrorCode.NORESOURCE); + EnumErrorCode errorCode = EnumErrorCode.OK; + + if (!hasPostageMin(3)) + errorCode = EnumErrorCode.NOSTAMPS; + + if (!hasPaperMin(2)) { + if (errorCode == EnumErrorCode.NOSTAMPS) + errorCode = EnumErrorCode.NOSTAMPSNOPAPER; + else + errorCode = EnumErrorCode.NOPAPER; + } + + if (errorCode != EnumErrorCode.OK) { + setErrorState(errorCode); return; } - if (!hasPostageMin(3)) { // Assumes that the trade station owner should have a notice. - setErrorState(EnumErrorCode.NOSTAMPS); + + IInventory inventory = getOrCreateTradeInventory(); + ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD); + + if (tradeGood == null) { + setErrorState(EnumErrorCode.NOTRADE); return; } + boolean hasRequest = hasItemCount(TradeStation.SLOT_EXCHANGE_1, TradeStation.SLOT_EXCHANGE_COUNT, null, 1); + if (!hasRequest) { + setErrorState(EnumErrorCode.NOTRADE); + return; + } + + boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.stackSize); + if(!hasSupplies) { + setErrorState(EnumErrorCode.NOSUPPLIES); + return; + } + + if (inventory instanceof TradeStation) { + if (!((TradeStation)inventory).canReceivePayment()) { + setErrorState(EnumErrorCode.NOSPACE); + return; + } + } + setErrorState(EnumErrorCode.OK); } @@ -113,31 +154,64 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided return address.isValid(); } - private float percentOccupied(int startSlot, int countSlots) { - int max = 0; - int avail = 0; + /** + * Returns true if there are 'itemCount' of 'item' in the inventory + * wildcard when item == null, counts all types of items + */ + private boolean hasItemCount(int startSlot, int countSlots, ItemStack item, int itemCount) { + int count = 0; IInventory tradeInventory = this.getOrCreateTradeInventory(); for (int i = startSlot; i < startSlot + countSlots; i++) { - max += 64; - if (tradeInventory.getStackInSlot(i) == null) + ItemStack itemInSlot = tradeInventory.getStackInSlot(i); + if (itemInSlot == null) continue; - avail += tradeInventory.getStackInSlot(i).stackSize; + if (item == null || StackUtils.isIdenticalItem(itemInSlot, item)) + count += itemInSlot.stackSize; + if (count >= itemCount) + return true; } - return ((float) avail / (float) max); + return false; } - public boolean hasPaperMin(float percentage) { - return percentOccupied(TradeStation.SLOT_LETTERS_1, TradeStation.SLOT_LETTERS_COUNT) > percentage; + /** + * Returns the percentage of the inventory that is occupied by 'item' + * if item == null, returns the percentage occupied by all kinds of items + */ + private float percentOccupied(int startSlot, int countSlots, ItemStack item) { + int count = 0; + int total = 0; + + IInventory tradeInventory = this.getOrCreateTradeInventory(); + for (int i = startSlot; i < startSlot + countSlots; i++) { + ItemStack itemInSlot = tradeInventory.getStackInSlot(i); + if (itemInSlot == null) { + total += 64; + } else { + total += itemInSlot.getMaxStackSize(); + if (item == null || StackUtils.isIdenticalItem(itemInSlot, item)) + count += itemInSlot.stackSize; + } + } + + return ((float)count / (float)total); + } + + public boolean hasPaperMin(int count) { + return hasItemCount(TradeStation.SLOT_LETTERS_1, TradeStation.SLOT_LETTERS_COUNT, new ItemStack(Items.paper), count); } public boolean hasInputBufMin(float percentage) { - return percentOccupied(TradeStation.SLOT_INPUTBUF_1, TradeStation.SLOT_BUFFER_COUNT) > percentage; + IInventory inventory = getOrCreateTradeInventory(); + ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD); + if (tradeGood == null) + return true; + return percentOccupied(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood) > percentage; } public boolean hasOutputBufMin(float percentage) { - return percentOccupied(TradeStation.SLOT_OUTPUTBUF_1, TradeStation.SLOT_BUFFER_COUNT) > percentage; + return percentOccupied(TradeStation.SLOT_RECEIVE_BUFFER, TradeStation.SLOT_RECEIVE_BUFFER_COUNT, null) > percentage; } public boolean hasPostageMin(int postage) { @@ -153,17 +227,19 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided continue; posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.stackSize; + if (posted >= postage) + return true; } - return posted >= postage; + return false; } /* ADDRESS */ - public MailAddress getAddress() { + public IMailAddress getAddress() { return address; } - public void setAddress(MailAddress address) { + public void setAddress(IMailAddress address) { if (address == null) throw new NullPointerException("address must not be null"); @@ -181,12 +257,11 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided return; } - this.address = address; + this.address = new MailAddress(address); PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address); setErrorState(EnumErrorCode.OK); - sendNetworkUpdate(); } else - this.address = address; + this.address = new MailAddress(address); } /* TRADING */ @@ -231,7 +306,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided if (!tradegood.isItemEqual(stack)) return 0; - return StackUtils.addToInventory(stack, inventory, doAdd, TradeStation.SLOT_INPUTBUF_1, TradeStation.SLOT_BUFFER_COUNT); + return StackUtils.addToInventory(stack, inventory, doAdd, TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT); } @Override @@ -242,7 +317,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided ItemStack product = null; IInventory inventory = getOrCreateTradeInventory(); - for (int i = TradeStation.SLOT_OUTPUTBUF_1; i < TradeStation.SLOT_OUTPUTBUF_1 + TradeStation.SLOT_BUFFER_COUNT; i++) { + for (int i = TradeStation.SLOT_RECEIVE_BUFFER; i < TradeStation.SLOT_RECEIVE_BUFFER + TradeStation.SLOT_RECEIVE_BUFFER_COUNT; i++) { ItemStack stackSlot = inventory.getStackInSlot(i); if (stackSlot == null) continue; @@ -278,7 +353,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) return false; - if(slotIndex >= TradeStation.SLOT_OUTPUTBUF_1 && slotIndex < TradeStation.SLOT_OUTPUTBUF_1 + TradeStation.SLOT_BUFFER_COUNT) + if(slotIndex >= TradeStation.SLOT_RECEIVE_BUFFER && slotIndex < TradeStation.SLOT_RECEIVE_BUFFER + TradeStation.SLOT_RECEIVE_BUFFER_COUNT) return true; return false; @@ -298,7 +373,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided return itemstack.getItem() instanceof IStamps; } - if (slotIndex >= TradeStation.SLOT_INPUTBUF_1 && slotIndex < TradeStation.SLOT_BUFFER_COUNT) { + if (slotIndex >= TradeStation.SLOT_SEND_BUFFER && slotIndex < TradeStation.SLOT_SEND_BUFFER_COUNT) { IInventory inventory = getOrCreateTradeInventory(); ItemStack tradegood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD); if(tradegood == null) @@ -405,8 +480,8 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided @Override public LinkedList getCustomTriggers() { LinkedList res = new LinkedList(); - res.add(PluginMail.lowPaper25); - res.add(PluginMail.lowPaper10); + res.add(PluginMail.lowPaper64); + res.add(PluginMail.lowPaper32); res.add(PluginMail.lowInput25); res.add(PluginMail.lowInput10); res.add(PluginMail.lowPostage40); diff --git a/src/main/java/forestry/mail/gui/ContainerCatalogue.java b/src/main/java/forestry/mail/gui/ContainerCatalogue.java index 1b4e27641..85341d988 100755 --- a/src/main/java/forestry/mail/gui/ContainerCatalogue.java +++ b/src/main/java/forestry/mail/gui/ContainerCatalogue.java @@ -15,26 +15,27 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Set; -import forestry.api.mail.MailAddress; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.EnumAddressee; +import forestry.mail.network.PacketLetterInfo; +import forestry.mail.EnumStationState; import forestry.core.gui.ContainerForestry; import forestry.core.gui.IGuiSelectable; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; -import forestry.mail.EnumStationState; -import forestry.mail.network.PacketTradeInfo; public class ContainerCatalogue extends ContainerForestry implements IGuiSelectable { private final EntityPlayer player; - private final LinkedHashMap stations; + private final LinkedHashMap stations; private TradeStationInfo currentTrade = null; private Iterator iterator = null; @@ -57,7 +58,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta this.player = player; // Filter out any trade stations which do not actually offer anything. - stations = new LinkedHashMap(); + stations = new LinkedHashMap(); rebuildStationsList(); } @@ -183,7 +184,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta needsSynch = true; } - public void handleTradeInfoUpdate(PacketTradeInfo packet) { + public void handleTradeInfoUpdate(PacketLetterInfo packet) { setTradeInfo(packet.tradeInfo); } @@ -207,7 +208,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta crafter.sendProgressBarUpdate(this, 2, currentFilter); } - Proxies.net.sendToPlayer(new PacketTradeInfo(PacketIds.TRADING_INFO, currentTrade), player); + Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, EnumAddressee.TRADER, currentTrade, null), player); needsSynch = false; } } diff --git a/src/main/java/forestry/mail/gui/ContainerLetter.java b/src/main/java/forestry/mail/gui/ContainerLetter.java index a21c26b3a..27d4b47b8 100755 --- a/src/main/java/forestry/mail/gui/ContainerLetter.java +++ b/src/main/java/forestry/mail/gui/ContainerLetter.java @@ -11,17 +11,23 @@ package forestry.mail.gui; import java.util.Iterator; -import java.util.Locale; +import java.util.UUID; +import org.apache.commons.lang3.StringUtils; + +import com.mojang.authlib.GameProfile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; + import forestry.api.mail.ILetter; import forestry.api.mail.IPostalCarrier; import forestry.api.mail.ITradeStation; -import forestry.api.mail.MailAddress; +import forestry.api.mail.IMailAddress; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; +import forestry.api.mail.EnumAddressee; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotClosed; import forestry.core.gui.slots.SlotCustom; @@ -29,17 +35,16 @@ import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; -import forestry.mail.EnumAddressee; import forestry.mail.Letter; import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemLetter.LetterInventory; import forestry.mail.items.ItemStamps; -import forestry.mail.network.PacketTradeInfo; +import forestry.mail.network.PacketLetterInfo; public class ContainerLetter extends ContainerItemInventory { private final LetterInventory letterInventory; - private String carrier = EnumAddressee.PLAYER.toString().toLowerCase(Locale.ENGLISH); + private EnumAddressee carrier = EnumAddressee.PLAYER; private TradeStationInfo tradeInfo = null; public ContainerLetter(EntityPlayer player, LetterInventory inventory) { @@ -91,8 +96,10 @@ public class ContainerLetter extends ContainerItemInventory { if (Proxies.common.isSimulating(entityplayer.worldObj)) { ILetter letter = letterInventory.getLetter(); - if (!letter.isProcessed()) - letter.setSender(new MailAddress(entityplayer.getGameProfile())); + if (!letter.isProcessed()) { + IMailAddress sender = PostManager.postRegistry.getMailAddress(entityplayer.getGameProfile()); + letter.setSender(sender); + } } super.onContainerClosed(entityplayer); @@ -107,11 +114,11 @@ public class ContainerLetter extends ContainerItemInventory { return letterInventory.getLetter(); } - public void setCarrierType(String type) { + public void setCarrierType(EnumAddressee type) { this.carrier = type; } - public String getCarrierType() { + public EnumAddressee getCarrierType() { return this.carrier; } @@ -128,39 +135,50 @@ public class ContainerLetter extends ContainerItemInventory { else postal = PostManager.postRegistry.getRegisteredCarriers().values().iterator().next(); - setCarrierType(postal.getUID()); + EnumAddressee type = EnumAddressee.fromString(postal.getUID()); + setCarrierType(type); } - public void setRecipient(MailAddress address) { - if (address == null) + public void setRecipient(String recipientName, EnumAddressee type) { + if (StringUtils.isBlank(recipientName) || type == EnumAddressee.INVALID) return; - - getLetter().setRecipient(address); - carrier = address.getType(); // / Send to server - PacketPayload payload = new PacketPayload(0, 0, 2); - payload.stringPayload[0] = getRecipient().getName(); - payload.stringPayload[1] = this.carrier; + PacketPayload payload = new PacketPayload(0,0,2); + payload.stringPayload[0] = recipientName; + payload.stringPayload[1] = type.toString(); PacketUpdate packet = new PacketUpdate(PacketIds.LETTER_RECIPIENT, payload); Proxies.net.sendToServer(packet); } public void handleSetRecipient(EntityPlayer player, PacketUpdate packet) { - String identifierName = packet.payload.stringPayload[0]; - String type = packet.payload.stringPayload[1]; - MailAddress recipient = MailAddress.makeMailAddress(identifierName, type); + String recipientName = packet.payload.stringPayload[0]; + String typeName = packet.payload.stringPayload[1]; + + EnumAddressee type = EnumAddressee.fromString(typeName); + IMailAddress recipient; + if (type == EnumAddressee.PLAYER) { + GameProfile gameProfile = MinecraftServer.getServer().func_152358_ax().func_152655_a(recipientName); + if (gameProfile == null) + gameProfile = new GameProfile(new UUID(0, 0), recipientName); + recipient = PostManager.postRegistry.getMailAddress(gameProfile); + } else if (type == EnumAddressee.TRADER) { + recipient = PostManager.postRegistry.getMailAddress(recipientName); + } else { + return; + } + getLetter().setRecipient(recipient); // Update the trading info updateTradeInfo(player.worldObj, recipient); - // Update trade info on client - Proxies.net.sendToPlayer(new PacketTradeInfo(PacketIds.TRADING_INFO, tradeInfo), player); + // Update info on client + Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, type, tradeInfo, recipient), player); } - public MailAddress getRecipient() { + public IMailAddress getRecipient() { if (getLetter().getRecipients().length > 0) return getLetter().getRecipients()[0]; else @@ -188,7 +206,7 @@ public class ContainerLetter extends ContainerItemInventory { } /* Managing Trade info */ - public void updateTradeInfo(World world, MailAddress address) { + public void updateTradeInfo(World world, IMailAddress address) { // Updating is done by the server. if (!Proxies.common.isSimulating(world)) return; @@ -203,8 +221,13 @@ public class ContainerLetter extends ContainerItemInventory { setTradeInfo(station.getTradeInfo()); } - public void handleTradeInfoUpdate(PacketTradeInfo packet) { - this.setTradeInfo(packet.tradeInfo); + public void handleLetterInfoUpdate(PacketLetterInfo packet) { + carrier = packet.type; + if (packet.type == EnumAddressee.PLAYER) { + getLetter().setRecipient(packet.address); + } else if (packet.type == EnumAddressee.TRADER) { + this.setTradeInfo(packet.tradeInfo); + } } public TradeStationInfo getTradeInfo() { diff --git a/src/main/java/forestry/mail/gui/ContainerMailbox.java b/src/main/java/forestry/mail/gui/ContainerMailbox.java index 6d697647a..68620e852 100755 --- a/src/main/java/forestry/mail/gui/ContainerMailbox.java +++ b/src/main/java/forestry/mail/gui/ContainerMailbox.java @@ -10,7 +10,7 @@ ******************************************************************************/ package forestry.mail.gui; -import forestry.api.mail.MailAddress; +import forestry.api.mail.PostManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; @@ -22,6 +22,7 @@ import forestry.core.gui.slots.SlotClosed; import forestry.core.proxy.Proxies; import forestry.mail.POBox; import forestry.mail.gadgets.MachineMailbox; +import forestry.api.mail.IMailAddress; import forestry.plugins.PluginMail; public class ContainerMailbox extends ContainerForestry { @@ -35,7 +36,7 @@ public class ContainerMailbox extends ContainerForestry { // Mailbox contents this.mailbox = tile; - IInventory inv = mailbox.getOrCreateMailInventory(); + IInventory inv = mailbox.getOrCreateMailInventory(player.player); if (inv instanceof POBox) mailinventory = (POBox) inv; @@ -58,7 +59,7 @@ public class ContainerMailbox extends ContainerForestry { ItemStack stack = super.slotClick(slotIndex, button, par3, player); if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null) { - MailAddress address = new MailAddress(mailbox.getOwnerProfile()); + IMailAddress address = PostManager.postRegistry.getMailAddress(mailbox.getOwnerProfile()); PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), address, mailinventory.getPOBoxInfo()); } diff --git a/src/main/java/forestry/mail/gui/ContainerTradeName.java b/src/main/java/forestry/mail/gui/ContainerTradeName.java index ee3f34d3d..b97913f2e 100755 --- a/src/main/java/forestry/mail/gui/ContainerTradeName.java +++ b/src/main/java/forestry/mail/gui/ContainerTradeName.java @@ -20,7 +20,8 @@ import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.InventoryAdapter; import forestry.mail.gadgets.MachineTrader; -import forestry.api.mail.MailAddress; +import forestry.api.mail.PostManager; +import forestry.api.mail.IMailAddress; import org.apache.commons.lang3.StringUtils; @@ -35,7 +36,7 @@ public class ContainerTradeName extends ContainerForestry { isLinked = machine.isLinked(); } - public MailAddress getAddress() { + public IMailAddress getAddress() { return machine.getAddress(); } @@ -50,13 +51,13 @@ public class ContainerTradeName extends ContainerForestry { PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_ADDRESS_SET, payload); Proxies.net.sendToServer(packet); - MailAddress address = new MailAddress(addressName); + IMailAddress address = PostManager.postRegistry.getMailAddress(addressName); machine.setAddress(address); } public void handleSetAddress(PacketUpdate packet) { String addressName = packet.payload.stringPayload[0]; - MailAddress address = new MailAddress(addressName); + IMailAddress address = PostManager.postRegistry.getMailAddress(addressName); machine.setAddress(address); } diff --git a/src/main/java/forestry/mail/gui/ContainerTrader.java b/src/main/java/forestry/mail/gui/ContainerTrader.java index 26bdb81d1..ea85064cb 100755 --- a/src/main/java/forestry/mail/gui/ContainerTrader.java +++ b/src/main/java/forestry/mail/gui/ContainerTrader.java @@ -16,12 +16,11 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; import forestry.core.gui.slots.SlotCustom; import forestry.mail.TradeStation; import forestry.mail.gadgets.MachineTrader; import forestry.mail.items.ItemStamps; -import forestry.api.mail.MailAddress; +import forestry.api.mail.IMailAddress; public class ContainerTrader extends ContainerForestry { @@ -51,15 +50,15 @@ public class ContainerTrader extends ContainerForestry { for (int j = 0; j < 2; j++) addSlot(new SlotCustom(inventory, TradeStation.SLOT_LETTERS_1 + j + i * 2, 15 + j * 18, 73 + i * 18, new Object[] { Items.paper })); - // Input buffer - for (int i = 0; i < 6; i++) - for (int j = 0; j < 2; j++) - addSlot(new Slot(inventory, TradeStation.SLOT_INPUTBUF_1 + j + i * 2, 123 + j * 18, 19 + i * 18)); + // Buffers + final int bufCols = 5; + for (int i = 0; i < 3; i++) + for (int j = 0; j < bufCols; j++) + addSlot(new Slot(inventory, TradeStation.SLOT_RECEIVE_BUFFER + j + i * bufCols, 123 + j * 18, 19 + i * 18)); - // Output buffer - for (int i = 0; i < 6; i++) - for (int j = 0; j < 2; j++) - addSlot(new SlotClosed(inventory, TradeStation.SLOT_OUTPUTBUF_1 + j + i * 2, 177 + j * 18, 19 + i * 18)); + for (int i = 0; i < 2; i++) + for (int j = 0; j < bufCols; j++) + addSlot(new Slot(inventory, TradeStation.SLOT_SEND_BUFFER + j + i * bufCols, 123 + j * 18, (19 + (18 * 4)) + i * 18)); // Player inventory for (int i = 0; i < 3; i++) @@ -75,7 +74,7 @@ public class ContainerTrader extends ContainerForestry { return machine.isLinked(); } - public MailAddress getAddress() { + public IMailAddress getAddress() { return machine.getAddress(); } diff --git a/src/main/java/forestry/mail/gui/GuiCatalogue.java b/src/main/java/forestry/mail/gui/GuiCatalogue.java index 95b19e5ed..3fc16135e 100755 --- a/src/main/java/forestry/mail/gui/GuiCatalogue.java +++ b/src/main/java/forestry/mail/gui/GuiCatalogue.java @@ -23,7 +23,7 @@ import forestry.core.config.SessionVars; import forestry.core.gadgets.TileForestry; import forestry.core.gui.GuiForestry; import forestry.core.utils.StringUtil; -import forestry.mail.EnumAddressee; +import forestry.api.mail.EnumAddressee; public class GuiCatalogue extends GuiForestry { @@ -136,7 +136,7 @@ public class GuiCatalogue extends GuiForestry { TradeStationInfo info = container.getTradeInfo(); if(info != null) { SessionVars.setStringVar("mail.letter.recipient", info.address.getName()); - SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.asString(EnumAddressee.TRADER)); + SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.TRADER.toString()); } mc.displayGuiScreen((GuiScreen)null); break; diff --git a/src/main/java/forestry/mail/gui/GuiLetter.java b/src/main/java/forestry/mail/gui/GuiLetter.java index 881585196..65fb85f71 100755 --- a/src/main/java/forestry/mail/gui/GuiLetter.java +++ b/src/main/java/forestry/mail/gui/GuiLetter.java @@ -20,7 +20,7 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import forestry.api.mail.IPostalCarrier; -import forestry.api.mail.MailAddress; +import forestry.api.mail.IMailAddress; import forestry.api.mail.PostManager; import forestry.core.config.Defaults; import forestry.core.config.SessionVars; @@ -30,7 +30,7 @@ import forestry.core.gui.GuiTextBox; import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; -import forestry.mail.EnumAddressee; +import forestry.api.mail.EnumAddressee; import forestry.mail.items.ItemLetter.LetterInventory; public class GuiLetter extends GuiForestry { @@ -48,7 +48,7 @@ public class GuiLetter extends GuiForestry { GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); //mc.renderEngine.bindTexture(Defaults.TEXTURE_PATH_GUI + "/letter.png"); - IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType()); + IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType().toString()); if(carrier != null) drawTexturedModelRectFromIcon(startX + xPos, startY + yPos - 5, carrier.getIcon(), 26, 26); @@ -56,7 +56,7 @@ public class GuiLetter extends GuiForestry { @Override protected String getLegacyTooltip(EntityPlayer player) { - return StringUtil.localize("gui.addressee." + container.getCarrierType().toLowerCase(Locale.ENGLISH)); + return StringUtil.localize("gui.addressee." + container.getCarrierType().toString()); } @Override @@ -95,10 +95,9 @@ public class GuiLetter extends GuiForestry { Keyboard.enableRepeatEvents(true); address = new GuiTextField(this.fontRendererObj, guiLeft + 46, guiTop + 13, 93, 13); - MailAddress recipient = container.getRecipient(); + IMailAddress recipient = container.getRecipient(); if (recipient != null) { address.setText(recipient.getName()); - setRecipient(recipient); } text = new GuiTextBox(this.fontRendererObj, guiLeft + 17, guiTop + 31, 122, 57); @@ -158,8 +157,8 @@ public class GuiLetter extends GuiForestry { if (addressFocus != address.isFocused()) { String recipient = this.address.getText(); if (StringUtils.isNotBlank(recipient)) { - MailAddress recipientAddress = MailAddress.makeMailAddress(recipient, container.getCarrierType()); - setRecipient(recipientAddress); + EnumAddressee recipientType = container.getCarrierType(); + setRecipient(recipient, recipientType); } } addressFocus = address.isFocused(); @@ -174,7 +173,7 @@ public class GuiLetter extends GuiForestry { fontRendererObj.drawSplitString(text.getText(), guiLeft + 20, guiTop + 34, 119, fontColor.get("gui.mail.lettertext")); } else { address.drawTextBox(); - if (container.getCarrierType().equals(EnumAddressee.TRADER.toString().toLowerCase(Locale.ENGLISH))) + if (container.getCarrierType() == EnumAddressee.TRADER) drawTradePreview(guiLeft + 18, guiTop + 32); else text.drawTextBox(); @@ -215,9 +214,9 @@ public class GuiLetter extends GuiForestry { @Override public void onGuiClosed() { - MailAddress recipientAddress = MailAddress.makeMailAddress(this.address.getText(), container.getCarrierType()); - - setRecipient(recipientAddress); + String recipientName = this.address.getText(); + EnumAddressee recipientType = container.getCarrierType(); + setRecipient(recipientName, recipientType); setText(); Keyboard.enableRepeatEvents(false); super.onGuiClosed(); @@ -233,24 +232,24 @@ public class GuiLetter extends GuiForestry { return; String recipient = SessionVars.getStringVar("mail.letter.recipient"); - String type = SessionVars.getStringVar("mail.letter.addressee"); + String typeName = SessionVars.getStringVar("mail.letter.addressee"); - if (recipient != null && type != null) { + if (StringUtils.isNotBlank(recipient) && StringUtils.isNotBlank(typeName)) { address.setText(recipient); - MailAddress recipientAddress = MailAddress.makeMailAddress(recipient, type); - setRecipient(recipientAddress); + + EnumAddressee type = EnumAddressee.fromString(typeName); + setRecipient(recipient, type); } SessionVars.clearStringVar("mail.letter.recipient"); SessionVars.clearStringVar("mail.letter.addressee"); } - private void setRecipient(MailAddress recipientAddress) { - if (this.isProcessedLetter || recipientAddress == null) + private void setRecipient(String recipientName, EnumAddressee type) { + if (this.isProcessedLetter || StringUtils.isBlank(recipientName) || type == null || type == EnumAddressee.INVALID) return; - container.setRecipient(recipientAddress); - container.updateTradeInfo(this.mc.theWorld, recipientAddress); + container.setRecipient(recipientName, type); } private void setText() { diff --git a/src/main/java/forestry/mail/gui/GuiTrader.java b/src/main/java/forestry/mail/gui/GuiTrader.java index f32521eba..4ce91a6b3 100755 --- a/src/main/java/forestry/mail/gui/GuiTrader.java +++ b/src/main/java/forestry/mail/gui/GuiTrader.java @@ -16,7 +16,6 @@ import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; import forestry.core.utils.StringUtil; import forestry.mail.gadgets.MachineTrader; -import forestry.api.mail.MailAddress; public class GuiTrader extends GuiForestry { @@ -33,8 +32,14 @@ public class GuiTrader extends GuiForestry { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { super.drawGuiContainerForegroundLayer(mouseX, mouseY); - String name = StringUtil.localize("tile.for." + tile.getInventoryName()); + String name = StringUtil.localizeTile(tile.getUnlocalizedName()); this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.mail.text")); + + String receive = StringUtil.localize("gui.mail.receive"); + this.fontRendererObj.drawString(receive, getCenteredOffset(receive, 70) + 51, 45, fontColor.get("gui.mail.text")); + + String send = StringUtil.localize("gui.mail.send"); + this.fontRendererObj.drawString(send, getCenteredOffset(send, 70) + 51, 99, fontColor.get("gui.mail.text")); } @Override diff --git a/src/main/java/forestry/mail/network/PacketLetterInfo.java b/src/main/java/forestry/mail/network/PacketLetterInfo.java new file mode 100644 index 000000000..cc9ace882 --- /dev/null +++ b/src/main/java/forestry/mail/network/PacketLetterInfo.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * 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.network; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.UUID; + +import net.minecraft.item.ItemStack; +import com.mojang.authlib.GameProfile; + +import forestry.api.mail.TradeStationInfo; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.EnumAddressee; +import forestry.api.mail.PostManager; +import forestry.core.network.ForestryPacket; +import forestry.mail.EnumStationState; + +public class PacketLetterInfo extends ForestryPacket { + + public EnumAddressee type; + public TradeStationInfo tradeInfo; + public IMailAddress address; + + public PacketLetterInfo() { + } + + public PacketLetterInfo(int id, EnumAddressee type, TradeStationInfo info, IMailAddress address) { + super(id); + this.type = type; + if (type == EnumAddressee.TRADER) + this.tradeInfo = info; + else if (type == EnumAddressee.PLAYER) + this.address = address; + } + + @Override + public void writeData(DataOutputStream data) throws IOException { + + if (type == null || type == EnumAddressee.INVALID) { + data.writeShort(-1); + return; + } + + data.writeShort(0); + + data.writeUTF(type.toString()); + + if (type == EnumAddressee.PLAYER) { + + if (address == null) { + data.writeShort(-1); + return; + } + data.writeShort(0); + + GameProfile profile = address.getPlayerProfile(); + + data.writeLong(profile.getId().getMostSignificantBits()); + data.writeLong(profile.getId().getLeastSignificantBits()); + data.writeUTF(profile.getName()); + + } else if (type == EnumAddressee.TRADER) { + + if (tradeInfo == null) { + data.writeShort(-1); + return; + } + + data.writeShort(0); + + data.writeUTF(tradeInfo.address.getName()); + + data.writeLong(tradeInfo.owner.getId().getMostSignificantBits()); + data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits()); + data.writeUTF(tradeInfo.owner.getName()); + + writeItemStack(tradeInfo.tradegood, data); + data.writeShort(tradeInfo.required.length); + for (int i = 0; i < tradeInfo.required.length; i++) + writeItemStack(tradeInfo.required[i], data); + data.writeShort(tradeInfo.state.ordinal()); + } + } + + @Override + public void readData(DataInputStream data) throws IOException { + + if (data.readShort() < 0) + return; + + type = EnumAddressee.fromString(data.readUTF()); + + if (type == EnumAddressee.PLAYER) { + if (data.readShort() < 0) + return; + GameProfile player = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF()); + this.address = PostManager.postRegistry.getMailAddress(player); + + } else if (type == EnumAddressee.TRADER) { + if (data.readShort() < 0) + return; + IMailAddress address = PostManager.postRegistry.getMailAddress(data.readUTF()); + GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF()); + ItemStack tradegood; + ItemStack[] required; + + tradegood = readItemStack(data); + required = new ItemStack[data.readShort()]; + for (int i = 0; i < required.length; i++) + required[i] = readItemStack(data); + + this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]); + } + } + +} diff --git a/src/main/java/forestry/mail/network/PacketTradeInfo.java b/src/main/java/forestry/mail/network/PacketTradeInfo.java deleted file mode 100755 index 63ba14da3..000000000 --- a/src/main/java/forestry/mail/network/PacketTradeInfo.java +++ /dev/null @@ -1,82 +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.mail.network; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.UUID; - -import forestry.api.mail.MailAddress; -import net.minecraft.item.ItemStack; - -import com.mojang.authlib.GameProfile; - -import forestry.api.mail.TradeStationInfo; -import forestry.core.network.ForestryPacket; -import forestry.mail.EnumStationState; - -public class PacketTradeInfo extends ForestryPacket { - - public TradeStationInfo tradeInfo; - - public PacketTradeInfo() { - } - - public PacketTradeInfo(int id, TradeStationInfo info) { - super(id); - this.tradeInfo = info; - } - - @Override - public void writeData(DataOutputStream data) throws IOException { - - if (tradeInfo == null) { - data.writeShort(-1); - return; - } - - data.writeShort(0); - - data.writeUTF(tradeInfo.address.getName()); - - data.writeLong(tradeInfo.owner.getId().getMostSignificantBits()); - data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits()); - data.writeUTF(tradeInfo.owner.getName()); - - writeItemStack(tradeInfo.tradegood, data); - data.writeShort(tradeInfo.required.length); - for (int i = 0; i < tradeInfo.required.length; i++) - writeItemStack(tradeInfo.required[i], data); - data.writeShort(tradeInfo.state.ordinal()); - } - - @Override - public void readData(DataInputStream data) throws IOException { - - short isNotNull = data.readShort(); - if (isNotNull < 0) - return; - - MailAddress address = new MailAddress(data.readUTF()); - GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF()); - ItemStack tradegood; - ItemStack[] required; - - tradegood = readItemStack(data); - required = new ItemStack[data.readShort()]; - for (int i = 0; i < required.length; i++) - required[i] = readItemStack(data); - - this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]); - } - -} diff --git a/src/main/java/forestry/mail/proxy/ClientProxyMail.java b/src/main/java/forestry/mail/proxy/ClientProxyMail.java index 48ce4c1ae..7ffa4b197 100755 --- a/src/main/java/forestry/mail/proxy/ClientProxyMail.java +++ b/src/main/java/forestry/mail/proxy/ClientProxyMail.java @@ -10,7 +10,7 @@ ******************************************************************************/ package forestry.mail.proxy; -import forestry.api.mail.MailAddress; +import com.mojang.authlib.GameProfile; import net.minecraft.world.World; import forestry.core.network.ForestryPacket; @@ -20,6 +20,8 @@ import forestry.mail.POBox; import forestry.mail.POBoxInfo; import forestry.mail.PostRegistry; import forestry.mail.gui.GuiMailboxInfo; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.PostManager; public class ClientProxyMail extends ProxyMail { @@ -38,7 +40,8 @@ public class ClientProxyMail extends ProxyMail { if (!Proxies.common.isSimulating(Proxies.common.getRenderWorld())) Proxies.net.sendToServer(new ForestryPacket(PacketIds.POBOX_INFO_REQUEST)); else { - MailAddress address = new MailAddress(Proxies.common.getClientInstance().thePlayer.getGameProfile()); + GameProfile profile = Proxies.common.getClientInstance().thePlayer.getGameProfile(); + IMailAddress address = PostManager.postRegistry.getMailAddress(profile); POBox pobox = PostRegistry.getPOBox(Proxies.common.getRenderWorld(), address); if (pobox != null) setPOBoxInfo(Proxies.common.getRenderWorld(), address, pobox.getPOBoxInfo()); @@ -46,7 +49,7 @@ public class ClientProxyMail extends ProxyMail { } @Override - public void setPOBoxInfo(World world, MailAddress address, POBoxInfo info) { + public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) { if (address.isClientPlayer(world)) GuiMailboxInfo.instance.setPOBoxInfo(info); } diff --git a/src/main/java/forestry/mail/proxy/ProxyMail.java b/src/main/java/forestry/mail/proxy/ProxyMail.java index 523c21694..36fb92b10 100755 --- a/src/main/java/forestry/mail/proxy/ProxyMail.java +++ b/src/main/java/forestry/mail/proxy/ProxyMail.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.mail.proxy; -import forestry.api.mail.MailAddress; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; @@ -18,6 +17,7 @@ import forestry.core.network.PacketIds; import forestry.core.proxy.Proxies; import forestry.mail.POBoxInfo; import forestry.mail.network.PacketPOBoxInfo; +import forestry.api.mail.IMailAddress; public class ProxyMail { @@ -27,7 +27,7 @@ public class ProxyMail { public void resetMailboxInfo() { } - public void setPOBoxInfo(World world, MailAddress address, POBoxInfo info) { + public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) { EntityPlayer player = address.getPlayer(world); if (player != null) Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player); diff --git a/src/main/java/forestry/mail/triggers/TriggerLowPaper.java b/src/main/java/forestry/mail/triggers/TriggerLowPaper.java index 3d9402c1c..f2e374310 100755 --- a/src/main/java/forestry/mail/triggers/TriggerLowPaper.java +++ b/src/main/java/forestry/mail/triggers/TriggerLowPaper.java @@ -21,9 +21,9 @@ import forestry.mail.gadgets.MachineTrader; public class TriggerLowPaper extends Trigger { - float threshold; + int threshold; - public TriggerLowPaper(String tag, float threshold) { + public TriggerLowPaper(String tag, int threshold) { super(tag, "lowPaper"); this.threshold = threshold; } diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index e75a3e390..d1ede8490 100755 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -64,6 +64,7 @@ import forestry.core.items.ItemAssemblyKit; import forestry.core.items.ItemCrated; import forestry.core.items.ItemForestry; import forestry.core.items.ItemForestryBlock; +import forestry.core.items.ItemTypedBlock; import forestry.core.items.ItemForestryPickaxe; import forestry.core.items.ItemForestryShovel; import forestry.core.items.ItemFruit; @@ -111,7 +112,7 @@ public class PluginCore extends NativePlugin implements IFuelHandler { definitionEscritoire = ((BlockBase) ForestryBlock.core.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_ESCRITOIRE_META, "forestry.Escritoire", TileEscritoire.class, Proxies.render.getRenderEscritoire())); - ForestryBlock.soil.registerBlock(new BlockSoil(), ItemForestryBlock.class, "soil"); + ForestryBlock.soil.registerBlock(new BlockSoil(), ItemTypedBlock.class, "soil"); ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 0); ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 1); @@ -354,9 +355,6 @@ public class PluginCore extends NativePlugin implements IFuelHandler { ForestryItem.cratedWheat.registerItem(new ItemCrated(new ItemStack(Items.wheat)), "cratedWheat"); ForestryItem.cratedMycelium.registerItem(new ItemCrated(new ItemStack(Blocks.mycelium)), "cratedMycelium"); ForestryItem.cratedMulch.registerItem(new ItemCrated(ForestryItem.mulch.getItemStack()), "cratedMulch"); - ForestryItem.cratedSilver.registerItem(new ItemCrated(), "cratedSilver"); - ForestryItem.cratedBrass.registerItem(new ItemCrated(), "cratedBrass"); - ForestryItem.cratedNikolite.registerItem(new ItemCrated(), "cratedNikolite"); ForestryItem.cratedCookies.registerItem(new ItemCrated(new ItemStack(Items.cookie)), "cratedCookies"); ForestryItem.cratedRedstone.registerItem(new ItemCrated(new ItemStack(Items.redstone)), "cratedRedstone"); ForestryItem.cratedLapis.registerItem(new ItemCrated(new ItemStack(Items.dye, 1, 4)), "cratedLapis"); @@ -365,10 +363,6 @@ public class PluginCore extends NativePlugin implements IFuelHandler { ForestryItem.cratedGlowstone.registerItem(new ItemCrated(new ItemStack(Items.glowstone_dust)), "cratedGlowstone"); ForestryItem.cratedApples.registerItem(new ItemCrated(new ItemStack(Items.apple)), "cratedApples"); ForestryItem.cratedNetherwart.registerItem(new ItemCrated(new ItemStack(Items.nether_wart)), "cratedNetherwart"); - ForestryItem.cratedResin.registerItem(new ItemCrated(), "cratedResin"); - ForestryItem.cratedRubber.registerItem(new ItemCrated(), "cratedRubber"); - ForestryItem.cratedScrap.registerItem(new ItemCrated(), "cratedScrap"); - ForestryItem.cratedUUM.registerItem(new ItemCrated(), "cratedUUM"); ForestryItem.cratedPhosphor.registerItem(new ItemCrated(ForestryItem.phosphor.getItemStack()), "cratedPhosphor"); ForestryItem.cratedAsh.registerItem(new ItemCrated(ForestryItem.ash.getItemStack()), "cratedAsh"); ForestryItem.cratedCharcoal.registerItem(new ItemCrated(new ItemStack(Items.coal, 1, 1)), "cratedCharcoal"); diff --git a/src/main/java/forestry/plugins/PluginFarming.java b/src/main/java/forestry/plugins/PluginFarming.java index b5980eb2c..801cb5224 100755 --- a/src/main/java/forestry/plugins/PluginFarming.java +++ b/src/main/java/forestry/plugins/PluginFarming.java @@ -40,7 +40,7 @@ import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.ISaveEventHandler; -import forestry.core.items.ItemForestryBlock; +import forestry.core.items.ItemTypedBlock; import forestry.core.proxy.Proxies; import forestry.core.triggers.Trigger; import forestry.core.utils.ShapedRecipeCustom; @@ -107,7 +107,7 @@ public class PluginFarming extends NativePlugin { Farmables.farmInterface = new FarmHelper(); - ForestryBlock.mushroom.registerBlock(new BlockMushroom(), ItemForestryBlock.class, "mushroom"); + ForestryBlock.mushroom.registerBlock(new BlockMushroom(), ItemTypedBlock.class, "mushroom"); Farmables.farmables.put("farmArboreal", new ArrayList()); Farmables.farmables.get("farmArboreal").add(new FarmableVanillaSapling()); diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index 251c8b33e..a247d5bd2 100755 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -59,6 +59,9 @@ public class PluginIC2 implements IPlugin { public static ItemStack waterCell; public static ItemStack rubber; public static ItemStack scrap; + public static ItemStack silver; + public static ItemStack brass; + public static ItemStack uuMatter; public static int fuelcanMeta; public PluginIC2() { @@ -101,16 +104,6 @@ public class PluginIC2 implements IPlugin { // Remove some items from the recycler registerBackpackItems(); - - if (rubbersapling != null && resin != null) { - String imc = String.format("farmArboreal@%s.%s.%s.%s", - GameData.getBlockRegistry().getNameForObject(StackUtils.getBlock(rubbersapling)), - rubbersapling.getItemDamage(), - GameData.getItemRegistry().getNameForObject(resin.getItem()), - resin.getItemDamage()); - Proxies.log.finest("Sending IMC '%s'.", imc); - FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", imc); - } } private void initFermentation() { @@ -128,68 +121,113 @@ public class PluginIC2 implements IPlugin { private void initLiquidContainers() { emptyCell = IC2Items.getItem("cell"); - lavaCell = IC2Items.getItem("lavaCell"); - waterCell = IC2Items.getItem("waterCell"); - if (emptyCell == null || lavaCell == null || waterCell == null) { - Proxies.log.fine("Any of the following IC2 items could not be found: empty cell, water cell, lava cell. Skipped adding IC2 liquid containers."); + if (emptyCell == null) { + Proxies.log.fine("IC2 empty cell could not be found. Skipped adding IC2 liquid containers."); return; } - LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); - LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); - if (GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can").stackSize > 0) - Proxies.common - .addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', Blocks.sand); + lavaCell = IC2Items.getItem("lavaCell"); + if (lavaCell != null) + LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); + + waterCell = IC2Items.getItem("waterCell"); + if (waterCell != null) { + LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); + + ItemStack bogEarthCan = GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"); + if (bogEarthCan.stackSize > 0) + Proxies.common.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', Blocks.sand); + } } private void initRubberChain() { treetap = IC2Items.getItem("treetap"); - resin = IC2Items.getItem("resin"); rubberwood = IC2Items.getItem("rubberWood"); + + resin = IC2Items.getItem("resin"); + if (resin != null) + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), resin); + else + Proxies.log.fine("Missing IC2 resin, skipping centrifuge recipe for propolis to resin."); + rubbersapling = IC2Items.getItem("rubberSapling"); - rubberleaves = IC2Items.getItem("rubberLeaves"); - fuelcanFilled = IC2Items.getItem("filledFuelCan"); - fuelcanEmpty = IC2Items.getItem("fuelCan"); - if (treetap == null || resin == null || rubberwood == null || rubbersapling == null || rubberleaves == null || fuelcanFilled == null - || fuelcanEmpty == null) { - Proxies.log - .fine("Any of the following IC2 blocks and items could not be found: resin, rubber wood, saplings or leaves, filled fuel cans, empty fuel cans. Skipped adding rubber chain."); - return; + if (rubbersapling != null) { + RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); + BackpackManager.backpackItems[2].add(rubbersapling); + } else { + Proxies.log.fine("Missing IC2 rubber sapling, skipping fermenter recipe for converting rubber sapling to biomass."); } - // Add extra recipes - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), resin); - ItemStack fuelcanStack = new ItemStack(fuelcanFilled.getItem(), 1, 0); - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("value", 15288); - fuelcanStack.setTagCompound(compound); - RecipeManagers.bottlerManager.addRecipe(20, LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, Defaults.BOTTLER_FUELCAN_VOLUME), fuelcanEmpty, fuelcanStack); + if (rubbersapling != null && resin != null) { + String saplingName = GameData.getBlockRegistry().getNameForObject(StackUtils.getBlock(rubbersapling)); + String resinName = GameData.getItemRegistry().getNameForObject(resin.getItem()); + String imc = String.format("farmArboreal@%s.%s.%s.%s", + saplingName, rubbersapling.getItemDamage(), + resinName, resin.getItemDamage()); + Proxies.log.finest("Sending IMC '%s'.", imc); + FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", imc); + } - RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); + rubberleaves = IC2Items.getItem("rubberLeaves"); + if (rubberleaves != null) + BackpackManager.backpackItems[2].add(rubberleaves); + else + Proxies.log.fine("Missing IC2 rubber leaves"); + + fuelcanFilled = IC2Items.getItem("filledFuelCan"); + fuelcanEmpty = IC2Items.getItem("fuelCan"); + if (fuelcanEmpty != null && fuelcanFilled != null) { + ItemStack fuelcanStack = new ItemStack(fuelcanFilled.getItem(), 1, 0); + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("value", 15288); + fuelcanStack.setTagCompound(compound); + RecipeManagers.bottlerManager.addRecipe(20, LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, Defaults.BOTTLER_FUELCAN_VOLUME), fuelcanEmpty, fuelcanStack); + } else { + Proxies.log.fine("Missing IC2 fuelcanEmpty or fuelcanFilled, skipping bottler recipe for ethanol to filled fuel can."); + } - // Add backpack items - BackpackManager.backpackItems[2].add(rubbersapling); - BackpackManager.backpackItems[2].add(rubberleaves); // Rubber wood is added via ore dictionary. } private void initCrates() { - resin = IC2Items.getItem("resin"); - rubber = IC2Items.getItem("rubber"); - scrap = IC2Items.getItem("scrap"); // Add crates for the IC2 items that exist. + + resin = IC2Items.getItem("resin"); if (resin != null) { + ForestryItem.cratedResin.registerItem(new ItemCrated(), "cratedResin"); ((ItemCrated) ForestryItem.cratedResin.item()).setContained(ForestryItem.cratedResin.getItemStack(), resin); } + rubber = IC2Items.getItem("rubber"); if (rubber != null) { + ForestryItem.cratedRubber.registerItem(new ItemCrated(), "cratedRubber"); ((ItemCrated) ForestryItem.cratedRubber.item()).setContained(ForestryItem.cratedRubber.getItemStack(), rubber); } + scrap = IC2Items.getItem("scrap"); if (scrap != null) { + ForestryItem.cratedScrap.registerItem(new ItemCrated(), "cratedScrap"); ((ItemCrated) ForestryItem.cratedScrap.item()).setContained(ForestryItem.cratedScrap.getItemStack(), scrap); } + + uuMatter = IC2Items.getItem("matter"); + if (uuMatter != null) { + ForestryItem.cratedUUM.registerItem(new ItemCrated(), "cratedUUM"); + ((ItemCrated) ForestryItem.cratedUUM.item()).setContained(ForestryItem.cratedUUM.getItemStack(), uuMatter); + } + + silver = IC2Items.getItem("silverIngot"); + if (silver != null) { + ForestryItem.cratedSilver.registerItem(new ItemCrated(), "cratedSilver"); + ((ItemCrated) ForestryItem.cratedSilver.item()).setContained(ForestryItem.cratedSilver.getItemStack(), silver); + } + + brass = IC2Items.getItem("bronzeIngot"); + if (brass != null) { + ForestryItem.cratedBrass.registerItem(new ItemCrated(), "cratedBrass"); + ((ItemCrated) ForestryItem.cratedBrass.item()).setContained(ForestryItem.cratedBrass.getItemStack(), brass); + } } private void registerBackpackItems() { diff --git a/src/main/java/forestry/plugins/PluginMail.java b/src/main/java/forestry/plugins/PluginMail.java index 22b471e6e..0329b1ea7 100755 --- a/src/main/java/forestry/plugins/PluginMail.java +++ b/src/main/java/forestry/plugins/PluginMail.java @@ -38,7 +38,7 @@ import forestry.core.triggers.Trigger; import forestry.core.utils.LiquidHelper; import forestry.core.utils.ShapedRecipeCustom; import forestry.mail.CommandMail; -import forestry.mail.EnumAddressee; +import forestry.api.mail.EnumAddressee; import forestry.mail.GuiHandlerMail; import forestry.mail.PacketHandlerMail; import forestry.mail.PostRegistry; @@ -65,8 +65,8 @@ public class PluginMail extends NativePlugin { @SidedProxy(clientSide = "forestry.mail.proxy.ClientProxyMail", serverSide = "forestry.mail.proxy.ProxyMail") public static ProxyMail proxy; public static Trigger triggerHasMail; - public static Trigger lowPaper25; - public static Trigger lowPaper10; + public static Trigger lowPaper64; + public static Trigger lowPaper32; public static Trigger lowPostage40; public static Trigger lowPostage20; public static Trigger lowInput25; @@ -90,8 +90,8 @@ public class PluginMail extends NativePlugin { new TickHandlerMailClient(); triggerHasMail = new TriggerHasMail(); - lowPaper25 = new TriggerLowPaper("mail.lowPaper.25", 0.25f); - lowPaper10 = new TriggerLowPaper("mail.lowPaper.10", 0.1f); + lowPaper64 = new TriggerLowPaper("mail.lowPaper.64", 64); + lowPaper32 = new TriggerLowPaper("mail.lowPaper.32", 32); lowPostage40 = new TriggerLowStamps("mail.lowStamps.40", 40); lowPostage20 = new TriggerLowStamps("mail.lowStamps.20", 20); lowInput25 = new TriggerLowInput("mail.lowInput.25", 0.25f); diff --git a/src/main/java/forestry/plugins/PluginNatura.java b/src/main/java/forestry/plugins/PluginNatura.java index 61a45fcf0..5ccf0fba9 100755 --- a/src/main/java/forestry/plugins/PluginNatura.java +++ b/src/main/java/forestry/plugins/PluginNatura.java @@ -12,7 +12,9 @@ package forestry.plugins; import java.util.ArrayList; +import cpw.mods.fml.common.registry.GameData; import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.event.FMLInterModComms; @@ -33,6 +35,7 @@ public class PluginNatura extends NativePlugin { public static Block leavesNatura; public static Block saplingNatura; + public static Block saplingNaturaRare; @Override public boolean isAvailable() { @@ -47,9 +50,20 @@ public class PluginNatura extends NativePlugin { logWillow = GameRegistry.findBlock(NATURA, "willow"); leavesNatura = GameRegistry.findBlock(NATURA, "floraleaves"); saplingNatura = GameRegistry.findBlock(NATURA, "florasapling"); - + saplingNaturaRare = GameRegistry.findBlock(NATURA, "Rare Sapling"); + + ArrayList saplingItemKeys = new ArrayList(); + if(saplingNatura != null) - FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingNatura)); + saplingItemKeys.add("florasapling"); + if(saplingNaturaRare != null) + saplingItemKeys.add("Rare Sapling"); + + for (String key : saplingItemKeys) { + Item saplingItem = GameRegistry.findItem(NATURA, key); + String saplingName = GameData.getItemRegistry().getNameForObject(saplingItem); + FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName)); + } } @Override protected void registerItems() {} diff --git a/src/main/resources/assets/forestry/textures/gui/beealyzer.png b/src/main/resources/assets/forestry/textures/gui/beealyzer.png index 726c4c757..4bc31f73c 100755 Binary files a/src/main/resources/assets/forestry/textures/gui/beealyzer.png and b/src/main/resources/assets/forestry/textures/gui/beealyzer.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/mailtrader.png b/src/main/resources/assets/forestry/textures/gui/mailtrader.png index 534268b95..9cc2bcb9b 100755 Binary files a/src/main/resources/assets/forestry/textures/gui/mailtrader.png and b/src/main/resources/assets/forestry/textures/gui/mailtrader.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/worktable.png b/src/main/resources/assets/forestry/textures/gui/worktable.png index dd59d8ff0..48d18d27e 100755 Binary files a/src/main/resources/assets/forestry/textures/gui/worktable.png and b/src/main/resources/assets/forestry/textures/gui/worktable.png differ diff --git a/src/main/resources/assets/forestry/textures/items/errors/noPaper.png b/src/main/resources/assets/forestry/textures/items/errors/noPaper.png new file mode 100644 index 000000000..da8fb928b Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/errors/noPaper.png differ diff --git a/src/main/resources/assets/forestry/textures/items/errors/notPostpaid.png b/src/main/resources/assets/forestry/textures/items/errors/notPostpaid.png deleted file mode 100755 index 2f373319d..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/errors/notPostpaid.png and /dev/null differ