mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 03:49:29 +00:00
Unify tool speed calculation in one accessible place, instead of having the same code floating around 3 times.
This commit is contained in:
1 parent
7ca3acad88
commit
2dd426f1d7
4 files changed
+52
-89
No files matched your search
@@ -680,4 +680,45 @@ public class AbilityHelper
|
||||
return world.func_147447_a(vec3, vec31, par3, !par3, par3);
|
||||
}
|
||||
|
||||
public static float calcToolSpeed(ToolCore tool, NBTTagCompound tags)
|
||||
{
|
||||
float mineSpeed = tags.getInteger("MiningSpeed");
|
||||
int heads = 1;
|
||||
if (tags.hasKey("MiningSpeed2"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeed2");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedHandle"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedHandle");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedExtra"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedExtra");
|
||||
heads++;
|
||||
}
|
||||
float speedMod = 1f;
|
||||
if(tool instanceof HarvestTool)
|
||||
speedMod = ((HarvestTool) tool).breakSpeedModifier();
|
||||
|
||||
float trueSpeed = mineSpeed / (heads * 100f) * speedMod;
|
||||
trueSpeed += calcStoneboundBonus(tool, tags);
|
||||
|
||||
return trueSpeed;
|
||||
}
|
||||
|
||||
public static float calcStoneboundBonus(ToolCore tool, NBTTagCompound tags)
|
||||
{
|
||||
int durability = tags.getInteger("Damage");
|
||||
float stonebound = tags.getFloat("Shoddy");
|
||||
float stoneboundMod = 72f;
|
||||
if(tool instanceof HarvestTool)
|
||||
stoneboundMod = ((HarvestTool) tool).stoneboundModifier();
|
||||
|
||||
return (float) Math.log(durability / stoneboundMod + 1) * 2 * stonebound;
|
||||
}
|
||||
}
|
||||
@@ -141,38 +141,14 @@ public abstract class HarvestTool extends ToolCore
|
||||
|
||||
public float calculateStrength (NBTTagCompound tags, Block block, int meta)
|
||||
{
|
||||
float mineSpeed = tags.getInteger("MiningSpeed");
|
||||
int heads = 1;
|
||||
if (tags.hasKey("MiningSpeed2"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeed2");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedHandle"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedHandle");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedExtra"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedExtra");
|
||||
heads++;
|
||||
}
|
||||
float trueSpeed = mineSpeed / (heads * 100f) * breakSpeedModifier();
|
||||
int hlvl = block.getHarvestLevel(meta);
|
||||
int durability = tags.getInteger("Damage");
|
||||
if (hlvl > tags.getInteger("HarvestLevel"))
|
||||
return 0.1f;
|
||||
|
||||
float stonebound = tags.getFloat("Shoddy");
|
||||
float bonusLog = (float) Math.log(durability / stoneboundModifier() + 1) * 2 * stonebound;
|
||||
trueSpeed += bonusLog;
|
||||
|
||||
if (hlvl <= tags.getInteger("HarvestLevel"))
|
||||
return trueSpeed;
|
||||
return 0.1f;
|
||||
return AbilityHelper.calcToolSpeed(this, tags);
|
||||
}
|
||||
|
||||
|
||||
public float breakSpeedModifier()
|
||||
{
|
||||
return 1.0f;
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.world.World;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import tconstruct.library.armor.ArmorCore;
|
||||
import tconstruct.library.tools.AbilityHelper;
|
||||
import tconstruct.library.tools.HarvestTool;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
import tconstruct.tools.logic.CraftingStationLogic;
|
||||
@@ -315,36 +316,8 @@ public class CraftingStationGui extends GuiContainer
|
||||
}
|
||||
else if (categories.contains("harvest"))
|
||||
{
|
||||
float mineSpeed = tags.getInteger("MiningSpeed");
|
||||
int heads = 1;
|
||||
|
||||
if (tags.hasKey("MiningSpeed2"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeed2");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedHandle"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedHandle");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedExtra"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedExtra");
|
||||
heads++;
|
||||
}
|
||||
|
||||
float trueSpeed = mineSpeed / (heads * 100f);
|
||||
if(tool instanceof HarvestTool)
|
||||
trueSpeed *= ((HarvestTool) tool).breakSpeedModifier();
|
||||
|
||||
|
||||
float localStonebound = 72f;
|
||||
if (tool instanceof HarvestTool)
|
||||
localStonebound = ((HarvestTool) tool).stoneboundModifier();
|
||||
float stoneboundSpeed = (float) Math.log(durability / localStonebound + 1) * 2 * stonebound;
|
||||
float trueSpeed = AbilityHelper.calcToolSpeed(tool, tags);
|
||||
float stoneboundSpeed = AbilityHelper.calcToolSpeed(tool, tags);
|
||||
|
||||
DecimalFormat df = new DecimalFormat("##.##");
|
||||
df.setRoundingMode(RoundingMode.DOWN);
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.library.client.TConstructClientRegistry;
|
||||
import tconstruct.library.client.ToolGuiElement;
|
||||
import tconstruct.library.tools.AbilityHelper;
|
||||
import tconstruct.library.tools.HarvestTool;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
import tconstruct.library.util.HarvestLevels;
|
||||
@@ -324,36 +325,8 @@ public class ToolStationGui extends GuiContainer
|
||||
}
|
||||
else if (categories.contains("harvest"))
|
||||
{
|
||||
float mineSpeed = tags.getInteger("MiningSpeed");
|
||||
int heads = 1;
|
||||
|
||||
if (tags.hasKey("MiningSpeed2"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeed2");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedHandle"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedHandle");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (tags.hasKey("MiningSpeedExtra"))
|
||||
{
|
||||
mineSpeed += tags.getInteger("MiningSpeedExtra");
|
||||
heads++;
|
||||
}
|
||||
|
||||
float trueSpeed = mineSpeed / (heads * 100f);
|
||||
if(tool instanceof HarvestTool)
|
||||
trueSpeed *= ((HarvestTool) tool).breakSpeedModifier();
|
||||
|
||||
|
||||
float localStonebound = 72f;
|
||||
if (tool instanceof HarvestTool)
|
||||
localStonebound = ((HarvestTool) tool).stoneboundModifier();
|
||||
float stoneboundSpeed = (float) Math.log(durability / localStonebound + 1) * 2 * stonebound;
|
||||
float trueSpeed = AbilityHelper.calcToolSpeed(tool, tags);
|
||||
float stoneboundSpeed = AbilityHelper.calcToolSpeed(tool, tags);
|
||||
|
||||
DecimalFormat df = new DecimalFormat("##.##");
|
||||
df.setRoundingMode(RoundingMode.DOWN);
|
||||
@@ -362,7 +335,7 @@ public class ToolStationGui extends GuiContainer
|
||||
trueSpeed = 0;
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("gui.toolstation14") + df.format(trueSpeed), 294, base + offset * 10, 0xffffff);
|
||||
offset++;
|
||||
if (stoneboundSpeed != 0)
|
||||
if (stoneboundSpeed != 0 && !Float.isNaN(stoneboundSpeed))
|
||||
{
|
||||
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
|
||||
fontRendererObj.drawString(bloss + df.format(stoneboundSpeed), 294, base + offset * 10, 0xffffff);
|
||||
|
||||
Reference in new issue
Block a user