Fix maintenance cover (#1496)

* New public variable init

Initiated new public variable which is calculate how much damage get turbine rotor per time, its needed to compare with actual rotor durability.

* Fix cover logic

Rewrited due a bug maintenance cover logic which is check turbine rotor needed maintenance or not.

* Added&rewrited some features for need maintenance.

Added new high accuracy mod for need maintenance cover which check rotor state.
Fixed old version low accuracy mod.

* redo older changes

removed variable

* fix some shit

forgot brakets

* Cleanup & reformat code

thanks Dimach for help with that
This commit is contained in:
UhoMazino 2018-12-09 18:43:20 +03:00 committed by Blood-Asp
parent 0beea9037c
commit 8a61e384f0

View file

@ -7,13 +7,16 @@ import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_CoverBehavior;
import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_Utility;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
public class GT_Cover_NeedMaintainance extends GT_CoverBehavior { public class GT_Cover_NeedMaintainance extends GT_CoverBehavior {
private boolean isRotor(ItemStack aRotor) {
return !(aRotor == null || !(aRotor.getItem() instanceof GT_MetaGenerated_Tool) || aRotor.getItemDamage() < 170 || aRotor.getItemDamage() > 176);
}
public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) {
boolean needsRepair = false; boolean needsRepair = false;
if (aTileEntity instanceof IGregTechTileEntity) { if (aTileEntity instanceof IGregTechTileEntity) {
@ -23,31 +26,24 @@ public class GT_Cover_NeedMaintainance extends GT_CoverBehavior {
GT_MetaTileEntity_MultiBlockBase multi = (GT_MetaTileEntity_MultiBlockBase) mTileEntity; GT_MetaTileEntity_MultiBlockBase multi = (GT_MetaTileEntity_MultiBlockBase) mTileEntity;
int ideal = multi.getIdealStatus(); int ideal = multi.getIdealStatus();
int real = multi.getRepairStatus(); int real = multi.getRepairStatus();
if ((aCoverVariable == 0 || aCoverVariable == 1) && (ideal - real > 0)) { ItemStack tRotor = multi.getRealInventory()[1];
int coverVar = aCoverVariable >>> 1;
if (coverVar < 5) {
if (ideal - real > coverVar)
needsRepair = true;
} else if (coverVar == 5 || coverVar == 6) {
if (isRotor(tRotor)) {
long tMax = GT_MetaGenerated_Tool.getToolMaxDamage(tRotor);
long tCur = GT_MetaGenerated_Tool.getToolDamage(tRotor);
if (coverVar == 5) {
needsRepair = (tCur >= tMax * 8 / 10);
} else {
long mExpectedDamage = Math.round(Math.min(multi.mEUt / multi.damageFactorLow, Math.pow(multi.mEUt, multi.damageFactorHigh)));
needsRepair = tCur + mExpectedDamage * 2 >= tMax;
}
} else {
needsRepair = true; needsRepair = true;
} }
if ((aCoverVariable == 2 || aCoverVariable == 3) && (ideal - real > 1)) {
needsRepair = true;
}
if ((aCoverVariable == 4 || aCoverVariable == 5) && (ideal - real > 2)) {
needsRepair = true;
}
if ((aCoverVariable == 6 || aCoverVariable == 7) && (ideal - real > 3)) {
needsRepair = true;
}
if ((aCoverVariable == 8 || aCoverVariable == 9) && (ideal - real > 4)) {
needsRepair = true;
}
if(aCoverVariable == 10 || aCoverVariable == 11){
if(multi.getRealInventory()[1]==null || multi.getRealInventory()[1].getItem()!=GT_MetaGenerated_Tool_01.INSTANCE && multi.getRealInventory()[1].getItemDamage()<170){needsRepair = true;}
else{
ItemStack tTurbine = multi.getRealInventory()[1];
long tMax = GT_MetaGenerated_Tool.getToolMaxDamage(tTurbine);
long tCur = GT_MetaGenerated_Tool.getToolDamage(tTurbine);
if(tCur < tMax*2/10)
needsRepair = true;
}
} }
} }
} }
@ -61,21 +57,53 @@ public class GT_Cover_NeedMaintainance extends GT_CoverBehavior {
} }
public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
aCoverVariable = (aCoverVariable + (aPlayer.isSneaking()? -1 : 1)) % 12; aCoverVariable = (aCoverVariable + (aPlayer.isSneaking() ? -1 : 1)) % 14;
if(aCoverVariable <0){aCoverVariable = 11;} if (aCoverVariable < 0) {
aCoverVariable = 13;
}
switch (aCoverVariable) { switch (aCoverVariable) {
case 0: GT_Utility.sendChatToPlayer(aPlayer, trans("056", "Emit if 1 Maintenance Needed")); break; case 0:
case 1: GT_Utility.sendChatToPlayer(aPlayer, trans("057", "Emit if 1 Maintenance Needed(inverted)")); break; GT_Utility.sendChatToPlayer(aPlayer, trans("056", "Emit if 1 Maintenance Needed"));
case 2: GT_Utility.sendChatToPlayer(aPlayer, trans("058", "Emit if 2 Maintenance Needed")); break; break;
case 3: GT_Utility.sendChatToPlayer(aPlayer, trans("059", "Emit if 2 Maintenance Needed(inverted)")); break; case 1:
case 4: GT_Utility.sendChatToPlayer(aPlayer, trans("060", "Emit if 3 Maintenance Needed")); break; GT_Utility.sendChatToPlayer(aPlayer, trans("057", "Emit if 1 Maintenance Needed(inverted)"));
case 5: GT_Utility.sendChatToPlayer(aPlayer, trans("061", "Emit if 3 Maintenance Needed(inverted)")); break; break;
case 6: GT_Utility.sendChatToPlayer(aPlayer, trans("062", "Emit if 4 Maintenance Needed")); break; case 2:
case 7: GT_Utility.sendChatToPlayer(aPlayer, trans("063", "Emit if 4 Maintenance Needed(inverted)")); break; GT_Utility.sendChatToPlayer(aPlayer, trans("058", "Emit if 2 Maintenance Needed"));
case 8: GT_Utility.sendChatToPlayer(aPlayer, trans("064", "Emit if 5 Maintenance Needed")); break; break;
case 9: GT_Utility.sendChatToPlayer(aPlayer, trans("065", "Emit if 5 Maintenance Needed(inverted)")); break; case 3:
case 10: GT_Utility.sendChatToPlayer(aPlayer, trans("066", "Emit if rotor needs maintenance")); break; GT_Utility.sendChatToPlayer(aPlayer, trans("059", "Emit if 2 Maintenance Needed(inverted)"));
case 11: GT_Utility.sendChatToPlayer(aPlayer, trans("067", "Emit if rotor needs maintenance(inverted)")); break; break;
case 4:
GT_Utility.sendChatToPlayer(aPlayer, trans("060", "Emit if 3 Maintenance Needed"));
break;
case 5:
GT_Utility.sendChatToPlayer(aPlayer, trans("061", "Emit if 3 Maintenance Needed(inverted)"));
break;
case 6:
GT_Utility.sendChatToPlayer(aPlayer, trans("062", "Emit if 4 Maintenance Needed"));
break;
case 7:
GT_Utility.sendChatToPlayer(aPlayer, trans("063", "Emit if 4 Maintenance Needed(inverted)"));
break;
case 8:
GT_Utility.sendChatToPlayer(aPlayer, trans("064", "Emit if 5 Maintenance Needed"));
break;
case 9:
GT_Utility.sendChatToPlayer(aPlayer, trans("065", "Emit if 5 Maintenance Needed(inverted)"));
break;
case 10:
GT_Utility.sendChatToPlayer(aPlayer, trans("066", "Emit if rotor needs maintenance low accuracy mod"));
break;
case 11:
GT_Utility.sendChatToPlayer(aPlayer, trans("067", "Emit if rotor needs maintenance low accuracy mod(inverted)"));
break;
case 12:
GT_Utility.sendChatToPlayer(aPlayer, trans("068", "Emit if rotor needs maintenance high accuracy mod"));
break;
case 13:
GT_Utility.sendChatToPlayer(aPlayer, trans("069", "Emit if rotor needs maintenance high accuracy mod(inverted)"));
break;
} }
return aCoverVariable; return aCoverVariable;
} }