2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.blocks.logic;
|
|
|
|
|
|
|
|
|
|
import tconstruct.TConstruct;
|
2013-12-01 19:46:08 -05:00
|
|
|
import mantle.blocks.iface.IActiveLogic;
|
|
|
|
|
import mantle.blocks.iface.IFacingLogic;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-01-10 21:14:54 -05:00
|
|
|
import net.minecraft.network.NetworkManager;
|
2013-12-31 20:24:06 -05:00
|
|
|
import net.minecraft.network.Packet;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.network.packet.Packet132TileEntityData;
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
2013-12-31 20:24:06 -05:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
|
|
|
|
|
|
|
|
|
public class FaucetLogic extends TileEntity implements IFacingLogic, IActiveLogic, IFluidHandler
|
|
|
|
|
{
|
|
|
|
|
byte direction;
|
|
|
|
|
boolean active;
|
|
|
|
|
public FluidStack liquid;
|
|
|
|
|
|
|
|
|
|
public boolean activateFaucet ()
|
|
|
|
|
{
|
|
|
|
|
if (liquid == null && active)
|
|
|
|
|
{
|
2014-01-08 21:59:48 -05:00
|
|
|
int x = field_145851_c, z = field_145849_e;
|
2013-07-26 21:18:53 -07:00
|
|
|
switch (getRenderDirection())
|
|
|
|
|
{
|
|
|
|
|
case 2:
|
|
|
|
|
z++;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
z--;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
x++;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
x--;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 23:46:45 -05:00
|
|
|
TileEntity drainte = field_145850_b.func_147438_o(x, field_145848_d, z);
|
|
|
|
|
TileEntity tankte = field_145850_b.func_147438_o(field_145851_c, field_145848_d - 1, field_145849_e);
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
if (drainte != null && drainte instanceof IFluidHandler && tankte != null && tankte instanceof IFluidHandler)
|
|
|
|
|
{
|
|
|
|
|
FluidStack templiquid = ((IFluidHandler) drainte).drain(getForgeDirection(), TConstruct.ingotLiquidValue, false);
|
|
|
|
|
if (templiquid != null)
|
|
|
|
|
{
|
|
|
|
|
int drained = ((IFluidHandler) tankte).fill(ForgeDirection.UP, templiquid, false);
|
|
|
|
|
if (drained > 0)
|
|
|
|
|
{
|
|
|
|
|
liquid = ((IFluidHandler) drainte).drain(getForgeDirection(), drained, true);
|
|
|
|
|
((IFluidHandler) tankte).fill(ForgeDirection.UP, liquid, true);
|
2014-01-08 21:59:48 -05:00
|
|
|
field_145850_b.markBlockForUpdate(field_145851_c, field_145848_d, field_145849_e);
|
2013-07-26 21:18:53 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateEntity ()
|
|
|
|
|
{
|
|
|
|
|
if (liquid != null)
|
|
|
|
|
{
|
|
|
|
|
liquid.amount -= TConstruct.liquidUpdateAmount;
|
|
|
|
|
if (liquid.amount <= 0)
|
|
|
|
|
{
|
|
|
|
|
liquid = null;
|
|
|
|
|
if (!activateFaucet())
|
|
|
|
|
{
|
|
|
|
|
active = false;
|
2014-01-08 21:59:48 -05:00
|
|
|
field_145850_b.markBlockForUpdate(field_145851_c, field_145848_d, field_145849_e);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public byte getRenderDirection ()
|
|
|
|
|
{
|
|
|
|
|
return direction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ForgeDirection getForgeDirection ()
|
|
|
|
|
{
|
|
|
|
|
return ForgeDirection.VALID_DIRECTIONS[direction];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setDirection (int side)
|
|
|
|
|
{
|
|
|
|
|
//direction = (byte) side;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setDirection (float yaw, float pitch, EntityLivingBase player)
|
|
|
|
|
{
|
|
|
|
|
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
|
|
|
|
|
switch (facing)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
direction = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
direction = 5;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
direction = 3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
direction = 4;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-01-18 02:52:49 -05:00
|
|
|
public void func_145839_a (NBTTagCompound tags)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-18 02:52:49 -05:00
|
|
|
super.func_145839_a(tags);
|
2013-07-26 21:18:53 -07:00
|
|
|
readCustomNBT(tags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readCustomNBT (NBTTagCompound tags)
|
|
|
|
|
{
|
|
|
|
|
direction = tags.getByte("Direction");
|
|
|
|
|
if (tags.getBoolean("hasLiquid"))
|
|
|
|
|
{
|
|
|
|
|
this.liquid = FluidStack.loadFluidStackFromNBT(tags.getCompoundTag("Fluid"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this.liquid = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-01-18 02:52:49 -05:00
|
|
|
public void func_145841_b (NBTTagCompound tags)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-18 02:52:49 -05:00
|
|
|
super.func_145841_b(tags);
|
2013-07-26 21:18:53 -07:00
|
|
|
writeCustomNBT(tags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void writeCustomNBT (NBTTagCompound tags)
|
|
|
|
|
{
|
|
|
|
|
tags.setByte("Direction", direction);
|
|
|
|
|
tags.setBoolean("hasLiquid", liquid != null);
|
|
|
|
|
if (liquid != null)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound nbt = new NBTTagCompound();
|
2014-01-18 02:52:49 -05:00
|
|
|
liquid.func_145841_b(nbt);
|
2013-12-31 20:24:06 -05:00
|
|
|
tags.setTag("Fluid", nbt);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Packets */
|
|
|
|
|
@Override
|
|
|
|
|
public Packet getDescriptionPacket ()
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
|
writeCustomNBT(tag);
|
2014-01-08 21:59:48 -05:00
|
|
|
return new Packet132TileEntityData(field_145851_c, field_145848_d, field_145849_e, 1, tag);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-01-10 21:14:54 -05:00
|
|
|
public void onDataPacket (NetworkManager net, Packet132TileEntityData packet)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-09-07 01:35:45 -04:00
|
|
|
readCustomNBT(packet.data);
|
2014-01-08 21:59:48 -05:00
|
|
|
field_145850_b.markBlockForRenderUpdate(field_145851_c, field_145848_d, field_145849_e);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean getActive ()
|
|
|
|
|
{
|
|
|
|
|
return active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setActive (boolean flag)
|
|
|
|
|
{
|
|
|
|
|
if (!active)
|
|
|
|
|
{
|
|
|
|
|
active = true;
|
|
|
|
|
activateFaucet();
|
|
|
|
|
}
|
2013-10-07 19:58:36 +01:00
|
|
|
else
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
active = false;
|
2013-10-07 19:58:36 +01:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canFill (ForgeDirection from, Fluid fluid)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|