mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Fix #721 Crash when reusing the Habitat Locator
This commit is contained in:
1 parent
763df470a1
commit
fb966143f9
12 files changed
+332
-344
No files matched your search
@@ -11,8 +11,8 @@
|
||||
package forestry.apiculture.gui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -36,6 +36,102 @@ import forestry.core.render.TextureManager;
|
||||
|
||||
public class GuiHabitatLocator extends GuiForestry<ContainerHabitatLocator, HabitatLocatorInventory> {
|
||||
|
||||
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, "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<BiomeDictionary.Type, HabitatSlot> biomeToHabitat = new EnumMap<BiomeDictionary.Type, HabitatSlot>(BiomeDictionary.Type.class);
|
||||
|
||||
private int startX;
|
||||
private int startY;
|
||||
|
||||
public GuiHabitatLocator(EntityPlayer player, HabitatLocatorInventory item) {
|
||||
super(Defaults.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(player, item), item);
|
||||
|
||||
xSize = 176;
|
||||
ySize = 184;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
|
||||
if (slot.slot > 5) {
|
||||
x = 18 + (slot.slot - 6) * 20;
|
||||
y = 50;
|
||||
} else {
|
||||
x = 18 + slot.slot * 20;
|
||||
y = 32;
|
||||
}
|
||||
|
||||
slot.setPosition(x, y);
|
||||
this.widgetManager.add(slot);
|
||||
}
|
||||
|
||||
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 = StatCollector.translateToLocal("item.for.habitatLocator.name").toUpperCase();
|
||||
fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 16, fontColor.get("gui.screen"));
|
||||
|
||||
// Set active according to valid biomes.
|
||||
Set<BiomeDictionary.Type> activeBiomeTypes = EnumSet.noneOf(BiomeDictionary.Type.class);
|
||||
|
||||
for (HabitatSlot habitatSlot : habitatSlots) {
|
||||
habitatSlot.isActive = false;
|
||||
}
|
||||
|
||||
for (BiomeGenBase biome : inventory.getBiomesToSearch()) {
|
||||
Collections.addAll(activeBiomeTypes, BiomeDictionary.getTypesForBiome(biome));
|
||||
}
|
||||
|
||||
for (BiomeDictionary.Type biomeType : activeBiomeTypes) {
|
||||
HabitatSlot habitatSlot = biomeToHabitat.get(biomeType);
|
||||
if (habitatSlot != null) {
|
||||
habitatSlot.isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
slot.draw(startX, startY);
|
||||
}
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset afterwards.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
startX = (this.width - this.xSize) / 2;
|
||||
startY = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
public class HabitatSlot extends Widget {
|
||||
|
||||
private final int slot;
|
||||
@@ -84,101 +180,4 @@ public class GuiHabitatLocator extends GuiForestry<ContainerHabitatLocator, Habi
|
||||
|
||||
}
|
||||
|
||||
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, "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<BiomeDictionary.Type, HabitatSlot> biomeToHabitat = new HashMap<BiomeDictionary.Type, HabitatSlot>();
|
||||
|
||||
private int startX;
|
||||
private int startY;
|
||||
|
||||
public GuiHabitatLocator(EntityPlayer player, HabitatLocatorInventory item) {
|
||||
super(Defaults.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(player, item), item);
|
||||
|
||||
this.inventory.tryAnalyze();
|
||||
xSize = 176;
|
||||
ySize = 184;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
|
||||
if (slot.slot > 5) {
|
||||
x = 18 + (slot.slot - 6) * 20;
|
||||
y = 50;
|
||||
} else {
|
||||
x = 18 + slot.slot * 20;
|
||||
y = 32;
|
||||
}
|
||||
|
||||
slot.setPosition(x, y);
|
||||
this.widgetManager.add(slot);
|
||||
}
|
||||
|
||||
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 = StatCollector.translateToLocal("item.for.habitatLocator.name").toUpperCase();
|
||||
fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 16, fontColor.get("gui.screen"));
|
||||
|
||||
// Set active according to valid biomes.
|
||||
Set<BiomeDictionary.Type> activeBiomeTypes = new HashSet<BiomeDictionary.Type>();
|
||||
|
||||
for (HabitatSlot habitatSlot : habitatSlots) {
|
||||
habitatSlot.isActive = false;
|
||||
}
|
||||
|
||||
for (BiomeGenBase biome : inventory.biomesToSearch) {
|
||||
Collections.addAll(activeBiomeTypes, BiomeDictionary.getTypesForBiome(biome));
|
||||
}
|
||||
|
||||
for (BiomeDictionary.Type biomeType : activeBiomeTypes) {
|
||||
HabitatSlot habitatSlot = biomeToHabitat.get(biomeType);
|
||||
if (habitatSlot != null) {
|
||||
habitatSlot.isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
slot.draw(startX, startY);
|
||||
}
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset afterwards.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
startX = (this.width - this.xSize) / 2;
|
||||
startY = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,8 @@ public class ItemBeealyzer extends ItemInventoried {
|
||||
return BeeManager.beeRoot.isMember(itemStack);
|
||||
}
|
||||
|
||||
private void tryAnalyze() {
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
// Source slot to analyze empty
|
||||
if (getStackInSlot(SLOT_SPECIMEN) == null) {
|
||||
return;
|
||||
@@ -77,11 +78,6 @@ public class ItemBeealyzer extends ItemInventoried {
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryAnalyze();
|
||||
}
|
||||
|
||||
// / IHINTSOURCE
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
|
||||
@@ -57,107 +57,9 @@ import forestry.core.vect.Vect;
|
||||
|
||||
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<BiomeGenBase> biomesToSearch = new HashSet<BiomeGenBase>();
|
||||
private final ItemHabitatLocator habitatLocator;
|
||||
|
||||
public HabitatLocatorInventory(EntityPlayer player, ItemStack itemstack) {
|
||||
super(player, 3, itemstack);
|
||||
this.habitatLocator = (ItemHabitatLocator) itemstack.getItem();
|
||||
}
|
||||
|
||||
private static boolean isEnergy(ItemStack itemstack) {
|
||||
if (itemstack == null || itemstack.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack);
|
||||
}
|
||||
|
||||
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 = BeeManager.beeRoot.getMember(getStackInSlot(SLOT_ANALYZED));
|
||||
|
||||
// No bee, abort
|
||||
if (bee == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
biomesToSearch = new HashSet<BiomeGenBase>(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 ImmutableSet<IErrorState> getErrorStates() {
|
||||
if (getStackInSlot(SLOT_ANALYZED) != null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
|
||||
|
||||
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
|
||||
if (!BeeManager.beeRoot.isMember(specimen)) {
|
||||
errorStates.add(EnumErrorCode.NOTHINGANALYZE);
|
||||
}
|
||||
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
errorStates.add(EnumErrorCode.NOHONEY);
|
||||
}
|
||||
|
||||
return errorStates.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (slotIndex == SLOT_ENERGY) {
|
||||
Item item = itemStack.getItem();
|
||||
return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item();
|
||||
} else if (slotIndex == SLOT_SPECIMEN) {
|
||||
return BeeManager.beeRoot.isMember(itemStack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final String iconName = "forestry:biomefinder";
|
||||
|
||||
private Set<BiomeGenBase> biomesToSearch = new HashSet<BiomeGenBase>();
|
||||
private Set<BiomeGenBase> targetBiomes = new HashSet<BiomeGenBase>();
|
||||
private boolean biomeFound = false;
|
||||
private int searchRadiusIteration = 0;
|
||||
private int searchAngleIteration = 0;
|
||||
@@ -204,13 +106,16 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
list.add(StringUtil.localize("gui.humidity") + ": " + AlleleManager.climateHelper.toDisplay(humidity));
|
||||
}
|
||||
|
||||
public void startBiomeSearch(Set<BiomeGenBase> biomesToSearch) {
|
||||
public void startBiomeSearch(IBee bee, EntityPlayer player) {
|
||||
|
||||
this.biomesToSearch = biomesToSearch;
|
||||
this.targetBiomes = new HashSet<BiomeGenBase>(bee.getSuitableBiomes());
|
||||
this.searchAngleIteration = 0;
|
||||
this.searchRadiusIteration = 0;
|
||||
this.biomeFound = false;
|
||||
this.searchCenter = null;
|
||||
this.searchCenter = new Vect(player);
|
||||
|
||||
BiomeGenBase currentBiome = player.worldObj.getBiomeGenForCoords(searchCenter.x, searchCenter.z);
|
||||
removeInvalidBiomes(currentBiome, targetBiomes);
|
||||
|
||||
// reset the locator coordinates
|
||||
Proxies.common.setHabitatLocatorCoordinates(null, null);
|
||||
@@ -223,14 +128,7 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
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()) {
|
||||
if (targetBiomes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,7 +137,7 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
return;
|
||||
}
|
||||
|
||||
ChunkCoordinates target = findNearestBiome(player, biomesToSearch);
|
||||
ChunkCoordinates target = findNearestBiome(player, targetBiomes);
|
||||
|
||||
// send an update if we find the biome
|
||||
if (target != null) {
|
||||
@@ -254,7 +152,7 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
final int maxSearchRadiusIterations = 500;
|
||||
final int spacing = 20;
|
||||
|
||||
Vect playerPos = new Vect((int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
Vect playerPos = new Vect(player);
|
||||
|
||||
// If we are in a valid spot, we point to ourselves.
|
||||
ChunkCoordinates coordinates = getChunkCoordinates(playerPos, player.worldObj, biomesToSearch);
|
||||
@@ -369,4 +267,105 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
biomesToSearch.removeAll(endBiomes);
|
||||
}
|
||||
}
|
||||
|
||||
public static class HabitatLocatorInventory extends ItemInventory implements IErrorSource, IHintSource {
|
||||
|
||||
private static final short SLOT_ENERGY = 2;
|
||||
private static final short SLOT_SPECIMEN = 0;
|
||||
private static final short SLOT_ANALYZED = 1;
|
||||
|
||||
private final ItemHabitatLocator habitatLocator;
|
||||
|
||||
public HabitatLocatorInventory(EntityPlayer player, ItemStack itemstack) {
|
||||
super(player, 3, itemstack);
|
||||
this.habitatLocator = (ItemHabitatLocator) itemstack.getItem();
|
||||
}
|
||||
|
||||
private static boolean isEnergy(ItemStack itemstack) {
|
||||
if (itemstack == null || itemstack.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
|
||||
if (getStackInSlot(SLOT_ANALYZED) != null) {
|
||||
if (habitatLocator.biomeFound) {
|
||||
return;
|
||||
}
|
||||
} else if (getStackInSlot(SLOT_SPECIMEN) != null) {
|
||||
// Requires energy
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrease energy
|
||||
decrStackSize(SLOT_ENERGY, 1);
|
||||
|
||||
setInventorySlotContents(SLOT_ANALYZED, getStackInSlot(SLOT_SPECIMEN));
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
IBee bee = BeeManager.beeRoot.getMember(getStackInSlot(SLOT_ANALYZED));
|
||||
|
||||
// No bee, abort
|
||||
if (bee == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
habitatLocator.startBiomeSearch(bee, player);
|
||||
}
|
||||
|
||||
public Set<BiomeGenBase> getBiomesToSearch() {
|
||||
return habitatLocator.targetBiomes;
|
||||
}
|
||||
|
||||
// / 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 ImmutableSet<IErrorState> getErrorStates() {
|
||||
if (getStackInSlot(SLOT_ANALYZED) != null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
|
||||
|
||||
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
|
||||
if (!BeeManager.beeRoot.isMember(specimen)) {
|
||||
errorStates.add(EnumErrorCode.NOTHINGANALYZE);
|
||||
}
|
||||
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
errorStates.add(EnumErrorCode.NOHONEY);
|
||||
}
|
||||
|
||||
return errorStates.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (slotIndex == SLOT_ENERGY) {
|
||||
Item item = itemStack.getItem();
|
||||
return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item();
|
||||
} else if (slotIndex == SLOT_SPECIMEN) {
|
||||
return BeeManager.beeRoot.isMember(itemStack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,8 +102,8 @@ public class ItemImprinter extends ItemForestry {
|
||||
secondaryIndex = index;
|
||||
}
|
||||
|
||||
private void tryImprint() {
|
||||
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
ItemStack specimen = getStackInSlot(specimenSlot);
|
||||
if (specimen == null) {
|
||||
return;
|
||||
@@ -132,11 +132,6 @@ public class ItemImprinter extends ItemForestry {
|
||||
setInventorySlotContents(specimenSlot, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryImprint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "Imprinter";
|
||||
|
||||
@@ -40,7 +40,8 @@ public class ItemTreealyzer extends ItemInventoried {
|
||||
return GeneticsUtil.getGeneticEquivalent(itemStack) instanceof ITree;
|
||||
}
|
||||
|
||||
private void tryAnalyze() {
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
// Source slot to analyze empty
|
||||
if (getStackInSlot(SLOT_SPECIMEN) == null) {
|
||||
return;
|
||||
@@ -83,11 +84,6 @@ public class ItemTreealyzer extends ItemInventoried {
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryAnalyze();
|
||||
}
|
||||
|
||||
// / IHINTSOURCE
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
|
||||
@@ -164,7 +164,8 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron {
|
||||
return circuits;
|
||||
}
|
||||
|
||||
public void trySolder() {
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) {
|
||||
return;
|
||||
}
|
||||
@@ -217,11 +218,6 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
trySolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<IErrorState> getErrorStates() {
|
||||
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
|
||||
|
||||
@@ -48,4 +48,12 @@ public abstract class ContainerItemInventory<I extends ItemInventory> extends Co
|
||||
public final boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return inventory.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ItemStack slotClick(int slotIndex, int button, int modifier, EntityPlayer player) {
|
||||
ItemStack result = super.slotClick(slotIndex, button, modifier, player);
|
||||
inventory.onSlotClick(player);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,6 +176,9 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
return Integer.toString(i, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
ItemStack stack = getStackInSlot(i);
|
||||
@@ -250,7 +253,7 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
public final void markDirty() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,8 @@ package forestry.core.vect;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
@@ -42,6 +44,12 @@ public class Vect implements IVect {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vect(Entity entity) {
|
||||
this.x = (int) Math.round(entity.posX);
|
||||
this.y = (int) Math.round(entity.posY);
|
||||
this.z = (int) Math.round(entity.posZ);
|
||||
}
|
||||
|
||||
public static Vect getRandomPositionInArea(Random random, IVect area) {
|
||||
int x = random.nextInt(area.getX());
|
||||
int y = random.nextInt(area.getY());
|
||||
|
||||
@@ -250,7 +250,8 @@ public class ItemInfuser extends ItemForestry {
|
||||
super(player, 6, itemStack);
|
||||
}
|
||||
|
||||
private void trySeasoning() {
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
|
||||
// Need input
|
||||
ItemStack input = getStackInSlot(inputSlot);
|
||||
@@ -309,11 +310,6 @@ public class ItemInfuser extends ItemForestry {
|
||||
setInventorySlotContents(outputSlot, seasoned);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
trySeasoning();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "Infuser";
|
||||
|
||||
@@ -39,7 +39,8 @@ public class ItemFlutterlyzer extends ItemInventoried {
|
||||
return PluginLepidopterology.butterflyInterface.isMember(itemStack);
|
||||
}
|
||||
|
||||
private void tryAnalyze() {
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
// Source slot to analyze empty
|
||||
if (getStackInSlot(SLOT_SPECIMEN) == null) {
|
||||
return;
|
||||
@@ -76,11 +77,6 @@ public class ItemFlutterlyzer extends ItemInventoried {
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryAnalyze();
|
||||
}
|
||||
|
||||
/* IHINTSOURCE */
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
|
||||
@@ -53,6 +53,97 @@ public class ItemLetter extends ItemInventoried {
|
||||
EMPTY, SMALL, BIG
|
||||
}
|
||||
|
||||
public static ItemStack createStampedLetterStack(ILetter letter) {
|
||||
LetterSize size = getSize(letter);
|
||||
int meta = encodeMeta(LetterState.STAMPED, size);
|
||||
return ForestryItem.letters.getItemStack(1, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
if (Proxies.common.isSimulating(world)) {
|
||||
if (itemstack.stackSize == 1) {
|
||||
entityplayer.openGui(ForestryAPI.instance, GuiId.LetterGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ);
|
||||
} else {
|
||||
entityplayer.addChatMessage(new ChatComponentTranslation("for.chat.mail.wrongstacksize"));
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShareTag() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ICONS */
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[][] icons;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister register) {
|
||||
icons = new IIcon[3][4];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
icons[i][0] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".fresh");
|
||||
icons[i][1] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".stamped");
|
||||
icons[i][2] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".opened");
|
||||
icons[i][3] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".emptied");
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int damage) {
|
||||
|
||||
LetterState state = getState(damage);
|
||||
LetterSize size = getSize(damage);
|
||||
|
||||
return icons[size.ordinal()][state.ordinal()];
|
||||
}
|
||||
|
||||
public static int encodeMeta(LetterState state, LetterSize size) {
|
||||
int meta = size.ordinal() << 4;
|
||||
meta |= state.ordinal();
|
||||
return meta;
|
||||
}
|
||||
|
||||
public static LetterState getState(int meta) {
|
||||
int ordinal = meta & 0x0f;
|
||||
return LetterState.values()[ordinal];
|
||||
}
|
||||
|
||||
public static LetterSize getSize(int meta) {
|
||||
int ordinal = meta >> 4;
|
||||
return LetterSize.values()[ordinal];
|
||||
}
|
||||
|
||||
public static LetterSize getSize(ILetter letter) {
|
||||
int count = letter.countAttachments();
|
||||
|
||||
if (count > 5) {
|
||||
return LetterSize.BIG;
|
||||
} else if (count > 1) {
|
||||
return LetterSize.SMALL;
|
||||
} else {
|
||||
return LetterSize.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
|
||||
NBTTagCompound nbttagcompound = itemstack.getTagCompound();
|
||||
if (nbttagcompound == null) {
|
||||
list.add('<' + StringUtil.localize("gui.blank") + '>');
|
||||
return;
|
||||
}
|
||||
|
||||
ILetter letter = new Letter(nbttagcompound);
|
||||
letter.addTooltip(list);
|
||||
}
|
||||
|
||||
public static class LetterInventory extends ItemInventory implements IErrorSource, IHintSource {
|
||||
private ILetter letter;
|
||||
|
||||
@@ -152,11 +243,6 @@ public class ItemLetter extends ItemInventoried {
|
||||
return letter.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
letter.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return letter.isUseableByPlayer(entityplayer);
|
||||
@@ -210,94 +296,4 @@ public class ItemLetter extends ItemInventoried {
|
||||
|
||||
}
|
||||
|
||||
public static ItemStack createStampedLetterStack(ILetter letter) {
|
||||
LetterSize size = getSize(letter);
|
||||
int meta = encodeMeta(LetterState.STAMPED, size);
|
||||
return ForestryItem.letters.getItemStack(1, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
if (Proxies.common.isSimulating(world)) {
|
||||
if (itemstack.stackSize == 1) {
|
||||
entityplayer.openGui(ForestryAPI.instance, GuiId.LetterGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ);
|
||||
} else {
|
||||
entityplayer.addChatMessage(new ChatComponentTranslation("for.chat.mail.wrongstacksize"));
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShareTag() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ICONS */
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[][] icons;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister register) {
|
||||
icons = new IIcon[3][4];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
icons[i][0] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".fresh");
|
||||
icons[i][1] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".stamped");
|
||||
icons[i][2] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".opened");
|
||||
icons[i][3] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".emptied");
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int damage) {
|
||||
|
||||
LetterState state = getState(damage);
|
||||
LetterSize size = getSize(damage);
|
||||
|
||||
return icons[size.ordinal()][state.ordinal()];
|
||||
}
|
||||
|
||||
public static int encodeMeta(LetterState state, LetterSize size) {
|
||||
int meta = size.ordinal() << 4;
|
||||
meta |= state.ordinal();
|
||||
return meta;
|
||||
}
|
||||
|
||||
public static LetterState getState(int meta) {
|
||||
int ordinal = meta & 0x0f;
|
||||
return LetterState.values()[ordinal];
|
||||
}
|
||||
|
||||
public static LetterSize getSize(int meta) {
|
||||
int ordinal = meta >> 4;
|
||||
return LetterSize.values()[ordinal];
|
||||
}
|
||||
|
||||
public static LetterSize getSize(ILetter letter) {
|
||||
int count = letter.countAttachments();
|
||||
|
||||
if (count > 5) {
|
||||
return LetterSize.BIG;
|
||||
} else if (count > 1) {
|
||||
return LetterSize.SMALL;
|
||||
} else {
|
||||
return LetterSize.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
|
||||
NBTTagCompound nbttagcompound = itemstack.getTagCompound();
|
||||
if (nbttagcompound == null) {
|
||||
list.add('<' + StringUtil.localize("gui.blank") + '>');
|
||||
return;
|
||||
}
|
||||
|
||||
ILetter letter = new Letter(nbttagcompound);
|
||||
letter.addTooltip(list);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user