mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 11:59:14 +00:00
Fix JABBA-related issues with crafting station slots (#54)
* Fix shift-merging tools voiding items fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392> * Change 0-sized ItemStacks into null stacks in crafting station attached slots Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425> * Update buildscript * spotlessApply
This commit is contained in:
1 parent
18bfeaff32
commit
39be06c23b
571 files changed
+25959
-28223
No files matched your search
@@ -1,5 +1,9 @@
|
||||
package tconstruct.tools.gui;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -11,21 +15,12 @@ import tconstruct.library.accessory.AccessoryCore;
|
||||
import tconstruct.library.armor.ArmorCore;
|
||||
import tconstruct.library.modifier.IModifyable;
|
||||
import tconstruct.library.tools.AbilityHelper;
|
||||
import tconstruct.library.tools.DualHarvestTool;
|
||||
import tconstruct.library.tools.HarvestTool;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
import tconstruct.library.util.HarvestLevels;
|
||||
import tconstruct.library.weaponry.AmmoWeapon;
|
||||
import tconstruct.library.weaponry.IAmmo;
|
||||
import tconstruct.library.weaponry.ProjectileWeapon;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ToolStationGuiHelper {
|
||||
// non-instantiable
|
||||
private ToolStationGuiHelper() {}
|
||||
@@ -33,23 +28,21 @@ public final class ToolStationGuiHelper {
|
||||
private static final FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRenderer;
|
||||
private static int xPos, yPos;
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("#.##");
|
||||
private static final DecimalFormat df = new DecimalFormat("#.##");
|
||||
|
||||
private static void newline()
|
||||
{
|
||||
private static void newline() {
|
||||
yPos += 10;
|
||||
}
|
||||
|
||||
|
||||
private static void write(String s)
|
||||
{
|
||||
private static void write(String s) {
|
||||
fontRendererObj.drawString(s, xPos, yPos, 0xffffffff);
|
||||
newline();
|
||||
}
|
||||
|
||||
public static void drawToolStats (ItemStack stack, int x, int y)
|
||||
{
|
||||
String name = stack.getItem() instanceof ToolCore ? ((ToolCore) stack.getItem()).getLocalizedToolName() : stack.getDisplayName();
|
||||
public static void drawToolStats(ItemStack stack, int x, int y) {
|
||||
String name = stack.getItem() instanceof ToolCore
|
||||
? ((ToolCore) stack.getItem()).getLocalizedToolName()
|
||||
: stack.getDisplayName();
|
||||
Item item = stack.getItem();
|
||||
NBTTagCompound tags = stack.getTagCompound();
|
||||
Collection<String> categories = new LinkedList<String>();
|
||||
@@ -59,7 +52,7 @@ public final class ToolStationGuiHelper {
|
||||
yPos = y + 8;
|
||||
|
||||
// get the correct tags
|
||||
if(item instanceof IModifyable) {
|
||||
if (item instanceof IModifyable) {
|
||||
IModifyable modifyable = (IModifyable) item;
|
||||
tags = tags.getCompoundTag(modifyable.getBaseTagName());
|
||||
categories = Arrays.asList(modifyable.getTraits());
|
||||
@@ -70,24 +63,19 @@ public final class ToolStationGuiHelper {
|
||||
newline();
|
||||
|
||||
// does it have ammo instead of durability?
|
||||
if(item instanceof IAmmo)
|
||||
drawAmmo((IAmmo) item, stack);
|
||||
if (item instanceof IAmmo) drawAmmo((IAmmo) item, stack);
|
||||
// regular durability?
|
||||
else if(item instanceof ToolCore || item instanceof ArmorCore)
|
||||
drawDurability(tags);
|
||||
else if (item instanceof ToolCore || item instanceof ArmorCore) drawDurability(tags);
|
||||
|
||||
// tools
|
||||
if(item instanceof ToolCore) {
|
||||
if (item instanceof ToolCore) {
|
||||
ToolCore tool = (ToolCore) item;
|
||||
// DualHarvest tool?
|
||||
if (categories.contains("dualharvest"))
|
||||
drawDualHarvestStats(tool, tags);
|
||||
if (categories.contains("dualharvest")) drawDualHarvestStats(tool, tags);
|
||||
// or regular Harvest tool?
|
||||
else if (categories.contains("harvest"))
|
||||
drawHarvestStats(tool, tags);
|
||||
else if (categories.contains("harvest")) drawHarvestStats(tool, tags);
|
||||
// weapon?
|
||||
if (categories.contains("weapon"))
|
||||
drawWeaponStats(tool, tags);
|
||||
if (categories.contains("weapon")) drawWeaponStats(tool, tags);
|
||||
// throwing weapon?
|
||||
if (categories.contains("thrown") && tool instanceof AmmoWeapon)
|
||||
drawThrowingWeaponStats((AmmoWeapon) tool, tags);
|
||||
@@ -95,18 +83,15 @@ public final class ToolStationGuiHelper {
|
||||
if (categories.contains("bow") && tool instanceof ProjectileWeapon)
|
||||
drawProjectileWeaponStats((ProjectileWeapon) tool, tags, stack);
|
||||
// projectile?
|
||||
if (categories.contains("projectile"))
|
||||
drawProjectileStats(tags);
|
||||
if (categories.contains("projectile")) drawProjectileStats(tags);
|
||||
}
|
||||
// armor
|
||||
if(item instanceof ArmorCore)
|
||||
{
|
||||
if (item instanceof ArmorCore) {
|
||||
ArmorCore armor = (ArmorCore) item;
|
||||
drawArmorStats(armor, tags, stack);
|
||||
}
|
||||
// Accessory
|
||||
if(item instanceof AccessoryCore)
|
||||
{
|
||||
if (item instanceof AccessoryCore) {
|
||||
AccessoryCore accessory = (AccessoryCore) item;
|
||||
drawAccessoryStats(accessory, tags);
|
||||
}
|
||||
@@ -123,31 +108,25 @@ public final class ToolStationGuiHelper {
|
||||
final int availableDurability = maxDur - durability;
|
||||
|
||||
// big durabilities have to split to 2 lines
|
||||
if (maxDur >= 10000)
|
||||
{
|
||||
if (maxDur >= 10000) {
|
||||
write(StatCollector.translateToLocal("gui.toolstation1"));
|
||||
write("- " + availableDurability + "/" + maxDur);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
write(StatCollector.translateToLocal("gui.toolstation2") + availableDurability + "/" + maxDur);
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawAmmo(IAmmo ammoItem, ItemStack stack)
|
||||
{
|
||||
private static void drawAmmo(IAmmo ammoItem, ItemStack stack) {
|
||||
final int max = ammoItem.getMaxAmmo(stack);
|
||||
final int current = ammoItem.getAmmoCount(stack);
|
||||
|
||||
write(StatCollector.translateToLocal("gui.toolstation21") + current + "/" + max);
|
||||
write(StatCollector.translateToLocal("gui.toolstation21") + current + "/" + max);
|
||||
}
|
||||
|
||||
private static void drawModifiers(NBTTagCompound tags)
|
||||
{
|
||||
private static void drawModifiers(NBTTagCompound tags) {
|
||||
int modifiers = tags.getInteger("Modifiers");
|
||||
// remaining modifiers
|
||||
if (modifiers != 0)
|
||||
write(StatCollector.translateToLocal("gui.toolstation18") + modifiers);
|
||||
if (modifiers != 0) write(StatCollector.translateToLocal("gui.toolstation18") + modifiers);
|
||||
|
||||
// Modifier-header (if we have modifiers)
|
||||
if (tags.hasKey("ModifierTip1")) {
|
||||
@@ -160,14 +139,15 @@ public final class ToolStationGuiHelper {
|
||||
String locString = "modifier.toolstation." + tipName;
|
||||
// strip out the '(X of Y)' in some for the localization strings.. sigh
|
||||
int bracket = tipName.indexOf("(");
|
||||
if(bracket > 0)
|
||||
locString = "modifier.toolstation." + tipName.substring(0, bracket);
|
||||
if (bracket > 0) locString = "modifier.toolstation." + tipName.substring(0, bracket);
|
||||
locString = EnumChatFormatting.getTextWithoutFormattingCodes(locString.replace(" ", ""));
|
||||
|
||||
if(StatCollector.canTranslate(locString)) {
|
||||
tipName = tipName.replace(EnumChatFormatting.getTextWithoutFormattingCodes(tipName), StatCollector.translateToLocal(locString));
|
||||
if (StatCollector.canTranslate(locString)) {
|
||||
tipName = tipName.replace(
|
||||
EnumChatFormatting.getTextWithoutFormattingCodes(tipName),
|
||||
StatCollector.translateToLocal(locString));
|
||||
// re-add the X/Y
|
||||
if(bracket > 0)
|
||||
if (bracket > 0)
|
||||
tipName += " " + tags.getString(tooltip + tipNum).substring(bracket);
|
||||
}
|
||||
write("- " + tipName);
|
||||
@@ -176,40 +156,41 @@ public final class ToolStationGuiHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawHarvestStats(ToolCore tool, NBTTagCompound tags)
|
||||
{
|
||||
private static void drawHarvestStats(ToolCore tool, NBTTagCompound tags) {
|
||||
float mineSpeed = AbilityHelper.calcToolSpeed(tool, tags);
|
||||
float stoneboundSpeed = AbilityHelper.calcStoneboundBonus(tool, tags);
|
||||
|
||||
write(StatCollector.translateToLocal("gui.toolstation14") + df.format(mineSpeed));
|
||||
if(stoneboundSpeed != 0)
|
||||
{
|
||||
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
|
||||
if (stoneboundSpeed != 0) {
|
||||
String bloss = stoneboundSpeed > 0
|
||||
? StatCollector.translateToLocal("gui.toolstation4")
|
||||
: StatCollector.translateToLocal("gui.toolstation5");
|
||||
write(bloss + df.format(stoneboundSpeed));
|
||||
}
|
||||
write(StatCollector.translateToLocal("gui.toolstation15") + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel")));
|
||||
write(StatCollector.translateToLocal("gui.toolstation15")
|
||||
+ HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel")));
|
||||
}
|
||||
|
||||
private static void drawDualHarvestStats(ToolCore tool, NBTTagCompound tags)
|
||||
{
|
||||
private static void drawDualHarvestStats(ToolCore tool, NBTTagCompound tags) {
|
||||
float mineSpeed = AbilityHelper.calcDualToolSpeed(tool, tags, false);
|
||||
float mineSpeed2 = AbilityHelper.calcDualToolSpeed(tool, tags, true);
|
||||
float stoneboundSpeed = AbilityHelper.calcStoneboundBonus(tool, tags);
|
||||
|
||||
write(StatCollector.translateToLocal("gui.toolstation12"));
|
||||
write("- " + df.format(mineSpeed) + ", " + df.format(mineSpeed2));
|
||||
if (stoneboundSpeed != 0)
|
||||
{
|
||||
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
|
||||
if (stoneboundSpeed != 0) {
|
||||
String bloss = stoneboundSpeed > 0
|
||||
? StatCollector.translateToLocal("gui.toolstation4")
|
||||
: StatCollector.translateToLocal("gui.toolstation5");
|
||||
write(bloss + df.format(stoneboundSpeed));
|
||||
}
|
||||
|
||||
write(StatCollector.translateToLocal("gui.toolstation13"));
|
||||
write("- " + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel")) + ", " + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel2")));
|
||||
write("- " + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel")) + ", "
|
||||
+ HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel2")));
|
||||
}
|
||||
|
||||
private static void drawWeaponStats(ToolCore tool, NBTTagCompound tags)
|
||||
{
|
||||
private static void drawWeaponStats(ToolCore tool, NBTTagCompound tags) {
|
||||
// DAMAGE
|
||||
int attack = (tags.getInteger("Attack"));
|
||||
|
||||
@@ -218,19 +199,21 @@ public final class ToolStationGuiHelper {
|
||||
attack += stoneboundDamage;
|
||||
attack *= tool.getDamageModifier();
|
||||
|
||||
if (attack < 1)
|
||||
attack = 1;
|
||||
if (attack < 1) attack = 1;
|
||||
|
||||
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
|
||||
if (attack % 2 == 0)
|
||||
write(StatCollector.translateToLocal("gui.toolstation3") + attack / 2 + heart);
|
||||
else
|
||||
write(StatCollector.translateToLocal("gui.toolstation3") + df.format(attack / 2f) + heart);
|
||||
String heart = attack == 2
|
||||
? StatCollector.translateToLocal("gui.partcrafter8")
|
||||
: StatCollector.translateToLocal("gui.partcrafter9");
|
||||
if (attack % 2 == 0) write(StatCollector.translateToLocal("gui.toolstation3") + attack / 2 + heart);
|
||||
else write(StatCollector.translateToLocal("gui.toolstation3") + df.format(attack / 2f) + heart);
|
||||
|
||||
if (stoneboundDamage != 0)
|
||||
{
|
||||
heart = stoneboundDamage == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
|
||||
String bloss = stoneboundDamage > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
|
||||
if (stoneboundDamage != 0) {
|
||||
heart = stoneboundDamage == 2
|
||||
? StatCollector.translateToLocal("gui.partcrafter8")
|
||||
: StatCollector.translateToLocal("gui.partcrafter9");
|
||||
String bloss = stoneboundDamage > 0
|
||||
? StatCollector.translateToLocal("gui.toolstation4")
|
||||
: StatCollector.translateToLocal("gui.toolstation5");
|
||||
write(bloss + df.format(stoneboundDamage / 2f) + heart);
|
||||
}
|
||||
}
|
||||
@@ -240,20 +223,18 @@ public final class ToolStationGuiHelper {
|
||||
attackf *= weapon.getDamageModifier();
|
||||
attackf *= weapon.getProjectileSpeed();
|
||||
|
||||
if (attackf < 1)
|
||||
attackf = 1;
|
||||
if (attackf < 1) attackf = 1;
|
||||
|
||||
int attack = (int)attackf;
|
||||
int attack = (int) attackf;
|
||||
|
||||
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
|
||||
if (attack % 2 == 0)
|
||||
write(StatCollector.translateToLocal("gui.toolstation23") + attack / 2 + heart);
|
||||
else
|
||||
write(StatCollector.translateToLocal("gui.toolstation23") + df.format(attack / 2f) + heart);
|
||||
String heart = attack == 2
|
||||
? StatCollector.translateToLocal("gui.partcrafter8")
|
||||
: StatCollector.translateToLocal("gui.partcrafter9");
|
||||
if (attack % 2 == 0) write(StatCollector.translateToLocal("gui.toolstation23") + attack / 2 + heart);
|
||||
else write(StatCollector.translateToLocal("gui.toolstation23") + df.format(attack / 2f) + heart);
|
||||
}
|
||||
|
||||
private static void drawProjectileWeaponStats(ProjectileWeapon weapon, NBTTagCompound tags, ItemStack stack)
|
||||
{
|
||||
private static void drawProjectileWeaponStats(ProjectileWeapon weapon, NBTTagCompound tags, ItemStack stack) {
|
||||
// drawspeed
|
||||
final int drawSpeed = weapon.getWindupTime(stack);
|
||||
final float trueDraw = drawSpeed / 20f;
|
||||
@@ -264,8 +245,7 @@ public final class ToolStationGuiHelper {
|
||||
write(StatCollector.translateToLocal("gui.toolstation7") + df.format(flightSpeed) + "x");
|
||||
}
|
||||
|
||||
private static void drawProjectileStats(NBTTagCompound tags)
|
||||
{
|
||||
private static void drawProjectileStats(NBTTagCompound tags) {
|
||||
// weight
|
||||
final float weight = tags.getFloat("Mass");
|
||||
write(StatCollector.translateToLocal("gui.toolstation8") + df.format(weight));
|
||||
@@ -279,23 +259,22 @@ public final class ToolStationGuiHelper {
|
||||
write(StatCollector.translateToLocal("gui.toolstation22") + df.format(breakChance) + "%");
|
||||
}
|
||||
|
||||
private static void drawArmorStats(ArmorCore armor, NBTTagCompound tags, ItemStack stack)
|
||||
{
|
||||
private static void drawArmorStats(ArmorCore armor, NBTTagCompound tags, ItemStack stack) {
|
||||
// Damage reduction
|
||||
double damageReduction = tags.getDouble("DamageReduction");
|
||||
if(damageReduction > 0)
|
||||
if (damageReduction > 0)
|
||||
write(StatCollector.translateToLocal("gui.toolstation19") + df.format(damageReduction));
|
||||
|
||||
// Protection
|
||||
double protection = armor.getProtection(stack);
|
||||
double maxProtection = tags.getDouble("MaxDefense");
|
||||
|
||||
write(StatCollector.translateToLocal("gui.toolstation20") + df.format(protection) + "/" + df.format(maxProtection));
|
||||
write(StatCollector.translateToLocal("gui.toolstation20") + df.format(protection) + "/"
|
||||
+ df.format(maxProtection));
|
||||
}
|
||||
|
||||
private static void drawAccessoryStats(AccessoryCore core, NBTTagCompound tags)
|
||||
{
|
||||
if(tags.hasKey("MiningSpeed")) {
|
||||
private static void drawAccessoryStats(AccessoryCore core, NBTTagCompound tags) {
|
||||
if (tags.hasKey("MiningSpeed")) {
|
||||
float mineSpeed = tags.getInteger("MiningSpeed");
|
||||
float trueSpeed = mineSpeed / (100f);
|
||||
write(StatCollector.translateToLocal("gui.toolstation16") + trueSpeed);
|
||||
@@ -306,8 +285,9 @@ public final class ToolStationGuiHelper {
|
||||
* Renders the specified text to the screen, center-aligned.
|
||||
* Copied out of GUI
|
||||
*/
|
||||
public static void drawCenteredString(FontRenderer p_73732_1_, String p_73732_2_, int p_73732_3_, int p_73732_4_, int p_73732_5_)
|
||||
{
|
||||
p_73732_1_.drawStringWithShadow(p_73732_2_, p_73732_3_ - p_73732_1_.getStringWidth(p_73732_2_) / 2, p_73732_4_, p_73732_5_);
|
||||
public static void drawCenteredString(
|
||||
FontRenderer p_73732_1_, String p_73732_2_, int p_73732_3_, int p_73732_4_, int p_73732_5_) {
|
||||
p_73732_1_.drawStringWithShadow(
|
||||
p_73732_2_, p_73732_3_ - p_73732_1_.getStringWidth(p_73732_2_) / 2, p_73732_4_, p_73732_5_);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user