diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
| commit | cbe0e497be8e466c380a5b4fa781b314ede9ada3 (patch) | |
| tree | b85848b432adf458e3abda466ee46d9dfc3e454b /src/Java/gtPlusPlus/core/item/general | |
| parent | c40416b036c0e89451e1558253ccf07bbee028d0 (diff) | |
| download | GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.gz GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.bz2 GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.zip | |
Revert "$ Cleaned up the entire project."
This reverts commit 0669f5eb9d5029a8b94ec552171b0837605f7747.
# Conflicts:
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMTE_NuclearReactor.java
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_MassFabricator.java
Revert "% Cleaned up Imports."
This reverts commit 3654052fb63a571c5eaca7f20714b87c17f7e966.
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/general')
9 files changed, 1111 insertions, 1077 deletions
diff --git a/src/Java/gtPlusPlus/core/item/general/BedLocator_Base.java b/src/Java/gtPlusPlus/core/item/general/BedLocator_Base.java index fe93fdf70e..5a05ac7655 100644 --- a/src/Java/gtPlusPlus/core/item/general/BedLocator_Base.java +++ b/src/Java/gtPlusPlus/core/item/general/BedLocator_Base.java @@ -1,9 +1,10 @@ package gtPlusPlus.core.item.general; -import java.util.List; - import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; + +import java.util.List; + import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -12,91 +13,95 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; -public class BedLocator_Base extends Item { - - public int bed_X = 0; - public int bed_Y = 0; - public int bed_Z = 0; +public class BedLocator_Base extends Item{ - public BedLocator_Base(final String unlocalizedName) { + public int bed_X = 0; + public int bed_Y = 0; + public int bed_Z = 0; + + public BedLocator_Base(String unlocalizedName) { this.setUnlocalizedName(unlocalizedName); this.setTextureName(CORE.MODID + ":" + unlocalizedName); - this.setMaxStackSize(1); + this.setMaxStackSize(1); this.setCreativeTab(AddToCreativeTab.tabMachines); } - @SuppressWarnings({ - "unchecked", "rawtypes" - }) + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { - int NBT_X = this.bed_X; - int NBT_Y = this.bed_Y; - int NBT_Z = this.bed_Z; + + int NBT_X = bed_X; + int NBT_Y = bed_Y; + int NBT_Z = bed_Z; + if (stack.stackTagCompound != null) { NBT_X = stack.stackTagCompound.getInteger("pos_x"); NBT_Y = stack.stackTagCompound.getInteger("pos_y"); NBT_Z = stack.stackTagCompound.getInteger("pos_z"); - final String tempX = String.valueOf(NBT_X); - final String tempY = String.valueOf(NBT_Y); - final String tempZ = String.valueOf(NBT_Z); - final String formattedX = EnumChatFormatting.DARK_RED + tempX + EnumChatFormatting.GRAY; - final String formattedY = EnumChatFormatting.RED + tempY + EnumChatFormatting.GRAY; - final String formattedZ = EnumChatFormatting.RED + tempZ + EnumChatFormatting.GRAY; - - list.add(EnumChatFormatting.GRAY + "X: " + formattedX + "."); - list.add(EnumChatFormatting.GRAY + "Y: " + formattedY + "."); - list.add(EnumChatFormatting.GRAY + "Z: " + formattedZ + "."); - super.addInformation(stack, aPlayer, list, bool); - } + String tempX = String.valueOf(NBT_X); + String tempY = String.valueOf(NBT_Y); + String tempZ = String.valueOf(NBT_Z); + String formattedX = EnumChatFormatting.DARK_RED+tempX+EnumChatFormatting.GRAY; + String formattedY = EnumChatFormatting.RED+tempY+EnumChatFormatting.GRAY; + String formattedZ = EnumChatFormatting.RED+tempZ+EnumChatFormatting.GRAY; + + list.add(EnumChatFormatting.GRAY+"X: "+formattedX+"."); + list.add(EnumChatFormatting.GRAY+"Y: "+formattedY+"."); + list.add(EnumChatFormatting.GRAY+"Z: "+formattedZ+"."); + super.addInformation(stack, aPlayer, list, bool); + } } - // Ticking and NBT Handling - /* - * Called each tick as long the item is on a player inventory. Uses by maps - * to check if is on a player hand and update it's contents. - * - * public int fuelRemaining = 0; public int maximumFuel = 0; public String - * fuelType = ""; public float heat = 0; public float maxHeat = 5000; + //Ticking and NBT Handling + /* Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and + * update it's contents. * + * public int fuelRemaining = 0; + public int maximumFuel = 0; + public String fuelType = ""; + public float heat = 0; + public float maxHeat = 5000; + * */ @Override - public void onCreated(final ItemStack itemStack, final World world, final EntityPlayer player) { + public void onCreated(ItemStack itemStack, World world, EntityPlayer player) { itemStack.stackTagCompound = new NBTTagCompound(); this.bed_X = 0; this.bed_Y = 0; this.bed_Z = 0; - itemStack.stackTagCompound.setInteger("pos_x", this.bed_X); - itemStack.stackTagCompound.setInteger("pos_y", this.bed_Y); - itemStack.stackTagCompound.setInteger("pos_z", this.bed_Z); + itemStack.stackTagCompound.setInteger("pos_x", bed_X); + itemStack.stackTagCompound.setInteger("pos_y", bed_Y); + itemStack.stackTagCompound.setInteger("pos_z", bed_Z); } @Override - public ItemStack onItemRightClick(final ItemStack itemStack, final World world, final EntityPlayer par3Entity) { + public void onUpdate(ItemStack itemStack, World par2World, Entity par3Entity, int par4, boolean par5) { + + + } + + @Override + public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer par3Entity) { itemStack.stackTagCompound = new NBTTagCompound(); - if (par3Entity.getBedLocation() != null) { - this.bed_X = par3Entity.getBedLocation().posX; - this.bed_Y = par3Entity.getBedLocation().posY; - this.bed_Z = par3Entity.getBedLocation().posZ; + if (par3Entity.getBedLocation() != null){ + this.bed_X = par3Entity.getBedLocation().posX; + this.bed_Y = par3Entity.getBedLocation().posY; + this.bed_Z = par3Entity.getBedLocation().posZ; } else { this.bed_X = 0; this.bed_Y = 0; this.bed_Z = 0; } - itemStack.stackTagCompound.setInteger("pos_x", this.bed_X); - itemStack.stackTagCompound.setInteger("pos_y", this.bed_Y); - itemStack.stackTagCompound.setInteger("pos_z", this.bed_Z); + itemStack.stackTagCompound.setInteger("pos_x", bed_X); + itemStack.stackTagCompound.setInteger("pos_y", bed_Y); + itemStack.stackTagCompound.setInteger("pos_z", bed_Z); return super.onItemRightClick(itemStack, world, par3Entity); } - @Override - public void onUpdate(final ItemStack itemStack, final World par2World, final Entity par3Entity, final int par4, - final boolean par5) { - } } diff --git a/src/Java/gtPlusPlus/core/item/general/BufferCore.java b/src/Java/gtPlusPlus/core/item/general/BufferCore.java index 12d78b6f83..42f8c99c70 100644 --- a/src/Java/gtPlusPlus/core/item/general/BufferCore.java +++ b/src/Java/gtPlusPlus/core/item/general/BufferCore.java @@ -1,98 +1,98 @@ package gtPlusPlus.core.item.general; -import java.util.List; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.core.item.base.BaseItemWithDamageValue; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; + +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; -public class BufferCore extends BaseItemWithDamageValue { - +public class BufferCore extends BaseItemWithDamageValue{ + public int coreTier = 0; - - public BufferCore(final String unlocalizedName, final int i) { + + public BufferCore(String unlocalizedName, int i) { super(unlocalizedName); this.setTextureName(CORE.MODID + ":" + unlocalizedName); this.setMaxStackSize(2); this.coreTier = i; } - @SuppressWarnings({ - "unchecked", "rawtypes" - }) @Override - public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { - list.add(EnumChatFormatting.GRAY + "A key crafting component for making energy buffers."); + public String getItemStackDisplayName(ItemStack stack) { + return super.getItemStackDisplayName(stack)+" ["+CORE.VOLTAGES[this.coreTier-1]+"]."; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() + { + return true; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + list.add(EnumChatFormatting.GRAY+"A key crafting component for making energy buffers."); super.addInformation(stack, aPlayer, list, bool); } + public final int getCoreTier() { + return coreTier; + } + @Override - public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { - // Figure Out Damage - final String s = String.format("%X", HEX_OxFFFFFF); - // Utils.LOG_INFO(s); - // String rgb = Utils.hex2Rgb(s); - // Utils.LOG_INFO(rgb); - if (this.coreTier == 1) { + public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) { + //Figure Out Damage + String s = String.format("%X", HEX_OxFFFFFF); + //Utils.LOG_INFO(s); + //String rgb = Utils.hex2Rgb(s); + //Utils.LOG_INFO(rgb); + if (coreTier == 1){ HEX_OxFFFFFF = 0x4d4d4d; } - else if (this.coreTier == 2) { + else if (coreTier == 2){ HEX_OxFFFFFF = 0x666666; } - else if (this.coreTier == 3) { + else if (coreTier == 3){ HEX_OxFFFFFF = 0x8c8c8c; } - else if (this.coreTier == 4) { + else if (coreTier == 4){ HEX_OxFFFFFF = 0xa6a6a6; } - else if (this.coreTier == 5) { + else if (coreTier == 5){ HEX_OxFFFFFF = 0xcccccc; } - else if (this.coreTier == 6) { + else if (coreTier == 6){ HEX_OxFFFFFF = 0xe6e6e6; } - else if (this.coreTier == 7) { + else if (coreTier == 7){ HEX_OxFFFFFF = 0xffffcc; } - else if (this.coreTier == 8) { + else if (coreTier == 8){ HEX_OxFFFFFF = 0xace600; } - else if (this.coreTier == 9) { + else if (coreTier == 9){ HEX_OxFFFFFF = 0xffff00; } - /* - * else if (coreTier == 10){ HEX_OxFFFFFF = 0xff0000; } - */ - else if (this.coreTier == 10) { - HEX_OxFFFFFF = Utils.rgbtoHexValue(MathUtils.randInt(220, 250), MathUtils.randInt(221, 251), - MathUtils.randInt(220, 250)); + /*else if (coreTier == 10){ + HEX_OxFFFFFF = 0xff0000; + }*/ + else if (coreTier == 10){ + HEX_OxFFFFFF = Utils.rgbtoHexValue(MathUtils.randInt(220, 250), MathUtils.randInt(221, 251), MathUtils.randInt(220, 250)); } else { HEX_OxFFFFFF = 0xffffff; } + return HEX_OxFFFFFF; } - - public final int getCoreTier() { - return this.coreTier; - } - - @Override - public String getItemStackDisplayName(final ItemStack stack) { - return super.getItemStackDisplayName(stack) + " [" + CORE.VOLTAGES[this.coreTier - 1] + "]."; - } - - @Override - @SideOnly(Side.CLIENT) - public boolean requiresMultipleRenderPasses() { - return true; - } - + } diff --git a/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java index 22bb194fde..3c8e09e9e5 100644 --- a/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java +++ b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java @@ -1,8 +1,5 @@ package gtPlusPlus.core.item.general; -import java.util.List; - -import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.interfaces.IItemBlueprint; import gtPlusPlus.core.lib.CORE; @@ -10,6 +7,9 @@ import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.player.PlayerUtils; + +import java.util.List; + import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -19,208 +19,97 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; +import cpw.mods.fml.common.registry.GameRegistry; -public class ItemBlueprint extends Item implements IItemBlueprint { +public class ItemBlueprint extends Item implements IItemBlueprint{ - public ItemBlueprint(final String unlocalizedName) { + public ItemBlueprint(String unlocalizedName) { this.setUnlocalizedName(unlocalizedName); this.setTextureName(CORE.MODID + ":" + unlocalizedName); - this.setMaxStackSize(1); + this.setMaxStackSize(1); this.setCreativeTab(AddToCreativeTab.tabMachines); - // this.bpID = MathUtils.randInt(0, 1000); + //this.bpID = MathUtils.randInt(0, 1000); GameRegistry.registerItem(this, unlocalizedName); } - @SuppressWarnings({ - "unchecked", "rawtypes" - }) + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public void addInformation(final ItemStack itemStack, final EntityPlayer aPlayer, final List list, - final boolean bool) { - // Create some NBT if it's not there, otherwise this does nothing. - if (!itemStack.hasTagCompound()) { - this.createNBT(itemStack); + public void addInformation(ItemStack itemStack, EntityPlayer aPlayer, List list, boolean bool) { + //Create some NBT if it's not there, otherwise this does nothing. + if (!itemStack.hasTagCompound()){ + createNBT(itemStack); } - // Set up some default variables. + //Set up some default variables. int id = -1; String name = ""; boolean blueprint = false; - // Get proper display vars from NBT if it's there - if (itemStack.hasTagCompound()) { - // Utils.LOG_WARNING("Found TagCompound"); - id = (int) this.getNBT(itemStack, "mID"); - name = (String) this.getNBT(itemStack, "mName"); - blueprint = (boolean) this.getNBT(itemStack, "mBlueprint"); + //Get proper display vars from NBT if it's there + if (itemStack.hasTagCompound()){ + //Utils.LOG_WARNING("Found TagCompound"); + id = (int) getNBT(itemStack, "mID"); + name = (String) getNBT(itemStack, "mName"); + blueprint = (boolean) getNBT(itemStack, "mBlueprint"); } - // Write to tooltip list for each viable setting. + //Write to tooltip list for each viable setting. if (itemStack.hasTagCompound()) { - if (id != -1) { - list.add(EnumChatFormatting.GRAY + "Technical Document No. " + id); + if (id != -1){ + list.add(EnumChatFormatting.GRAY+"Technical Document No. "+id); } - if (blueprint) { - list.add(EnumChatFormatting.BLUE + "Currently holding a blueprint for " + name); + if(blueprint){ + list.add(EnumChatFormatting.BLUE+"Currently holding a blueprint for "+name); } else { - list.add(EnumChatFormatting.RED + "Currently not holding a blueprint for anything."); + list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything."); } - } + } else { - list.add(EnumChatFormatting.RED + "Currently not holding a blueprint for anything."); + list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything."); } super.addInformation(itemStack, aPlayer, list, bool); } - public boolean createNBT(final ItemStack itemStack) { - if (itemStack.hasTagCompound()) { - if (!itemStack.stackTagCompound.getBoolean("mBlueprint") - && !itemStack.stackTagCompound.getString("mName").equals("")) { - // No Blueprint and no name Set - Utils.LOG_WARNING("No Blueprint and no name Set"); - return false; - } - else if (itemStack.stackTagCompound.getBoolean("mBlueprint") - && !itemStack.stackTagCompound.getString("mName").equals("")) { - // Has Blueprint but invalid name set - Utils.LOG_WARNING("Has Blueprint but invalid name set"); - // itemStack.stackTagCompound = null; - // createNBT(itemStack); - return false; - } - else if (!itemStack.stackTagCompound.getBoolean("mBlueprint") - && itemStack.stackTagCompound.getString("mName").equals("")) { - // Has no Blueprint, but strangely has a name - Utils.LOG_WARNING("Has no Blueprint, but strangely has a name"); - // itemStack.stackTagCompound = null; - // createNBT(itemStack); - return false; - } - return false; - } - else if (!itemStack.hasTagCompound()) { - final int bpID = MathUtils.randInt(0, 1000); - final boolean hasRecipe = false; - final String recipeName = ""; - Utils.LOG_WARNING("Creating Blueprint, setting up it's NBT data. " + bpID); - itemStack.stackTagCompound = new NBTTagCompound(); - itemStack.stackTagCompound.setInteger("mID", bpID); - itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe); - itemStack.stackTagCompound.setString("mName", recipeName); - return true; - } - else { - final int bpID = MathUtils.randInt(0, 1000); - final boolean hasRecipe = false; - final String recipeName = ""; - Utils.LOG_WARNING("Creating a Blueprint, setting up it's NBT data. " + bpID); - itemStack.stackTagCompound = new NBTTagCompound(); - itemStack.stackTagCompound.setInteger("mID", bpID); - itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe); - itemStack.stackTagCompound.setString("mName", recipeName); - return true; - } - } - - @Override - public ItemStack[] getBlueprint(final ItemStack stack) { - ItemStack[] blueprint = new ItemStack[9]; - if (stack.hasTagCompound()) { - blueprint = this.readItemsFromNBT(stack); - } - try { - final ItemStack[] returnStack = new ItemStack[9]; - for (int o = 0; o < blueprint.length; o++) { - returnStack[o] = blueprint[o]; - if (returnStack[0] != null) { - returnStack[0].stackSize = 1; - } - } - return returnStack; - } - catch (final Throwable t) { - return null; - } - } - @Override - public String getItemStackDisplayName(final ItemStack p_77653_1_) { + public String getItemStackDisplayName(ItemStack p_77653_1_) { return "Blueprint [I am useless]"; } - public Object getNBT(final ItemStack itemStack, final String tagNBT) { - if (!itemStack.hasTagCompound()) { - return null; - } - Object o = null; - if (tagNBT.equals("mID")) { - o = itemStack.stackTagCompound.getInteger(tagNBT); - } - else if (tagNBT.equals("mBlueprint")) { - o = itemStack.stackTagCompound.getBoolean(tagNBT); - } - else if (tagNBT.equals("mName")) { - o = itemStack.stackTagCompound.getString(tagNBT); - } - else if (tagNBT.equals("")) { - // For More Tag Support - // o = itemStack.stackTagCompound.getInteger(tagNBT); - } - if (o != null) { - return o; - } - return null; - } - @Override - public boolean hasBlueprint(final ItemStack stack) { - if (stack.hasTagCompound()) { - return (boolean) this.getNBT(stack, "mBlueprint"); - } - return false; + public void onCreated(ItemStack itemStack, World world, EntityPlayer player) { + createNBT(itemStack); } @Override - public boolean isBlueprint(final ItemStack stack) { - return true; - } + public void onUpdate(ItemStack itemStack, World par2World, Entity par3Entity, int par4, boolean par5) { - @Override - public void onCreated(final ItemStack itemStack, final World world, final EntityPlayer player) { - this.createNBT(itemStack); } @Override - public ItemStack onItemRightClick(final ItemStack itemStack, final World world, final EntityPlayer par3Entity) { - // Let the player know what blueprint is held + public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer par3Entity) { + //Let the player know what blueprint is held if (itemStack.hasTagCompound()) { - PlayerUtils.messagePlayer(par3Entity, - "This Blueprint holds NBT data. " + "|" + this.getNBT(itemStack, "mID") + "|" - + this.getNBT(itemStack, "mBlueprint") + "|" + this.getNBT(itemStack, "mName") + "|" - + ItemUtils.getArrayStackNames(this.readItemsFromNBT(itemStack))); + PlayerUtils.messagePlayer(par3Entity, "This Blueprint holds NBT data. "+"|"+getNBT(itemStack, "mID")+"|"+getNBT(itemStack, "mBlueprint")+"|"+getNBT(itemStack, "mName")+"|"+ItemUtils.getArrayStackNames(readItemsFromNBT(itemStack))); } else { - this.createNBT(itemStack); - PlayerUtils.messagePlayer(par3Entity, "This is a placeholder. " + this.getNBT(itemStack, "mID")); + createNBT(itemStack); + PlayerUtils.messagePlayer(par3Entity, "This is a placeholder. "+getNBT(itemStack, "mID")); } - return super.onItemRightClick(itemStack, world, par3Entity); - } - - @Override - public void onUpdate(final ItemStack itemStack, final World par2World, final Entity par3Entity, final int par4, - final boolean par5) { + return super.onItemRightClick(itemStack, world, par3Entity); } - public ItemStack[] readItemsFromNBT(final ItemStack itemStack) { + public ItemStack[] readItemsFromNBT(ItemStack itemStack){ ItemStack[] blueprint = new ItemStack[9]; - if (itemStack.hasTagCompound()) { - final NBTTagCompound nbt = itemStack.getTagCompound(); - final NBTTagList list = nbt.getTagList("Items", 10); - blueprint = new ItemStack[IItemBlueprint.INV_SIZE]; - for (int i = 0; i < list.tagCount(); i++) { - final NBTTagCompound data = list.getCompoundTagAt(i); - final int slot = data.getInteger("Slot"); - if (slot >= 0 && slot < IItemBlueprint.INV_SIZE) { + if (itemStack.hasTagCompound()){ + NBTTagCompound nbt = itemStack.getTagCompound(); + NBTTagList list = nbt.getTagList("Items", 10); + blueprint = new ItemStack[INV_SIZE]; + for(int i = 0;i<list.tagCount();i++) + { + NBTTagCompound data = list.getCompoundTagAt(i); + int slot = data.getInteger("Slot"); + if(slot >= 0 && slot < INV_SIZE) + { blueprint[slot] = ItemStack.loadItemStackFromNBT(data); } } @@ -229,72 +118,175 @@ public class ItemBlueprint extends Item implements IItemBlueprint { return null; } + public ItemStack writeItemsToNBT(ItemStack itemStack, ItemStack[] craftingGrid){ + ItemStack[] blueprint = craftingGrid; + if (itemStack.hasTagCompound()){ + NBTTagCompound nbt = itemStack.getTagCompound(); + NBTTagList list = new NBTTagList(); + for(int i = 0;i<INV_SIZE;i++) + { + ItemStack stack = blueprint[i]; + if(stack != null) + { + NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); + itemStack.setTagCompound(nbt); + return itemStack; + } + return null; + } + @Override - public boolean setBlueprint(final ItemStack stack, final IInventory craftingTable, final ItemStack output) { + public boolean isBlueprint(ItemStack stack) { + return true; + } + + @Override + public boolean setBlueprint(ItemStack stack, IInventory craftingTable, ItemStack output) { boolean hasBP = false; ItemStack[] blueprint = new ItemStack[9]; - if (stack.hasTagCompound()) { - hasBP = (boolean) this.getNBT(stack, "mBlueprint"); - blueprint = this.readItemsFromNBT(stack); + if (stack.hasTagCompound()){ + hasBP = (boolean) getNBT(stack, "mBlueprint"); + blueprint = readItemsFromNBT(stack); } - if (!hasBP) { + if (!hasBP){ try { - for (int o = 0; o < craftingTable.getSizeInventory(); o++) { + for (int o=0; o<craftingTable.getSizeInventory(); o++){ blueprint[o] = craftingTable.getStackInSlot(o); - if (blueprint[0] != null) { + if (blueprint[0] != null){ blueprint[0].stackSize = 0; } } - this.writeItemsToNBT(stack, blueprint); - if (stack.hasTagCompound()) { - if (stack.getTagCompound().getCompoundTag("Items") != null) { + writeItemsToNBT(stack, blueprint); + if (stack.hasTagCompound()){ + if(stack.getTagCompound().getCompoundTag("Items") != null){ stack.stackTagCompound.setBoolean("mBlueprint", true); } else { - // Invalid BP saved? + //Invalid BP saved? } - hasBP = (boolean) this.getNBT(stack, "mBlueprint"); + hasBP = (boolean) getNBT(stack, "mBlueprint"); } - - if (output != null) { - this.setBlueprintName(stack, output.getDisplayName()); - return hasBP = true; + + if (output != null){ + setBlueprintName(stack, output.getDisplayName()); + return (hasBP = true); } return false; - } - catch (final Throwable t) { - return false; + } catch (Throwable t){ + return false; } } return false; } @Override - public void setBlueprintName(final ItemStack stack, final String name) { + public void setBlueprintName(ItemStack stack, String name) { stack.stackTagCompound.setString("mName", name); } - public ItemStack writeItemsToNBT(final ItemStack itemStack, final ItemStack[] craftingGrid) { - final ItemStack[] blueprint = craftingGrid; - if (itemStack.hasTagCompound()) { - final NBTTagCompound nbt = itemStack.getTagCompound(); - final NBTTagList list = new NBTTagList(); - for (int i = 0; i < IItemBlueprint.INV_SIZE; i++) { - final ItemStack stack = blueprint[i]; - if (stack != null) { - final NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); + @Override + public boolean hasBlueprint(ItemStack stack) { + if (stack.hasTagCompound()){ + return (boolean) getNBT(stack, "mBlueprint"); + } + return false; + } + + @Override + public ItemStack[] getBlueprint(ItemStack stack) { + ItemStack[] blueprint = new ItemStack[9]; + if (stack.hasTagCompound()){ + blueprint = readItemsFromNBT(stack); + } + try { + ItemStack[] returnStack = new ItemStack[9]; + for (int o=0; o<blueprint.length; o++){ + returnStack[o] = blueprint[o]; + if (returnStack[0] != null){ + returnStack[0].stackSize = 1; } } - nbt.setTag("Items", list); - itemStack.setTagCompound(nbt); - return itemStack; + return returnStack; + } catch (Throwable t){ + return null; } - return null; } + public boolean createNBT(ItemStack itemStack){ + if (itemStack.hasTagCompound()){ + if (!itemStack.stackTagCompound.getBoolean("mBlueprint") && !itemStack.stackTagCompound.getString("mName").equals("")){ + //No Blueprint and no name Set + Utils.LOG_WARNING("No Blueprint and no name Set"); + return false; + } + else if (itemStack.stackTagCompound.getBoolean("mBlueprint") && !itemStack.stackTagCompound.getString("mName").equals("")){ + //Has Blueprint but invalid name set + Utils.LOG_WARNING("Has Blueprint but invalid name set"); + //itemStack.stackTagCompound = null; + //createNBT(itemStack); + return false; + } + else if (!itemStack.stackTagCompound.getBoolean("mBlueprint") && itemStack.stackTagCompound.getString("mName").equals("")){ + //Has no Blueprint, but strangely has a name + Utils.LOG_WARNING("Has no Blueprint, but strangely has a name"); + //itemStack.stackTagCompound = null; + //createNBT(itemStack); + return false; + } + return false; + } + else if(!itemStack.hasTagCompound()){ + int bpID = MathUtils.randInt(0, 1000); + boolean hasRecipe = false; + String recipeName = ""; + Utils.LOG_WARNING("Creating Blueprint, setting up it's NBT data. "+bpID); + itemStack.stackTagCompound = new NBTTagCompound(); + itemStack.stackTagCompound.setInteger("mID", bpID); + itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe); + itemStack.stackTagCompound.setString("mName", recipeName); + return true; + } + else { + int bpID = MathUtils.randInt(0, 1000); + boolean hasRecipe = false; + String recipeName = ""; + Utils.LOG_WARNING("Creating a Blueprint, setting up it's NBT data. "+bpID); + itemStack.stackTagCompound = new NBTTagCompound(); + itemStack.stackTagCompound.setInteger("mID", bpID); + itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe); + itemStack.stackTagCompound.setString("mName", recipeName); + return true; + } + } + + public Object getNBT(ItemStack itemStack, String tagNBT){ + if (!itemStack.hasTagCompound()){ + return null; + } + Object o = null; + if (tagNBT.equals("mID")){ + o = itemStack.stackTagCompound.getInteger(tagNBT); + } + else if (tagNBT.equals("mBlueprint")){ + o = itemStack.stackTagCompound.getBoolean(tagNBT); + } + else if (tagNBT.equals("mName")){ + o = itemStack.stackTagCompound.getString(tagNBT); + } + else if (tagNBT.equals("")){ + //For More Tag Support + //o = itemStack.stackTagCompound.getInteger(tagNBT); + } + if (o != null) + return o; + return null; } + } diff --git a/src/Java/gtPlusPlus/core/item/general/ItemCloakingDevice.java b/src/Java/gtPlusPlus/core/item/general/ItemCloakingDevice.java index d0316730bf..c5f383955c 100644 --- a/src/Java/gtPlusPlus/core/item/general/ItemCloakingDevice.java +++ b/src/Java/gtPlusPlus/core/item/general/ItemCloakingDevice.java @@ -1,16 +1,15 @@ package gtPlusPlus.core.item.general; -import java.util.List; - -import baubles.api.BaubleType; -import baubles.api.IBauble; -import cpw.mods.fml.common.Optional; -import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.math.MathUtils; -import ic2.api.item.*; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; + +import java.util.List; + import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -20,235 +19,240 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; +import baubles.api.BaubleType; +import baubles.api.IBauble; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.registry.GameRegistry; -@Optional.InterfaceList(value = { - @Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles"), - @Optional.Interface(iface = "baubles.api.BaubleType", modid = "Baubles") -}) -public class ItemCloakingDevice extends Item implements IElectricItem, IElectricItemManager, IBauble { +@Optional.InterfaceList(value = {@Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles"), @Optional.Interface(iface = "baubles.api.BaubleType", modid = "Baubles")}) +public class ItemCloakingDevice extends Item implements IElectricItem, IElectricItemManager, IBauble{ - private final static int maxValueEU = 10000 * 20 * 500; - private final String unlocalizedName = "personalCloakingDevice"; - private final ItemStack thisStack; - protected double chargeEU = 0; + private final String unlocalizedName = "personalCloakingDevice"; + private final ItemStack thisStack; + private final static int maxValueEU = 10000*20*500; + protected double chargeEU = 0; - public ItemCloakingDevice(final double charge) { + public ItemCloakingDevice(double charge){ this.chargeEU = charge; this.setCreativeTab(AddToCreativeTab.tabMachines); - this.setUnlocalizedName(this.unlocalizedName); + this.setUnlocalizedName(unlocalizedName); this.setMaxStackSize(1); this.setTextureName(CORE.MODID + ":" + "personalCloakingDevice"); this.thisStack = ItemUtils.getSimpleStack(this); - this.charge(this.thisStack, charge, 3, true, false); - if (charge == 10000 * 20 * 500) { - this.setDamage(this.thisStack, 13); + this.charge(thisStack, charge, 3, true, false); + if (charge == 10000*20*500){ + this.setDamage(thisStack, 13); } - GameRegistry.registerItem(this, this.unlocalizedName + "-" + charge); - } - - @Override - public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { - list.add(""); - list.add(EnumChatFormatting.GREEN + "Worn as a Belt within Baubles." + EnumChatFormatting.GRAY); - list.add(EnumChatFormatting.GREEN + "Drains 10,000EU/t to provide invisibility." + EnumChatFormatting.GRAY); - list.add(""); - list.add(EnumChatFormatting.GOLD + "IC2/EU Information" + EnumChatFormatting.GRAY); - list.add(EnumChatFormatting.GRAY + "Tier: [" + EnumChatFormatting.YELLOW + this.getTier(this.thisStack) - + EnumChatFormatting.GRAY + "] Input Limit: [" + EnumChatFormatting.YELLOW - + this.getTransferLimit(this.thisStack) + EnumChatFormatting.GRAY + "EU/t]"); - list.add(EnumChatFormatting.GRAY + "Current Power: [" + EnumChatFormatting.YELLOW + (long) this.getCharge(stack) - + EnumChatFormatting.GRAY + "EU] [" + EnumChatFormatting.YELLOW - + MathUtils.findPercentage(this.getCharge(stack), this.getMaxCharge(stack)) + EnumChatFormatting.GRAY - + "%]"); - list.add(EnumChatFormatting.GRAY + "Time Remaining: [" + EnumChatFormatting.YELLOW + this.secondsLeft(stack) - + EnumChatFormatting.GRAY + " seconds]"); - super.addInformation(stack, aPlayer, list, bool); + GameRegistry.registerItem(this, unlocalizedName+"-"+charge); |
