From a57f3f9268af700bc3ef856f7cfafe206185bfa2 Mon Sep 17 00:00:00 2001 From: Rseifert Date: Fri, 1 Feb 2013 16:59:14 -0500 Subject: [PATCH] api changes and bug fixes Fixed: Liquid register event Fixed? Bucket and Vile stack lose on filling Added: IPipe interface to help ID pipes Added? Pipe drip effects --- minecraft/liquidmechanics/api/IPipe.java | 6 +++ .../common/LiquidMechanics.java | 2 + .../common/block/BlockPipe.java | 6 ++- .../common/block/BlockSink.java | 34 +++++++++++++- .../common/tileentity/TileEntityPipe.java | 45 ++++++++++++++++--- 5 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 minecraft/liquidmechanics/api/IPipe.java diff --git a/minecraft/liquidmechanics/api/IPipe.java b/minecraft/liquidmechanics/api/IPipe.java new file mode 100644 index 00000000..2cb02305 --- /dev/null +++ b/minecraft/liquidmechanics/api/IPipe.java @@ -0,0 +1,6 @@ +package liquidmechanics.api; + +public interface IPipe extends IColorCoded +{ + +} diff --git a/minecraft/liquidmechanics/common/LiquidMechanics.java b/minecraft/liquidmechanics/common/LiquidMechanics.java index 939a4ba6..6a9aa949 100644 --- a/minecraft/liquidmechanics/common/LiquidMechanics.java +++ b/minecraft/liquidmechanics/common/LiquidMechanics.java @@ -32,6 +32,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.liquids.LiquidDictionary; import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.oredict.OreDictionary; @@ -155,6 +156,7 @@ public class LiquidMechanics extends DummyModContainer GameRegistry.registerTileEntity(TileEntityGenerator.class, "lmGen"); GameRegistry.registerTileEntity(TileEntitySink.class, "lmSink"); System.out.println("Fluid Mechanics Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " Languages."); + MinecraftForge.EVENT_BUS.register(LiquidHandler.class); } diff --git a/minecraft/liquidmechanics/common/block/BlockPipe.java b/minecraft/liquidmechanics/common/block/BlockPipe.java index cd484396..c4f26ef2 100644 --- a/minecraft/liquidmechanics/common/block/BlockPipe.java +++ b/minecraft/liquidmechanics/common/block/BlockPipe.java @@ -1,7 +1,9 @@ package liquidmechanics.common.block; import java.util.List; +import java.util.Random; +import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.client.render.BlockRenderHelper; import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.TabLiquidMechanics; @@ -12,6 +14,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.liquids.LiquidStack; import universalelectricity.prefab.BlockMachine; public class BlockPipe extends BlockMachine @@ -23,6 +27,7 @@ public class BlockPipe extends BlockMachine this.setHardness(1f); this.setBlockName("lmPipe"); this.setResistance(3f); + //this.setTickRandomly(true); } @Override @@ -42,7 +47,6 @@ public class BlockPipe extends BlockMachine { return -1; } - /** * Lets the block know when one of its neighbor changes. Doesn't know which * neighbor changed (coordinates passed are their own) Args: x, y, z, diff --git a/minecraft/liquidmechanics/common/block/BlockSink.java b/minecraft/liquidmechanics/common/block/BlockSink.java index 74a903b7..a027be8f 100644 --- a/minecraft/liquidmechanics/common/block/BlockSink.java +++ b/minecraft/liquidmechanics/common/block/BlockSink.java @@ -80,7 +80,22 @@ public class BlockSink extends BlockMachine LiquidStack drain = tank.drain(LiquidContainerRegistry.BUCKET_VOLUME, false); if (drain != null && drain.amount >= LiquidContainerRegistry.BUCKET_VOLUME) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Item.bucketWater)); + ItemStack var12 = new ItemStack(Item.bucketEmpty, 1, 0); + if (!player.inventory.addItemStackToInventory(heldItem)) + { + world.spawnEntityInWorld(new EntityItem(world, (double) x + 0.5D, (double) y + 1.5D, (double) z + 0.5D, var12)); + } + else if (player instanceof EntityPlayerMP) + { + ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer); + } + + --heldItem.stackSize; + + if (heldItem.stackSize <= 0) + { + player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack) null); + } tank.drain(LiquidContainerRegistry.BUCKET_VOLUME, true); return true; } @@ -91,7 +106,22 @@ public class BlockSink extends BlockMachine LiquidStack drain = tank.drain(LiquidContainerRegistry.BUCKET_VOLUME / 4, false); if (drain != null && drain.amount >= LiquidContainerRegistry.BUCKET_VOLUME / 4) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Item.potion, 1, 0)); + ItemStack var12 = new ItemStack(Item.potion, 1, 0); + if (!player.inventory.addItemStackToInventory(var12)) + { + world.spawnEntityInWorld(new EntityItem(world, (double) x + 0.5D, (double) y + 1.5D, (double) z + 0.5D, var12)); + } + else if (player instanceof EntityPlayerMP) + { + ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer); + } + + --heldItem.stackSize; + + if (heldItem.stackSize <= 0) + { + player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack) null); + } tank.drain(LiquidContainerRegistry.BUCKET_VOLUME / 4, true); return true; } diff --git a/minecraft/liquidmechanics/common/tileentity/TileEntityPipe.java b/minecraft/liquidmechanics/common/tileentity/TileEntityPipe.java index 1638956d..c5e16257 100644 --- a/minecraft/liquidmechanics/common/tileentity/TileEntityPipe.java +++ b/minecraft/liquidmechanics/common/tileentity/TileEntityPipe.java @@ -1,6 +1,9 @@ package liquidmechanics.common.tileentity; +import java.util.Random; + import liquidmechanics.api.IColorCoded; +import liquidmechanics.api.IPipe; import liquidmechanics.api.IReadOut; import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.connectionHelper; @@ -10,12 +13,14 @@ import liquidmechanics.api.liquids.LiquidHandler; import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.handlers.UpdateConverter; import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.liquids.ILiquidTank; import net.minecraftforge.liquids.ITankContainer; @@ -30,7 +35,7 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLLog; -public class TileEntityPipe extends TileEntity implements ITankContainer, IReadOut, IColorCoded +public class TileEntityPipe extends TileEntity implements ITankContainer, IReadOut, IPipe { private ColorCode color = ColorCode.NONE; @@ -50,13 +55,16 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO this.validataConnections(); this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); - if (!worldObj.isRemote && ++count >= 20) + if (++count >= 20) { count = 0; this.updatePressure(); - + if (this.worldObj.isRemote) + { + this.randomDisplayTick(); + } LiquidStack stack = stored.getLiquid(); - if (stack != null && stack.amount >= 0) + if (!worldObj.isRemote && stack != null && stack.amount >= 0) { for (int i = 0; i < 6; i++) @@ -77,11 +85,11 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO { if (dir == ForgeDirection.UP && !color.getLiquidData().getCanFloat()) { - + /* do nothing */ } else if (dir == ForgeDirection.DOWN && color.getLiquidData().getCanFloat()) { - + /* do nothing */ } else { @@ -105,6 +113,29 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO } + public void randomDisplayTick() + { + Random random = new Random(); + LiquidStack stack = stored.getLiquid(); + if (stack != null && random.nextInt(10) == 0) + { + // TODO align this with the pipe model so not to drip where there is + // no pipe + double xx = (double) ((float) xCoord + random.nextDouble()); + double zz = (double) yCoord + .3D; + double yy = (double) ((float) zCoord + random.nextDouble()); + + if (ColorCode.get(stack) != ColorCode.RED) + { + worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D); + } + else + { + worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D); + } + } + } + /** * gets the current color mark of the pipe */ @@ -274,7 +305,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO { connectedBlocks[i] = null; } - //TODO switch side catch for IPressure + // TODO switch side catch for IPressure if (this.color != ColorCode.NONE && ent instanceof TileEntityTank && ((TileEntityTank) ent).getColor() != ColorCode.NONE && color != ((TileEntityTank) ent).getColor()) { connectedBlocks[i] = null;