diff options
author | draknyte1 <draknyte1@hotmail.com> | 2017-02-15 21:46:46 +1000 |
---|---|---|
committer | draknyte1 <draknyte1@hotmail.com> | 2017-02-15 21:46:46 +1000 |
commit | baa34a2bf005f99a8ba5d4bb2418fb90fe52bbcf (patch) | |
tree | 052daf27974166e9a953e5c90ec8f773c4ba39c4 /src/Java | |
parent | eddb2b3df83cc91e2bc5ec83c27c944525faa7e0 (diff) | |
download | GT5-Unofficial-baa34a2bf005f99a8ba5d4bb2418fb90fe52bbcf.tar.gz GT5-Unofficial-baa34a2bf005f99a8ba5d4bb2418fb90fe52bbcf.tar.bz2 GT5-Unofficial-baa34a2bf005f99a8ba5d4bb2418fb90fe52bbcf.zip |
+ Added the Fishtrap to the check for water, so they can have them on 1-2 sides.
$ Fixed an issue where an NPE would crash the game when adding loot.
Diffstat (limited to 'src/Java')
-rw-r--r-- | src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java index af8cc03fa3..9e7f050f22 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java @@ -2,6 +2,7 @@ package gtPlusPlus.core.tileentities.general; import java.util.UUID; +import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.inventories.*; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.item.ItemUtils; @@ -56,7 +57,7 @@ public class TileEntityFishTrap extends TileEntity{ surroundingBlocks[5] = worldObj.getBlock(locationX, locationY, locationZ-1); int waterCount = 0; for (Block checkBlock : surroundingBlocks){ - if (checkBlock == Blocks.water || checkBlock == Blocks.flowing_water || checkBlock.getUnlocalizedName().toLowerCase().contains("water")){ + if (checkBlock == Blocks.water || checkBlock == Blocks.flowing_water || checkBlock.getUnlocalizedName().toLowerCase().contains("water") || checkBlock == ModBlocks.blockFishTrap){ waterCount++; } } @@ -79,7 +80,11 @@ public class TileEntityFishTrap extends TileEntity{ int checkingSlot = 0; ItemStack loot = generateLootForFishTrap(); for (ItemStack contents : this.getInventory().getInventory()){ - if (contents.getItem() == loot.getItem()){ + if (contents == null){ + this.getInventory().setInventorySlotContents(checkingSlot, loot); + return true; + } + else if (contents.getItem() == loot.getItem()){ if (contents.stackSize < contents.getMaxStackSize()){ contents.stackSize++;; return true; @@ -89,10 +94,6 @@ public class TileEntityFishTrap extends TileEntity{ return true; } } - else if (contents.getItem() == null){ - this.getInventory().setInventorySlotContents(checkingSlot, loot); - return true; - } else { } @@ -141,38 +142,43 @@ public class TileEntityFishTrap extends TileEntity{ } if (this.isInWater){ - int calculateTickrate = 0; - if (this.waterSides < 2){ - calculateTickrate = 0; - } - else if (this.waterSides >= 2 && this.waterSides < 4){ - calculateTickrate = 3000; - } - else if (this.waterSides >= 4 && this.waterSides < 6){ - calculateTickrate = 2000; - } - else if (this.waterSides == 6){ - calculateTickrate = 900; - } - this.baseTickRate = calculateTickrate; + calculateTickrate(); } //Try add some loot once every 30 seconds. if (this.tickCount%this.baseTickRate==0){ if (this.isInWater){ //Add loot - Utils.LOG_INFO("Adding Loot to the fishtrap at x["+this.locationX+"] y["+this.locationY+"] z["+this.locationZ+"]"); + Utils.LOG_INFO("Adding Loot to the fishtrap at x["+this.locationX+"] y["+this.locationY+"] z["+this.locationZ+"] (Ticking for loot every "+this.baseTickRate+" ticks)"); tryAddLoot(); + markDirty(); } this.tickCount = 0; } - if (this.tickCount > 1000){ + if (this.tickCount > (this.baseTickRate+500)){ this.tickCount = 0; } } } + + public void calculateTickrate(){ + int calculateTickrate = 0; + if (this.waterSides < 2){ + calculateTickrate = 0; + } + else if (this.waterSides >= 2 && this.waterSides < 4){ + calculateTickrate = 3000; + } + else if (this.waterSides >= 4 && this.waterSides < 6){ + calculateTickrate = 2000; + } + else if (this.waterSides == 6){ + calculateTickrate = 900; + } + this.baseTickRate = calculateTickrate; + } public boolean anyPlayerInRange(){ return this.worldObj.getClosestPlayer(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, 32) != null; @@ -197,21 +203,22 @@ public class TileEntityFishTrap extends TileEntity{ @Override public void writeToNBT(NBTTagCompound tagCompound) { - super.writeToNBT(tagCompound); + //super.writeToNBT(tagCompound); inventoryContents.writeToNBT(getTag(tagCompound, "ContentsChest")); - UUID ownerUUID = getOwnerUUID(); + + /*UUID ownerUUID = getOwnerUUID(); if (ownerUUID != null){ tagCompound.setLong("OwnerUUIDMost", ownerUUID.getMostSignificantBits()); tagCompound.setLong("OwnerUUIDLeast", ownerUUID.getLeastSignificantBits()); - } + }*/ } @Override public void readFromNBT(NBTTagCompound tagCompound) { - super.readFromNBT(tagCompound); - + //super.readFromNBT(tagCompound); inventoryContents.readFromNBT(tagCompound.getCompoundTag("ContentsChest")); - setOwnerUUID(new UUID(tagCompound.getLong("OwnerUUIDMost"), tagCompound.getLong("OwnerUUIDLeast"))); + + /*setOwnerUUID(new UUID(tagCompound.getLong("OwnerUUIDMost"), tagCompound.getLong("OwnerUUIDLeast")));*/ } } |