Some liquid events. Non-API breaking. Add them at your leisure. This helps liquids know

what's happening to them. In case they're volatile or something ;)
This commit is contained in:
Christian 2012-11-16 01:28:29 -05:00
parent da00985e5f
commit ca16b4b1bd
2 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,87 @@
package net.minecraftforge.liquids;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
public class LiquidEvent extends Event {
public final LiquidStack liquid;
public final int x;
public final int y;
public final int z;
public final World world;
public LiquidEvent(LiquidStack liquid, World world, int x, int y, int z)
{
this.liquid = liquid;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
/**
* Mods should fire this event when they move liquids around (pipe networks etc)
*
* @author cpw
*
*/
public static class LiquidMotionEvent extends LiquidEvent {
public LiquidMotionEvent(LiquidStack liquid, World world, int x, int y, int z) {
super(liquid, world, x, y, z);
}
}
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#fill(LiquidStack, boolean)} their tank implementation.
* {@link LiquidTank} does.
*
* @author cpw
*
*/
public static class LiquidFillingEvent extends LiquidEvent {
public final ILiquidTank tank;
public LiquidFillingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank) {
super(liquid, world, x, y, z);
this.tank = tank;
}
}
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#drain(int, boolean)} from their tank.
* @author cpw
*
*/
public static class LiquidDrainingEvent extends LiquidEvent {
public final ILiquidTank tank;
public LiquidDrainingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank) {
super(liquid, world, x, y, z);
this.tank = tank;
}
}
/**
* Mods should fire this event when a liquid "spills", for example, if a block containing liquid is broken.
*
* @author cpw
*
*/
public static class LiquidSpilledEvent extends LiquidEvent {
public LiquidSpilledEvent(LiquidStack liquid, World world, int x, int y, int z) {
super(liquid, world, x, y, z);
}
}
/**
* A handy shortcut for firing the various liquid events
*
* @param event
*/
public static final void fireEvent(LiquidEvent event) {
MinecraftForge.EVENT_BUS.post(event);
}
}

View File

@ -1,5 +1,7 @@
package net.minecraftforge.liquids;
import net.minecraft.src.TileEntity;
/**
* Reference implementation of ILiquidTank. Use this or implement your own.
*/
@ -7,6 +9,7 @@ public class LiquidTank implements ILiquidTank {
private LiquidStack liquid;
private int capacity;
private int tankPressure;
private TileEntity tile;
public LiquidTank(int capacity) {
this(null, capacity);
@ -15,11 +18,22 @@ public class LiquidTank implements ILiquidTank {
public LiquidTank(int liquidId, int quantity, int capacity) {
this(new LiquidStack(liquidId, quantity), capacity);
}
public LiquidTank(int liquidId, int quantity, int capacity, TileEntity tile) {
this(liquidId, quantity, capacity);
this.tile = tile;
}
public LiquidTank(LiquidStack liquid, int capacity) {
this.liquid = liquid;
this.capacity = capacity;
}
public LiquidTank(LiquidStack liquid, int capacity, TileEntity tile)
{
this(liquid, capacity);
this.tile = tile;
}
@Override
public LiquidStack getLiquid() {
return this.liquid;
@ -54,6 +68,8 @@ public class LiquidTank implements ILiquidTank {
if(doFill) {
this.liquid = resource.copy();
this.liquid.amount = capacity;
if (tile!=null)
LiquidEvent.fireEvent(new LiquidEvent.LiquidFillingEvent(liquid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
}
return capacity;
}
@ -96,6 +112,9 @@ public class LiquidTank implements ILiquidTank {
if(liquid.amount <= 0)
liquid = null;
if (doDrain && tile!=null)
LiquidEvent.fireEvent(new LiquidEvent.LiquidDrainingEvent(drained, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
return drained;
}