diff --git a/src/dark/api/IToolReadOut.java b/src/dark/api/IToolReadOut.java index c34f04b6e..633e1aa68 100644 --- a/src/dark/api/IToolReadOut.java +++ b/src/dark/api/IToolReadOut.java @@ -1,12 +1,13 @@ package dark.api; +import dark.api.IToolReadOut.EnumTools; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.ForgeDirection; public interface IToolReadOut { /** Grabs the message displayed to the user on right click of the machine with the pipe gauge - * + * * @param user * @param side - may not work correctly yet but should give you a side * @return - a string to be displayed to the player for a reading. automatically adds ReadOut: @@ -17,5 +18,14 @@ public interface IToolReadOut { PIPE_GUAGE(), MULTI_METER(); + + public static EnumTools get(int meta) + { + if (meta < EnumTools.values().length) + { + return EnumTools.values()[meta]; + } + return null; + } } } diff --git a/src/dark/core/items/ItemTools.java b/src/dark/core/items/ItemTools.java new file mode 100644 index 000000000..65f774d53 --- /dev/null +++ b/src/dark/core/items/ItemTools.java @@ -0,0 +1,105 @@ +package dark.core.items; + +import java.util.HashMap; +import java.util.List; + +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.world.World; +import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; +import dark.api.IToolReadOut; +import dark.api.IToolReadOut.EnumTools; +import dark.core.helpers.FluidHelper; + +public class ItemTools extends ItemBasic +{ + public ItemTools(int id, Configuration config) + { + super(id, "lmTool", config); + this.setMaxDamage(0); + this.setHasSubtypes(true); + this.setCreativeTab(CreativeTabs.tabTools); + this.setMaxStackSize(1); + } + + @Override + public String getUnlocalizedName(ItemStack itemStack) + { + int meta = itemStack.getItemDamage(); + if (meta == 0) + { + return "item." + "PipeGauge"; + } + else if (meta == 1) + { + return "item." + "MultiMeter"; + } + 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) + { + if (tileEntity instanceof IToolReadOut) + { + String output = ((IToolReadOut) tileEntity).getMeterReading(player, ForgeDirection.getOrientation(side), EnumTools.PIPE_GUAGE); + if (output != null && !output.isEmpty()) + { + if (output.length() > 100) + { + output = output.substring(0, 100); + } + output.trim(); + player.sendChatToPlayer(ChatMessageComponent.func_111066_d("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.func_111066_d("FluidHandler> Side:"+ForgeDirection.getOrientation(side).toString()+" Tanks:" + tanks.length)); + for (FluidStack stack : FluidHelper.getFluidList(tanks)) + { + player.sendChatToPlayer(ChatMessageComponent.func_111066_d("Fluid>" + stack.amount + "mb of " + stack.getFluid().getName())); + } + return true; + } + } + } + if (tool == EnumTools.MULTI_METER) + { + + } + } + + } + + return false; + } + +}