aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/item/general
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-10-10 23:17:59 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-10-10 23:17:59 +1000
commitb1aa7032fe9e6bfedccf1bb08952c68100002489 (patch)
tree25b82e668a9ed1825fa3d021d0a80959ccc31639 /src/Java/gtPlusPlus/core/item/general
parent26e10439a576e08bc3261a6d7c6c00c6cad7b761 (diff)
downloadGT5-Unofficial-b1aa7032fe9e6bfedccf1bb08952c68100002489.tar.gz
GT5-Unofficial-b1aa7032fe9e6bfedccf1bb08952c68100002489.tar.bz2
GT5-Unofficial-b1aa7032fe9e6bfedccf1bb08952c68100002489.zip
+ Added Blueprints - These are capable of storing a crafting recipe in it, to be used with the workbench.
% More Internal work on the Workbench and it's handling of shit. + Added an interface for blueprints and other shit to utilize.
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/general')
-rw-r--r--src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java164
1 files changed, 164 insertions, 0 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..a15616711d
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java
@@ -0,0 +1,164 @@
+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.math.MathUtils;
+
+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{
+
+ protected String mName = "";
+ protected boolean mHasBlueprint = false;
+ private final int bpID;
+
+ /**
+ * The inventory of items the blueprint holds~
+ */
+ protected ItemStack[] blueprint = new ItemStack[9];
+
+ 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 stack, EntityPlayer aPlayer, List list, boolean bool) {
+ if (bpID >= 0){
+ list.add(EnumChatFormatting.GRAY+"Technical Document No. "+bpID);
+ }
+ if(mHasBlueprint){
+ list.add(EnumChatFormatting.BLUE+"Currently holding a blueprint for "+mName);
+ }
+ else {
+ list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything.");
+ }
+ super.addInformation(stack, aPlayer, list, bool);
+ }
+
+ @Override
+ public String getItemStackDisplayName(ItemStack p_77653_1_) {
+ return "Blueprint";
+ }
+
+ @Override
+ public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
+ itemStack.stackTagCompound = new NBTTagCompound();
+ //this.inventory = null;
+ //itemStack.stackTagCompound.set("pos_x", bed_X); TODO
+ }
+
+ @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
+ Utils.messagePlayer(par3Entity, "This is a placeholder.");
+ return super.onItemRightClick(itemStack, world, par3Entity);
+ }
+
+ public void readFromNBT(NBTTagCompound nbt){
+ 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);
+ }
+ }
+ }
+
+ public void writeToNBT(NBTTagCompound nbt){
+ 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);
+ }
+
+ @Override
+ public boolean isBlueprint(ItemStack stack) {
+ return true;
+ }
+
+ @Override
+ public boolean setBlueprint(ItemStack stack, IInventory craftingTable, ItemStack output) {
+ if (!mHasBlueprint){
+ try {
+ for (int o=0; o<craftingTable.getSizeInventory(); o++){
+ blueprint[o] = craftingTable.getStackInSlot(o);
+ if (blueprint[0] != null){
+ blueprint[0].stackSize = 0;
+ }
+ }
+ if (output != null){
+ setBlueprintName(output.getDisplayName());
+ return (mHasBlueprint = true);
+ }
+ return false;
+ } catch (Throwable t){
+ return false;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void setBlueprintName(String name) {
+ this.mName = name;
+ }
+
+ @Override
+ public boolean hasBlueprint(ItemStack stack) {
+ return mHasBlueprint;
+ }
+
+ @Override
+ public ItemStack[] getBlueprint(ItemStack 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;
+ }
+ }
+
+}