diff --git a/lang b/lang index 273421fbf..5bae723fd 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 273421fbfc587a8e364608cd16ed9c786e44d902 +Subproject commit 5bae723fd9bcbb26395b9aa748dd163d9d1fdbd9 diff --git a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java index 569932e52..a1838405a 100755 --- a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java @@ -37,7 +37,7 @@ import forestry.apiculture.gui.GuiBeealyzer; import forestry.apiculture.gui.GuiHabitatLocator; import forestry.apiculture.gui.GuiImprinter; import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory; -import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory; +import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; import forestry.apiculture.items.ItemImprinter.ImprinterInventory; import forestry.core.GuiHandlerBase; import forestry.core.gui.ContainerAlyzer; @@ -87,7 +87,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { if (equipped == null) return null; - return new GuiHabitatLocator(player.inventory, new BiomefinderInventory(equipped)); + return new GuiHabitatLocator(player.inventory, new HabitatLocatorInventory(equipped)); case HygroregulatorGUI: return new GuiAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z)); @@ -149,7 +149,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { if (equipped == null) return null; - return new ContainerHabitatLocator(player.inventory, new BiomefinderInventory(equipped)); + return new ContainerHabitatLocator(player.inventory, new HabitatLocatorInventory(equipped)); case HygroregulatorGUI: return new ContainerAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z)); diff --git a/src/main/java/forestry/apiculture/PacketHandlerApiculture.java b/src/main/java/forestry/apiculture/PacketHandlerApiculture.java index 1549ea933..15e29d067 100755 --- a/src/main/java/forestry/apiculture/PacketHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/PacketHandlerApiculture.java @@ -29,7 +29,7 @@ public class PacketHandlerApiculture implements IPacketHandler { case PacketIds.HABITAT_BIOME_POINTER: PacketCoordinates packetC = new PacketCoordinates(); packetC.readData(data); - Proxies.common.setBiomefinderCoordinates(player, packetC.getCoordinates()); + Proxies.common.setHabitatLocatorCoordinates(player, packetC.getCoordinates()); break; case PacketIds.IMPRINT_SELECTION_GET: onImprintSelectionGet(player); diff --git a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java index 6772a9fa6..c271e91cf 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java @@ -10,32 +10,25 @@ ******************************************************************************/ package forestry.apiculture.gui; -import forestry.apiculture.items.ItemBiomefinder; -import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory; -import forestry.core.config.ForestryItem; +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotFiltered; -import forestry.core.proxy.Proxies; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; +import forestry.core.gui.slots.SlotOutput; public class ContainerHabitatLocator extends ContainerItemInventory { - public final BiomefinderInventory inventory; - - public ContainerHabitatLocator(InventoryPlayer inventoryplayer, BiomefinderInventory inventory) { + public ContainerHabitatLocator(InventoryPlayer inventoryplayer, HabitatLocatorInventory inventory) { super(inventory, inventoryplayer.player); - this.inventory = inventory; - // Energy this.addSlotToContainer(new SlotFiltered(inventory, 2, 152, 8)); // Bee to analyze this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 32)); // Analyzed bee - this.addSlotToContainer(new SlotFiltered(inventory, 1, 152, 75)); + this.addSlotToContainer(new SlotOutput(inventory, 1, 152, 75)); // Player inventory for (int i1 = 0; i1 < 3; i1++) @@ -45,26 +38,4 @@ public class ContainerHabitatLocator extends ContainerItemInventory { for (int j1 = 0; j1 < 9; j1++) addSecuredSlot(inventoryplayer, j1, 8 + j1 * 18, 160); } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) { - - if (!Proxies.common.isSimulating(entityplayer.worldObj)) - return; - - ((ItemBiomefinder) ForestryItem.biomeFinder.item()).startBiomeSearch(entityplayer.worldObj, entityplayer, inventory.biomesToSearch); - - for (int i = 0; i < inventory.getSizeInventory() - 1; i++) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - Proxies.common.dropItemPlayer(entityplayer, stack); - inventory.setInventorySlotContents(i, null); - } - - inventory.onGuiSaved(entityplayer); - - } - } diff --git a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java index 24d232510..02fd94561 100755 --- a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java @@ -10,7 +10,24 @@ ******************************************************************************/ package forestry.apiculture.gui; -import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.biome.BiomeGenBase; + +import net.minecraftforge.common.BiomeDictionary; + +import org.lwjgl.opengl.GL11; + +import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; import forestry.core.config.Defaults; import forestry.core.gadgets.TileForestry; import forestry.core.gui.GuiForestry; @@ -18,15 +35,8 @@ import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.render.TextureManager; -import forestry.core.utils.StringUtil; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.IIcon; -import net.minecraft.world.biome.BiomeGenBase; -import org.lwjgl.opengl.GL11; + +import static net.minecraftforge.common.BiomeDictionary.Type.MOUNTAIN; public class GuiHabitatLocator extends GuiForestry { @@ -66,6 +76,8 @@ public class GuiHabitatLocator extends GuiForestry { if (!isActive) GL11.glColor4f(0.2f, 0.2f, 0.2f, 0.2f); + else + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); Proxies.common.bindTexture(SpriteSheet.ITEMS); manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos, getIcon(), 16, 16); @@ -75,35 +87,30 @@ public class GuiHabitatLocator extends GuiForestry { } - private final HabitatSlot[] habitatSlots = new HabitatSlot[] { new HabitatSlot(0, "Ocean"), // ocean - // + - // beach - new HabitatSlot(1, "Plains"), new HabitatSlot(2, "Desert"), // desert - // + - // desert - // hills + private final HabitatSlot[] habitatSlots = new HabitatSlot[] { + new HabitatSlot(0, "Ocean"), // ocean, beach + new HabitatSlot(1, "Plains"), + new HabitatSlot(2, "Desert"), // desert, desert hills new HabitatSlot(3, "Forest"), // forest, forestHills, river new HabitatSlot(4, "Jungle"), // jungle, jungleHills new HabitatSlot(5, "Taiga"), // taiga, taigaHills new HabitatSlot(6, "Hills"), // extremeHills, extremeHillsEdge - new HabitatSlot(7, "Swampland"), new HabitatSlot(8, "Snow"), // Ice - // plains, - // mountains, - // frozen - // rivers, - // frozen - // oceans - new HabitatSlot(9, "Mushroom"), // Ice plains, mountains, frozen - // rivers, frozen oceans - new HabitatSlot(10, "Hell"), new HabitatSlot(11, "End") }; - private final HashMap biomeToHabitat = new HashMap(); + new HabitatSlot(7, "Swamp"), + new HabitatSlot(8, "Snow"), // Ice plains, mountains, frozen rivers, frozen oceans + new HabitatSlot(9, "Mushroom"), + new HabitatSlot(10, "Nether"), + new HabitatSlot(11, "End") }; + private final Map biomeToHabitat = new HashMap(); private int startX; private int startY; + private final HabitatLocatorInventory inventory; - public GuiHabitatLocator(InventoryPlayer inventory, BiomefinderInventory item) { + public GuiHabitatLocator(InventoryPlayer inventory, HabitatLocatorInventory item) { super(Defaults.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(inventory, item), item); + this.inventory = item; + this.inventory.tryAnalyze(); xSize = 176; ySize = 184; @@ -123,53 +130,44 @@ public class GuiHabitatLocator extends GuiForestry { this.widgetManager.add(slot); } - biomeToHabitat.put(BiomeGenBase.ocean.biomeID, habitatSlots[0]); - biomeToHabitat.put(BiomeGenBase.beach.biomeID, habitatSlots[0]); - biomeToHabitat.put(BiomeGenBase.plains.biomeID, habitatSlots[1]); - biomeToHabitat.put(BiomeGenBase.desert.biomeID, habitatSlots[2]); - // biomeToHabitat.put(BiomeGenBase.desertHills.biomeID, - // habitatSlots[2]); // Removed for TFC compatibility - biomeToHabitat.put(BiomeGenBase.forest.biomeID, habitatSlots[3]); - biomeToHabitat.put(BiomeGenBase.forestHills.biomeID, habitatSlots[3]); - biomeToHabitat.put(BiomeGenBase.river.biomeID, habitatSlots[3]); - biomeToHabitat.put(BiomeGenBase.jungle.biomeID, habitatSlots[4]); - biomeToHabitat.put(BiomeGenBase.jungleHills.biomeID, habitatSlots[4]); - biomeToHabitat.put(BiomeGenBase.taiga.biomeID, habitatSlots[5]); - biomeToHabitat.put(BiomeGenBase.taigaHills.biomeID, habitatSlots[5]); - biomeToHabitat.put(BiomeGenBase.extremeHills.biomeID, habitatSlots[6]); - biomeToHabitat.put(BiomeGenBase.extremeHillsEdge.biomeID, habitatSlots[6]); - biomeToHabitat.put(BiomeGenBase.swampland.biomeID, habitatSlots[7]); - biomeToHabitat.put(BiomeGenBase.frozenOcean.biomeID, habitatSlots[8]); - biomeToHabitat.put(BiomeGenBase.frozenRiver.biomeID, habitatSlots[8]); - biomeToHabitat.put(BiomeGenBase.iceMountains.biomeID, habitatSlots[8]); - biomeToHabitat.put(BiomeGenBase.icePlains.biomeID, habitatSlots[8]); - biomeToHabitat.put(BiomeGenBase.mushroomIsland.biomeID, habitatSlots[9]); - biomeToHabitat.put(BiomeGenBase.mushroomIslandShore.biomeID, habitatSlots[9]); - biomeToHabitat.put(BiomeGenBase.hell.biomeID, habitatSlots[10]); - biomeToHabitat.put(BiomeGenBase.sky.biomeID, habitatSlots[11]); + biomeToHabitat.put(BiomeDictionary.Type.OCEAN, habitatSlots[0]); + biomeToHabitat.put(BiomeDictionary.Type.BEACH, habitatSlots[0]); + biomeToHabitat.put(BiomeDictionary.Type.PLAINS, habitatSlots[1]); + biomeToHabitat.put(BiomeDictionary.Type.SANDY, habitatSlots[2]); + biomeToHabitat.put(BiomeDictionary.Type.FOREST, habitatSlots[3]); + biomeToHabitat.put(BiomeDictionary.Type.RIVER, habitatSlots[3]); + biomeToHabitat.put(BiomeDictionary.Type.JUNGLE, habitatSlots[4]); + biomeToHabitat.put(BiomeDictionary.Type.CONIFEROUS, habitatSlots[5]); + biomeToHabitat.put(BiomeDictionary.Type.MOUNTAIN, habitatSlots[6]); + biomeToHabitat.put(BiomeDictionary.Type.SWAMP, habitatSlots[7]); + biomeToHabitat.put(BiomeDictionary.Type.SNOWY, habitatSlots[8]); + biomeToHabitat.put(BiomeDictionary.Type.MUSHROOM, habitatSlots[9]); + biomeToHabitat.put(BiomeDictionary.Type.NETHER, habitatSlots[10]); + biomeToHabitat.put(BiomeDictionary.Type.END, habitatSlots[11]); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - String str = StringUtil.localize("gui.habitatlocator").toUpperCase(); + String str = StatCollector.translateToLocal("item.for.habitatLocator.name").toUpperCase(); fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 16, fontColor.get("gui.screen")); - str = "(" + StringUtil.localize("gui.closetosearch") + ")"; - fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 76, fontColor.get("gui.table.header")); + // Set active according to valid biomes. + Set activeBiomeTypes = new HashSet(); - // Reset habitat slots - for (HabitatSlot slot : habitatSlots) - slot.isActive = false; + for (HabitatSlot habitatSlot : habitatSlots) { + habitatSlot.isActive = false; + } - // Set according to valid biomes. - ArrayList biomeids = ((ContainerHabitatLocator) inventorySlots).inventory.biomesToSearch; - for (int biomeid : biomeids) { - if (!biomeToHabitat.containsKey(biomeid)) - continue; + for (BiomeGenBase biome : inventory.biomesToSearch) { + Collections.addAll(activeBiomeTypes, BiomeDictionary.getTypesForBiome(biome)); + } - biomeToHabitat.get(biomeid).isActive = true; + for (BiomeDictionary.Type biomeType : activeBiomeTypes) { + HabitatSlot habitatSlot = biomeToHabitat.get(biomeType); + if (habitatSlot != null) + habitatSlot.isActive = true; } for (HabitatSlot slot : habitatSlots) diff --git a/src/main/java/forestry/apiculture/items/ItemBiomefinder.java b/src/main/java/forestry/apiculture/items/ItemBiomefinder.java deleted file mode 100755 index d665c9c5e..000000000 --- a/src/main/java/forestry/apiculture/items/ItemBiomefinder.java +++ /dev/null @@ -1,245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.items; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.apiculture.IBee; -import forestry.api.core.ForestryAPI; -import forestry.api.core.Tabs; -import forestry.apiculture.render.TextureBiomefinder; -import forestry.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.ForestryItem; -import forestry.core.interfaces.IErrorSource; -import forestry.core.interfaces.IHintSource; -import forestry.core.inventory.ItemInventory; -import forestry.core.items.ItemInventoried; -import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.vect.Vect; -import forestry.plugins.PluginApiculture; -import java.util.ArrayList; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - -public class ItemBiomefinder extends ItemInventoried { - - public static class BiomefinderInventory extends ItemInventory implements IErrorSource, IHintSource { - - public ArrayList biomesToSearch = new ArrayList(); - - private final short energySlot = 2; - private final short specimenSlot = 0; - private final short analyzeSlot = 1; - - public BiomefinderInventory(ItemStack itemstack) { - super(ItemBiomefinder.class, 3, itemstack); - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 2; i < inventoryStacks.length; 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; - - return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); - } - - private void tryAnalyze() { - - // Analyzed slot occupied, abort - if (inventoryStacks[analyzeSlot] != null) - return; - - // Source slot to analyze empty - if (getStackInSlot(specimenSlot) == null) - return; - - IBee bee = PluginApiculture.beeInterface.getMember(getStackInSlot(specimenSlot)); - // No bee, abort - if (bee == null) - return; - - // Requires energy - if (!isEnergy(getStackInSlot(energySlot))) - return; - - biomesToSearch = bee.getSuitableBiomeIds(); - - // Decrease energy - decrStackSize(energySlot, 1); - - setInventorySlotContents(analyzeSlot, getStackInSlot(specimenSlot)); - setInventorySlotContents(specimenSlot, null); - } - - @Override - public void markDirty() { - tryAnalyze(); - } - - // / IHINTSOURCE - @Override - public boolean hasHints() { - return Config.hints.get("habitatlocator") != null && Config.hints.get("habitatlocator").length > 0; - } - - @Override - public String[] getHints() { - return Config.hints.get("habitatlocator"); - } - - // / IERRORSOURCE - @Override - public boolean throwsErrors() { - return true; - } - - @Override - public EnumErrorCode getErrorState() { - if (PluginApiculture.beeInterface.isMember(inventoryStacks[specimenSlot]) && !isEnergy(getStackInSlot(energySlot))) - return EnumErrorCode.NOHONEY; - - return EnumErrorCode.OK; - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == energySlot) { - Item item = itemStack.getItem(); - return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item(); - } else if (slotIndex == specimenSlot || slotIndex == analyzeSlot) { - return PluginApiculture.beeInterface.isMember(itemStack); - } - return false; - } - - } - - public ItemBiomefinder() { - super(); - setMaxStackSize(1); - setCreativeTab(Tabs.tabApiculture); - } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { - - if (Proxies.common.isSimulating(world)) - entityplayer.openGui(ForestryAPI.instance, GuiId.HabitatLocatorGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); - - return itemstack; - } - - public void startBiomeSearch(World world, EntityPlayer player, ArrayList biomesToSearch) { - - ArrayList excludedBiomes = new ArrayList(); - excludedBiomes.add(BiomeGenBase.ocean.biomeID); - excludedBiomes.add(BiomeGenBase.frozenOcean.biomeID); - excludedBiomes.add(BiomeGenBase.beach.biomeID); - biomesToSearch.removeAll(excludedBiomes); - - // If we are in a valid biome, we point to ourself. - BiomeGenBase biome = world.getBiomeGenForCoords((int) player.posX, (int) player.posZ); - if (biomesToSearch.contains(biome.biomeID)) { - Proxies.common.setBiomefinderCoordinates(player, new ChunkCoordinates((int) player.posX, (int) player.posY, (int) player.posZ)); - return; - } - - if (Proxies.common.isSimulating(world) && biomesToSearch.size() > 0) { - ChunkCoordinates target = findNearestBiome(player, biomesToSearch); - Proxies.common.setBiomefinderCoordinates(player, target); - } - - } - - private ChunkCoordinates findNearestBiome(EntityPlayer player, ArrayList biomesToSearch) { - - int loadChunkDistance = 25; - ChunkCoordinates coordinates = null; - Vect pos = new Vect((int) player.posX, (int) player.posY, (int) player.posZ); - for (int i = 0; i < 100; i++) { - // Test direction +X - if ((coordinates = getChunkCoordinates(pos.add(new Vect(10 * i, 0, 0)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - // Test direction +X+Z - if ((coordinates = getChunkCoordinates(pos.add(new Vect(10 * i, 0, 10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - // Test direction +X-Z - if ((coordinates = getChunkCoordinates(pos.add(new Vect(10 * i, 0, -10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - - // Test direction -X - if ((coordinates = getChunkCoordinates(pos.add(new Vect(-10 * i, 0, 0)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - // Test direction -X+Z - if ((coordinates = getChunkCoordinates(pos.add(new Vect(-10 * i, 0, 10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - // Test direction -X-Z - if ((coordinates = getChunkCoordinates(pos.add(new Vect(-10 * i, 0, -10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - - // Test direction +Z - if ((coordinates = getChunkCoordinates(pos.add(new Vect(0, 0, 10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - // Test direction -Z - if ((coordinates = getChunkCoordinates(pos.add(new Vect(0, 0, -10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null) - return coordinates; - } - return coordinates; - } - - private ChunkCoordinates getChunkCoordinates(Vect pos, World world, ArrayList biomesToSearch, boolean loadChunks) { - - BiomeGenBase biome = world.getBiomeGenForCoords(pos.x, pos.z); - - if (biomesToSearch.contains(biome.biomeID)) - return new ChunkCoordinates(pos.x, pos.y, pos.z); - - return null; - } - - /* TEXTURES */ - @SideOnly(Side.CLIENT) - @Override - public void registerIcons(IIconRegister register) { - if(register instanceof TextureMap) { - TextureAtlasSprite texture = new TextureBiomefinder(); - ((TextureMap)register).setTextureEntry("forestry:biomefinder", texture); - itemIcon = texture; - } - } - -} diff --git a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java new file mode 100644 index 000000000..3e05487e1 --- /dev/null +++ b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java @@ -0,0 +1,353 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.items; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.common.BiomeManager; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.Forestry; +import forestry.api.apiculture.IBee; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.ForestryAPI; +import forestry.api.core.Tabs; +import forestry.api.genetics.AlleleManager; +import forestry.apiculture.render.TextureHabitatLocator; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.ForestryItem; +import forestry.core.interfaces.IErrorSource; +import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.ItemInventory; +import forestry.core.items.ItemInventoried; +import forestry.core.network.GuiId; +import forestry.core.network.PacketCoordinates; +import forestry.core.network.PacketIds; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StringUtil; +import forestry.core.vect.Vect; +import forestry.plugins.PluginApiculture; + +public class ItemHabitatLocator extends ItemInventoried { + + public static class HabitatLocatorInventory extends ItemInventory implements IErrorSource, IHintSource { + + private static final short SLOT_ENERGY = 2; + private static final short SLOT_SPECIMEN = 0; + private static final short SLOT_ANALYZED = 1; + + public Set biomesToSearch = new HashSet(); + private ItemHabitatLocator habitatLocator; + + public HabitatLocatorInventory(ItemStack itemstack) { + super(ItemHabitatLocator.class, 3, itemstack); + this.habitatLocator = (ItemHabitatLocator)itemstack.getItem(); + } + + private boolean isEnergy(ItemStack itemstack) { + if (itemstack == null || itemstack.stackSize <= 0) + return false; + + return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + } + + public void tryAnalyze() { + + if (getStackInSlot(SLOT_SPECIMEN) != null) { + // Requires energy + if (!isEnergy(getStackInSlot(SLOT_ENERGY))) + return; + + // Decrease energy + decrStackSize(SLOT_ENERGY, 1); + + setInventorySlotContents(SLOT_ANALYZED, getStackInSlot(SLOT_SPECIMEN)); + setInventorySlotContents(SLOT_SPECIMEN, null); + } + + IBee bee = PluginApiculture.beeInterface.getMember(getStackInSlot(SLOT_ANALYZED)); + + // No bee, abort + if (bee == null) + return; + + biomesToSearch = new HashSet(bee.getSuitableBiomes()); + habitatLocator.startBiomeSearch(biomesToSearch); + } + + @Override + public void markDirty() { + tryAnalyze(); + } + + // / IHINTSOURCE + @Override + public boolean hasHints() { + return Config.hints.get("habitatlocator") != null && Config.hints.get("habitatlocator").length > 0; + } + + @Override + public String[] getHints() { + return Config.hints.get("habitatlocator"); + } + + // / IERRORSOURCE + @Override + public boolean throwsErrors() { + return true; + } + + @Override + public EnumErrorCode getErrorState() { + if (PluginApiculture.beeInterface.isMember(inventoryStacks[SLOT_SPECIMEN]) && !isEnergy(getStackInSlot(SLOT_ENERGY))) + return EnumErrorCode.NOHONEY; + + return EnumErrorCode.OK; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_ENERGY) { + Item item = itemStack.getItem(); + return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item(); + } else if (slotIndex == SLOT_SPECIMEN) { + return PluginApiculture.beeInterface.isMember(itemStack); + } + return false; + } + + } + + private Set biomesToSearch = new HashSet(); + private boolean biomeFound = false; + private int searchRadiusIteration = 0; + private int searchAngleIteration = 0; + private Vect searchCenter; + + public ItemHabitatLocator() { + super(); + setMaxStackSize(1); + setCreativeTab(Tabs.tabApiculture); + } + + @Override + public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { + + if (Proxies.common.isSimulating(world)) + entityplayer.openGui(ForestryAPI.instance, GuiId.HabitatLocatorGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ); + + return itemstack; + } + + /* TEXTURES */ + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IIconRegister register) { + if(register instanceof TextureMap) { + TextureAtlasSprite texture = new TextureHabitatLocator(); + ((TextureMap)register).setTextureEntry("forestry:biomefinder", texture); + itemIcon = texture; + } + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) { + BiomeGenBase currentBiome = player.worldObj.getBiomeGenForCoords((int) player.posX, (int) player.posZ); + + EnumTemperature temperature = EnumTemperature.getFromBiome(currentBiome); + EnumHumidity humidity = EnumHumidity.getFromValue(currentBiome.rainfall); + + list.add(StringUtil.localize("gui.currentBiome") + ": " + currentBiome.biomeName); + list.add(StringUtil.localize("gui.temperature") + ": " + AlleleManager.climateHelper.toDisplay(temperature)); + list.add(StringUtil.localize("gui.humidity") + ": " + AlleleManager.climateHelper.toDisplay(humidity)); + } + + public void startBiomeSearch(Set biomesToSearch) { + + this.biomesToSearch = biomesToSearch; + this.searchAngleIteration = 0; + this.searchRadiusIteration = 0; + this.biomeFound = false; + this.searchCenter = null; + + // reset the locator coordinates + Proxies.common.setHabitatLocatorCoordinates(null, null); + } + + @Override + public void onUpdate(ItemStack p_77663_1_, World world, Entity player, int p_77663_4_, boolean p_77663_5_) { + + if (!Proxies.common.isSimulating(world)) + return; + + if (this.searchCenter == null) { + this.searchCenter = new Vect((int) player.posX, (int) player.posY, (int) player.posZ); + + BiomeGenBase currentBiome = world.getBiomeGenForCoords(searchCenter.x, searchCenter.z); + removeInvalidBiomes(currentBiome, biomesToSearch); + } + + if (biomesToSearch.isEmpty()) + return; + + // once we've found the biome, slow down to conserve cpu and network data + if (biomeFound && world.getTotalWorldTime() % 20 != 0) { + return; + } + + ChunkCoordinates target = findNearestBiome(player, biomesToSearch); + + // send an update if we find the biome + if (target != null) { + Proxies.common.setHabitatLocatorCoordinates(player, target); + biomeFound = true; + } + } + + private ChunkCoordinates findNearestBiome(Entity player, Collection biomesToSearch) { + + final int maxChecksPerTick = 100; + final int maxSearchRadiusIterations = 500; + final int spacing = 20; + + Vect playerPos = new Vect((int) player.posX, (int) player.posY, (int) player.posZ); + + // If we are in a valid spot, we point to ourselves. + ChunkCoordinates coordinates = getChunkCoordinates(playerPos, player.worldObj, biomesToSearch); + if (coordinates != null) { + searchAngleIteration = 0; + searchRadiusIteration = 0; + return new ChunkCoordinates(playerPos.x, playerPos.y, playerPos.z); + } + + // check in a circular pattern, starting at the center and increasing radius each step + final int radius = spacing * (searchRadiusIteration + 1); + + double angleSpacing = 2.0f * Math.asin(spacing / (2.0 * radius)); + + // round to nearest divisible angle, for an even distribution + angleSpacing = 2.0 * Math.PI / Math.round(2.0 * Math.PI / angleSpacing); + + // do a limited number of checks per tick + for (int i = 0; i < maxChecksPerTick; i++) { + + double angle = angleSpacing * searchAngleIteration; + if (angle > 2.0 * Math.PI) { + searchAngleIteration = 0; + searchRadiusIteration++; + if (searchRadiusIteration > maxSearchRadiusIterations) { + searchAngleIteration = 0; + searchRadiusIteration = 0; + searchCenter = playerPos; + } + return null; + } else { + searchAngleIteration++; + } + + int xOffset = Math.round((float) (radius * Math.cos(angle))); + int zOffset = Math.round((float) (radius * Math.sin(angle))); + Vect pos = searchCenter.add(xOffset, 0, zOffset); + + coordinates = getChunkCoordinates(pos, player.worldObj, biomesToSearch); + if (coordinates != null) { + searchAngleIteration = 0; + searchRadiusIteration = 0; + return coordinates; + } + } + + return null; + } + + private static ChunkCoordinates getChunkCoordinates(Vect pos, World world, Collection biomesToSearch) { + + // to avoid reporting very tiny patches, check around the point want + final int minBiomeRadius = 8; + + BiomeGenBase biome; + + biome = world.getBiomeGenForCoords(pos.x, pos.z); + if (!biomesToSearch.contains(biome)) + return null; + + biome = world.getBiomeGenForCoords(pos.x - minBiomeRadius, pos.z); + if (!biomesToSearch.contains(biome)) + return null; + + biome = world.getBiomeGenForCoords(pos.x + minBiomeRadius, pos.z); + if (!biomesToSearch.contains(biome)) + return null; + + biome = world.getBiomeGenForCoords(pos.x, pos.z - minBiomeRadius); + if (!biomesToSearch.contains(biome)) + return null; + + biome = world.getBiomeGenForCoords(pos.x, pos.z + minBiomeRadius); + if (!biomesToSearch.contains(biome)) + return null; + + return new ChunkCoordinates(pos.x, pos.y, pos.z); + } + + private static final Set waterBiomes = new HashSet(); + private static final Set netherBiomes = new HashSet(); + private static final Set endBiomes = new HashSet(); + static { + Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.BEACH)); + Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.OCEAN)); + Collections.addAll(waterBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.RIVER)); + + Collections.addAll(netherBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.NETHER)); + + Collections.addAll(endBiomes, BiomeDictionary.getBiomesForType(BiomeDictionary.Type.END)); + } + + private static void removeInvalidBiomes(BiomeGenBase currentBiome, Set biomesToSearch) { + + biomesToSearch.removeAll(waterBiomes); + + if (BiomeDictionary.isBiomeOfType(currentBiome, BiomeDictionary.Type.NETHER)) { + biomesToSearch.retainAll(netherBiomes); + } else { + biomesToSearch.removeAll(netherBiomes); + } + + if (BiomeDictionary.isBiomeOfType(currentBiome, BiomeDictionary.Type.END)) { + biomesToSearch.retainAll(endBiomes); + } else { + biomesToSearch.removeAll(endBiomes); + } + } +} diff --git a/src/main/java/forestry/apiculture/render/TextureBiomefinder.java b/src/main/java/forestry/apiculture/render/TextureHabitatLocator.java old mode 100755 new mode 100644 similarity index 81% rename from src/main/java/forestry/apiculture/render/TextureBiomefinder.java rename to src/main/java/forestry/apiculture/render/TextureHabitatLocator.java index 548bd9116..068338274 --- a/src/main/java/forestry/apiculture/render/TextureBiomefinder.java +++ b/src/main/java/forestry/apiculture/render/TextureHabitatLocator.java @@ -16,23 +16,25 @@ import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; -public class TextureBiomefinder extends TextureAtlasSprite { +public class TextureHabitatLocator extends TextureAtlasSprite { - private static TextureBiomefinder instance; - public static TextureBiomefinder getInstance() { return instance; } + private static TextureHabitatLocator instance; + public static TextureHabitatLocator getInstance() { return instance; } private ChunkCoordinates targetBiome; + private boolean targetBiomeFound; public double currentAngle; public double angleDelta; - public TextureBiomefinder() { + public TextureHabitatLocator() { super("biomefinder"); instance = this; } public void setTargetCoordinates(ChunkCoordinates coordinates) { this.targetBiome = coordinates; + this.targetBiomeFound = false; } @Override @@ -54,8 +56,16 @@ public class TextureBiomefinder extends TextureAtlasSprite { targetAngle = Math.random() * Math.PI * 2.0d; } else { double xPart = targetBiome.posX - playerX; - double yPart = targetBiome.posZ - playerZ; - targetAngle = (playerYaw - 90.0f) * Math.PI / 180.0d - Math.atan2(yPart, xPart); + double zPart = targetBiome.posZ - playerZ; + + if (Math.abs(xPart) + Math.abs(zPart) < 10 || targetBiomeFound) { + // spin steadily when the biome is found + targetAngle = currentAngle + 1; + targetBiomeFound = true; + } else { + playerYaw %= 360.0D; + targetAngle = -((playerYaw - 90.0f) * Math.PI / 180.0d - Math.atan2(zPart, xPart)); + } } if(!hasSpin) { diff --git a/src/main/java/forestry/core/config/ForestryItem.java b/src/main/java/forestry/core/config/ForestryItem.java index 259792017..d1249f4a5 100755 --- a/src/main/java/forestry/core/config/ForestryItem.java +++ b/src/main/java/forestry/core/config/ForestryItem.java @@ -87,7 +87,7 @@ public enum ForestryItem { kitShovel, // Do not touch - contagious! tent, - biomeFinder, + habitatLocator, // Moistener mouldyWheat, decayingWheat, diff --git a/src/main/java/forestry/core/proxy/ClientProxyCommon.java b/src/main/java/forestry/core/proxy/ClientProxyCommon.java index 45aec45bb..f2f60c53d 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ClientProxyCommon.java @@ -11,7 +11,7 @@ package forestry.core.proxy; import com.mojang.authlib.GameProfile; -import forestry.apiculture.render.TextureBiomefinder; +import forestry.apiculture.render.TextureHabitatLocator; import forestry.core.ForestryClient; import forestry.core.TickHandlerCoreClient; import forestry.core.WorldGenerator; @@ -23,6 +23,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.particle.EntityExplodeFX; import net.minecraft.client.resources.IResourceManager; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -56,12 +57,8 @@ public class ClientProxyCommon extends ProxyCommon { } @Override - public void setBiomefinderCoordinates(EntityPlayer player, ChunkCoordinates coordinates) { - if (isSimulating(player.worldObj)) - super.setBiomefinderCoordinates(player, coordinates); - else - TextureBiomefinder.getInstance().setTargetCoordinates(coordinates); - // TextureHabitatLocatorFX.instance.setTargetCoordinates(coordinates); + public void setHabitatLocatorCoordinates(Entity player, ChunkCoordinates coordinates) { + TextureHabitatLocator.getInstance().setTargetCoordinates(coordinates); } @Override diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 40eff4ed2..0d0a482fe 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -40,6 +40,7 @@ import java.util.EnumSet; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.IResourceManager; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; @@ -134,7 +135,7 @@ public class ProxyCommon { player.dropPlayerItemWithRandomChoice(stack, true); } - public void setBiomefinderCoordinates(EntityPlayer player, ChunkCoordinates coordinates) { + public void setHabitatLocatorCoordinates(Entity player, ChunkCoordinates coordinates) { if (coordinates != null) Forestry.packetHandler.sendPacket(new PacketCoordinates(PacketIds.HABITAT_BIOME_POINTER, coordinates).getPacket(), (EntityPlayerMP) player); } diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index e59c2293b..0438bd913 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -118,6 +118,7 @@ import forestry.apiculture.items.ItemArmorApiarist; import forestry.apiculture.items.ItemBeeGE; import forestry.apiculture.items.ItemBeealyzer; import forestry.apiculture.items.ItemCandleBlock; +import forestry.apiculture.items.ItemHabitatLocator; import forestry.apiculture.items.ItemHiveFrame; import forestry.apiculture.items.ItemHoneycomb; import forestry.apiculture.items.ItemImprinter; @@ -366,9 +367,7 @@ public class PluginApiculture extends ForestryPlugin { ForestryItem.beeLarvaeGE.registerItem((new ItemBeeGE(EnumBeeType.LARVAE)), "beeLarvaeGE"); ForestryItem.beealyzer.registerItem((new ItemBeealyzer()), "beealyzer"); - // Disabling Habitat Locator, because it's b0rked and seems to flubber up other icons. - /*ForestryItem.biomeFinder = new ItemBiomefinder(Config.getOrCreateItemIdProperty("biomeFinder", Defaults.ID_ITEM_BIOME_FINDER)) - .setUnlocalizedName("biomeFinder");*/ + ForestryItem.habitatLocator.registerItem(new ItemHabitatLocator(), "habitatLocator"); ForestryItem.imprinter.registerItem((new ItemImprinter()), "imprinter"); // / COMB FRAMES @@ -457,8 +456,11 @@ public class PluginApiculture extends ForestryPlugin { '#', ForestryItem.craftingMaterial.getItemStack(1, 3)); // / HABITAT LOCATOR - //Proxies.common.addRecipe(ForestryItem.biomeFinder.getItemStack(), - // new Object[] { " X ", "X#X", " X ", '#', Items.redstone, 'X', "ingotBronze" }); + Proxies.common.addRecipe(ForestryItem.habitatLocator.getItemStack(), + " X ", + "X#X", + " X ", + '#', Items.redstone, 'X', "ingotBronze"); // Bees Proxies.common.addRecipe(ForestryItem.scoop.getItemStack(1),