Fixed a crash and re-add pipe gauge

This commit is contained in:
DarkGuardsman 2014-01-13 07:55:46 -05:00
parent 150267acc6
commit 1bc51d43ba
2 changed files with 127 additions and 1 deletions

View file

@ -15,7 +15,7 @@ import calclavia.lib.utility.FluidHelper;
public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandler> implements IFluidNetwork public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandler> implements IFluidNetwork
{ {
protected FluidTank tank; protected FluidTank tank = new FluidTank(0);
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1]; protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
protected boolean loadPart = false; protected boolean loadPart = false;
protected long ticks = 0; protected long ticks = 0;
@ -281,6 +281,10 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
@Override @Override
public FluidTank getTank() public FluidTank getTank()
{ {
if (this.tank == null)
{
this.tank = new FluidTank(0);
}
return this.tank; return this.tank;
} }

View file

@ -0,0 +1,122 @@
package resonantinduction.mechanical.item;
import java.util.List;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.IReadOut;
import resonantinduction.api.IReadOut.EnumTools;
import resonantinduction.core.Reference;
import resonantinduction.core.Settings;
import resonantinduction.core.prefab.item.ItemBase;
import calclavia.lib.utility.FluidHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemReadoutTools extends ItemBase
{
Icon pipeGuage;
public ItemReadoutTools()
{
super("PipeGuage", Settings.getNextItemID());
this.setHasSubtypes(true);
this.setCreativeTab(CreativeTabs.tabTools);
this.setMaxStackSize(1);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister)
{
this.pipeGuage = iconRegister.registerIcon(Reference.PREFIX + "readout.PipeGauge");
}
@SideOnly(Side.CLIENT)
@Override
public Icon getIconFromDamage(int meta)
{
if (meta == 0)
{
return pipeGuage;
}
return null;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
int meta = itemStack.getItemDamage();
if (meta == 0)
{
return "item." + "PipeGauge";
}
return "item." + this.getUnlocalizedName() + "." + meta;
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this, 1, 0));
par3List.add(new ItemStack(this, 1, 1));
}
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
EnumTools tool = EnumTools.get(itemStack.getItemDamage());
if (tool != null)
{
ForgeDirection hitSide = ForgeDirection.getOrientation(side);
if (tileEntity instanceof IReadOut)
{
String output = ((IReadOut) tileEntity).getMeterReading(player, hitSide, tool);
if (output != null && !output.isEmpty())
{
if (output.length() > 100)
{
output = output.substring(0, 100);
}
output.trim();
player.sendChatToPlayer(ChatMessageComponent.createFromText("ReadOut> " + output));
return true;
}
}
if (tool == EnumTools.PIPE_GUAGE)
{
if (tileEntity instanceof IFluidHandler)
{
FluidTankInfo[] tanks = ((IFluidHandler) tileEntity).getTankInfo(ForgeDirection.getOrientation(side));
if (tanks != null)
{
player.sendChatToPlayer(ChatMessageComponent.createFromText("FluidHandler> Side:" + hitSide.toString() + " Tanks:" + tanks.length));
for (FluidStack stack : FluidHelper.getFluidList(tanks))
{
player.sendChatToPlayer(ChatMessageComponent.createFromText("Fluid>" + stack.amount + "mb of " + stack.getFluid().getName()));
}
return true;
}
}
}
}
}
return false;
}
}