diff options
author | draknyte1 <draknyte1@hotmail.com> | 2016-11-02 15:49:00 +1000 |
---|---|---|
committer | draknyte1 <draknyte1@hotmail.com> | 2016-11-02 15:49:00 +1000 |
commit | d594987b2cfdefa447ee585a68d4a4bef4ece3a5 (patch) | |
tree | 814813fc14ce5dcd8dfa7aeaecd939ac42d12877 /src/Java/gtPlusPlus/core/item/general | |
parent | 26292158575a0f0acb51ae50715887f871d2b5a0 (diff) | |
parent | 49a520da5da01594b5c42652d9db5c7c04e49ad8 (diff) | |
download | GT5-Unofficial-d594987b2cfdefa447ee585a68d4a4bef4ece3a5.tar.gz GT5-Unofficial-d594987b2cfdefa447ee585a68d4a4bef4ece3a5.tar.bz2 GT5-Unofficial-d594987b2cfdefa447ee585a68d4a4bef4ece3a5.zip |
Merge branch 'master' of https://github.com/draknyte1/GTplusplus
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/general')
4 files changed, 309 insertions, 12 deletions
diff --git a/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java new file mode 100644 index 0000000000..3c8e09e9e5 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java @@ -0,0 +1,292 @@ +package gtPlusPlus.core.item.general; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.interfaces.IItemBlueprint; +import gtPlusPlus.core.lib.CORE; +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; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +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 ItemBlueprint(String unlocalizedName) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(CORE.MODID + ":" + unlocalizedName); + this.setMaxStackSize(1); + this.setCreativeTab(AddToCreativeTab.tabMachines); + //this.bpID = MathUtils.randInt(0, 1000); + GameRegistry.registerItem(this, unlocalizedName); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + 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. + 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) getNBT(itemStack, "mID"); + name = (String) getNBT(itemStack, "mName"); + blueprint = (boolean) getNBT(itemStack, "mBlueprint"); + } + //Write to tooltip list for each viable setting. + if (itemStack.hasTagCompound()) { + if (id != -1){ + list.add(EnumChatFormatting.GRAY+"Technical Document No. "+id); + } + if(blueprint){ + list.add(EnumChatFormatting.BLUE+"Currently holding a blueprint for "+name); + } + else { + list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything."); + } + } + else { + list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything."); + } + super.addInformation(itemStack, aPlayer, list, bool); + } + + @Override + public String getItemStackDisplayName(ItemStack p_77653_1_) { + return "Blueprint [I am useless]"; + } + + @Override + public void onCreated(ItemStack itemStack, World world, EntityPlayer player) { + createNBT(itemStack); + } + + @Override + public void onUpdate(ItemStack itemStack, World par2World, Entity par3Entity, int par4, boolean par5) { + + } + + @Override + 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. "+"|"+getNBT(itemStack, "mID")+"|"+getNBT(itemStack, "mBlueprint")+"|"+getNBT(itemStack, "mName")+"|"+ItemUtils.getArrayStackNames(readItemsFromNBT(itemStack))); + } + else { + createNBT(itemStack); + PlayerUtils.messagePlayer(par3Entity, "This is a placeholder. "+getNBT(itemStack, "mID")); + } + + + return super.onItemRightClick(itemStack, world, par3Entity); + } + + public ItemStack[] readItemsFromNBT(ItemStack itemStack){ + ItemStack[] blueprint = new ItemStack[9]; + 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); + } + } + return blueprint; + } + 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 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) getNBT(stack, "mBlueprint"); + blueprint = readItemsFromNBT(stack); + } + + if (!hasBP){ + try { + for (int o=0; o<craftingTable.getSizeInventory(); o++){ + blueprint[o] = craftingTable.getStackInSlot(o); + if (blueprint[0] != null){ + blueprint[0].stackSize = 0; + } + } + writeItemsToNBT(stack, blueprint); + if (stack.hasTagCompound()){ + if(stack.getTagCompound().getCompoundTag("Items") != null){ + stack.stackTagCompound.setBoolean("mBlueprint", true); + } + else { + //Invalid BP saved? + } + hasBP = (boolean) getNBT(stack, "mBlueprint"); + } + + if (output != null){ + setBlueprintName(stack, output.getDisplayName()); + return (hasBP = true); + } + return false; + } catch (Throwable t){ + return false; + } + } + return false; + } + + @Override + public void setBlueprintName(ItemStack stack, String name) { + stack.stackTagCompound.setString("mName", name); + } + + @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; + } + } + return returnStack; + } catch (Throwable t){ + 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 22b6ed27f1..c5f383955c 100644 --- a/src/Java/gtPlusPlus/core/item/general/ItemCloakingDevice.java +++ b/src/Java/gtPlusPlus/core/item/general/ItemCloakingDevice.java @@ -2,7 +2,7 @@ package gtPlusPlus.core.item.general; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.item.UtilsItems; +import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.math.MathUtils; import ic2.api.item.ElectricItem; import ic2.api.item.IElectricItem; @@ -21,8 +21,10 @@ 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{ private final String unlocalizedName = "personalCloakingDevice"; @@ -36,7 +38,7 @@ public class ItemCloakingDevice extends Item implements IElectricItem, IElectric this.setUnlocalizedName(unlocalizedName); this.setMaxStackSize(1); this.setTextureName(CORE.MODID + ":" + "personalCloakingDevice"); - this.thisStack = UtilsItems.getSimpleStack(this); + this.thisStack = ItemUtils.getSimpleStack(this); this.charge(thisStack, charge, 3, true, false); if (charge == 10000*20*500){ this.setDamage(thisStack, 13); diff --git a/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java b/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java index 728d498e2b..4f1d7f4ecf 100644 --- a/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java +++ b/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java @@ -3,8 +3,9 @@ package gtPlusPlus.core.item.general; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.item.UtilsItems; +import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.player.PlayerUtils; import ic2.api.item.ElectricItem; import ic2.api.item.IElectricItem; import ic2.api.item.IElectricItemManager; @@ -20,8 +21,10 @@ 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 ItemHealingDevice extends Item implements IElectricItem, IElectricItemManager, IBauble{ private final String unlocalizedName = "personalHealingDevice"; @@ -34,7 +37,7 @@ public class ItemHealingDevice extends Item implements IElectricItem, IElectricI this.setUnlocalizedName(unlocalizedName); this.setMaxStackSize(1); this.setTextureName(CORE.MODID + ":" + "personalCloakingDevice"); - this.thisStack = UtilsItems.getSimpleStack(this); + this.thisStack = ItemUtils.getSimpleStack(this); GameRegistry.registerItem(this, unlocalizedName); } @@ -218,8 +221,8 @@ public class ItemHealingDevice extends Item implements IElectricItem, IElectricI Utils.LOG_INFO("rx:"+rx); arg1.heal(rx*2); discharge(arg0, (1638400/4)*rx, 6, true, true, false); - Utils.messagePlayer((EntityPlayer) arg1, "Your NanoBooster Whirs! Leaving you feeling stronger. It Healed "+rx+" hp."); - Utils.messagePlayer((EntityPlayer) arg1, "You check it's remaining uses, it has "+secondsLeft(arg0)+"."); + PlayerUtils.messagePlayer((EntityPlayer) arg1, "Your NanoBooster Whirs! Leaving you feeling stronger. It Healed "+rx+" hp."); + PlayerUtils.messagePlayer((EntityPlayer) arg1, "You check it's remaining uses, it has "+secondsLeft(arg0)+"."); } } } diff --git a/src/Java/gtPlusPlus/core/item/general/RF2EU_Battery.java b/src/Java/gtPlusPlus/core/item/general/RF2EU_Battery.java index f1141e1ef4..7844d96f3f 100644 --- a/src/Java/gtPlusPlus/core/item/general/RF2EU_Battery.java +++ b/src/Java/gtPlusPlus/core/item/general/RF2EU_Battery.java @@ -2,7 +2,7 @@ package gtPlusPlus.core.item.general; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.item.UtilsItems; +import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.math.MathUtils; import ic2.api.item.ElectricItem; import ic2.api.item.IElectricItem; @@ -44,7 +44,7 @@ public class RF2EU_Battery extends ItemEnergyContainer implements IElectricItem, this.setUnlocalizedName(unlocalizedName); this.setMaxStackSize(1); this.setTextureName(CORE.MODID + ":" + "itemIngot"); - this.thisStack = UtilsItems.getSimpleStack(this); + this.thisStack = ItemUtils.getSimpleStack(this); GameRegistry.registerItem(this, unlocalizedName); } @@ -206,7 +206,7 @@ public class RF2EU_Battery extends ItemEnergyContainer implements IElectricItem, public double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate) { if ((stack.stackTagCompound == null) || (!stack.stackTagCompound.hasKey("Energy"))) { - double euCharge = getCharge(UtilsItems.getSimpleStack(this)); + double euCharge = getCharge(ItemUtils.getSimpleStack(this)); if (euCharge != 0 && euCharge >= 1){ return (int) (MathUtils.decimalRoundingToWholes(euCharge*rfPerEU)); } @@ -254,7 +254,7 @@ public class RF2EU_Battery extends ItemEnergyContainer implements IElectricItem, public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { if ((container.stackTagCompound == null) || (!container.stackTagCompound.hasKey("Energy"))) { - double euCharge = getCharge(UtilsItems.getSimpleStack(this)); + double euCharge = getCharge(ItemUtils.getSimpleStack(this)); if (euCharge != 0 && euCharge >= 1){ return (int) (MathUtils.decimalRoundingToWholes(euCharge*rfPerEU)); } @@ -277,7 +277,7 @@ public class RF2EU_Battery extends ItemEnergyContainer implements IElectricItem, public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { if ((container.stackTagCompound == null) || (!container.stackTagCompound.hasKey("Energy"))) { - double euCharge = getCharge(UtilsItems.getSimpleStack(this)); + double euCharge = getCharge(ItemUtils.getSimpleStack(this)); if (euCharge != 0 && euCharge >= 1){ return (int) (MathUtils.decimalRoundingToWholes(euCharge*rfPerEU)); } @@ -299,7 +299,7 @@ public class RF2EU_Battery extends ItemEnergyContainer implements IElectricItem, public int getEnergyStored(ItemStack container) { if ((container.stackTagCompound == null) || (!container.stackTagCompound.hasKey("Energy"))) { - double euCharge = getCharge(UtilsItems.getSimpleStack(this)); + double euCharge = getCharge(ItemUtils.getSimpleStack(this)); if (euCharge != 0 && euCharge >= 1){ return (int) (MathUtils.decimalRoundingToWholes(euCharge*rfPerEU)); } |