diff options
Diffstat (limited to 'src/Java/gtPlusPlus')
9 files changed, 219 insertions, 22 deletions
diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java b/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java index 8315bbb4d9..2c742b99db 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_ProjectTable.java @@ -88,7 +88,7 @@ public class Machine_ProjectTable extends BlockContainer } final TileEntity te = world.getTileEntity(x, y, z); - if ((te != null) && (te instanceof TileEntityWorkbench)) + if ((te != null) && (te instanceof TileEntityProjectTable)) { if (!holdingWrench){ player.openGui(GTplusplus.instance, 0, world, x, y, z); diff --git a/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java b/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java index f667796098..1b5ca07d6a 100644 --- a/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java +++ b/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java @@ -26,7 +26,7 @@ public class Container_ProjectTable extends Container { public static int StorageSlotNumber = 9; //Number of slots in storage area public static int InOutputSlotNumber = StorageSlotNumber; //Same plus Output Slot public static int InventorySlotNumber = 36; //Inventory Slots (Inventory and Hotbar) - public static int InventoryOutSlotNumber = InventorySlotNumber + 1; //Inventory Slot Number + Output + public static int InventoryOutSlotNumber = InventorySlotNumber + 2; //Inventory Slot Number + Output public static int FullSlotNumber = InventorySlotNumber + InOutputSlotNumber; //All slots private final int[] slotOutputs = new int[2]; @@ -48,8 +48,8 @@ public class Container_ProjectTable extends Container { int o=0; //Output slots - this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 136, 64)); - this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 136, 64)); + this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 26+(18*4), 7)); + this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26+(18*4), 43)); for (int i=1; i<2; i++){ this.slotOutputs[o] = i; @@ -99,16 +99,16 @@ public class Container_ProjectTable extends Container { } if (aSlotIndex == 0){ - Utils.LOG_WARNING("Player Clicked on the Data Stick slot"); + Utils.LOG_INFO("Player Clicked on the Data Stick slot"); //TODO }if (aSlotIndex == 1){ - Utils.LOG_WARNING("Player Clicked on the output slot"); + Utils.LOG_INFO("Player Clicked on the output slot"); //TODO } for (final int x : this.slotGrid){ if (aSlotIndex == x){ - Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); } } } @@ -118,7 +118,7 @@ public class Container_ProjectTable extends Container { @Override public boolean canInteractWith(final EntityPlayer par1EntityPlayer){ - if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockWorkbench){ + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockProjectTable){ return false; } @@ -129,7 +129,10 @@ public class Container_ProjectTable extends Container { @Override public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { - ItemStack var3 = null; + + return null; + + /*ItemStack var3 = null; final Slot var4 = (Slot)this.inventorySlots.get(par2); if ((var4 != null) && var4.getHasStack()) @@ -182,7 +185,7 @@ public class Container_ProjectTable extends Container { var4.onPickupFromSlot(par1EntityPlayer, var5); } - return var3; + return var3;*/ } //Can merge Slot diff --git a/src/Java/gtPlusPlus/core/inventories/projecttable/InventoryProjectMain.java b/src/Java/gtPlusPlus/core/inventories/projecttable/InventoryProjectMain.java index f1b3ae76a2..4857c9b29c 100644 --- a/src/Java/gtPlusPlus/core/inventories/projecttable/InventoryProjectMain.java +++ b/src/Java/gtPlusPlus/core/inventories/projecttable/InventoryProjectMain.java @@ -1,5 +1,6 @@ package gtPlusPlus.core.inventories.projecttable; +import gtPlusPlus.core.util.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -69,7 +70,17 @@ public class InventoryProjectMain implements IInventory{ @Override public ItemStack getStackInSlot(final int slot) { + //Utils.LOG_INFO("getStackInSlot["+slot+"]"); + try { + if (slot>= this.inventory.length){ + //Utils.LOG_INFO("Returning invalid slot item."); + return null; + } return this.inventory[slot]; + } catch (Throwable t){ + t.printStackTrace(); + return null; + } } @Override @@ -104,6 +115,9 @@ public class InventoryProjectMain implements IInventory{ @Override public void setInventorySlotContents(final int slot, final ItemStack stack) { + if (slot >= this.inventory.length){ + return; + } this.inventory[slot] = stack; if ((stack != null) && (stack.stackSize > this.getInventoryStackLimit())) diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index 1d169acc55..c55aa85819 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -48,6 +48,7 @@ public final class ModItems { public static ToolMaterial STABALLOY = EnumHelper.addToolMaterial("Staballoy", 3, 2500, 7, 1.0F, 18); + public static Item ZZZ_Empty; public static Item AAA_Broken; public static Item itemAlkalusDisk; @@ -231,6 +232,8 @@ public final class ModItems { //Default item used when recipes fail, handy for debugging. AAA_Broken = new BaseItemIngot_OLD("AAA_Broken", "Errors - Tell Alkalus", Utils.rgbtoHexValue(128, 128, 128), 0); + ZZZ_Empty = new ItemEmpty(); + itemAlkalusDisk = new BaseItemDamageable("itemAlkalusDisk", AddToCreativeTab.tabMisc, 1, 0, "Unknown Use", EnumRarity.rare, EnumChatFormatting.AQUA, false, null); //Debug Loading diff --git a/src/Java/gtPlusPlus/core/item/general/ItemEmpty.java b/src/Java/gtPlusPlus/core/item/general/ItemEmpty.java new file mode 100644 index 0000000000..65c6ec6b97 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/general/ItemEmpty.java @@ -0,0 +1,20 @@ +package gtPlusPlus.core.item.general; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; +import net.minecraft.item.ItemStack; + +public class ItemEmpty extends CoreItem{ + + public ItemEmpty() { + super("item.empty", AddToCreativeTab.tabMisc); + } + + @Override + public String getItemStackDisplayName(ItemStack tItem) { + return "Empty"; + } + + + +} diff --git a/src/Java/gtPlusPlus/core/slots/SlotDataStick.java b/src/Java/gtPlusPlus/core/slots/SlotDataStick.java index 2c8e073769..dd06493865 100644 --- a/src/Java/gtPlusPlus/core/slots/SlotDataStick.java +++ b/src/Java/gtPlusPlus/core/slots/SlotDataStick.java @@ -6,6 +6,7 @@ import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.common.items.GT_MetaGenerated_Item_01; import gregtech.common.items.GT_MetaGenerated_Item_02; import gregtech.common.items.behaviors.Behaviour_DataStick; +import gtPlusPlus.core.util.Utils; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -22,10 +23,11 @@ public class SlotDataStick extends Slot{ boolean isValid = false; if (itemstack != null){ - if ((itemstack.getItem() instanceof GT_MetaGenerated_Item_01 && itemstack.getItemDamage() == 708) || (itemstack == ItemList.Tool_DataStick.get(1))){ + if ((itemstack.getItem() instanceof GT_MetaGenerated_Item_01 && itemstack.getItemDamage() == 32708) || (itemstack == ItemList.Tool_DataStick.get(1))){ isValid = true; } } + //Utils.LOG_INFO("Tried inserting "+itemstack.getDisplayName()+" | "+itemstack.getItemDamage()+" | "); return isValid; } diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java index 75d0078587..9a1f52b0be 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java @@ -6,6 +6,8 @@ import java.util.Vector; import gtPlusPlus.core.inventories.*; import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain; import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.nbt.NBTUtils; import ic2.api.network.INetworkDataProvider; import ic2.api.network.INetworkUpdateListener; import ic2.api.tile.IWrenchable; @@ -107,6 +109,40 @@ public class TileEntityProjectTable extends TileEntity implements INetworkDataPr } + @Override + public void updateEntity() { + + //Data stick + ItemStack dataStick = this.inventoryOutputs.getStackInSlot(0); + if (dataStick != null){ + Utils.LOG_INFO("Found Data Stick."); + ItemStack newStick = NBTUtils.writeItemsToNBT(dataStick, this.inventoryGrid.getInventory()); + NBTUtils.setBookTitle(newStick, "Encrypted Project Data"); + int slotm=0; + Utils.LOG_INFO("Uploading to Data Stick."); + for (ItemStack is : NBTUtils.readItemsFromNBT(newStick)){ + if (is != null){ + Utils.LOG_INFO("Uploaded "+is.getDisplayName()+" into memory slot "+slotm+"."); + } + else { + Utils.LOG_INFO("Left memory slot "+slotm+" blank."); + } + slotm++; + } + Utils.LOG_INFO("Encrypting Data Stick."); + this.inventoryOutputs.setInventorySlotContents(1, newStick); + this.inventoryOutputs.setInventorySlotContents(0, null); + } + super.updateEntity(); + } + + @Override + public boolean canUpdate() { + return true; + } + + + }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java new file mode 100644 index 0000000000..010016d5f1 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java @@ -0,0 +1,75 @@ +package gtPlusPlus.core.util.nbt; + +import static gtPlusPlus.core.item.ModItems.ZZZ_Empty; + +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.util.item.ItemUtils; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class NBTUtils { + + public static NBTTagCompound getNBT(ItemStack aStack) { + NBTTagCompound rNBT = aStack.getTagCompound(); + return ((rNBT == null) ? new NBTTagCompound() : rNBT); + } + + public static void setBookTitle(ItemStack aStack, String aTitle) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setString("title", aTitle); + GT_Utility.ItemNBT.setNBT(aStack, tNBT); + } + + public static String getBookTitle(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + return tNBT.getString("title"); + } + + public static ItemStack[] readItemsFromNBT(ItemStack itemstack){ + NBTTagCompound tNBT = getNBT(itemstack); + final NBTTagList list = tNBT.getTagList("Items", 10); + ItemStack inventory[] = new ItemStack[list.tagCount()]; + for(int i = 0;i<list.tagCount();i++){ + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if((slot >= 0) && (slot < list.tagCount())){ + if (ItemStack.loadItemStackFromNBT(data) == ItemUtils.getSimpleStack(ZZZ_Empty)){ + inventory[slot] = null; + } + else { + inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + + } + } + return inventory; + } + + public static ItemStack writeItemsToNBT(ItemStack itemstack, ItemStack[] stored){ + NBTTagCompound tNBT = getNBT(itemstack); + final NBTTagList list = new NBTTagList(); + for(int i = 0;i<stored.length;i++){ + final ItemStack stack = stored[i]; + if(stack != null){ + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + else { + final NBTTagCompound data = new NBTTagCompound(); + ItemStack nullstack = ItemUtils.getSimpleStack(ZZZ_Empty); + nullstack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + tNBT.setTag("Items", list); + itemstack.setTagCompound(tNBT); + return itemstack; + } + + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GT4Entity_AutoCrafter.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GT4Entity_AutoCrafter.java index 5a0d966073..471976ded3 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GT4Entity_AutoCrafter.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GT4Entity_AutoCrafter.java @@ -25,10 +25,33 @@ public class GT4Entity_AutoCrafter extends GT_MetaTileEntity_MultiBlockBase { - private boolean isDisassembling = false; + private MODE mMachineMode = MODE.ASSEMBLY; private byte mTier = 1; private final int mHeatingCapacity = 4700; + public static enum MODE{ + CRAFTING("DISASSEMBLY","ASSEMBLY"), + ASSEMBLY("CRAFTING","DISASSEMBLY"), + DISASSEMBLY("ASSEMBLY","CRAFTING"); + + private final String lastMode; + private final String nextMode; + + MODE(String previous, String next){ + this.lastMode = previous; + this.nextMode = next; + } + + public MODE nextMode(){ + return MODE.valueOf(this.nextMode); + } + + public MODE lastMode(){ + return MODE.valueOf(this.lastMode); + } + + } + @Override public boolean isFacingValid(byte aFacing) { @@ -184,12 +207,15 @@ extends GT_MetaTileEntity_MultiBlockBase @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - isDisassembling = Utils.invertBoolean(isDisassembling); - if (this.isDisassembling){ - PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: §cDisassembly"); + mMachineMode = mMachineMode.nextMode(); + if (mMachineMode == MODE.CRAFTING){ + PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: §dAuto-Crafting"); + } + else if (mMachineMode == MODE.ASSEMBLY){ + PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: §aAssembly"); } else { - PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: §aAssembly"); + PlayerUtils.messagePlayer(aPlayer, "You are now running the Auto-Crafter in mode: §cDisassembly"); } super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); } @@ -200,9 +226,12 @@ extends GT_MetaTileEntity_MultiBlockBase final long tVoltage = this.getMaxInputVoltage(); final byte tTier = this.mTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - if (this.isDisassembling){ + if (mMachineMode == MODE.DISASSEMBLY){ return doDisassembly(); } + else if (mMachineMode == MODE.CRAFTING){ + return false; + } else { final ArrayList<ItemStack> tInputList = this.getStoredInputs(); for (int tInputList_sS = tInputList.size(), i = 0; i < tInputList_sS - 1; ++i) { @@ -346,11 +375,15 @@ extends GT_MetaTileEntity_MultiBlockBase final String tRunning = (this.mMaxProgresstime>0 ? "Auto-Crafter running":"Auto-Crafter stopped"); final String tMaintainance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance"); String tMode; - if (this.isDisassembling){ + if (mMachineMode == MODE.DISASSEMBLY){ tMode = "§cDisassembly"; } - else { - tMode = "§aAssembly"; + else if (mMachineMode == MODE.ASSEMBLY){ + tMode = "§aAssembly"; + + } + else { + tMode = "§dAuto-Crafting"; } return new String[]{ @@ -365,15 +398,26 @@ extends GT_MetaTileEntity_MultiBlockBase return true; } + + //else if (mMachineMode == MODE.ASEEMBLY){ + + private String getMode(){ + return this.mMachineMode.name(); + } + + @Override public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("isDisassembling", this.isDisassembling); + String mMode = getMode(); + aNBT.setString("mMode", mMode); super.saveNBTData(aNBT); } @Override public void loadNBTData(NBTTagCompound aNBT) { - this.isDisassembling = aNBT.getBoolean("isDisassembling"); + String modeString = aNBT.getString("mMode"); + MODE newMode = MODE.valueOf(modeString); + this.mMachineMode = newMode; super.loadNBTData(aNBT); } |