2015-04-17 00:42:05 +02:00
|
|
|
package techreborn.items;
|
|
|
|
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-02-16 11:00:03 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-07-25 17:37:11 +02:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.IFluidContainerItem;
|
2015-05-06 02:50:34 +02:00
|
|
|
import techreborn.client.TechRebornCreativeTab;
|
2015-06-07 06:36:37 +02:00
|
|
|
import techreborn.init.ModItems;
|
2015-11-24 22:39:22 +01:00
|
|
|
import techreborn.lib.ModInfo;
|
2015-04-17 00:42:05 +02:00
|
|
|
|
2015-07-02 20:51:24 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-02-16 14:49:25 +01:00
|
|
|
public class ItemCells extends ItemTextureBase implements IFluidContainerItem {
|
2015-11-23 20:19:18 +01:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public static ItemStack getCellByName(String name, int count) {
|
2015-09-23 18:27:41 +02:00
|
|
|
return getCellByName(name, count, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ItemStack getCellByName(String name, int count, boolean lookForIC2) {
|
2015-07-25 17:37:11 +02:00
|
|
|
Fluid fluid = FluidRegistry.getFluid("fluid" + name.toLowerCase());
|
2015-11-23 20:19:18 +01:00
|
|
|
// if (lookForIC2 && IC2Items.getItem("FluidCell") != null) {
|
|
|
|
// if (fluid != null) {
|
|
|
|
// ItemStack stack = IC2Items.getItem("FluidCell").copy();
|
|
|
|
// if (stack != null && stack.getItem() instanceof IFluidContainerItem) {
|
|
|
|
// IFluidContainerItem containerItem = (IFluidContainerItem) stack.getItem();
|
|
|
|
// containerItem.fill(stack, new FluidStack(fluid.getID(), 2147483647), true);
|
|
|
|
// stack.stackSize = count;
|
|
|
|
// return stack;
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// Core.logHelper.debug("Could not find " + "fluid" + name + " in the fluid registry!");
|
|
|
|
// }
|
|
|
|
// } //TODO ic2
|
2015-06-19 20:01:38 +02:00
|
|
|
int index = -1;
|
|
|
|
for (int i = 0; i < types.length; i++) {
|
|
|
|
if (types[i].equals(name)) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ItemStack(ModItems.cells, count, index);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getCellByName(String name) {
|
|
|
|
return getCellByName(name, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final String[] types = new String[]
|
|
|
|
{"Berylium", "biomass", "calciumCarbonate", "calcium", "carbon",
|
|
|
|
"chlorine", "deuterium", "diesel", "ethanol", "glyceryl",
|
|
|
|
"helium3", "helium", "heliumPlasma", "hydrogen", "ice", "lithium",
|
|
|
|
"mercury", "methane", "nitrocarbon", "nitroCoalfuel",
|
|
|
|
"nitroDiesel", "nitrogen", "nitrogenDioxide", "oil", "potassium",
|
|
|
|
"seedOil", "silicon", "sodium", "sodiumPersulfate",
|
2015-09-23 18:27:41 +02:00
|
|
|
"sodiumSulfide", "sulfur", "sulfuricAcid", "tritium", "wolframium", "empty"};
|
2015-08-09 12:05:32 +02:00
|
|
|
|
|
|
|
|
2015-11-23 20:19:18 +01:00
|
|
|
public ItemCells() {
|
|
|
|
setUnlocalizedName("techreborn.cell");
|
|
|
|
setHasSubtypes(true);
|
|
|
|
setCreativeTab(TechRebornCreativeTab.instance);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 20:19:18 +01:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
// gets Unlocalized Name depending on meta data
|
|
|
|
public String getUnlocalizedName(ItemStack itemStack) {
|
|
|
|
int meta = itemStack.getItemDamage();
|
|
|
|
if (meta < 0 || meta >= types.length) {
|
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getUnlocalizedName() + "." + types[meta];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds Dusts SubItems To Creative Tab
|
|
|
|
public void getSubItems(Item item, CreativeTabs creativeTabs, List list) {
|
|
|
|
for (int meta = 0; meta < types.length; ++meta) {
|
2016-02-16 11:00:03 +01:00
|
|
|
ItemStack stack = new ItemStack(item, 1, meta);
|
|
|
|
if(FluidRegistry.getFluid("fluid" +types[meta].toLowerCase()) != null){
|
|
|
|
this.fill(stack, new FluidStack(FluidRegistry.getFluid("fluid" +types[meta].toLowerCase()), getCapacity(stack)), true);
|
|
|
|
}
|
|
|
|
list.add(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack getFluid(ItemStack container) {
|
|
|
|
return FluidStack.loadFluidStackFromNBT(container.getTagCompound());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCapacity(ItemStack container) {
|
|
|
|
return 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(ItemStack container, FluidStack resource, boolean doFill) {
|
|
|
|
if (container.stackSize != 1) {
|
|
|
|
return 0;
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2016-02-16 11:00:03 +01:00
|
|
|
if (resource == null || resource.amount != getCapacity(container)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(FluidRegistry.getFluid("fluid" +types[container.getItemDamage()].toLowerCase()) == null){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (doFill)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = container.getTagCompound();
|
|
|
|
if (tag == null)
|
|
|
|
{
|
|
|
|
tag = new NBTTagCompound();
|
|
|
|
}
|
|
|
|
resource.writeToNBT(tag);
|
|
|
|
container.setTagCompound(tag);
|
|
|
|
}
|
|
|
|
return getCapacity(container);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-04-17 00:42:05 +02:00
|
|
|
|
2016-02-16 11:00:03 +01:00
|
|
|
@Override
|
|
|
|
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
|
|
|
|
if (maxDrain < getCapacity(container)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
FluidStack fluidStack = getFluid(container);
|
|
|
|
if (doDrain && fluidStack != null) {
|
|
|
|
ItemStack empty = ItemCells.getCellByName("empty");
|
|
|
|
if(empty != null) {
|
|
|
|
container.setItemDamage(empty.getItemDamage());
|
|
|
|
container.setTagCompound(empty.getTagCompound());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
container.stackSize = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fluidStack;
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-04-17 00:42:05 +02:00
|
|
|
|
2015-11-24 22:39:22 +01:00
|
|
|
@Override
|
|
|
|
public String getTextureName(int damage) {
|
|
|
|
return ModInfo.MOD_ID + ":items/cells/" + types[damage] + "Cell";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxMeta() {
|
|
|
|
return types.length;
|
|
|
|
}
|
2015-04-17 00:42:05 +02:00
|
|
|
}
|