The true and ultimate auto-maintenance fix for servers (checked works)

This commit is contained in:
Technus 2016-10-30 12:20:47 +01:00
parent c30e62421f
commit b5686c2651
2 changed files with 18 additions and 44 deletions

View file

@ -23,9 +23,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import scala.actors.threadpool.Arrays;
import java.util.List;
public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch { public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch {
public boolean mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mAuto; public boolean mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mAuto;
@ -115,23 +112,25 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch
@Override @Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if(aBaseMetaTileEntity.isServerSide() && mAuto && aTick % 100 ==0){
aBaseMetaTileEntity.setActive(!autoMaintainanceCheck());
}
super.onPostTick(aBaseMetaTileEntity, aTick); super.onPostTick(aBaseMetaTileEntity, aTick);
if(aBaseMetaTileEntity.isServerSide() && mAuto && aTick % 100L ==0L){
aBaseMetaTileEntity.setActive(!isRecipeInputEqual(false));
}
} }
public boolean autoMaintainanceCheck(){ public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess) {
boolean tSuccess = true; ItemStack[] mInputs=new ItemStack[]{ItemList.Duct_Tape.get(4, new Object[]{}),
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)}; GT_OreDictUnificator.get(OrePrefixes.cell, Materials.Lubricant, 2),
List<ItemStack> aInputs = Arrays.asList(mInventory); GT_OreDictUnificator.get(OrePrefixes.screw, Materials.Steel, 4),
if (mInputs.length > 0 && aInputs == null) tSuccess = false; GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Advanced, 2)};
int amt = 0;
int amt;
for (ItemStack tStack : mInputs) { for (ItemStack tStack : mInputs) {
if (tStack != null) { if (tStack != null) {
amt = tStack.stackSize; amt = tStack.stackSize;
boolean temp = true; boolean temp = true;
for (ItemStack aStack : aInputs) { for (ItemStack aStack : mInventory) {
if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) {
amt -= aStack.stackSize; amt -= aStack.stackSize;
if (amt < 1) { if (amt < 1) {
@ -140,39 +139,15 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch
} }
} }
} }
if (temp) tSuccess = false; if (temp) return false;
} }
} }
return tSuccess;
} if (aDecreaseStacksizeBySuccess) {
public boolean autoMaintainance() {
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) { for (ItemStack tStack : mInputs) {
if (tStack != null) { if (tStack != null) {
amt = tStack.stackSize; amt = tStack.stackSize;
for (ItemStack aStack : aInputs) { for (ItemStack aStack : mInventory) {
if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) {
if (aStack.stackSize < amt){ if (aStack.stackSize < amt){
amt -= aStack.stackSize; amt -= aStack.stackSize;
@ -192,9 +167,8 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch
this.mSoftHammer = true; this.mSoftHammer = true;
this.mSolderingTool = true; this.mSolderingTool = true;
this.mWrench = true; this.mWrench = true;
return true;
} }
return false; return true;
} }
public void onToolClick(ItemStack aStack, EntityLivingBase aPlayer) { public void onToolClick(ItemStack aStack, EntityLivingBase aPlayer) {

View file

@ -216,7 +216,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
mSolderingTool = true; mSolderingTool = true;
mCrowbar = true; mCrowbar = true;
} else { } else {
if (tHatch.mAuto && (!mWrench||!mScrewdriver||!mSoftHammer||!mHardHammer||!mSolderingTool||!mCrowbar))tHatch.autoMaintainance(); if (tHatch.mAuto && !(mWrench&&mScrewdriver&&mSoftHammer&&mHardHammer&&mSolderingTool&&mCrowbar))tHatch.isRecipeInputEqual(true);
if (tHatch.mWrench) mWrench = true; if (tHatch.mWrench) mWrench = true;
if (tHatch.mScrewdriver) mScrewdriver = true; if (tHatch.mScrewdriver) mScrewdriver = true;
if (tHatch.mSoftHammer) mSoftHammer = true; if (tHatch.mSoftHammer) mSoftHammer = true;