Fix #385 Server crash when opening AlvearySieve

This commit is contained in:
mezz committed 2014-12-20 00:13:28 -08:00
1 parent d63377532c
commit 71dcbdf0e4
1 file changed
+12 -22
@@ -10,6 +10,9 @@
******************************************************************************/
package forestry.apiculture.gadgets;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeListener;
@@ -18,11 +21,8 @@ import forestry.api.core.ForestryAPI;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IIndividual;
import forestry.core.interfaces.ICrafter;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.GuiId;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListener {
@@ -32,11 +32,10 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
public static final int SLOT_POLLEN_1 = 0;
public static final int SLOTS_POLLEN_COUNT = 4;
public static final int SLOT_SIEVE = 4;
private final InventoryAdapter inventory = new InventoryAdapter(5, "Items", 1);
public TileAlvearySieve() {
super(BLOCK_META);
setInternalInventory(new TileInventoryAdapter(this, 5, "Items", 1));
}
@Override
@@ -44,7 +43,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
player.openGui(ForestryAPI.instance, GuiId.AlvearySieveGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
@Override
public boolean hasFunction() {
return true;
@@ -61,7 +59,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
((IAlvearyComponent)getCentralTE()).registerBeeListener(this);
}
@Override
protected void updateServerSide() {
super.updateServerSide();
@@ -74,19 +71,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
((IAlvearyComponent)getCentralTE()).registerBeeListener(this);
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
inventory.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
inventory.writeToNBT(nbttagcompound);
}
/* TEXTURES & INTERNAL */
@Override
public int getIcon(int side, int metadata) {
@@ -96,15 +80,19 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
}
private void destroySieve() {
TileInventoryAdapter inventory = getInternalInventory();
inventory.setInventorySlotContents(SLOT_SIEVE, null);
}
private void destroyPollen() {
TileInventoryAdapter inventory = getInternalInventory();
for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) {
inventory.setInventorySlotContents(i, null);
}
}
private boolean canStorePollen() {
TileInventoryAdapter inventory = getInternalInventory();
if(inventory.getStackInSlot(SLOT_SIEVE) == null)
return false;
@@ -117,6 +105,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
}
private void storePollenStack(ItemStack itemstack) {
TileInventoryAdapter inventory = getInternalInventory();
for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) {
if(inventory.getStackInSlot(i) == null) {
inventory.setInventorySlotContents(i, itemstack);
@@ -133,6 +122,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
@Override
public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) {
TileInventoryAdapter inventory = getInternalInventory();
if(slotIndex == SLOT_SIEVE) {
destroyPollen();
return inventory.getStackInSlot(SLOT_SIEVE);
@@ -157,7 +147,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
public boolean onPollenRetrieved(IBee queen, IIndividual pollen, boolean isHandled) {
if(isHandled)
return isHandled;
return true;
if(!canStorePollen())
return false;