aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity
diff options
context:
space:
mode:
authorBlood-Asp <bloodasphendrik@gmail.com>2016-10-23 12:15:42 +0200
committerTechnus <daniel112092@gmail.com>2016-10-24 11:17:46 +0200
commiteea7afb539330455c570af959fa9d14d30f94eca (patch)
tree24cab5b85802c59d45d815b0db1cbc311243df2f /src/main/java/gregtech/api/metatileentity
parent0a84e7c5a76e92e3e140972986434180ec9016fb (diff)
downloadGT5-Unofficial-eea7afb539330455c570af959fa9d14d30f94eca.tar.gz
GT5-Unofficial-eea7afb539330455c570af959fa9d14d30f94eca.tar.bz2
GT5-Unofficial-eea7afb539330455c570af959fa9d14d30f94eca.zip
Auto maintenance (LuV) and optimization + my texture for it
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java90
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java2
2 files changed, 88 insertions, 4 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java
index 049f34dfba..f32c39aa5b 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java
@@ -1,9 +1,17 @@
package gregtech.api.metatileentity.implementations;
+import java.util.ArrayList;
+import java.util.List;
+
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.ItemList;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.Textures;
+import gregtech.api.gui.GT_Container_2by2;
import gregtech.api.gui.GT_Container_MaintenanceHatch;
+import gregtech.api.gui.GT_GUIContainer_2by2;
import gregtech.api.gui.GT_GUIContainer_MaintenanceHatch;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -18,30 +26,42 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import scala.actors.threadpool.Arrays;
public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch {
- public boolean mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false;
+ public boolean mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mAuto;
+ public GT_MetaTileEntity_MultiBlockBase mController = null;
public GT_MetaTileEntity_Hatch_Maintenance(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 1, "For maintaining Multiblocks");
+ mAuto = false;
+ }
+
+ public GT_MetaTileEntity_Hatch_Maintenance(int aID, String aName, String aNameRegional, int aTier, boolean aAuto) {
+ super(aID, aName, aNameRegional, aTier, 4, "For automaticly maintaining Multiblocks");
+ mAuto = aAuto;
}
- public GT_MetaTileEntity_Hatch_Maintenance(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
- super(aName, aTier, 1, aDescription, aTextures);
+ public GT_MetaTileEntity_Hatch_Maintenance(String aName, int aTier, String aDescription, ITexture[][][] aTextures, boolean aAuto) {
+ super(aName, aTier, aAuto ? 4 : 1, aDescription, aTextures);
+ mAuto = aAuto;
}
@Override
public String[] getDescription() {
+ if(mAuto)return new String[]{mDescription, "Cannot be shared between Multiblocks!","4 Duct tape, 2 Lubricant Cells","4 Steel Screws, 2 Adv. Circuits","For each auto-repair"};
return new String[]{mDescription, "Cannot be shared between Multiblocks!"};
}
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
+ if(mAuto)return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_AUTOMAINTENANCE)};
return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_MAINTENANCE)};
}
@Override
public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
+ if(mAuto)return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_AUTOMAINTENANCE)};
return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_MAINTENANCE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_DUCTTAPE)};
}
@@ -72,7 +92,8 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
- return new GT_MetaTileEntity_Hatch_Maintenance(mName, mTier, mDescription, mTextures);
+ if(aTileEntity.getMetaTileID()==111) return new GT_MetaTileEntity_Hatch_Maintenance(mName, mTier, mDescription, mTextures, true);
+ return new GT_MetaTileEntity_Hatch_Maintenance(mName, mTier, mDescription, mTextures, false);
}
@Override
@@ -84,13 +105,70 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch
@Override
public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
+ if(mAuto) return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity);
return new GT_Container_MaintenanceHatch(aPlayerInventory, aBaseMetaTileEntity);
}
@Override
public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
+ if(mAuto) return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, getLocalName());
return new GT_GUIContainer_MaintenanceHatch(aPlayerInventory, aBaseMetaTileEntity);
}
+
+ @Override
+ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
+ if (aBaseMetaTileEntity.isServerSide() && aTimer % 100 == 0 && mController != null) {
+ if(!mController.mCrowbar || !mController.mHardHammer || !mController.mScrewdriver || !mController.mSoftHammer || !mController.mSolderingTool || !mController.mWrench){
+ boolean tSuccess = true;
+ ItemStack[] mInputs = new ItemStack[]{ItemList.Duct_Tape.get(4, new Object[]{}),GT_OreDictUnificator.get(OrePrefixes.cell, Materials.Lubricant, 2),GT_OreDictUnificator.get(OrePrefixes.screw, Materials.Steel, 4),GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Advanced, 2)};
+ List<ItemStack> aInputs = Arrays.asList(mInventory);
+ if (mInputs.length > 0 && aInputs == null) tSuccess = false;
+ int amt = 0;
+ for (ItemStack tStack : mInputs) {
+ if (tStack != null) {
+ amt = tStack.stackSize;
+ boolean temp = true;
+ for (ItemStack aStack : aInputs) {
+ if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) {
+ amt -= aStack.stackSize;
+ if (amt < 1) {
+ temp = false;
+ break;
+ }
+ }
+ }
+ if (temp) tSuccess = false;
+ }
+ }
+ if(tSuccess){
+ for (ItemStack tStack : mInputs) {
+ if (tStack != null) {
+ amt = tStack.stackSize;
+ for (ItemStack aStack : aInputs) {
+ if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) {
+ if (aStack.stackSize < amt){
+ amt -= aStack.stackSize;
+ aStack.stackSize = 0;
+ }else{
+ aStack.stackSize -= amt;
+ amt = 0;
+ break;
+ }
+ }
+ }
+ }
+ }
+ this.mCrowbar = true;
+ this.mHardHammer = true;
+ this.mScrewdriver = true;
+ this.mSoftHammer = true;
+ this.mSolderingTool = true;
+ this.mWrench = true;
+ }
+ }
+ }
+ super.onPostTick(aBaseMetaTileEntity, aTimer);
+ }
public void onToolClick(ItemStack aStack, EntityLivingBase aPlayer) {
if (aStack == null || aPlayer == null) return;
@@ -125,4 +203,8 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return false;
}
+
+ public void setController(GT_MetaTileEntity_MultiBlockBase aController){
+ mController = aController;
+ }
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index c3b0f0c33c..87442bb70f 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -207,6 +207,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
for (GT_MetaTileEntity_Hatch_Maintenance tHatch : mMaintenanceHatches) {
if (isValidMetaTileEntity(tHatch)) {
if (!this.disableMaintenance) {
+ tHatch.setController(this);
if (tHatch.mWrench) mWrench = true;
if (tHatch.mScrewdriver) mScrewdriver = true;
if (tHatch.mSoftHammer) mSoftHammer = true;
@@ -762,6 +763,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
if (aMetaTileEntity == null) return false;
if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) {
((GT_MetaTileEntity_Hatch) aMetaTileEntity).mMachineBlock = (byte) aBaseCasingIndex;
+ ((GT_MetaTileEntity_Hatch_Maintenance) aMetaTileEntity).setController(this);
return mMaintenanceHatches.add((GT_MetaTileEntity_Hatch_Maintenance) aMetaTileEntity);
}
return false;