mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-24 22:04:34 +00:00
Fix #2159 Minecart Apiary Gui Crash
This commit is contained in:
1 parent
508b26ca45
commit
d34ad60d31
6 files changed
+183
-118
No files matched your search
@@ -10,15 +10,27 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
import forestry.apiculture.entities.EntityMinecartBeeHousingBase;
|
||||
import forestry.core.gui.ContainerAnalyzerProviderHelper;
|
||||
import forestry.core.gui.ContainerEntity;
|
||||
import forestry.core.gui.slots.SlotLockable;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.packets.PacketGuiUpdateEntity;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerMinecartBeehouse extends ContainerEntity<EntityMinecartBeeHousingBase> implements IContainerBeeHousing {
|
||||
/* Attributes - Final*/
|
||||
private final ContainerAnalyzerProviderHelper providerHelper;
|
||||
|
||||
public ContainerMinecartBeehouse(InventoryPlayer player, EntityMinecartBeeHousingBase entity, boolean hasFrames) {
|
||||
super(entity, player, 8, 108);
|
||||
providerHelper = new ContainerAnalyzerProviderHelper(this, player);
|
||||
|
||||
ContainerBeeHelper.addSlots(this, entity, hasFrames);
|
||||
|
||||
entity.getBeekeepingLogic().clearCachedValues();
|
||||
@@ -38,4 +50,27 @@ public class ContainerMinecartBeehouse extends ContainerEntity<EntityMinecartBee
|
||||
}
|
||||
}
|
||||
|
||||
/* Methods - Implement IContainerAnalyzerProvider */
|
||||
@Nullable
|
||||
public Slot getAnalyzerSlot(){
|
||||
return providerHelper.getAnalyzerSlot();
|
||||
}
|
||||
|
||||
/* Methods - Implement ContainerForestry */
|
||||
@Override
|
||||
protected void addSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
addSlotToContainer(new SlotLockable(playerInventory, slot, x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addHotbarSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
addSlotToContainer(new SlotLockable(playerInventory, slot, x, y));
|
||||
}
|
||||
|
||||
/* Methods - Implement IGuiSelectable */
|
||||
@Override
|
||||
public void handleSelectionRequest(EntityPlayerMP player, int primary, int secondary) {
|
||||
providerHelper.analyzeSpecimen(secondary);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,5 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gui;
|
||||
|
||||
public interface IContainerBeeHousing {
|
||||
import forestry.core.gui.IContainerAnalyzerProvider;
|
||||
|
||||
public interface IContainerBeeHousing extends IContainerAnalyzerProvider {
|
||||
}
|
||||
@@ -2,127 +2,28 @@ package forestry.core.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.gui.slots.SlotAnalyzer;
|
||||
import forestry.core.gui.slots.SlotLockable;
|
||||
import forestry.core.inventory.ItemInventoryAlyzer;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.database.inventory.InventoryDatabaseAnalyzer;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
import forestry.modules.ModuleHelper;
|
||||
|
||||
public class ContainerAnalyzerProvider<T extends TileEntity> extends ContainerTile<T> implements IGuiSelectable {
|
||||
public class ContainerAnalyzerProvider<T extends TileEntity> extends ContainerTile<T> implements IContainerAnalyzerProvider {
|
||||
/* Attributes - Final*/
|
||||
private final EntityPlayer player;
|
||||
@Nullable
|
||||
private final ItemInventoryAlyzer alyzerInventory;
|
||||
private final int analyzerIndex;
|
||||
private final ContainerAnalyzerProviderHelper providerHelper;
|
||||
|
||||
/* Constructors */
|
||||
public ContainerAnalyzerProvider(T tileForestry, InventoryPlayer playerInventory, int xInv, int yInv) {
|
||||
super(tileForestry, playerInventory, xInv, yInv);
|
||||
|
||||
this.player = playerInventory.player;
|
||||
|
||||
ItemInventoryAlyzer alyzerInventory = null;
|
||||
int analyzerIndex = -1;
|
||||
for(int i = 0;i < playerInventory.getSizeInventory();i++){
|
||||
ItemStack stack = playerInventory.getStackInSlot(i);
|
||||
if(stack.isEmpty() || stack.getItem() != ModuleCore.getItems().portableAlyzer){
|
||||
continue;
|
||||
}
|
||||
analyzerIndex = i;
|
||||
alyzerInventory = new ItemInventoryAlyzer(playerInventory.player, stack);
|
||||
Slot slot = getSlotFromInventory(playerInventory, i);
|
||||
if(slot instanceof SlotLockable){
|
||||
SlotLockable lockable = (SlotLockable) slot;
|
||||
lockable.lock();
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.analyzerIndex = analyzerIndex;
|
||||
this.alyzerInventory = alyzerInventory;
|
||||
|
||||
if(alyzerInventory != null) {
|
||||
addSlotToContainer(new SlotAnalyzer(alyzerInventory, ItemInventoryAlyzer.SLOT_ENERGY, -110, 20));
|
||||
}
|
||||
|
||||
providerHelper = new ContainerAnalyzerProviderHelper(this, playerInventory);
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
/* Methods - Implement IContainerAnalyzerProvider */
|
||||
@Nullable
|
||||
public Slot getAnalyzerSlot(){
|
||||
if(alyzerInventory == null){
|
||||
return null;
|
||||
}
|
||||
return getSlotFromInventory(alyzerInventory, 0);
|
||||
}
|
||||
|
||||
private ItemStack analyzeSpecimen(int selectedSlot) {
|
||||
if(selectedSlot < 0 || alyzerInventory == null){
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
Slot specimenSlot = getForestrySlot( selectedSlot);
|
||||
ItemStack specimen = specimenSlot.getStack();
|
||||
if (specimen.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
|
||||
if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
|
||||
specimenSlot.putStack(convertedSpecimen);
|
||||
specimen = convertedSpecimen;
|
||||
}
|
||||
|
||||
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
|
||||
|
||||
// No individual, abort
|
||||
if (speciesRoot == null) {
|
||||
return specimen;
|
||||
}
|
||||
|
||||
IIndividual individual = speciesRoot.getMember(specimen);
|
||||
|
||||
// Analyze if necessary
|
||||
if (individual != null && !individual.isAnalyzed()) {
|
||||
final boolean requiresEnergy = ModuleHelper.isEnabled(ForestryModuleUids.APICULTURE);
|
||||
if (requiresEnergy) {
|
||||
// Requires energy
|
||||
if (!ItemInventoryAlyzer.isAlyzingFuel(alyzerInventory.getStackInSlot(InventoryDatabaseAnalyzer.SLOT_ENERGY))) {
|
||||
return specimen;
|
||||
}
|
||||
}
|
||||
|
||||
if (individual.analyze()) {
|
||||
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
|
||||
breedingTracker.registerSpecies(individual.getGenome().getPrimary());
|
||||
breedingTracker.registerSpecies(individual.getGenome().getSecondary());
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
individual.writeToNBT(nbttagcompound);
|
||||
specimen = specimen.copy();
|
||||
specimen.setTagCompound(nbttagcompound);
|
||||
|
||||
if (requiresEnergy) {
|
||||
// Decrease energy
|
||||
alyzerInventory.decrStackSize(InventoryDatabaseAnalyzer.SLOT_ENERGY, 1);
|
||||
}
|
||||
}
|
||||
specimenSlot.putStack(specimen);
|
||||
}
|
||||
return specimen;
|
||||
return providerHelper.getAnalyzerSlot();
|
||||
}
|
||||
|
||||
/* Methods - Implement ContainerForestry */
|
||||
@@ -139,6 +40,6 @@ public class ContainerAnalyzerProvider<T extends TileEntity> extends ContainerTi
|
||||
/* Methods - Implement IGuiSelectable */
|
||||
@Override
|
||||
public void handleSelectionRequest(EntityPlayerMP player, int primary, int secondary) {
|
||||
analyzeSpecimen(secondary);
|
||||
providerHelper.analyzeSpecimen(secondary);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.gui.slots.SlotAnalyzer;
|
||||
import forestry.core.gui.slots.SlotLockable;
|
||||
import forestry.core.inventory.ItemInventoryAlyzer;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.database.inventory.InventoryDatabaseAnalyzer;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
import forestry.modules.ModuleHelper;
|
||||
|
||||
public class ContainerAnalyzerProviderHelper {
|
||||
/* Attributes - Final*/
|
||||
private final EntityPlayer player;
|
||||
private final ContainerForestry container;
|
||||
@Nullable
|
||||
private final ItemInventoryAlyzer alyzerInventory;
|
||||
private final int analyzerIndex;
|
||||
|
||||
public ContainerAnalyzerProviderHelper(ContainerForestry container, InventoryPlayer playerInventory) {
|
||||
this.player = playerInventory.player;
|
||||
this.container = container;
|
||||
|
||||
ItemInventoryAlyzer alyzerInventory = null;
|
||||
int analyzerIndex = -1;
|
||||
for(int i = 0;i < playerInventory.getSizeInventory();i++){
|
||||
ItemStack stack = playerInventory.getStackInSlot(i);
|
||||
if(stack.isEmpty() || stack.getItem() != ModuleCore.getItems().portableAlyzer){
|
||||
continue;
|
||||
}
|
||||
analyzerIndex = i;
|
||||
alyzerInventory = new ItemInventoryAlyzer(playerInventory.player, stack);
|
||||
Slot slot = container.getSlotFromInventory(playerInventory, i);
|
||||
if(slot instanceof SlotLockable){
|
||||
SlotLockable lockable = (SlotLockable) slot;
|
||||
lockable.lock();
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.analyzerIndex = analyzerIndex;
|
||||
this.alyzerInventory = alyzerInventory;
|
||||
|
||||
if(alyzerInventory != null) {
|
||||
container.addSlotToContainer(new SlotAnalyzer(alyzerInventory, ItemInventoryAlyzer.SLOT_ENERGY, -110, 20));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Slot getAnalyzerSlot(){
|
||||
if(alyzerInventory == null){
|
||||
return null;
|
||||
}
|
||||
return container.getSlotFromInventory(alyzerInventory, 0);
|
||||
}
|
||||
|
||||
public ItemStack analyzeSpecimen(int selectedSlot) {
|
||||
if(selectedSlot < 0 || alyzerInventory == null){
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
Slot specimenSlot = container.getForestrySlot( selectedSlot);
|
||||
ItemStack specimen = specimenSlot.getStack();
|
||||
if (specimen.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
|
||||
if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
|
||||
specimenSlot.putStack(convertedSpecimen);
|
||||
specimen = convertedSpecimen;
|
||||
}
|
||||
|
||||
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
|
||||
|
||||
// No individual, abort
|
||||
if (speciesRoot == null) {
|
||||
return specimen;
|
||||
}
|
||||
|
||||
IIndividual individual = speciesRoot.getMember(specimen);
|
||||
|
||||
// Analyze if necessary
|
||||
if (individual != null && !individual.isAnalyzed()) {
|
||||
final boolean requiresEnergy = ModuleHelper.isEnabled(ForestryModuleUids.APICULTURE);
|
||||
if (requiresEnergy) {
|
||||
// Requires energy
|
||||
if (!ItemInventoryAlyzer.isAlyzingFuel(alyzerInventory.getStackInSlot(InventoryDatabaseAnalyzer.SLOT_ENERGY))) {
|
||||
return specimen;
|
||||
}
|
||||
}
|
||||
|
||||
if (individual.analyze()) {
|
||||
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
|
||||
breedingTracker.registerSpecies(individual.getGenome().getPrimary());
|
||||
breedingTracker.registerSpecies(individual.getGenome().getSecondary());
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
individual.writeToNBT(nbttagcompound);
|
||||
specimen = specimen.copy();
|
||||
specimen.setTagCompound(nbttagcompound);
|
||||
|
||||
if (requiresEnergy) {
|
||||
// Decrease energy
|
||||
alyzerInventory.decrStackSize(InventoryDatabaseAnalyzer.SLOT_ENERGY, 1);
|
||||
}
|
||||
}
|
||||
specimenSlot.putStack(specimen);
|
||||
}
|
||||
return specimen;
|
||||
}
|
||||
}
|
||||
@@ -64,16 +64,16 @@ public abstract class GuiAnalyzerProvider<C extends Container> extends GuiForest
|
||||
this.analyzer = GuiElementFactory.INSTANCE.createAnalyzer(window, -189 - screenDistance, 0, hasBoarder, this);
|
||||
updateVisibility();
|
||||
|
||||
SlotAnalyzer slotAnalyzer = null;
|
||||
if (container instanceof ContainerAnalyzerProvider) {
|
||||
ContainerAnalyzerProvider containerAnalyzer = (ContainerAnalyzerProvider) container;
|
||||
SlotAnalyzer analyzer = null;
|
||||
if (container instanceof IContainerAnalyzerProvider) {
|
||||
IContainerAnalyzerProvider containerAnalyzer = (IContainerAnalyzerProvider) container;
|
||||
Slot analyzerSlot = containerAnalyzer.getAnalyzerSlot();
|
||||
if (analyzerSlot instanceof SlotAnalyzer) {
|
||||
((SlotAnalyzer) analyzerSlot).setGui(this);
|
||||
slotAnalyzer = (SlotAnalyzer) analyzerSlot;
|
||||
analyzer = (SlotAnalyzer) analyzerSlot;
|
||||
}
|
||||
}
|
||||
this.slotAnalyzer = slotAnalyzer;
|
||||
this.slotAnalyzer = analyzer;
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
@@ -96,13 +96,8 @@ public abstract class GuiAnalyzerProvider<C extends Container> extends GuiForest
|
||||
this.guiLeft = (this.width - this.xSize + analyzer.getWidth() + (screenDistance)) / 2;
|
||||
}
|
||||
window.init(guiLeft, guiTop + (ySize - 166) / 2);
|
||||
/*analyzer.setXOffset(guiLeft);
|
||||
analyzer.setYOffset(guiTop + (ySize - 166) / 2);*/
|
||||
|
||||
/*GuiButtonToggle toggle = new GuiButtonToggle(0, guiLeft + buttonX, guiTop + buttonY, 18, 20, false);
|
||||
toggle.initTextureValues(0, 192, 0, 20, GeneticAnalyzer.TEXTURE);
|
||||
buttonList.add(toggle);*/
|
||||
addButton(new GuiToggleButton(0, guiLeft + buttonX, guiTop + buttonY, 18, 20, TOGGLE_BUTTON)).enabled = ((ContainerAnalyzerProvider) inventorySlots).getAnalyzerSlot() != null;
|
||||
addButton(new GuiToggleButton(0, guiLeft + buttonX, guiTop + buttonY, 18, 20, TOGGLE_BUTTON)).enabled = ((IContainerAnalyzerProvider) inventorySlots).getAnalyzerSlot() != null;
|
||||
dirty = true;
|
||||
|
||||
if (slotAnalyzer != null) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public interface IContainerAnalyzerProvider extends IGuiSelectable {
|
||||
@Nullable
|
||||
Slot getAnalyzerSlot();
|
||||
}
|
||||
Reference in new issue
Block a user