aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus')
-rw-r--r--src/Java/gtPlusPlus/core/lib/CORE.java12
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java41
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java117
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java90
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GT4Entity_AutoCrafter.java124
5 files changed, 340 insertions, 44 deletions
diff --git a/src/Java/gtPlusPlus/core/lib/CORE.java b/src/Java/gtPlusPlus/core/lib/CORE.java
index 4bbb705ff9..1aa2546383 100644
--- a/src/Java/gtPlusPlus/core/lib/CORE.java
+++ b/src/Java/gtPlusPlus/core/lib/CORE.java
@@ -2,6 +2,8 @@ package gtPlusPlus.core.lib;
import java.util.*;
+import com.mojang.authlib.GameProfile;
+
import gregtech.api.GregTech_API;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.array.Pair;
@@ -27,7 +29,7 @@ public class CORE {
//Math Related
public static final float PI = (float) Math.PI;
public static volatile Random RANDOM = new XSTR();
-
+
public static boolean DEVENV = false;
public static final String name = "GT++";
@@ -45,9 +47,11 @@ public class CORE {
public static final boolean MAIN_GREGTECH_5U_EXPERIMENTAL_FORK = Meta_GT_Proxy.areWeUsingGregtech5uExperimental();
public static final int GREGTECH_API_VERSION = GregTech_API.VERSION;
public static IGregtech_RecipeAdder RA;
-
+
public static boolean mEnableCape = false;
-
+
+ public static GameProfile gameProfile = new GameProfile(UUID.nameUUIDFromBytes("gtplusplus.core".getBytes()), "[GT++]");
+
@Deprecated
public static IGregtech_RecipeAdder sRecipeAdder;
public static GregtechRecipe GT_Recipe = new GregtechRecipe();
@@ -97,7 +101,7 @@ public class CORE {
//Updates
public static boolean enableUpdateChecker = true;
-
+
//Debug
public static boolean disableEnderIOIntegration = false;
public static boolean MACHINE_INFO = true;
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java
new file mode 100644
index 0000000000..e3bfc81291
--- /dev/null
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java
@@ -0,0 +1,41 @@
+package gtPlusPlus.xmod.gregtech.common.helpers;
+
+import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.xmod.gregtech.common.helpers.autocrafter.AC_Helper_Container;
+import gtPlusPlus.xmod.gregtech.common.helpers.autocrafter.AC_Helper_Utils;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.GT4Entity_AutoCrafter;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.inventory.Container;
+import net.minecraft.world.World;
+import net.minecraft.world.WorldServer;
+import net.minecraftforge.common.util.FakePlayerFactory;
+
+public class CraftingHelper{
+
+ public final String mInventoryName;
+ public final int mPosX;
+ public final int mPosY;
+ public final int mPosZ;
+ public final GT4Entity_AutoCrafter crafter;
+ public final World world;
+ public final EntityPlayerMP player;
+ public final AC_Helper_Container inventory;
+
+ public CraftingHelper(GT4Entity_AutoCrafter AC){
+ Utils.LOG_INFO("[A-C] Created a crafting helper.");
+ crafter = AC;
+ AC_Helper_Utils.addCrafter(AC);
+ //Get some variables.
+ world = AC.getBaseMetaTileEntity().getWorld();
+ mPosX = AC.getBaseMetaTileEntity().getXCoord();
+ mPosY = AC.getBaseMetaTileEntity().getYCoord();
+ mPosZ = AC.getBaseMetaTileEntity().getZCoord();
+ //Create Fake player to handle crating.
+ player = FakePlayerFactory.get((WorldServer) world, CORE.gameProfile);
+ //Set storage container
+ inventory = new AC_Helper_Container(player.inventory, world, mPosX, mPosY, mPosZ);
+ mInventoryName = inventory.getMatrix().getInventoryName();
+
+ }
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java
new file mode 100644
index 0000000000..f5b066fdc2
--- /dev/null
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Container.java
@@ -0,0 +1,117 @@
+package gtPlusPlus.xmod.gregtech.common.helpers.autocrafter;
+
+import gtPlusPlus.core.util.Utils;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.InventoryPlayer;
+import net.minecraft.inventory.Container;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.InventoryCraftResult;
+import net.minecraft.inventory.InventoryCrafting;
+import net.minecraft.inventory.Slot;
+import net.minecraft.inventory.SlotCrafting;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.CraftingManager;
+import net.minecraft.world.World;
+
+public class AC_Helper_Container extends Container
+{
+ /** The crafting matrix inventory (3x3). */
+ public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
+ public IInventory craftResult = new InventoryCraftResult();
+ private World worldObj;
+
+ public InventoryCrafting getMatrix(){
+ return this.craftMatrix;
+ }
+
+ public boolean putItemsIntoGrid(ItemStack[] inputs){
+ if (inputs.length < 9){
+ return false;
+ }
+ for (int i=0;i<9;i++){
+ this.putStackInSlot(i, inputs[i]);
+ }
+ this.onCraftMatrixChanged(this.craftMatrix);
+ return true;
+ }
+
+ public AC_Helper_Container(InventoryPlayer playerInventory, World world, int x, int y, int z)
+ {
+ this.worldObj = world;
+ this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));
+ int l;
+ int i1;
+
+ for (l = 0; l < 3; ++l)
+ {
+ for (i1 = 0; i1 < 3; ++i1)
+ {
+ this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
+ }
+ }
+
+ for (l = 0; l < 3; ++l)
+ {
+ for (i1 = 0; i1 < 9; ++i1)
+ {
+ this.addSlotToContainer(new Slot(playerInventory, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
+ }
+ }
+
+ for (l = 0; l < 9; ++l)
+ {
+ this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
+ }
+
+ this.onCraftMatrixChanged(this.craftMatrix);
+ }
+
+ /**
+ * Callback for when the crafting matrix is changed.
+ */
+ public void onCraftMatrixChanged(IInventory p_75130_1_)
+ {
+ this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
+ Utils.LOG_INFO("Crafted "+this.craftResult.getStackInSlot(0));
+
+ }
+
+ /**
+ * Called when the container is closed.
+ */
+ public void onContainerClosed(EntityPlayer p_75134_1_)
+ {
+ super.onContainerClosed(p_75134_1_);
+
+ if (!this.worldObj.isRemote)
+ {
+ for (int i = 0; i < 9; ++i)
+ {
+ ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
+
+ if (itemstack != null)
+ {
+ p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
+ }
+ }
+ }
+ }
+
+ public boolean canInteractWith(EntityPlayer p_75145_1_)
+ {
+ return true;
+ }
+
+ /**
+ * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
+ */
+ public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_){
+ ItemStack itemstack = null;
+ return itemstack;
+ }
+
+ public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_)
+ {
+ return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_);
+ }
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java
new file mode 100644
index 0000000000..052b611250
--- /dev/null
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/autocrafter/AC_Helper_Utils.java
@@ -0,0 +1,90 @@
+package gtPlusPlus.xmod.gregtech.common.helpers.autocrafter;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.GT4Entity_AutoCrafter;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.inventory.Container;
+import net.minecraft.world.World;
+import net.minecraft.world.WorldServer;
+import net.minecraftforge.common.util.FakePlayerFactory;
+
+public class AC_Helper_Utils {
+
+ //AC maps
+ public static final Map<Integer, GT4Entity_AutoCrafter> sAutocrafterMap = new HashMap<Integer, GT4Entity_AutoCrafter>();
+
+ //Add Crafter
+ public final static int addCrafter(GT4Entity_AutoCrafter AC) {
+ if (!sAutocrafterMap.containsValue(AC)){
+ int increase = sAutocrafterMap.size()+1;
+ sAutocrafterMap.put(increase, AC);
+ Utils.LOG_INFO("[A-C] "+"Added Auto-Crafter to index on position "+increase+".");
+ return increase;
+ }
+ else {
+ Utils.LOG_INFO("[A-C] Tried adding an Auto-Crafter to Index, but found one already there.");
+ }
+ return 0;
+ }
+
+ //Remove Crafter
+ public final static boolean removeCrafter(int frequency) {
+ if (!sAutocrafterMap.isEmpty()){
+ if (sAutocrafterMap.containsKey(frequency)){
+ sAutocrafterMap.remove(frequency);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public final static boolean removeCrafter(GT4Entity_AutoCrafter AC) {
+ if (!sAutocrafterMap.isEmpty()){
+ if (sAutocrafterMap.containsValue(AC)){
+ sAutocrafterMap.remove(AC);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ //Get Crafter
+ public final static GT4Entity_AutoCrafter getCrafterByID(int ID) {
+ if (!sAutocrafterMap.isEmpty()) {
+ Set<Entry<Integer, GT4Entity_AutoCrafter>> players = sAutocrafterMap.entrySet();
+ Iterator<Entry<Integer, GT4Entity_AutoCrafter>> i = players.iterator();
+ while (i.hasNext()) {
+ Entry<Integer, GT4Entity_AutoCrafter> current = i.next();
+ if (current.getKey().equals(ID)) {
+ return current.getValue();
+ }
+ }
+ }
+ Utils.LOG_WARNING("Failed. [getCrafterByID]");
+ return null;
+ }
+
+ public final static int getIDByCrafter(GT4Entity_AutoCrafter AC) {
+ if (!sAutocrafterMap.isEmpty()) {
+ Set<Entry<Integer, GT4Entity_AutoCrafter>> players = sAutocrafterMap.entrySet();
+ Iterator<Entry<Integer, GT4Entity_AutoCrafter>> i = players.iterator();
+ while (i.hasNext()) {
+ Entry<Integer, GT4Entity_AutoCrafter> current = i.next();
+ if (current.getValue().equals(AC)) {
+ return current.getKey();
+ }
+ }
+ }
+ Utils.LOG_WARNING("Failed. [getIDByCrafter]");
+ return 0;
+ }
+
+}
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 0a648f5b5d..2902e6fc93 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
@@ -18,6 +18,8 @@ import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.nbt.NBTUtils;
import gtPlusPlus.core.util.player.PlayerUtils;
+import gtPlusPlus.xmod.gregtech.common.helpers.CraftingHelper;
+import gtPlusPlus.xmod.gregtech.common.helpers.autocrafter.AC_Helper_Utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerWorkbench;
@@ -37,9 +39,9 @@ extends GT_MetaTileEntity_MultiBlockBase
private MODE mMachineMode = MODE.ASSEMBLY;
private byte mTier = 1;
private final int mHeatingCapacity = 4700;
-
+
/** The crafting matrix inventory (3x3). */
- public ContainerWorkbench ContainerWorkbench;
+ public CraftingHelper mInventoryCrafter;
public static enum MODE{
CRAFTING("DISASSEMBLY","ASSEMBLY"),
@@ -208,6 +210,7 @@ extends GT_MetaTileEntity_MultiBlockBase
return false;
}
+ mInventoryCrafter = new CraftingHelper(this);
return tAmount >= 16;
}
@@ -242,50 +245,67 @@ extends GT_MetaTileEntity_MultiBlockBase
return doDisassembly();
}
else if (mMachineMode == MODE.CRAFTING){
-
- GT_MetaTileEntity_Hatch_InputBus craftingInput = null;
-
- //Set Crafting input hatch
- if (!this.mInputBusses.isEmpty()){
- for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses){
- if (x.mInventory.length == 9){
- craftingInput = x;
+
+ //Try - Debug
+ try{
+
+ GT_MetaTileEntity_Hatch_InputBus craftingInput = null;
+
+ //Set Crafting input hatch
+ if (!this.mInputBusses.isEmpty()){
+ for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses){
+ if (x.mInventory.length == 9){
+ craftingInput = x;
+ }
}
}
- }
- //Return if no input hatch set.
- if (craftingInput == null){
- Utils.LOG_INFO("Cannot do Auto-Crafting without a 9-slot Input Bus [MV].");
- return false;
+ //Return if no input hatch set.
+ if (craftingInput == null){
+ Utils.LOG_INFO("Cannot do Auto-Crafting without a 9-slot Input Bus [MV].");
+ return false;
- }
-
- //Read stored data from encrypter data stick.
- ItemStack storedData[] = NBTUtils.readItemsFromNBT(aStack);
- if (storedData.length >= 1){
- int number = 0;
- for (ItemStack a : storedData){
- if (a.getItem() == ModItems.ZZZ_Empty){
- a=null;
- Utils.LOG_INFO("Allocating free memory into crafting manager slot "+number+".");
- ContainerWorkbench.craftMatrix.setInventorySlotContents(number, null);
- ContainerWorkbench.craftMatrix.markDirty();
- }
- else {
- Utils.LOG_INFO("Downloading "+a.getDisplayName()+" into crafting manager slot "+number+".");
- ContainerWorkbench.craftMatrix.setInventorySlotContents(number, a);
- ContainerWorkbench.craftMatrix.markDirty();
+ }
+
+ //Read stored data from encrypter data stick.
+ ItemStack storedData[] = NBTUtils.readItemsFromNBT(aStack);
+ ItemStack loadedData[] = new ItemStack[9];
+ if (storedData.length >= 1){
+ int number = 0;
+ for (ItemStack a : storedData){
+ if (a.getItem() == ModItems.ZZZ_Empty){
+ Utils.LOG_INFO("Allocating free memory into crafting manager slot "+number+".");
+ loadedData[number] = null;
+ //ContainerWorkbench.craftMatrix.setInventorySlotContents(number, null);
+ //ContainerWorkbench.craftMatrix.markDirty();
+ }
+ else {
+ Utils.LOG_INFO("Downloading "+a.getDisplayName()+" into crafting manager slot "+number+".");
+ loadedData[number] = a;
+ //ContainerWorkbench.craftMatrix.setInventorySlotContents(number, a);
+ //ContainerWorkbench.craftMatrix.markDirty();
+ }
+ number++;
}
- number++;
}
+
+ if (mInventoryCrafter != null){
+ Utils.LOG_INFO("Now crafting with "+mInventoryCrafter.mInventoryName);
+ this.mInventoryCrafter.inventory.putItemsIntoGrid(loadedData);
+ }
+
+ //Do Crafting
+ //Utils.LOG_INFO("Crafting Grid Size: "+ContainerWorkbench.craftMatrix.getSizeInventory());
+ //Utils.LOG_INFO("Crafting Grid Result: "+ContainerWorkbench.craftResult.getSizeInventory());
+ //Utils.LOG_INFO("Crafting Grid Result: "+ContainerWorkbench.craftResult.getStackInSlot(0));
+
+
+
+
+
}
-
- //Do Crafting
- Utils.LOG_INFO("Crafting Grid Size: "+ContainerWorkbench.craftMatrix.getSizeInventory());
- Utils.LOG_INFO("Crafting Grid Result: "+ContainerWorkbench.craftResult.getSizeInventory());
- Utils.LOG_INFO("Crafting Grid Result: "+ContainerWorkbench.craftResult.getStackInSlot(0));
-
-
+ //End Debug
+ catch (Throwable t){}
+
return false;
}
@@ -478,4 +498,28 @@ extends GT_MetaTileEntity_MultiBlockBase
super.loadNBTData(aNBT);
}
+ @Override
+ public void explodeMultiblock() {
+ AC_Helper_Utils.removeCrafter(this);
+ super.explodeMultiblock();
+ }
+
+ @Override
+ public void onExplosion() {
+ AC_Helper_Utils.removeCrafter(this);
+ super.onExplosion();
+ }
+
+ @Override
+ public void onRemoval() {
+ AC_Helper_Utils.removeCrafter(this);
+ super.onRemoval();
+ }
+
+ @Override
+ public void doExplosion(long aExplosionPower) {
+ AC_Helper_Utils.removeCrafter(this);
+ super.doExplosion(aExplosionPower);
+ }
+
}