diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java index 750c207a..7c4ef1af 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -71,14 +71,13 @@ public interface IEnergyConnected extends IColoredTileEntity, IHasWorldObjectAnd } } else if (GregTech_API.mOutputRF && tTileEntity instanceof IEnergyReceiver) { ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - long rfOUT = aVoltage * GregTech_API.mEUtoRF / 100; - int rfOut = rfOUT>Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)rfOUT; + int rfOut = GT_Utility.safeInt(aVoltage * GregTech_API.mEUtoRF / 100); if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) == rfOut) { ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); rUsedAmperes++; } - if (GregTech_API.mRFExplosions && GregTech_API.sMachineExplosions && ((IEnergyReceiver) tTileEntity).getMaxEnergyStored(tDirection) < rfOut * 600) { - if (rfOut > 32 * GregTech_API.mEUtoRF / 100) { + if (GregTech_API.mRFExplosions && GregTech_API.sMachineExplosions && ((IEnergyReceiver) tTileEntity).getMaxEnergyStored(tDirection) < rfOut * 600L) { + if (rfOut > 32L * GregTech_API.mEUtoRF / 100L) { int aExplosionPower = rfOut; float tStrength = aExplosionPower < V[0] ? 1.0F : diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index f144bba6..e25fa296 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -515,6 +515,11 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B calculateOverclockedNess(aRecipe.mEUt, aRecipe.mDuration); } + /** + * Calcualtes overclocked ness using long integers + * @param aEUt - recipe EUt + * @param aDuration - recipe Duration + */ protected void calculateOverclockedNess(int aEUt, int aDuration) { if(mTier==0){ //Long time calculation @@ -524,12 +529,12 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B mEUt=Integer.MAX_VALUE-1; mMaxProgresstime=Integer.MAX_VALUE-1; }else{ - mEUt=aEUt/2; + mEUt=aEUt/4; mMaxProgresstime=(int)xMaxProgresstime; } }else{ //Long EUt calculation - long xEUt=(long)aEUt; + long xEUt=aEUt; //Isnt too low EUt check? long tempEUt = xEUtInteger.MAX_VALUE-1){ - mEUt=Integer.MAX_VALUE-1; - mMaxProgresstime=Integer.MAX_VALUE-1; + mEUt = Integer.MAX_VALUE-1; + mMaxProgresstime = Integer.MAX_VALUE-1; }else{ - mEUt=(int)xEUt; - mEUt=mEUt==0 ? 1 : mEUt; - //mMaxProgresstime is set already + mEUt = (int)xEUt; + mEUt = mEUt == 0 ? 1 : mEUt; + mMaxProgresstime = mMaxProgresstime<1 ? 1 : mMaxProgresstime;//set time to 1 tick } } } @@ -745,6 +750,15 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B * @return see constants above */ public int checkRecipe() { + return checkRecipe(false); + } + + /** + * + * @param skipOC disables OverclockedNess calculation and check - if you do you must implement your own method... + * @return + */ + public int checkRecipe(boolean skipOC){ GT_Recipe_Map tMap = getRecipeList(); if (tMap == null) return DID_NOT_FIND_RECIPE; GT_Recipe tRecipe = tMap.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, V[mTier], new FluidStack[]{getFillableStack()}, getSpecialSlot(), getAllInputs()); @@ -761,9 +775,12 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)) mOutputItems[i] = tRecipe.getOutput(i); mOutputFluid = tRecipe.getFluidOutput(0); - calculateOverclockedNess(tRecipe); - //In case recipe is too OP for that machine - if(mMaxProgresstime==Integer.MAX_VALUE-1 && mEUt==Integer.MAX_VALUE-1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + if(!skipOC) { + calculateOverclockedNess(tRecipe); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } return FOUND_AND_SUCCESSFULLY_USED_RECIPE; } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Transformer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Transformer.java index c5954593..27472e76 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Transformer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Transformer.java @@ -147,23 +147,22 @@ public class GT_MetaTileEntity_Transformer extends GT_MetaTileEntity_TieredMachi ((IEnergySource) tTileEntity).drawEnergy(tEU); aBaseMetaTileEntity.injectEnergyUnits((byte) 6, tEU, 1); } else if (GregTech_API.mInputRF && tTileEntity instanceof IEnergyProvider && ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(i)), 1, true) == 1) { - long tEU = (long) ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(i)), (int) maxEUInput() * 100 / GregTech_API.mRFtoEU, false); + long tEU = (long) ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(i)), GT_Utility.safeInt(maxEUInput() * 100L / GregTech_API.mRFtoEU), false); tEU = tEU * GregTech_API.mRFtoEU / 100; aBaseMetaTileEntity.injectEnergyUnits((byte) 6, Math.min(tEU, maxEUInput()), 1); } else if (GregTech_API.mInputRF && tTileEntity instanceof IEnergyStorage && ((IEnergyStorage) tTileEntity).extractEnergy(1, true) == 1) { - long tEU = (long) ((IEnergyStorage) tTileEntity).extractEnergy((int) maxEUInput() * 100 / GregTech_API.mRFtoEU, false); + long tEU = (long) ((IEnergyStorage) tTileEntity).extractEnergy(GT_Utility.safeInt(maxEUInput() * 100L / GregTech_API.mRFtoEU), false); tEU = tEU * GregTech_API.mRFtoEU / 100; aBaseMetaTileEntity.injectEnergyUnits((byte) 6, Math.min(tEU, maxEUInput()), 1); } else if (GregTech_API.mInputRF && GregTech_API.meIOLoaded && tTileEntity instanceof IPowerContainer && ((IPowerContainer) tTileEntity).getEnergyStored() > 0) { int storedRF = ((IPowerContainer) tTileEntity).getEnergyStored(); - long EXTRACTRF = maxEUInput() * 100 / GregTech_API.mRFtoEU; - int extractRF = EXTRACTRF>Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)EXTRACTRF; + int extractRF = GT_Utility.safeInt(maxEUInput() * 100L / GregTech_API.mRFtoEU); long tEU = 0; if (tTileEntity instanceof TileCapBank) { ICapBankNetwork network = ((TileCapBank) tTileEntity).getNetwork(); if (network != null && network.getEnergyStoredL() > 0) { - tEU = Math.min((Math.min(Math.min(network.getEnergyStoredL(), storedRF - extractRF), network.getMaxOutput())) * GregTech_API.mRFtoEU / 100, maxEUInput()); - network.addEnergy((int) -(tEU * 100 / GregTech_API.mRFtoEU)); + tEU = Math.min((Math.min(Math.min(network.getEnergyStoredL(), storedRF - extractRF), network.getMaxOutput())) * (long)GregTech_API.mRFtoEU / 100L, maxEUInput()); + network.addEnergy(GT_Utility.safeInt(-(tEU * 100 / GregTech_API.mRFtoEU))); } } else { if (storedRF > extractRF) { @@ -171,7 +170,7 @@ public class GT_MetaTileEntity_Transformer extends GT_MetaTileEntity_TieredMachi tEU = maxEUInput(); } else { ((IPowerContainer) tTileEntity).setEnergyStored(0); - tEU = storedRF * GregTech_API.mRFtoEU / 100; + tEU = storedRF * (long)GregTech_API.mRFtoEU / 100L; } } aBaseMetaTileEntity.injectEnergyUnits((byte) 6, Math.min(tEU, maxEUInput()), 1); diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 9183a49d..a4117aa4 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -96,6 +96,14 @@ public class GT_Utility { GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); } + public static int safeInt(long number, int margin){ + return number>Integer.MAX_VALUE-margin ? Integer.MAX_VALUE-margin :(int)number; + } + + public static int safeInt(long number){ + return number>GT_Values.V[GT_Values.V.length-1] ? safeInt(GT_Values.V[GT_Values.V.length-1],1) : number= 4)) { this.mOutputItems[0] = GT_ModHandler.getRecipeOutput(new ItemStack[]{getInputAt(0), getInputAt(0), null, getInputAt(0), getInputAt(0)}); if (this.mOutputItems[0] != null) { if (canOutput(new ItemStack[]{this.mOutputItems[0]})) { getInputAt(0).stackSize -= 4; - this.mEUt = (32 * (1 << this.mTier - 1) * (1 << this.mTier - 1)); - this.mMaxProgresstime = (32 / (1 << this.mTier - 1)); - return 2; + calculateOverclockedNess(32,32); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + return FOUND_AND_SUCCESSFULLY_USED_RECIPE; } } - return 0; + return DID_NOT_FIND_RECIPE; } if ((ItemList.Schematic_3by3.isStackEqual(getInputAt(1))) && (getInputAt(0).stackSize >= 9)) { this.mOutputItems[0] = GT_ModHandler.getRecipeOutput(new ItemStack[]{getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0)}); if (this.mOutputItems[0] != null) { if (canOutput(new ItemStack[]{this.mOutputItems[0]})) { getInputAt(0).stackSize -= 9; - this.mEUt = (32 * (1 << this.mTier - 1) * (1 << this.mTier - 1)); - this.mMaxProgresstime = (64 / (1 << this.mTier - 1)); - return 2; + calculateOverclockedNess(32,64); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; } } - return 0; + return DID_NOT_FIND_RECIPE; } } - return 0; + return DID_NOT_FIND_RECIPE; } public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { if (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) { if ((ItemList.Schematic_1by1.isStackEqual(getInputAt(1))) || (ItemList.Schematic_2by2.isStackEqual(getInputAt(1))) || (ItemList.Schematic_3by3.isStackEqual(getInputAt(1)))) { - if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe(getBaseMetaTileEntity(), true, gregtech.api.enums.GT_Values.V[this.mTier], null, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), getInputAt(1)}) != null) { + if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe(getBaseMetaTileEntity(), true, gregtech.api.enums.GT_Values.V[mTier], null, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), getInputAt(1)}) != null) { return true; } if (ItemList.Schematic_1by1.isStackEqual(getInputAt(1)) && GT_ModHandler.getRecipeOutput(new ItemStack[]{aStack}) != null) diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Charger.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Charger.java index 8937dfbc..6e265b41 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Charger.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Charger.java @@ -7,6 +7,7 @@ import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer; import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; import static gregtech.api.enums.GT_Values.V; @@ -27,22 +28,20 @@ public class GT_MetaTileEntity_Charger extends GT_MetaTileEntity_BasicBatteryBuf @Override public long getMinimumStoredEU() { - return V[mTier] * 64 * mInventory.length; + return V[mTier] * 64L * mInventory.length; } @Override - public long maxEUStore() { - return V[mTier] * 256 * mInventory.length; - } + public long maxEUStore() { return V[mTier] * 256L * mInventory.length;} @Override public long maxAmperesIn() { - return mChargeableCount * 8; + return mChargeableCount * 8L; } @Override public long maxAmperesOut() { - return mBatteryCount * 4; + return mBatteryCount * 4L; } @Override @@ -57,7 +56,7 @@ public class GT_MetaTileEntity_Charger extends GT_MetaTileEntity_BasicBatteryBuf if (mMetaTileEntity.dechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) { for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { if (mMetaTileEntity.mInventory[i] != null && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) { - mBaseMetaTileEntity.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(mMetaTileEntity.mInventory[i], (int) Math.min(V[mTier] * 15, mBaseMetaTileEntity.getEUCapacity() - mBaseMetaTileEntity.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), true, false, false), true); + mBaseMetaTileEntity.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(mMetaTileEntity.mInventory[i], GT_Utility.safeInt(Math.min(V[mTier] * 15, mBaseMetaTileEntity.getEUCapacity() - mBaseMetaTileEntity.getStoredEU())), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), true, false, false), true); if (mMetaTileEntity.mInventory[i].stackSize <= 0) mMetaTileEntity.mInventory[i] = null; } @@ -66,7 +65,7 @@ public class GT_MetaTileEntity_Charger extends GT_MetaTileEntity_BasicBatteryBuf if (mMetaTileEntity.rechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() > 0) { for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { if (mBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { - mBaseMetaTileEntity.decreaseStoredEU(GT_ModHandler.chargeElectricItem(mMetaTileEntity.mInventory[i], (int) Math.min(V[this.mTier] * 15, mBaseMetaTileEntity.getStoredEU()), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()), true, false), true); + mBaseMetaTileEntity.decreaseStoredEU(GT_ModHandler.chargeElectricItem(mMetaTileEntity.mInventory[i], GT_Utility.safeInt(Math.min(V[mTier] * 15, mBaseMetaTileEntity.getStoredEU())), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()), true, false), true); if (mMetaTileEntity.mInventory[i].stackSize <= 0) mMetaTileEntity.mInventory[i] = null; } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java index 315207d6..2d6f1105 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java @@ -13,7 +13,7 @@ import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_Disassembler extends GT_MetaTileEntity_BasicMachine { public GT_MetaTileEntity_Disassembler(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 1, "Disassembles Machines at " + (50 + 10 * aTier) + "% Efficiency", 1, 9, "Disassembler.png", "", new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_DISASSEMBLER), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_DISASSEMBLER), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_DISASSEMBLER)}); + super(aID, aName, aNameRegional, aTier, 1, "Disassembles Machines at " + Math.max(50 + 10 * aTier,100) + "% Efficiency", 1, 9, "Disassembler.png", "", new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_DISASSEMBLER), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_DISASSEMBLER), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_DISASSEMBLER_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_DISASSEMBLER)}); } public GT_MetaTileEntity_Disassembler(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { @@ -30,17 +30,22 @@ public class GT_MetaTileEntity_Disassembler if (tNBT != null) { tNBT = tNBT.getCompoundTag("GT.CraftingComponents"); if (tNBT != null) { - this.mEUt = (16 * (1 << this.mTier - 1) * (1 << this.mTier - 1)); - this.mMaxProgresstime = 80; + boolean isAnyOutput=false; + calculateOverclockedNess(16,80); + this.mMaxProgresstime = 80;//Override speed overclocking + //In case recipe is too OP for that machine + if (mEUt == Integer.MAX_VALUE - 1)//&& mMaxProgresstime==Integer.MAX_VALUE-1 + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; for (int i = 0; i < this.mOutputItems.length; i++) { if (getBaseMetaTileEntity().getRandomNumber(100) < 50 + 10 * this.mTier) { this.mOutputItems[i] = GT_Utility.loadItem(tNBT, "Ingredient." + i); if (this.mOutputItems[i] != null) { - this.mMaxProgresstime *= 1.7; + this.mMaxProgresstime *= (mTier>5 ? 1.7F-(mTier/8.0F) : 1.7F); + isAnyOutput=true; } } } - if(mMaxProgresstime==80){ + if(!isAnyOutput){ return 0; } getInputAt(0).stackSize -= 1; diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java index da08f325..c1bfb28f 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java @@ -1,9 +1,6 @@ package gregtech.common.tileentities.machines.basic; -import gregtech.api.enums.ConfigCategories; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.enums.Textures; +import gregtech.api.enums.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -49,15 +46,17 @@ public class GT_MetaTileEntity_Massfabricator @Override public long maxEUStore() { - return V[mTier] * 512; + return V[mTier] * 512L; } public int checkRecipe() { FluidStack tFluid = getDrainableStack(); if ((tFluid == null) || (tFluid.amount < getCapacity())) { this.mOutputFluid = Materials.UUMatter.getFluid(1L); - this.mEUt = (((int) gregtech.api.enums.GT_Values.V[1]) * (int)Math.pow(2, this.mTier + 2)); - this.mMaxProgresstime = (sDurationMultiplier / (1 << this.mTier - 1)); + calculateOverclockedNessMassFabricator(); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; if (((tFluid = getFillableStack()) != null) && (tFluid.amount >= sUUAperUUM) && (tFluid.isFluidEqual(Materials.UUAmplifier.getFluid(1L)))) { tFluid.amount -= sUUAperUUM; this.mMaxProgresstime /= sUUASpeedBonus; @@ -68,6 +67,43 @@ public class GT_MetaTileEntity_Massfabricator return 0; } + private void calculateOverclockedNessMassFabricator() { + if(mTier==0){ + //Long time calculation + long xMaxProgresstime = (long)sDurationMultiplier*2L; + if(xMaxProgresstime>Integer.MAX_VALUE-1){ + //make impossible if too long + mEUt=Integer.MAX_VALUE-1; + mMaxProgresstime=Integer.MAX_VALUE-1; + }else{ + mEUt=((int)GT_Values.V[1] * (1<<(mTier+3)))/2; + mMaxProgresstime=(int)xMaxProgresstime; + } + }else{ + //Long EUt calculation + long xEUt=(GT_Values.V[1] * (1L<<(mTier+3)))/2; + + long tempEUt = GT_Values.V[1]; + + mMaxProgresstime = sDurationMultiplier; + + while (tempEUt <= V[mTier -1] * (long)mAmperage) { + tempEUt *= 2;//this actually controls overclocking + xEUt *= 2;//this is effect of everclocking + mMaxProgresstime /= 2;//this is effect of overclocking + xEUt = mMaxProgresstime==0 ? (int)(xEUt/1.5F) : xEUt;//U know, if the time is less than 1 tick make the machine use 2x less power + } + if(xEUt>Integer.MAX_VALUE-1){ + mEUt = Integer.MAX_VALUE-1; + mMaxProgresstime = Integer.MAX_VALUE-1; + }else{ + mEUt = (int)xEUt; + mEUt = mEUt == 0 ? 1 : mEUt; + mMaxProgresstime = mMaxProgresstime<1 ? 1 : mMaxProgresstime;//set time to 1 tick + } + } + } + public boolean isFluidInputAllowed(FluidStack aFluid) { return aFluid.isFluidEqual(Materials.UUAmplifier.getFluid(1L)); } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java index 0f7ddde6..f269cc6c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java @@ -160,7 +160,7 @@ public class GT_MetaTileEntity_MicrowaveEnergyTransmitter extends GT_MetaTileEnt if ((getBaseMetaTileEntity().isAllowedToWork()) && (getBaseMetaTileEntity().getRedstone())) { if (getBaseMetaTileEntity().getStoredEU() > (V[mTier] * 16)) { if (mPassiveEnergyUse) { - getBaseMetaTileEntity().decreaseStoredEnergyUnits((long) Math.pow(2, mTier), false); + getBaseMetaTileEntity().decreaseStoredEnergyUnits(2L< 0) { - int tLoss = 1; - if (mMaxLossDistance != 0) { - tLoss = 10 + tDistance * (mMaxLoss - 10) / mMaxLossDistance; + int tLoss = 1; + if (mMaxLossDistance != 0) { + tLoss = GT_Utility.safeInt(10 + tDistance * (mMaxLoss - 10) / mMaxLossDistance); + } + if(getBaseMetaTileEntity().getStoredEU()>=V[mTier] + ((V[mTier] * tLoss) / 100)){ + if (((IEnergyConnected) tTile).injectEnergyUnits((byte) 6, tEnergyTrans, 1) > 0) { + getBaseMetaTileEntity().decreaseStoredEnergyUnits(V[mTier] + ((V[mTier] * tLoss) / 100), false); } - getBaseMetaTileEntity().decreaseStoredEnergyUnits(V[mTier] + ((V[mTier] * tLoss) / 100), false); } } }