Started on pipe channels aka troughs

This commit is contained in:
DarkGuardsman 2014-02-17 22:25:34 -05:00
parent bc32f6145d
commit b35a1d29a5
19 changed files with 736 additions and 862 deletions

View file

@ -0,0 +1,17 @@
package resonantinduction.archaic.channel;
import resonantinduction.core.Settings;
import resonantinduction.core.prefab.fluid.BlockFluidNetwork;
import universalelectricity.api.UniversalElectricity;
/** Early tier version of the basic pipe. Open on the top, and can't support pressure.
*
* @author Darkguardsman */
public class BlockChannel extends BlockFluidNetwork
{
public BlockChannel(int id)
{
super(Settings.CONFIGURATION.getBlock("Channel", id).getInt(id), UniversalElectricity.machine);
}
}

View file

@ -0,0 +1,60 @@
package resonantinduction.archaic.channel;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ItemChannelRenderer implements IItemRenderer
{
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
return true;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
GL11.glPushMatrix();
GL11.glRotatef(180f, 0f, 0f, 1f);
int meta = item.getItemDamage();
if (type == ItemRenderType.ENTITY)
{
GL11.glTranslatef(-.5F, -1F, -.5F);
RenderChannel.render(meta, Byte.parseByte("001100", 2));
}
else if (type == ItemRenderType.INVENTORY)
{
GL11.glTranslatef(0F, -1F, 0F);
RenderChannel.render(meta, Byte.parseByte("001100", 2));
}
else if (type == ItemRenderType.EQUIPPED)
{
GL11.glTranslatef(-1F, -1.2F, 0.5F);
RenderChannel.render(meta, Byte.parseByte("000011", 2));
}
else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON)
{
GL11.glTranslatef(-2F, -1.5F, 0.2F);
RenderChannel.render(meta, Byte.parseByte("001100", 2));
}
else
{
RenderChannel.render(item.getItemDamage(), Byte.parseByte("000011", 2));
}
GL11.glPopMatrix();
}
}

View file

@ -4,7 +4,7 @@
// Keep in mind that you still need to fill in some blanks
// - ZeuX
package resonantinduction.mechanical.fluid.pipe;
package resonantinduction.archaic.channel;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;

View file

@ -0,0 +1,38 @@
package resonantinduction.archaic.channel;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference;
import resonantinduction.mechanical.fluid.pipe.ModelPipe;
import resonantinduction.mechanical.fluid.pipe.PartPipe;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderChannel
{
public static final RenderChannel INSTANCE = new RenderChannel();
public static ModelOpenTrough MODEL_TROUGH_PIPE = new ModelOpenTrough();
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe.png");
public void render(PartPipe part, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
render(0, part.getAllCurrentConnections());
GL11.glPopMatrix();
}
public static void render(int meta, byte sides)
{
RenderUtility.enableBlending();
RenderUtility.bind(TEXTURE);
MODEL_TROUGH_PIPE.render(sides, meta == 0 ? true : false);
RenderUtility.disableBlending();
}
}

View file

@ -0,0 +1,9 @@
package resonantinduction.archaic.channel;
import calclavia.lib.prefab.tile.TileAdvanced;
/** @author Darkguardsman */
public class TileChannel extends TileAdvanced
{
}

View file

@ -11,9 +11,9 @@ import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.Settings;
import resonantinduction.core.TabRI;
import resonantinduction.core.prefab.fluid.ItemBlockFluidContainer;
import resonantinduction.mechanical.belt.BlockConveyorBelt;
import resonantinduction.mechanical.belt.TileConveyorBelt;
import resonantinduction.mechanical.fluid.pipe.ItemBlockFluidContainer;
import resonantinduction.mechanical.fluid.pipe.ItemPipe;
import resonantinduction.mechanical.fluid.tank.BlockTank;
import resonantinduction.mechanical.fluid.tank.TileTank;

View file

@ -6,7 +6,7 @@ import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
import resonantinduction.core.prefab.fluid.TileFluidNetwork;
/**
* Enum to hold info about each pipe material. Values are by default and some can change with pipe

View file

@ -1,110 +0,0 @@
package resonantinduction.mechanical.fluid.pipe;
import calclavia.lib.render.ColorCode;
import calclavia.lib.render.ColorCode.IColoredId;
public enum EnumPipeType implements IColoredId
{
Base(0, 0, true), COLOR(new IPipeType()
{
@Override
public ColorCode getColor(int meta)
{
return ColorCode.get(meta);
}
@Override
public String getName(int pipeID)
{
if (pipeID < 16 && pipeID > 0)
{
return ColorCode.get(pipeID - 1).name;
}
return "";
}
}, 1, 16, true);
private IPipeType type;
public int metaStart = 1;
public int metaEnd = 16;
public boolean canColor = false;
private EnumPipeType()
{
this.metaStart = this.ordinal() * 16;
this.metaEnd = this.metaStart + 15;
}
private EnumPipeType(int metaStart, int metaEnd, boolean canColor)
{
}
private EnumPipeType(IPipeType type, int metaStart, int metaEnd, boolean canColor)
{
this.type = type;
this.metaStart = metaStart;
this.metaEnd = metaEnd;
this.canColor = canColor;
}
public static EnumPipeType get(int meta)
{
for (EnumPipeType type : EnumPipeType.values())
{
if (meta >= type.metaStart && meta <= type.metaEnd)
{
return type;
}
}
return null;
}
public static boolean canColor(int meta)
{
EnumPipeType type = get(meta);
if (type != null)
{
return type.canColor;
}
return false;
}
public static int getUpdatedID(int pipeID, ColorCode newColor)
{
if (pipeID == 0)
{
return 1 + newColor.ordinal();
}
return pipeID;
}
public static ColorCode getColorCode(int meta)
{
EnumPipeType type = get(meta);
if (type != null)
{
return type.getColor(meta);
}
return ColorCode.UNKOWN;
}
@Override
public ColorCode getColor(int meta)
{
if (type != null)
{
return type.getColor(meta);
}
return ColorCode.UNKOWN;
}
public String getName(int pipeID)
{
if (type != null)
{
return type.getName(pipeID);
}
return "";
}
}

View file

@ -1,8 +0,0 @@
package resonantinduction.mechanical.fluid.pipe;
import calclavia.lib.render.ColorCode.IColoredId;
public interface IPipeType extends IColoredId
{
public String getName(int pipeID);
}

View file

@ -1,133 +0,0 @@
package resonantinduction.mechanical.fluid.pipe;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
import resonantinduction.mechanical.fluid.tank.TileTank;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;
import universalelectricity.api.energy.UnitDisplay.UnitPrefix;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.LanguageUtility;
public class ItemBlockFluidContainer extends ItemBlock
{
public ItemBlockFluidContainer(int id)
{
super(id);
this.setMaxDamage(0);
this.setHasSubtypes(true);
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid"));
if (fluid != null)
{
list.add("Fluid: " + fluid.getFluid().getLocalizedName());
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
}
}
}
public static ItemStack getWrenchedItem(World world, Vector3 vec)
{
TileEntity entity = vec.getTileEntity(world);
if (entity instanceof TileTank && ((TileTank) entity).getInternalTank() != null && ((TileTank) entity).getInternalTank().getFluid() != null)
{
ItemStack itemStack = new ItemStack(Mechanical.blockTank);
FluidStack stack = ((TileTank) entity).getInternalTank().getFluid();
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if (stack != null)
{
((TileTank) entity).drain(ForgeDirection.UNKNOWN, stack.amount, true);
itemStack.getTagCompound().setCompoundTag("fluid", stack.writeToNBT(new NBTTagCompound()));
}
return itemStack;
}
return null;
}
@Override
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
{
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
if (itemStack.getTagCompound() != null && !player.capabilities.isCreativeMode && itemStack.getTagCompound().hasKey("fluid"))
{
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0));
}
}
}
@Override
public int getItemStackLimit(ItemStack stack)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
return 1;
}
return this.maxStackSize;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
String translation = LanguageUtility.getLocal(Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage());
if (translation == null || translation.isEmpty())
{
return Block.blocksList[this.getBlockID()].getUnlocalizedName();
}
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, (metadata / EnumPipeMaterial.spacing)))
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).setSubID(stack.getItemDamage());
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
((TileFluidNetwork) tile).fill(ForgeDirection.UNKNOWN, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true);
}
}
return true;
}
return false;
}
}

View file

@ -4,44 +4,35 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import resonantinduction.archaic.channel.ModelOpenTrough;
import resonantinduction.core.Reference;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderPipe
{
public static final RenderPipe INSTANCE = new RenderPipe();
public static final RenderPipe INSTANCE = new RenderPipe();
public static ModelPipe MODEL_PIPE = new ModelPipe();
public static ModelOpenTrough MODEL_TROUGH_PIPE = new ModelOpenTrough();
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe.png");
public static ModelPipe MODEL_PIPE = new ModelPipe();
public static ModelOpenTrough MODEL_TROUGH_PIPE = new ModelOpenTrough();
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe.png");
public void render(PartPipe part, double x, double y, double z, float f)
{
EnumPipeMaterial material = part.getMaterial();
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
render(0, part.getAllCurrentConnections());
GL11.glPopMatrix();
}
public void render(PartPipe part, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
render(0, part.getAllCurrentConnections());
GL11.glPopMatrix();
}
public static ResourceLocation getTexture(EnumPipeMaterial material)
{
return TEXTURE;
}
public static void render(int meta, byte sides)
{
if (meta < EnumPipeMaterial.values().length)
{
RenderUtility.enableBlending();
RenderUtility.bind((getTexture(EnumPipeMaterial.values()[meta])));
MODEL_PIPE.render(sides);
RenderUtility.disableBlending();
}
}
public static void render(int meta, byte sides)
{
RenderUtility.enableBlending();
RenderUtility.bind(TEXTURE);
MODEL_PIPE.render(sides);
RenderUtility.disableBlending();
}
}

View file

@ -1,42 +0,0 @@
package resonantinduction.mechanical.fluid.prefab;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import calclavia.lib.prefab.block.BlockTile;
/**
* @author Calclavia
*
*/
public abstract class BlockFluidNetwork extends BlockTile
{
public BlockFluidNetwork(int id, Material material)
{
super(id, material);
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).refresh();
((TileFluidNetwork) tile).getNetwork().reconstruct();
}
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int par5)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).refresh();
}
}
}

View file

@ -1,112 +0,0 @@
package resonantinduction.mechanical.fluid.prefab;
import resonantinduction.mechanical.fluid.pipe.EnumPipeType;
import resonantinduction.mechanical.fluid.pipe.IPipeType;
import calclavia.lib.render.ColorCode;
import calclavia.lib.render.ColorCode.IColoredId;
public enum EnumTankTypes implements IColoredId
{
Base(0, 0, true), COLOR(new IPipeType()
{
@Override
public ColorCode getColor(int meta)
{
return ColorCode.get(meta);
}
@Override
public String getName(int pipeID)
{
if (pipeID < 16 && pipeID > 0)
{
return ColorCode.get(pipeID - 1).name;
}
return "";
}
}, 1, 16, true);
private IPipeType type;
public int metaStart = 1;
public int metaEnd = 16;
public boolean canColor = false;
private EnumTankTypes()
{
this.metaStart = this.ordinal() * 16;
this.metaEnd = this.metaStart + 15;
}
private EnumTankTypes(int metaStart, int metaEnd, boolean canColor)
{
}
private EnumTankTypes(IPipeType type, int metaStart, int metaEnd, boolean canColor)
{
this.type = type;
this.metaStart = metaStart;
this.metaEnd = metaEnd;
this.canColor = canColor;
}
public static EnumPipeType get(int meta)
{
for (EnumPipeType type : EnumPipeType.values())
{
if (meta >= type.metaStart && meta <= type.metaEnd)
{
return type;
}
}
return null;
}
public static boolean canColor(int meta)
{
EnumPipeType type = get(meta);
if (type != null)
{
return type.canColor;
}
return false;
}
public static int getUpdatedID(int pipeID, ColorCode newColor)
{
if (pipeID == 0)
{
return 1 + newColor.ordinal();
}
return pipeID;
}
public static ColorCode getColorCode(int meta)
{
EnumPipeType type = get(meta);
if (type != null)
{
return type.getColor(meta);
}
return ColorCode.UNKOWN;
}
@Override
public ColorCode getColor(int meta)
{
if (type != null)
{
return type.getColor(meta);
}
return ColorCode.UNKOWN;
}
public String getName(int pipeID)
{
if (type != null)
{
return type.getName(pipeID);
}
return "";
}
}

View file

@ -1,316 +0,0 @@
package resonantinduction.mechanical.fluid.prefab;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import resonantinduction.api.IInformation;
import resonantinduction.api.mechanical.fluid.IFluidConnector;
import resonantinduction.api.mechanical.fluid.IFluidNetwork;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.Mechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiverWithID;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.TileAdvanced;
import calclavia.lib.utility.FluidUtility;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A prefab class for tiles that use the fluid network.
*
* @author DarkCow
*
*/
public abstract class TileFluidNetwork extends TileAdvanced implements IFluidConnector, IPacketReceiverWithID, IInformation
{
protected FluidTank tank;
protected Object[] connectedBlocks = new Object[6];
protected int colorID = 0;
/** Copy of the tank's content last time it updated */
protected FluidStack prevStack = null;
/** Network used to link all parts together */
protected IFluidNetwork network;
public static final int PACKET_DESCRIPTION = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_RENDER = Mechanical.contentRegistry.getNextPacketID();
public static final int PACKET_TANK = Mechanical.contentRegistry.getNextPacketID();
/** Bitmask that handles connections for the renderer **/
public byte renderSides = 0;
@Override
public void initiate()
{
super.initiate();
refresh();
getNetwork().reconstruct();
}
@Override
public void invalidate()
{
this.getNetwork().split(this);
super.invalidate();
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return this.getNetwork().fill(this, from, resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
return this.getNetwork().drain(this, from, resource, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return this.getNetwork().drain(this, from, maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return this.getNetwork().getTankInfo();
}
@Override
public Object[] getConnections()
{
return this.connectedBlocks;
}
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
byte previousConnections = renderSides;
this.connectedBlocks = new Object[6];
this.renderSides = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
this.sendRenderUpdate();
this.getNetwork().reconstruct();
}
}
}
/**
* Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof IFluidConnector)
{
this.getNetwork().merge(((IFluidConnector) tileEntity).getNetwork());
this.setRenderSide(side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
public void setRenderSide(ForgeDirection direction, boolean doRender)
{
if (doRender)
{
renderSides = (byte) (renderSides | (1 << direction.ordinal()));
}
else
{
renderSides = (byte) (renderSides & ~(1 << direction.ordinal()));
}
}
public boolean canRenderSide(ForgeDirection direction)
{
return (renderSides & (1 << direction.ordinal())) != 0;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.colorID = nbt.getInteger("subID");
if (nbt.hasKey("stored"))
{
NBTTagCompound tag = nbt.getCompoundTag("stored");
String name = tag.getString("LiquidName");
int amount = nbt.getInteger("Amount");
Fluid fluid = FluidRegistry.getFluid(name);
if (fluid != null)
{
FluidStack liquid = new FluidStack(fluid, amount);
this.getInternalTank().setFluid(liquid);
}
}
else
{
this.getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
if (id == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
else if (id == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
return true;
}
else if (id == PACKET_TANK)
{
this.tank = new FluidTank(data.readInt()).readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
public void sendRenderUpdate()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
}
public void sendTankUpdate()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, getInternalTank().getCapacity(), getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
}
@Override
public void onFluidChanged()
{
if (!worldObj.isRemote)
{
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
{
sendTankUpdate();
}
prevStack = tank.getFluid();
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
}
public int getSubID()
{
return this.colorID;
}
public void setSubID(int id)
{
this.colorID = id;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@Override
public FluidTank getInternalTank()
{
if (this.tank == null)
{
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
return this.tank;
}
@Override
public void getInformation(List<String> info)
{
info.add(this.getNetwork().toString());
}
@Override
public IFluidConnector getInstance(ForgeDirection from)
{
return this;
}
}

View file

@ -10,10 +10,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import resonantinduction.core.prefab.fluid.BlockFluidNetwork;
import resonantinduction.core.prefab.fluid.ItemBlockFluidContainer;
import resonantinduction.core.render.RIBlockRenderingHandler;
import resonantinduction.mechanical.fluid.pipe.EnumPipeMaterial;
import resonantinduction.mechanical.fluid.pipe.ItemBlockFluidContainer;
import resonantinduction.mechanical.fluid.prefab.BlockFluidNetwork;
import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.FluidUtility;
@ -23,121 +22,118 @@ import cpw.mods.fml.relauncher.SideOnly;
public class BlockTank extends BlockFluidNetwork
{
public BlockTank(int id)
{
super(id, UniversalElectricity.machine);
setHardness(1f);
setResistance(5f);
}
public BlockTank(int id)
{
super(id, UniversalElectricity.machine);
setHardness(1f);
setResistance(5f);
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean renderAsNormalBlock()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean renderAsNormalBlock()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return RIBlockRenderingHandler.ID;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return RIBlockRenderingHandler.ID;
}
@Override
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side)
{
int checkBlockID = blockAccess.getBlockId(x, y, z);
return super.shouldSideBeRendered(blockAccess, x, y, z, side);
}
@Override
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side)
{
int checkBlockID = blockAccess.getBlockId(x, y, z);
return super.shouldSideBeRendered(blockAccess, x, y, z, side);
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
return FluidUtility.playerActivatedFluidItem(world, x, y, z, entityplayer, side);
}
return true;
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
return FluidUtility.playerActivatedFluidItem(world, x, y, z, entityplayer, side);
}
return true;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileTank();
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileTank();
}
@Override
public boolean hasComparatorInputOverride()
{
return true;
}
@Override
public boolean hasComparatorInputOverride()
{
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{
TileTank tileEntity = (TileTank) world.getBlockTileEntity(x, y, z);
if (tileEntity != null && tileEntity.getNetwork().getTank().getFluid() != null)
{
return 15 * (tileEntity.getNetwork().getTank().getFluidAmount() / tileEntity.getNetwork().getTank().getCapacity());
}
return 0;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{
TileTank tileEntity = (TileTank) world.getBlockTileEntity(x, y, z);
if (tileEntity != null && tileEntity.getNetwork().getTank().getFluid() != null)
{
return 15 * (tileEntity.getNetwork().getTank().getFluidAmount() / tileEntity.getNetwork().getTank().getCapacity());
}
return 0;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
return new ItemStack(this, 1, EnumPipeMaterial.getDropItemMeta(world, x, y, z));
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
return new ItemStack(this, 1, 0);
}
@Override
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileTank)
{
ret.add(new ItemStack(this, 1, EnumPipeMaterial.getDropItemMeta(world, x, y, z)));
}
return ret;
}
@Override
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileTank)
{
ret.add(new ItemStack(this, 1, 0));
}
return ret;
}
@SuppressWarnings("unchecked")
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (EnumPipeMaterial data : EnumPipeMaterial.values())
{
par3List.add(new ItemStack(this, 1, data.ordinal() * EnumPipeMaterial.spacing));
break;
}
}
@SuppressWarnings("unchecked")
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this, 1, 0));
@Override
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
ItemStack dropStack = ItemBlockFluidContainer.getWrenchedItem(world, new Vector3(x, y, z));
if (dropStack != null)
{
if (entityPlayer.getHeldItem() == null)
{
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, dropStack);
}
else
{
InventoryUtility.dropItemStack(world, new Vector3(x, y, z), dropStack);
}
world.setBlockToAir(x, y, z);
}
}
return true;
}
}
@Override
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
ItemStack dropStack = ItemBlockFluidContainer.getWrenchedItem(world, new Vector3(x, y, z));
if (dropStack != null)
{
if (entityPlayer.getHeldItem() == null)
{
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, dropStack);
}
else
{
InventoryUtility.dropItemStack(world, new Vector3(x, y, z), dropStack);
}
world.setBlockToAir(x, y, z);
}
}
return true;
}
}

View file

@ -5,7 +5,7 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import resonantinduction.api.mechanical.fluid.IFluidConnector;
import resonantinduction.api.mechanical.fluid.IFluidNetwork;
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
import resonantinduction.core.prefab.fluid.TileFluidNetwork;
public class TileTank extends TileFluidNetwork
{

View file

@ -0,0 +1,39 @@
package resonantinduction.core.prefab.fluid;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import calclavia.lib.prefab.block.BlockTile;
/** @author Calclavia */
public abstract class BlockFluidNetwork extends BlockTile
{
public BlockFluidNetwork(int id, Material material)
{
super(id, material);
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).refresh();
((TileFluidNetwork) tile).getNetwork().reconstruct();
}
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int par5)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).refresh();
}
}
}

View file

@ -0,0 +1,134 @@
package resonantinduction.core.prefab.fluid;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.fluid.pipe.EnumPipeMaterial;
import resonantinduction.mechanical.fluid.tank.TileTank;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;
import universalelectricity.api.energy.UnitDisplay.UnitPrefix;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.LanguageUtility;
/** @author Darkguardsman */
public class ItemBlockFluidContainer extends ItemBlock
{
public ItemBlockFluidContainer(int id)
{
super(id);
this.setMaxDamage(0);
this.setHasSubtypes(true);
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid"));
if (fluid != null)
{
list.add("Fluid: " + fluid.getFluid().getLocalizedName());
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
}
}
}
public static ItemStack getWrenchedItem(World world, Vector3 vec)
{
TileEntity entity = vec.getTileEntity(world);
if (entity instanceof TileTank && ((TileTank) entity).getInternalTank() != null && ((TileTank) entity).getInternalTank().getFluid() != null)
{
ItemStack itemStack = new ItemStack(Mechanical.blockTank);
FluidStack stack = ((TileTank) entity).getInternalTank().getFluid();
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if (stack != null)
{
((TileTank) entity).drain(ForgeDirection.UNKNOWN, stack.amount, true);
itemStack.getTagCompound().setCompoundTag("fluid", stack.writeToNBT(new NBTTagCompound()));
}
return itemStack;
}
return null;
}
@Override
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
{
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
if (itemStack.getTagCompound() != null && !player.capabilities.isCreativeMode && itemStack.getTagCompound().hasKey("fluid"))
{
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0));
}
}
}
@Override
public int getItemStackLimit(ItemStack stack)
{
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
return 1;
}
return this.maxStackSize;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
String translation = LanguageUtility.getLocal(Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage());
if (translation == null || translation.isEmpty())
{
return Block.blocksList[this.getBlockID()].getUnlocalizedName();
}
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, (metadata / EnumPipeMaterial.spacing)))
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).setSubID(stack.getItemDamage());
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
((TileFluidNetwork) tile).fill(ForgeDirection.UNKNOWN, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true);
}
}
return true;
}
return false;
}
}

View file

@ -0,0 +1,311 @@
package resonantinduction.core.prefab.fluid;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import resonantinduction.api.IInformation;
import resonantinduction.api.mechanical.fluid.IFluidConnector;
import resonantinduction.api.mechanical.fluid.IFluidNetwork;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.Mechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiverWithID;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.TileAdvanced;
import calclavia.lib.utility.FluidUtility;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** A prefab class for tiles that use the fluid network.
*
* @author DarkGuardsman */
public abstract class TileFluidNetwork extends TileAdvanced implements IFluidConnector, IPacketReceiverWithID, IInformation
{
protected FluidTank tank;
protected Object[] connectedBlocks = new Object[6];
protected int colorID = 0;
/** Copy of the tank's content last time it updated */
protected FluidStack prevStack = null;
/** Network used to link all parts together */
protected IFluidNetwork network;
public static final int PACKET_DESCRIPTION = 0;
public static final int PACKET_RENDER = 1;
public static final int PACKET_TANK = 2;
/** Bitmask that handles connections for the renderer **/
public byte renderSides = 0;
@Override
public void initiate()
{
super.initiate();
refresh();
getNetwork().reconstruct();
}
@Override
public void invalidate()
{
this.getNetwork().split(this);
super.invalidate();
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return this.getNetwork().fill(this, from, resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
return this.getNetwork().drain(this, from, resource, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return this.getNetwork().drain(this, from, maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return this.getNetwork().getTankInfo();
}
@Override
public Object[] getConnections()
{
return this.connectedBlocks;
}
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
byte previousConnections = renderSides;
this.connectedBlocks = new Object[6];
this.renderSides = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides)
{
this.sendRenderUpdate();
this.getNetwork().reconstruct();
}
}
}
/** Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too */
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote)
{
if (tileEntity instanceof IFluidConnector)
{
this.getNetwork().merge(((IFluidConnector) tileEntity).getNetwork());
this.setRenderSide(side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
public void setRenderSide(ForgeDirection direction, boolean doRender)
{
if (doRender)
{
renderSides = (byte) (renderSides | (1 << direction.ordinal()));
}
else
{
renderSides = (byte) (renderSides & ~(1 << direction.ordinal()));
}
}
public boolean canRenderSide(ForgeDirection direction)
{
return (renderSides & (1 << direction.ordinal())) != 0;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.colorID = nbt.getInteger("subID");
if (nbt.hasKey("stored"))
{
NBTTagCompound tag = nbt.getCompoundTag("stored");
String name = tag.getString("LiquidName");
int amount = nbt.getInteger("Amount");
Fluid fluid = FluidRegistry.getFluid(name);
if (fluid != null)
{
FluidStack liquid = new FluidStack(fluid, amount);
this.getInternalTank().setFluid(liquid);
}
}
else
{
this.getInternalTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("subID", this.colorID);
nbt.setCompoundTag("FluidTank", this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
if (id == PACKET_DESCRIPTION)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
this.tank = new FluidTank(data.readInt());
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
else if (id == PACKET_RENDER)
{
this.colorID = data.readInt();
this.renderSides = data.readByte();
return true;
}
else if (id == PACKET_TANK)
{
this.tank = new FluidTank(data.readInt()).readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
}
public void sendRenderUpdate()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
}
public void sendTankUpdate()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, getInternalTank().getCapacity(), getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
}
@Override
public void onFluidChanged()
{
if (!worldObj.isRemote)
{
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
{
sendTankUpdate();
}
prevStack = tank.getFluid();
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
}
public int getSubID()
{
return this.colorID;
}
public void setSubID(int id)
{
this.colorID = id;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@Override
public FluidTank getInternalTank()
{
if (this.tank == null)
{
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
return this.tank;
}
@Override
public void getInformation(List<String> info)
{
info.add(this.getNetwork().toString());
}
@Override
public IFluidConnector getInstance(ForgeDirection from)
{
return this;
}
}