diff options
author | draknyte1 <draknyte1@hotmail.com> | 2017-02-15 20:20:41 +1000 |
---|---|---|
committer | draknyte1 <draknyte1@hotmail.com> | 2017-02-15 20:20:41 +1000 |
commit | 018ffe2534807c6dc53aa118fa15bac9b3f821cf (patch) | |
tree | 6664c0777040664bf5fe338f05e2a95c5f0d7e93 /src/Java/gtPlusPlus | |
parent | f03b1c8457aa428f0aacbe5062676248f8133bb7 (diff) | |
download | GT5-Unofficial-018ffe2534807c6dc53aa118fa15bac9b3f821cf.tar.gz GT5-Unofficial-018ffe2534807c6dc53aa118fa15bac9b3f821cf.tar.bz2 GT5-Unofficial-018ffe2534807c6dc53aa118fa15bac9b3f821cf.zip |
+ Added basic loot generation for the FishTrap. (Can be infinitely expanded).
Diffstat (limited to 'src/Java/gtPlusPlus')
-rw-r--r-- | src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java | 92 |
1 files changed, 67 insertions, 25 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java index 004d551947..6f056dbd37 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java @@ -32,10 +32,10 @@ public class TileEntityFishTrap extends TileEntity{ public boolean setTileLocation(){ if (this.hasWorldObj()){ if (!this.getWorldObj().isRemote){ - locationX = this.xCoord; - locationY = this.yCoord; - locationZ = this.zCoord; - return true; + locationX = this.xCoord; + locationY = this.yCoord; + locationZ = this.zCoord; + return true; } } return false; @@ -48,23 +48,23 @@ public class TileEntityFishTrap extends TileEntity{ //Utils.LOG_INFO("FT has world object"); if (!this.getWorldObj().isRemote){ //Utils.LOG_INFO("running code serverside"); - surroundingBlocks[0] = worldObj.getBlock(locationX, locationY+1, locationZ); //Above - surroundingBlocks[1] = worldObj.getBlock(locationX, locationY-1, locationZ); //Below - surroundingBlocks[2] = worldObj.getBlock(locationX+1, locationY, locationZ); - surroundingBlocks[3] = worldObj.getBlock(locationX-1, locationY, locationZ); - surroundingBlocks[4] = worldObj.getBlock(locationX, locationY, locationZ+1); - surroundingBlocks[5] = worldObj.getBlock(locationX, locationY, locationZ-1); - int waterCount = 0; - for (Block checkBlock : surroundingBlocks){ - //Utils.LOG_INFO("found "+checkBlock.getLocalizedName()); - if (checkBlock == Blocks.water || checkBlock == Blocks.flowing_water || checkBlock.getUnlocalizedName().toLowerCase().contains("water")){ - waterCount++; + surroundingBlocks[0] = worldObj.getBlock(locationX, locationY+1, locationZ); //Above + surroundingBlocks[1] = worldObj.getBlock(locationX, locationY-1, locationZ); //Below + surroundingBlocks[2] = worldObj.getBlock(locationX+1, locationY, locationZ); + surroundingBlocks[3] = worldObj.getBlock(locationX-1, locationY, locationZ); + surroundingBlocks[4] = worldObj.getBlock(locationX, locationY, locationZ+1); + surroundingBlocks[5] = worldObj.getBlock(locationX, locationY, locationZ-1); + int waterCount = 0; + for (Block checkBlock : surroundingBlocks){ + //Utils.LOG_INFO("found "+checkBlock.getLocalizedName()); + if (checkBlock == Blocks.water || checkBlock == Blocks.flowing_water || checkBlock.getUnlocalizedName().toLowerCase().contains("water")){ + waterCount++; + } + } + if (waterCount >= 4){ + //Utils.LOG_INFO("found water"); + return true; } - } - if (waterCount >= 4){ - //Utils.LOG_INFO("found water"); - return true; - } } } //Utils.LOG_INFO("Error finding water"); @@ -74,21 +74,62 @@ public class TileEntityFishTrap extends TileEntity{ public InventoryFishTrap getInventory(){ return this.inventoryContents; } - + public boolean tryAddLoot(){ + Utils.LOG_INFO("1"); if (this.getInventory().getInventory() != null){ + Utils.LOG_INFO("2"); int checkingSlot = 0; + ItemStack loot = generateLootForFishTrap(); for (ItemStack contents : this.getInventory().getInventory()){ - if (contents == null){ - this.getInventory().setInventorySlotContents(checkingSlot, ItemUtils.getSimpleStack(Items.fish)); + Utils.LOG_INFO("checkingSlots"); + if (contents == loot){ + if (contents.stackSize < loot.getMaxStackSize()){ + contents.stackSize++; + } + else { + this.getInventory().setInventorySlotContents(checkingSlot, loot); + } + } + if (contents == null || contents != loot){ + Utils.LOG_INFO("3"); + this.getInventory().setInventorySlotContents(checkingSlot, loot); + return true; + } + else { + } checkingSlot++; } } - + return false; } + private ItemStack generateLootForFishTrap() { + int lootWeight = MathUtils.randInt(0, 100); + ItemStack loot; + if (lootWeight <= 10){ + loot = ItemUtils.getSimpleStack(Items.slime_ball); + } + else if (lootWeight <= 20){ + loot = ItemUtils.getSimpleStack(Items.bone); + } + else if (lootWeight <= 40){ + loot = ItemUtils.getSimpleStack(Blocks.sand); + } + else if (lootWeight <= 80){ + loot = ItemUtils.getSimpleStack(Items.fish); + } + else if (lootWeight <= 100){ + loot = ItemUtils.getSimpleStack(Items.fish); + } + else { + loot = ItemUtils.getSimpleStack(Blocks.diamond_ore); + } + return loot; + } + @Override public void updateEntity(){ if (!this.worldObj.isRemote){ @@ -100,13 +141,14 @@ public class TileEntityFishTrap extends TileEntity{ Utils.LOG_INFO("In water? "+this.isInWater+" tick:"+this.tickCount); } else { - + } //Try add some loot once every 30 seconds. if (this.tickCount%300==0){ if (this.isInWater){ //Add loot Utils.LOG_INFO("Adding Loot to the fishtrap at x["+this.locationX+"] y["+this.locationY+"] z["+this.locationZ+"]"); + tryAddLoot(); } this.tickCount = 0; } |