diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-03-13 12:30:37 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-03-13 12:30:37 +0000 |
commit | d8da94ede0ae3df9ea5c47145043c09874bffebe (patch) | |
tree | c584f96be0ffac1b1b4b96d326a34411290a64bf /src/Java | |
parent | 94d7c2c8af9f13d70ab115f377e85502c3a96f7c (diff) | |
download | GT5-Unofficial-d8da94ede0ae3df9ea5c47145043c09874bffebe.tar.gz GT5-Unofficial-d8da94ede0ae3df9ea5c47145043c09874bffebe.tar.bz2 GT5-Unofficial-d8da94ede0ae3df9ea5c47145043c09874bffebe.zip |
% Mild improvements to BTF_Inventory.java.
% Finished Agricultural Sewer.
Diffstat (limited to 'src/Java')
5 files changed, 157 insertions, 28 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java b/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java index 25968f1908..43a325f190 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java @@ -3,6 +3,7 @@ package gtPlusPlus.api.objects.minecraft; import java.util.ArrayList; import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.tileentities.base.TileEntityBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; @@ -160,5 +161,47 @@ public class BTF_Inventory implements ISidedInventory{ return this.mTile != null ? mTile.getInventoryName() : ""; } + public boolean isFull() { + for (int s=0;s<this.getSizeInventory();s++) { + ItemStack slot = mInventory[s]; + if (slot == null || slot.stackSize != slot.getMaxStackSize()) { + return false; + } + } + return true; + } + + public boolean isEmpty() { + for (int s=0;s<this.getSizeInventory();s++) { + ItemStack slot = mInventory[s]; + if (slot == null) { + continue; + } + else { + return false; + } + } + return true; + } + + public boolean addItemStack(ItemStack aInput) { + if (isEmpty() || !isFull()) { + for (int s = 0; s < this.getSizeInventory(); s++) { + ItemStack slot = mInventory[s]; + if (slot == null + || (GT_Utility.areStacksEqual(aInput, slot) && slot.stackSize != slot.getMaxStackSize())) { + if (slot == null) { + slot = aInput.copy(); + } else { + slot.stackSize++; + } + this.setInventorySlotContents(s, slot); + return true; + } + } + } + return false; + } + } diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java b/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java index 6aa3800b51..7bb7ad51b9 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java @@ -5,22 +5,18 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.tileentities.general.TileEntityInfiniteFluid; import gtPlusPlus.core.tileentities.machines.TileEntityPooCollector; +import gtPlusPlus.core.util.data.StringUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; -import net.minecraftforge.fluids.ItemFluidContainer; public class Machine_PooCollector extends BlockContainer { @@ -42,7 +38,7 @@ public class Machine_PooCollector extends BlockContainer { @Override @SideOnly(Side.CLIENT) public IIcon getIcon(final int p_149691_1_, final int p_149691_2_) { - return p_149691_1_ == 1 ? this.textureTop : this.blockIcon; + return p_149691_1_ <= 1 ? this.textureTop : this.blockIcon; } @Override @@ -61,7 +57,7 @@ public class Machine_PooCollector extends BlockContainer { if (world.isRemote) { return true; } else { - TileEntityInfiniteFluid tank = (TileEntityInfiniteFluid) world.getTileEntity(x, y, z); + TileEntityPooCollector tank = (TileEntityPooCollector) world.getTileEntity(x, y, z); if (tank != null) { Item handItem; try { @@ -69,7 +65,9 @@ public class Machine_PooCollector extends BlockContainer { } catch (Throwable t) { handItem = null; } - if (handItem != null + + //Fluid container code + /*if (handItem != null && (handItem instanceof IFluidContainerItem || handItem instanceof ItemFluidContainer || FluidContainerRegistry.isFilledContainer(player.getHeldItem()))) { if (tank.tank.getFluid() == null) { @@ -94,9 +92,17 @@ public class Machine_PooCollector extends BlockContainer { } } + }*/ + + if (!tank.mInventory.isEmpty()) { + PlayerUtils.messagePlayer(player, "Inventory contains:"); + PlayerUtils.messagePlayer(player, ItemUtils.getArrayStackNames(tank.mInventory.getRealInventory())); + } + else { + PlayerUtils.messagePlayer(player, "No solids collected yet."); } if (tank.tank.getFluid() != null) { - PlayerUtils.messagePlayer(player, "This tank contains " + tank.tank.getFluidAmount() + "L of " + PlayerUtils.messagePlayer(player, "Tank contains " + tank.tank.getFluidAmount() + "L of " + tank.tank.getFluid().getLocalizedName()); } } @@ -106,12 +112,12 @@ public class Machine_PooCollector extends BlockContainer { @Override public int getRenderBlockPass() { - return 1; + return 0; } @Override public boolean isOpaqueCube() { - return false; + return super.isOpaqueCube(); } @Override diff --git a/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java b/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java index 91ceb30911..1f7097afc9 100644 --- a/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java +++ b/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java @@ -354,6 +354,22 @@ public class RECIPES_Machines { ItemUtils.getSimpleStack(ModBlocks.blockCustomJukebox), 20 * 30, 30); + + //Poo Collector + CORE.RA.addSixSlotAssemblingRecipe( + new ItemStack[] { + CI.machineHull_MV, + CI.getTieredComponent(OrePrefixes.circuit, 2, GTNH ? 4 : 2), + CI.getTieredComponent(OrePrefixes.pipe, 2, GTNH ? 4 : 2), + CI.getElectricPump(2, GTNH ? 4 : 2), + ALLOY.EGLIN_STEEL.getPlate(GTNH ? 8 : 4), + ALLOY.POTIN.getScrew(GTNH ? 12 : 6) + }, + ALLOY.TUMBAGA.getFluid(144 * 4), + ItemUtils.getSimpleStack(ModBlocks.blockPooCollector), + 20 * 60, + 30); + //Basic Steam Turbine diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java index d5325d912f..9c6dc580b6 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java @@ -3,13 +3,25 @@ package gtPlusPlus.core.tileentities.machines; import java.util.List; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BTF_FluidTank; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.tileentities.base.TileEntityBase; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityChicken; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityMooshroom; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -21,9 +33,9 @@ import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -public class TileEntityPooCollector extends TileEntity implements IFluidHandler { +public class TileEntityPooCollector extends TileEntityBase implements IFluidHandler { - public FluidTank tank = new FluidTank(Integer.MAX_VALUE); + public FluidTank tank = new BTF_FluidTank(64000); private boolean needsUpdate = false; private int updateTimer = 0; private boolean hasRegistered = false; @@ -31,7 +43,7 @@ public class TileEntityPooCollector extends TileEntity implements IFluidHandler private BlockPos internalBlockLocation; public TileEntityPooCollector() { - super(); + super(9); } @Override @@ -133,15 +145,6 @@ public class TileEntityPooCollector extends TileEntity implements IFluidHandler } } } - if (!hasRegistered) { - //Register to the Handler. - /*if (!this.worldObj.isRemote) { - ThreadPooCollector.addTask(this); - if (!ThreadPooCollector.getInstance().isRunning) { - ThreadPooCollector.getInstance().run(); - } - }*/ - } } public void onTick() { @@ -149,7 +152,7 @@ public class TileEntityPooCollector extends TileEntity implements IFluidHandler if (this.worldObj == null || this.worldObj.isRemote) { return; } - if (internalTickCounter % 100 == 0) { + if (internalTickCounter % MathUtils.randInt(200, 300) == 0) { if (internalBlockLocation == null) { internalBlockLocation = new BlockPos(this); } @@ -191,12 +194,73 @@ public class TileEntityPooCollector extends TileEntity implements IFluidHandler public void onPostTick(List<EntityAnimal> animals) { for (EntityAnimal aPooMaker : animals) { - Logger.INFO("Sewer found "+aPooMaker.getCommandSenderName()); + //Logger.INFO("Sewer found "+aPooMaker.getCommandSenderName()); + addDrop(aPooMaker); + if (this.tank.getFluidAmount() < this.tank.getCapacity()) { + + int aPooAmount = 0; + if (aPooMaker instanceof EntityChicken) { + aPooAmount = MathUtils.randInt(1, 40); + } + else if (aPooMaker instanceof EntityHorse) { + aPooAmount = MathUtils.randInt(20, 40); + } + else if (aPooMaker instanceof EntityCow) { + aPooAmount = MathUtils.randInt(18, 45); + } + else if (aPooMaker instanceof EntityMooshroom) { + aPooAmount = 17; + } + else if (aPooMaker instanceof EntitySheep) { + aPooAmount = MathUtils.randInt(8, 30); + } + else { + aPooAmount = MathUtils.randInt(5, 35); + } + + aPooAmount = Math.max(Math.min(this.tank.getCapacity()-this.tank.getFluidAmount(), aPooAmount), 1); + + this.tank.fill(FluidUtils.getFluidStack(AgriculturalChem.PoopJuice, aPooAmount), true); + } + else { + ItemStack aDirtStack = ItemUtils.getSimpleStack(AgriculturalChem.dustDirt); + if (!this.mInventory.addItemStack(aDirtStack)) { + EntityItem entity = new EntityItem(worldObj, xCoord, yCoord+1.5, zCoord, aDirtStack); + worldObj.spawnEntityInWorld(entity); + } + } } } public boolean addDrop(EntityAnimal aAnimal) { + int aChance = MathUtils.randInt(0, 50000); + if (aChance > 0) { + ItemStack aPoop; + if (aChance<= 100) { + aPoop = ItemUtils.getItemStackOfAmountFromOreDict("dustManureByproducts", 1); + } + else if (aChance <= 500) { + aPoop = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1); + } + else if (aChance <= 1250) { + aPoop = ItemUtils.getItemStackOfAmountFromOreDict("dustTinyManureByproducts", 1); + } + else { + return false; + } + //Add poop to world + Logger.INFO("Adding animal waste for "+aAnimal.getCommandSenderName()); + + //Add to inventory if not full, else espawn in world + if (!this.mInventory.addItemStack(aPoop)) { + EntityItem entity = new EntityItem(worldObj, xCoord, yCoord+1.5, zCoord, aPoop); + worldObj.spawnEntityInWorld(entity); + } + + } + + return false; } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 9ce51d5858..d32ff4e160 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -663,7 +663,7 @@ public class ItemUtils { } public static String getArrayStackNames(final ItemStack[] aStack) { - String itemNames = "Item Array: "; + String itemNames = ""; int aPos = 0; for (final ItemStack alph : aStack) { if (alph == null) { |