Fix render allocs of the tools (#321)

Co-authored-by: UltraProdigy <187078471+UltraProdigy@users.noreply.github.com>
This commit is contained in:
boubou19andUltraProdigy authored and GitHub committed 2026-08-26 15:27:40 +00:00
1 parent d4c3e45a4b
commit 024f86db75
6 files changed
+60 -25

No files matched your search

@@ -50,6 +50,8 @@ public class FlexibleToolRenderer implements IItemRenderer {
}
private static final int toolIcons = 10;
private final IIcon[] compactIconBuffer = new IIcon[toolIcons];
private final IIcon[] rawIconBuffer = new IIcon[toolIcons];
protected void specialAnimation(ItemRenderType type, ItemStack item) {}
@@ -60,12 +62,11 @@ public class FlexibleToolRenderer implements IItemRenderer {
Entity ent = null;
if (data.length > 1) ent = (Entity) data[1];
IIcon[] parts = new IIcon[toolIcons];
int iconParts = getIcons(item, type, ent, parts);
int iconParts = getIcons(item, type, ent, compactIconBuffer);
// drawing the inventory is a simple procedure
if (type == ItemRenderType.INVENTORY) {
renderInventory(iconParts, parts, item);
renderInventory(iconParts, compactIconBuffer, item);
return;
}
@@ -82,7 +83,7 @@ public class FlexibleToolRenderer implements IItemRenderer {
float[] xSub = new float[iconParts];
float[] ySub = new float[iconParts];
for (int i = 0; i < iconParts; ++i) {
IIcon icon = parts[i];
IIcon icon = compactIconBuffer[i];
xMin[i] = icon.getMinU();
xMax[i] = icon.getMaxU();
yMin[i] = icon.getMinV();
@@ -262,23 +263,26 @@ public class FlexibleToolRenderer implements IItemRenderer {
boolean isInventory = type == ItemRenderType.INVENTORY;
ToolCore tool = (ToolCore) item.getItem();
IIcon[] tempParts = new IIcon[iconParts];
label: {
if (!isInventory && ent instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) ent;
ItemStack itemInUse = player.getItemInUse();
if (itemInUse != null) {
int useCount = player.getItemInUseCount();
for (int i = iconParts; i-- > 0;) tempParts[i] = tool.getIcon(item, i, player, itemInUse, useCount);
for (int i = iconParts; i-- > 0;) {
rawIconBuffer[i] = tool.getIcon(item, i, player, itemInUse, useCount);
}
break label;
}
}
for (int i = iconParts; i-- > 0;) tempParts[i] = tool.getIcon(item, i);
for (int i = iconParts; i-- > 0;) {
rawIconBuffer[i] = tool.getIcon(item, i);
}
}
int count = 0;
for (int i = 0; i < iconParts; ++i) {
IIcon part = tempParts[i];
IIcon part = rawIconBuffer[i];
if (part == null || part == ToolCore.blankSprite || part == ToolCore.emptyIcon) ++count;
else parts[i - count] = part;
}
@@ -408,9 +408,10 @@ public abstract class BowBase extends ToolCore {
}
protected IIcon getCorrectIcon2(Map<Integer, IIcon> icons, int id) {
if (!icons.containsKey(id)) return blankSprite;
Integer boxedId = id;
if (icons.containsKey(boxedId)) return icons.get(boxedId);
return icons.get(id);
return blankSprite;
}
/* Animations */
@@ -364,9 +364,9 @@ public class TConstructRegistry {
* @return Tool Material
*/
public static ToolMaterial getMaterial(int key) {
if (toolMaterials.containsKey(key)) {
return (toolMaterials.get(key));
}
Integer boxedKey = key;
ToolMaterial material = toolMaterials.get(boxedKey);
if (material != null || toolMaterials.containsKey(boxedKey)) return material;
// This is probably an old tool whose material has been removed from the game.
// Fall back to wood.
@@ -62,6 +62,8 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq
protected int damageVsEntity;
public static IIcon blankSprite;
public static IIcon emptyIcon;
private static final String[] effectKeys = { "Effect1", "Effect2", "Effect3", "Effect4", "Effect5", "Effect6",
"Effect7", "Effect8", "Effect9" };
public ToolCore(int baseDamage) {
super();
@@ -246,7 +248,7 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq
}
// Effects
else if (renderPass <= 10) {
String effect = "Effect" + (1 + renderPass - getPartAmount());
String effect = getEffectKey(1 + renderPass - getPartAmount());
if (tags.hasKey(effect)) return effectIcons.get(tags.getInteger(effect));
}
return blankSprite;
@@ -254,8 +256,14 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq
return emptyIcon;
}
protected static String getEffectKey(int effect) {
if (effect > 0 && effect <= effectKeys.length) return effectKeys[effect - 1];
return "Effect" + effect;
}
protected IIcon getCorrectIcon(Map<Integer, IIcon> icons, int id) {
if (icons.containsKey(id)) return icons.get(id);
Integer boxedId = id;
if (icons.containsKey(boxedId)) return icons.get(boxedId);
// default icon
return icons.get(-1);
@@ -563,11 +571,31 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq
protected int getCorrectColor(ItemStack stack, int renderPass, NBTTagCompound tags, String key,
Map<Integer, IIcon> map) {
// Avoid render-time concatenation for built-in parts while preserving addon keys.
String colorKey;
String renderKey;
if ("Handle".equals(key)) {
colorKey = "HandleColor";
renderKey = "RenderHandle";
} else if ("Head".equals(key)) {
colorKey = "HeadColor";
renderKey = "RenderHead";
} else if ("Accessory".equals(key)) {
colorKey = "AccessoryColor";
renderKey = "RenderAccessory";
} else if ("Extra".equals(key)) {
colorKey = "ExtraColor";
renderKey = "RenderExtra";
} else {
colorKey = key + "Color";
renderKey = "Render" + key;
}
// custom coloring
if (tags.hasKey(key + "Color")) return tags.getInteger(key + "Color");
if (tags.hasKey(colorKey)) return tags.getInteger(colorKey);
// custom texture?
int matId = tags.getInteger("Render" + key);
int matId = tags.getInteger(renderKey);
if (map.containsKey(matId)) return super.getColorFromItemStack(stack, renderPass);
// color default texture with material color
@@ -575,8 +603,8 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq
}
protected int getDefaultColor(int renderPass, int materialID) {
if (TConstructRegistry.getMaterial(materialID) != null)
return TConstructRegistry.getMaterial(materialID).primaryColor();
tconstruct.library.tools.ToolMaterial material = TConstructRegistry.getMaterial(materialID);
if (material != null) return material.primaryColor();
return 0xffffffff;
}
@@ -242,7 +242,7 @@ public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWe
// are we drawing an effect?
if (renderPass >= getPartAmount()) {
// is the effect animated?
String effect = "Effect" + (1 + renderPass - getPartAmount());
String effect = getEffectKey(1 + renderPass - getPartAmount());
if (tags.hasKey(effect)) {
int index = tags.getInteger(effect);
if (animationEffectIcons.get(index) != null) return getCorrectAnimationIcon(
@@ -280,15 +280,17 @@ public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWe
protected IIcon getCorrectAnimationIcon(Map<Integer, IIcon[]> icons, int id, float progress) {
// animation count, standard texture as reference
float count = icons.get(-1).length - 1;
IIcon[] defaultAnimation = icons.get(-1);
float count = defaultAnimation.length - 1;
int step = Math.round(progress * count);
step = Math.max(0, step);
if (icons.containsKey(id)) return icons.get(id)[step];
Integer boxedId = id;
if (icons.containsKey(boxedId)) return icons.get(boxedId)[step];
// default icon
return icons.get(-1)[step];
return defaultAnimation[step];
}
@Override
@@ -316,7 +318,7 @@ public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWe
}
// Effects
else if (renderPass <= 10) {
String effect = "Effect" + (1 + renderPass - getPartAmount());
String effect = getEffectKey(1 + renderPass - getPartAmount());
if (tags.hasKey(effect)) return effectIcons.get(tags.getInteger(effect));
}
return blankSprite;
@@ -308,7 +308,7 @@ public class Crossbow extends ProjectileWeapon {
// are we drawing an effect?
if (renderPass >= getPartAmount()) {
// is the effect animated?
String effect = "Effect" + (1 + renderPass - getPartAmount());
String effect = getEffectKey(1 + renderPass - getPartAmount());
if (tags.hasKey(effect)) {
int index = tags.getInteger(effect);
if (animationEffectIcons.get(index) != null)