diff options
6 files changed, 288 insertions, 1 deletions
diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index bb92613fe2..d0b501b58f 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -41,6 +41,7 @@ public final class ModBlocks { public static Block blockMiningExplosive; public static Block blockHellfire; + public static Block blockInfiniteFLuidTank; public static void init() { Utils.LOG_INFO("Initializing Blocks."); @@ -63,6 +64,7 @@ public final class ModBlocks { blockHeliumGenerator = new HeliumGenerator(); blockFirePit = new FirePit(); blockFishTrap = new FishTrap(); + blockInfiniteFLuidTank = new FluidTankInfinite(); blockOreFluorite = new BlockBaseOre("oreFluorite", "Fluorite", Material.rock, BlockTypes.ORE, Utils.rgbtoHexValue(120, 120, 30), 3); blockMiningExplosive = new MiningExplosives(); blockHellfire = new HellFire(); diff --git a/src/Java/gtPlusPlus/core/block/general/FluidTankInfinite.java b/src/Java/gtPlusPlus/core/block/general/FluidTankInfinite.java new file mode 100644 index 0000000000..fec8e5d315 --- /dev/null +++ b/src/Java/gtPlusPlus/core/block/general/FluidTankInfinite.java @@ -0,0 +1,97 @@ +package gtPlusPlus.core.block.general; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.LanguageRegistry; +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.TileEntityFishTrap; +import gtPlusPlus.core.tileentities.general.TileEntityInfiniteFluid; +import gtPlusPlus.core.util.player.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.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +public class FluidTankInfinite extends BlockContainer { + + @SideOnly(Side.CLIENT) + private IIcon textureTop; + @SideOnly(Side.CLIENT) + private IIcon textureBottom; + @SideOnly(Side.CLIENT) + private IIcon textureFront; + + @SuppressWarnings("deprecation") + public FluidTankInfinite() { + super(Material.iron); + this.setBlockName("blockInfiniteFluidTank"); + this.setCreativeTab(AddToCreativeTab.tabMachines); + GameRegistry.registerBlock(this, "blockInfiniteFluidTank"); + LanguageRegistry.addName(this, "Infinite Fluid Tank"); + + } + + /** + * Gets the block's texture. Args: side, meta + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(final int p_149691_1_, final int p_149691_2_) { + return p_149691_1_ == 1 ? this.textureTop + : (p_149691_1_ == 0 ? this.textureBottom + : ((p_149691_1_ != 2) && (p_149691_1_ != 4) ? this.blockIcon : this.textureFront)); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(final IIconRegister p_149651_1_) { + this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "cover_crafting"); + this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "cover_crafting"); + this.textureBottom = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "cover_crafting"); + this.textureFront = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "cover_crafting"); + } + + /** + * Called upon block activation (right click on the block.) + */ + @Override + public boolean onBlockActivated(final World world, final int x, final int y, final int z, final EntityPlayer player, + final int side, final float lx, final float ly, final float lz) { + if (world.isRemote) { + return true; + } + else { + TileEntityInfiniteFluid tank = (TileEntityInfiniteFluid) world.getTileEntity(x, y, z); + if (tank != null){ + PlayerUtils.messagePlayer(player, "This tank contains "+tank.tank.getFluidAmount()+"L of "+tank.tank.getFluid().getLocalizedName()); + } + } + return true; + } + + @Override + public int getRenderBlockPass() { + return 1; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public TileEntity createNewTileEntity(final World world, final int p_149915_2_) { + return new TileEntityInfiniteFluid(); + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) { + super.onBlockAdded(world, x, y, z); + } + +} diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java index 02b562c3ec..b7b19aca36 100644 --- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java +++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java @@ -20,6 +20,7 @@ public class ModTileEntities { GameRegistry.registerTileEntity(TileEntityWorkbenchAdvanced.class, "TileWorkbenchAdvanced"); GameRegistry.registerTileEntity(TileEntityFishTrap.class, "TileFishTrap"); GameRegistry.registerTileEntity(TileEntityFirepit.class, "TileFirePit"); + GameRegistry.registerTileEntity(TileEntityInfiniteFluid.class, "TileInfiniteFluid"); } diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java index 0edae3b1b9..8e361e6219 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java @@ -101,7 +101,7 @@ public class TileEntityFishTrap extends TileEntity implements ISidedInventory { int checkingSlot = 0; final ItemStack loot = this.generateLootForFishTrap().copy(); try { - Utils.LOG_INFO("Trying to add "+loot.getDisplayName()+" | "+loot.getItemDamage()); + //Utils.LOG_INFO("Trying to add "+loot.getDisplayName()+" | "+loot.getItemDamage()); for (final ItemStack contents : this.getInventory().getInventory()) { diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityInfiniteFluid.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityInfiniteFluid.java new file mode 100644 index 0000000000..7a5be32ef4 --- /dev/null +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityInfiniteFluid.java @@ -0,0 +1,127 @@ +package gtPlusPlus.core.tileentities.general; + +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.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidEvent; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +public class TileEntityInfiniteFluid extends TileEntity implements IFluidHandler { + + public FluidTank tank = new FluidTank(Integer.MAX_VALUE); + private boolean needsUpdate = false; + private int updateTimer = 0; + + public TileEntityInfiniteFluid() { + } + + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + needsUpdate = true; + return this.tank.fill(resource, doFill); + } + + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + return this.tank.drain(resource.amount, doDrain); + } + + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + needsUpdate = true; + FluidStack fluid = this.tank.getFluid(); + // return this.tank.drain(maxDrain, doDrain); + if (fluid == null) { + return null; + } + + int drained = maxDrain; + if (fluid.amount < drained) { + drained = fluid.amount; + } + + FluidStack stack = new FluidStack(fluid, drained); + if (doDrain) { + fluid.amount -= drained; + if (fluid.amount <= 0) { + fluid = null; + } + + if (this != null) { + FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord, this.tank, 0)); + } + } + return stack; + } + + public boolean canFill(ForgeDirection from, Fluid fluid) { + return true; + } + + public boolean canDrain(ForgeDirection from, Fluid fluid) { + return true; + } + + public FluidTankInfo[] getTankInfo(ForgeDirection from) { + return new FluidTankInfo[] { this.tank.getInfo() }; + } + + public float getAdjustedVolume() { + float amount = tank.getFluidAmount(); + float capacity = tank.getCapacity(); + float volume = (amount / capacity) * 0.8F; + return volume; + } + + public void updateEntity() { + if (needsUpdate) { + + if (this.tank.getFluid() != null){ + FluidStack bigStorage = this.tank.getFluid(); + bigStorage.amount = this.tank.getCapacity(); + this.tank.setFluid(bigStorage); + } + + if (updateTimer == 0) { + updateTimer = 10; // every 10 ticks it will send an update + } else { + --updateTimer; + if (updateTimer == 0) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + needsUpdate = false; + } + } + } + } + + @Override + public void readFromNBT(NBTTagCompound tag) { + tank.readFromNBT(tag); + super.readFromNBT(tag); + } + + @Override + public void writeToNBT(NBTTagCompound tag) { + tank.writeToNBT(tag); + super.writeToNBT(tag); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound tag = new NBTTagCompound(); + writeToNBT(tag); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.blockMetadata, tag); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + NBTTagCompound tag = pkt.func_148857_g(); + readFromNBT(tag); + } + +} diff --git a/src/Java/gtPlusPlus/core/util/inventory/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/inventory/InventoryUtils.java new file mode 100644 index 0000000000..51ae393c06 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/inventory/InventoryUtils.java @@ -0,0 +1,60 @@ +package gtPlusPlus.core.util.inventory; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public class InventoryUtils { + + private final static Random mRandom = new Random(); + + public static void dropInventoryItems(World world, int x, int y, int z, Block block){ + Object tileentity = world.getTileEntity(x, y, z); + + if (tileentity != null) + { + for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1) + { + ItemStack itemstack = (ItemStack) ((IInventory) tileentity).getStackInSlot(i1); + + if (itemstack != null) + { + float f = mRandom.nextFloat() * 0.8F + 0.1F; + float f1 = mRandom.nextFloat() * 0.8F + 0.1F; + EntityItem entityitem; + + for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) + { + int j1 = mRandom.nextInt(21) + 10; + + if (j1 > itemstack.stackSize) + { + j1 = itemstack.stackSize; + } + + itemstack.stackSize -= j1; + entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); + float f3 = 0.05F; + entityitem.motionX = (double)((float)mRandom.nextGaussian() * f3); + entityitem.motionY = (double)((float)mRandom.nextGaussian() * f3 + 0.2F); + entityitem.motionZ = (double)((float)mRandom.nextGaussian() * f3); + + if (itemstack.hasTagCompound()) + { + entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); + } + } + } + } + + world.func_147453_f(x, y, z, block); + } + + } + +} |