Skip to content

Commit

Permalink
Fix #384 Client crash at forestry.farming.gadgets.TileHatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Dec 20, 2014
1 parent 46348fc commit d633775
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 41 deletions.
47 changes: 27 additions & 20 deletions src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java
Expand Up @@ -140,8 +140,12 @@ protected void updateServerSide() {
return;

// Add swarm effects
if (worldObj.getTotalWorldTime() % 200 * 10 == 0)
onQueenChange(getStructureInventory().getStackInSlot(SLOT_QUEEN));
if (worldObj.getTotalWorldTime() % 200 == 0) {
ISidedInventory inventory = getStructureInventory();
if (inventory != null)
onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
}

if (getErrorState() == EnumErrorCode.OK)
queen.doFX(beekeepingLogic.getEffectData(), this);

Expand All @@ -166,15 +170,18 @@ protected void updateClientSide() {
if (!isMaster())
return;

if (getStructureInventory() == null)
ISidedInventory inventory = getStructureInventory();
if (inventory == null)
return;

// / Multiplayer FX
if (PluginApiculture.beeInterface.isMated(getStructureInventory().getStackInSlot(SLOT_QUEEN)))
ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN);
if (PluginApiculture.beeInterface.isMated(queenStack)) {
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 == 0) {
IBee displayQueen = PluginApiculture.beeInterface.getMember(getStructureInventory().getStackInSlot(SLOT_QUEEN));
IBee displayQueen = PluginApiculture.beeInterface.getMember(queenStack);
displayQueen.doFX(beekeepingLogic.getEffectData(), this);
}
}
}

private void equalizeTemperature() {
Expand Down Expand Up @@ -544,37 +551,37 @@ public TileInventoryAdapter getStructureInventory() {
@Override
public int getSizeInventory() {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getSizeInventory();
else
if (inv == null)
return 0;

return inv.getSizeInventory();
}

@Override
public ItemStack getStackInSlot(int slotIndex) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getStackInSlot(slotIndex);
else
if (inv == null)
return null;

return inv.getStackInSlot(slotIndex);
}

@Override
public ItemStack decrStackSize(int slotIndex, int amount) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.decrStackSize(slotIndex, amount);
else
if (inv == null)
return null;

return inv.decrStackSize(slotIndex, amount);
}

@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getStackInSlotOnClosing(slotIndex);
else
if (inv == null)
return null;

return inv.getStackInSlotOnClosing(slotIndex);
}

@Override
Expand All @@ -598,10 +605,10 @@ public String getInventoryName() {
@Override
public int getInventoryStackLimit() {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getInventoryStackLimit();
else
if (inv == null)
return 0;

return inv.getInventoryStackLimit();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/forestry/core/utils/Utils.java
Expand Up @@ -60,15 +60,15 @@ public static void dropInventory(TileForestry tile, World world, int x, int y, i
if (tile instanceof ITileStructure) {

IInventory inventory = ((ITileStructure) tile).getInventory();
if (inventory != null)
if (inventory != null) {
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (inventory.getStackInSlot(i) == null)
continue;

StackUtils.dropItemStackAsEntity(inventory.getStackInSlot(i), world, x, y, z);
inventory.setInventorySlotContents(i, null);
}

}
} else {

IInventory inventory;
Expand Down
48 changes: 29 additions & 19 deletions src/main/java/forestry/farming/gadgets/TileHatch.java
Expand Up @@ -13,6 +13,7 @@
import buildcraft.api.statements.ITriggerExternal;
import cpw.mods.fml.common.Optional;
import forestry.api.core.ITileStructure;
import forestry.core.config.Defaults;
import forestry.core.inventory.AdjacentInventoryCache;
import forestry.core.inventory.ITileFilter;
import forestry.core.inventory.InvTools;
Expand Down Expand Up @@ -57,7 +58,11 @@ protected void updateServerSide() {

/* AUTO-EJECTING */
private IInventory getProductInventory() {
return new InventoryMapper(getStructureInventory(), TileFarmPlain.SLOT_PRODUCTION_1, TileFarmPlain.SLOT_COUNT_PRODUCTION);
TileInventoryAdapter inventory = getStructureInventory();
if (inventory == null)
return null;

return new InventoryMapper(inventory, TileFarmPlain.SLOT_PRODUCTION_1, TileFarmPlain.SLOT_COUNT_PRODUCTION);
}

protected void dumpStash() {
Expand Down Expand Up @@ -87,37 +92,37 @@ public TileInventoryAdapter getStructureInventory() {
@Override
public int getSizeInventory() {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getSizeInventory();
else
if (inv == null)
return 0;

return inv.getSizeInventory();
}

@Override
public ItemStack getStackInSlot(int slotIndex) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getStackInSlot(slotIndex);
else
if (inv == null)
return null;

return inv.getStackInSlot(slotIndex);
}

@Override
public ItemStack decrStackSize(int slotIndex, int amount) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.decrStackSize(slotIndex, amount);
else
if (inv == null)
return null;

return inv.decrStackSize(slotIndex, amount);
}

@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getStackInSlotOnClosing(slotIndex);
else
if (inv == null)
return null;

return inv.getStackInSlotOnClosing(slotIndex);
}

@Override
Expand All @@ -130,10 +135,10 @@ public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
@Override
public int getInventoryStackLimit() {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getInventoryStackLimit();
else
if (inv == null)
return 0;

return inv.getInventoryStackLimit();
}

@Override
Expand Down Expand Up @@ -171,7 +176,8 @@ public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
if (!(struct instanceof TileFarmPlain))
return false;

if (!getStructureInventory().isItemValidForSlot(slotIndex, itemstack))
TileInventoryAdapter inventory = getStructureInventory();
if (inventory == null || !inventory.isItemValidForSlot(slotIndex, itemstack))
return false;

TileFarmPlain housing = (TileFarmPlain) struct;
Expand All @@ -196,15 +202,19 @@ public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {

@Override
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
if (!getStructureInventory().canExtractItem(slotIndex, itemstack, side))
TileInventoryAdapter inventory = getStructureInventory();
if (inventory == null || !inventory.canExtractItem(slotIndex, itemstack, side))
return false;

return slotIndex >= TileFarmPlain.SLOT_PRODUCTION_1 && slotIndex < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION;
}

@Override
public int[] getAccessibleSlotsFromSide(int side) {
return getStructureInventory().getAccessibleSlotsFromSide(side);
TileInventoryAdapter inventory = getStructureInventory();
if (inventory == null)
return Defaults.FACINGS_NONE;
return inventory.getAccessibleSlotsFromSide(side);
}

/* ITRIGGERPROVIDER */
Expand Down

0 comments on commit d633775

Please sign in to comment.