From ea0b8ec5a4139b5b442ea5c16dbbd5a9fd23c5c8 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 22:06:21 -0500 Subject: [PATCH] Tint Code Refactoring and some cleanup wo the lang file --- .../noppes/npcs/client/gui/SubGuiNpcTint.java | 44 +++++----- .../client/gui/mainmenu/GuiNpcDisplay.java | 7 +- .../npcs/client/model/part/ModelLegs.java | 2 +- .../npcs/client/model/part/ModelTail.java | 2 +- .../client/model/util/ModelPartInterface.java | 2 +- .../client/renderer/RenderNPCInterface.java | 16 ++-- .../npcs/controllers/data/CustomTintData.java | 88 +++++++++---------- .../assets/customnpcs/lang/en_US.lang | 8 +- 8 files changed, 85 insertions(+), 84 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java index f39e37678..13064c47b 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java @@ -1,10 +1,8 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; -import noppes.npcs.DataStats; import noppes.npcs.client.gui.util.*; import noppes.npcs.controllers.data.CustomTintData; -import noppes.npcs.controllers.data.DialogImage; public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, ITextfieldListener { private CustomTintData tintData; @@ -22,35 +20,35 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I public void initGui() { super.initGui(); int y = 30; - addLabel(new GuiNpcLabel(0, "tint.enablecustom", guiLeft + 5, guiTop + y + 5)); - addButton(new GuiNpcButtonYesNo(0, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableCustomTint())); + addLabel(new GuiNpcLabel(0, "tint.enable", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(0, guiLeft + 122, guiTop + y, 56, 20, tintData.isTintEnabled())); y+=22; - if (tintData.isEnableCustomTint()) { - addLabel(new GuiNpcLabel(1, "tint.enablenpc", guiLeft + 5, guiTop + y + 5)); - addButton(new GuiNpcButtonYesNo(1, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableNpcTint())); + if (tintData.isTintEnabled()) { + addLabel(new GuiNpcLabel(1, "tint.enablegeneral", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(1, guiLeft + 122, guiTop + y, 56, 20, tintData.isGeneralTintEnabled())); y+=22; - if(tintData.isEnableNpcTint()) { - String color = Integer.toHexString(tintData.getColorNpcTint()); + if(tintData.isGeneralTintEnabled()) { + String color = Integer.toHexString(tintData.getGeneralTint()); while (color.length() < 6) color = 0 + color; addLabel(new GuiNpcLabel(2, "tint.tint", guiLeft + 4, guiTop + y + 5)); addButton(new GuiNpcButton(2, guiLeft + 122, guiTop + y, 60, 20, color)); - getButton(2).setTextColor(tintData.getColorNpcTint()); + getButton(2).setTextColor(tintData.getGeneralTint()); y+=22; addLabel(new GuiNpcLabel(3,"tint.alpha", guiLeft + 5, guiTop + y + 5)); - addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + y, 60, 20, tintData.getColorNpcTintAlpha() + "")); + addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + y, 60, 20, tintData.getGeneralAlpha() + "")); getTextField(3).integersOnly = true; getTextField(3).setMinMaxDefault(1, 100, 40); y+=22; } addLabel(new GuiNpcLabel(4, "tint.enablehurt", guiLeft + 5, guiTop + y + 5)); - addButton(new GuiNpcButtonYesNo(4, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableHurtTint())); + addButton(new GuiNpcButtonYesNo(4, guiLeft + 122, guiTop + y, 56, 20, tintData.isHurtTintEnabled())); y+=22; - if (tintData.isEnableHurtTint()) { - String color2 = Integer.toHexString(tintData.getColorHurtTint()); + if (tintData.isHurtTintEnabled()) { + String color2 = Integer.toHexString(tintData.getHurtTint()); while (color2.length() < 6) color2 = 0 + color2; addLabel(new GuiNpcLabel(5, "tint.hurt", guiLeft + 4, guiTop + y + 5)); addButton(new GuiNpcButton(5, guiLeft + 122, guiTop + y, 60, 20, color2)); - getButton(5).setTextColor(tintData.getColorHurtTint()); + getButton(5).setTextColor(tintData.getHurtTint()); } } addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190, 98, 20, "gui.done")); @@ -61,23 +59,23 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I int id = guibutton.id; GuiNpcButton button = (GuiNpcButton) guibutton; if (id == 0) { - tintData.setEnableCustomTint(((GuiNpcButtonYesNo) button).getBoolean()); + tintData.setTintEnabled(((GuiNpcButtonYesNo) button).getBoolean()); initGui(); } if (id == 1) { - tintData.setEnableNpcTint(((GuiNpcButtonYesNo) button).getBoolean()); + tintData.setGeneralTintEnabled(((GuiNpcButtonYesNo) button).getBoolean()); initGui(); } if (id == 4) { - tintData.setEnableHurtTint(((GuiNpcButtonYesNo) button).getBoolean()); + tintData.setHurtTintEnabled(((GuiNpcButtonYesNo) button).getBoolean()); initGui(); } if (button.id == 2) { - setSubGui(new SubGuiColorSelector(tintData.getColorNpcTint())); + setSubGui(new SubGuiColorSelector(tintData.getGeneralTint())); lastColorClicked = 0; } if (button.id == 5) { - setSubGui(new SubGuiColorSelector(tintData.getColorHurtTint())); + setSubGui(new SubGuiColorSelector(tintData.getHurtTint())); lastColorClicked = 1; } if (id == 66) { @@ -88,9 +86,9 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I @Override public void subGuiClosed(SubGuiInterface subgui) { if (lastColorClicked == 0) { - tintData.setColorNpcTint(((SubGuiColorSelector) subgui).color); + tintData.setGeneralTint(((SubGuiColorSelector) subgui).color); } else if (lastColorClicked == 1) { - tintData.setColorHurtTint(((SubGuiColorSelector) subgui).color); + tintData.setHurtTint(((SubGuiColorSelector) subgui).color); } initGui(); save(); @@ -99,7 +97,7 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I @Override public void unFocused(GuiNpcTextField textfield) { if(textfield.id==3){ - tintData.setColorNpcTintAlpha(textfield.getInteger()); + tintData.setGeneralAlpha(textfield.getInteger()); } } } diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java index 13a1a68e5..2b266184f 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -43,7 +43,6 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene y+=23; addLabel(new GuiNpcLabel(11,"gui.title", guiLeft + 5, y + 5)); addTextField(new GuiNpcTextField(11,this, fontRendererObj, guiLeft + 50, y, 206, 20, display.title)); - this.addButton(new GuiNpcButton(13, guiLeft + 259, y , 80, 20, "Tint settings")); y+=23; addLabel(new GuiNpcLabel(1,"display.model", guiLeft + 5, y + 5)); @@ -82,16 +81,18 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene addLabel(new GuiNpcLabel(5,"display.livingAnimation", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(5, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no"}, display.disableLivingAnimation?1:0)); - addLabel(new GuiNpcLabel(6,"Collides With Entities", guiLeft + 185, y + 5)); + addLabel(new GuiNpcLabel(6,"display.collides", guiLeft + 185, y + 5)); this.addButton(new GuiNpcButton(6, guiLeft + 300, y, 100, 20, new String[]{"gui.yes","gui.no","Only CNPCs","Only Players","CNPCs & Players"}, display.collidesWith)); y+=23; addLabel(new GuiNpcLabel(7,"display.visible", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(7, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no","gui.partly"}, display.visible)); + this.addButton(new GuiNpcButton(13, guiLeft + 185, y , 100, 20, "display.tintsettings")); + y+=23; addLabel(new GuiNpcLabel(10,"display.bossbar", guiLeft + 5, y + 5)); - this.addButton(new GuiNpcButton(10, guiLeft + 120, y, 110, 20, new String[]{"display.hide","display.show","display.showAttacking"}, display.showBossBar)); + this.addButton(new GuiNpcButton(10, guiLeft + 60, y, 110, 20, new String[]{"display.hide","display.show","display.showAttacking"}, display.showBossBar)); GeckoAddonClient.Instance.geckoNpcDisplayInitGui(this); } diff --git a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java index cc959b665..9807c9e11 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java @@ -389,7 +389,7 @@ public class ModelLegs extends ModelScaleRenderer{ } CustomTintData customTintData = entity.display.customTintData; boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && - !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); + !(customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled()); if(bo){ float red = (entity.modelData.legParts.color >> 16 & 255) / 255f; float green = (entity.modelData.legParts.color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelTail.java b/src/main/java/noppes/npcs/client/model/part/ModelTail.java index 7541a7168..ede9ddc2e 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelTail.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelTail.java @@ -153,7 +153,7 @@ public class ModelTail extends ModelScaleRenderer { } CustomTintData customTintData = entity.display.customTintData; boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && - !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); + !(customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled()); if(bo){ float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java index 25d9d70e6..8c02f6af3 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java @@ -62,7 +62,7 @@ public abstract class ModelPartInterface extends ModelRenderer { } CustomTintData customTintData = entity.display.customTintData; boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && - !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); + !(customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled()); if(bo){ float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 01eeffc30..a2d32d85a 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -373,7 +373,7 @@ public class RenderNPCInterface extends RenderLiving{ GL11.glDisable(GL11.GL_TEXTURE_2D); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); CustomTintData customTintData = p_76986_1_.display.customTintData; - if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0 || (customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint())) + if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0 || (customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled())) { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_ALPHA_TEST); @@ -381,13 +381,13 @@ public class RenderNPCInterface extends RenderLiving{ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glDepthFunc(GL11.GL_EQUAL); - if ((p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) && (!customTintData.isEnableCustomTint() || customTintData.isEnableHurtTint())) + if ((p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) && (!customTintData.isTintEnabled() || customTintData.isHurtTintEnabled())) { float r, g, b; - if(customTintData.isEnableCustomTint()) { - r = (float) (customTintData.getColorHurtTint() >> 16 & 255) / 255.0F * f14; - g = (float) (customTintData.getColorHurtTint() >> 8 & 255) / 255.0F * f14; - b = (float) (customTintData.getColorHurtTint() & 255) / 255.0F * f14; + if(customTintData.isTintEnabled()) { + r = (float) (customTintData.getHurtTint() >> 16 & 255) / 255.0F * f14; + g = (float) (customTintData.getHurtTint() >> 8 & 255) / 255.0F * f14; + b = (float) (customTintData.getHurtTint() & 255) / 255.0F * f14; }else{ r=f14; g=0; @@ -469,8 +469,8 @@ public class RenderNPCInterface extends RenderLiving{ { EntityNPCInterface npc = (EntityNPCInterface) p_77030_1_; CustomTintData tintData = npc.display.customTintData; - int alpha = (int) (0xff*((double)tintData.getColorNpcTintAlpha()/100d)) << 24; - return (tintData.isEnableCustomTint() && tintData.isEnableNpcTint())?tintData.getColorNpcTint()+alpha:0; + int alpha = (int) (0xff*((double)tintData.getGeneralAlpha()/100d)) << 24; + return (tintData.isTintEnabled() && tintData.isGeneralTintEnabled())?tintData.getGeneralTint()+alpha:0; } protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7) { diff --git a/src/main/java/noppes/npcs/controllers/data/CustomTintData.java b/src/main/java/noppes/npcs/controllers/data/CustomTintData.java index c19c425ac..f1013d55e 100644 --- a/src/main/java/noppes/npcs/controllers/data/CustomTintData.java +++ b/src/main/java/noppes/npcs/controllers/data/CustomTintData.java @@ -3,81 +3,81 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; public class CustomTintData { - private boolean enableCustomTint = false; - private boolean enableHurtTint = true; - private boolean enableNpcTint = false; - private int colorHurtTint = 0xff0000; - private int colorNpcTint = 0x000000; - private int colorNpcTintAlpha = 40; + private boolean tintEnabled = false; + private boolean hurtTintEnabled = true; + private boolean generalTintEnabled = false; + private int hurtTint = 0xff0000; + private int generalTint = 0x000000; + private int generalAlpha = 40; public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { - nbttagcompound.setBoolean("EnableCustomTint", enableCustomTint); - if(enableCustomTint) { - nbttagcompound.setBoolean("EnableHurtTint", enableHurtTint); - nbttagcompound.setBoolean("EnableNpcTint", enableNpcTint); - nbttagcompound.setInteger("ColorHurtTint", colorHurtTint); - nbttagcompound.setInteger("ColorNpcTint", colorNpcTint); - nbttagcompound.setInteger("ColorNpcTintAlpha", colorNpcTintAlpha); + nbttagcompound.setBoolean("TintEnabled", tintEnabled); + if(tintEnabled) { + nbttagcompound.setBoolean("HurtTintEnabled", hurtTintEnabled); + nbttagcompound.setBoolean("GeneralTintEnabled", generalTintEnabled); + nbttagcompound.setInteger("HurtTint", hurtTint); + nbttagcompound.setInteger("GeneralTint", generalTint); + nbttagcompound.setInteger("GeneralAlpha", generalAlpha); } return nbttagcompound; } public void readFromNBT(NBTTagCompound nbttagcompound) { - enableCustomTint = nbttagcompound.getBoolean("EnableCustomTint"); - if(enableCustomTint) { - enableHurtTint = nbttagcompound.getBoolean("EnableHurtTint"); - enableNpcTint = nbttagcompound.getBoolean("EnableNpcTint"); - colorHurtTint = nbttagcompound.getInteger("ColorHurtTint"); - colorNpcTint = nbttagcompound.getInteger("ColorNpcTint"); - colorNpcTintAlpha = nbttagcompound.getInteger("ColorNpcTintAlpha"); + tintEnabled = nbttagcompound.getBoolean("TintEnabled"); + if(tintEnabled) { + hurtTintEnabled = nbttagcompound.getBoolean("HurtTintEnabled"); + generalTintEnabled = nbttagcompound.getBoolean("GeneralTintEnabled"); + hurtTint = nbttagcompound.getInteger("HurtTint"); + generalTint = nbttagcompound.getInteger("GeneralTint"); + generalAlpha = nbttagcompound.getInteger("GeneralAlpha"); } } - public boolean isEnableHurtTint() { - return enableHurtTint; + public boolean isHurtTintEnabled() { + return hurtTintEnabled; } - public void setEnableHurtTint(boolean enableHurtTint) { - this.enableHurtTint = enableHurtTint; + public void setHurtTintEnabled(boolean hurtTintEnabled) { + this.hurtTintEnabled = hurtTintEnabled; } - public int getColorHurtTint() { - return colorHurtTint; + public int getHurtTint() { + return hurtTint; } - public void setColorHurtTint(int colorHurtTint) { - this.colorHurtTint = colorHurtTint; + public void setHurtTint(int colorHurtTint) { + this.hurtTint = colorHurtTint; } - public int getColorNpcTint() { - return colorNpcTint; + public int getGeneralTint() { + return generalTint; } - public void setColorNpcTint(int colorNpcTint) { - this.colorNpcTint = colorNpcTint; + public void setGeneralTint(int generalTint) { + this.generalTint = generalTint; } - public boolean isEnableCustomTint() { - return enableCustomTint; + public boolean isTintEnabled() { + return tintEnabled; } - public void setEnableCustomTint(boolean enableCustomTint) { - this.enableCustomTint = enableCustomTint; + public void setTintEnabled(boolean tintEnabled) { + this.tintEnabled = tintEnabled; } - public boolean isEnableNpcTint() { - return enableNpcTint; + public boolean isGeneralTintEnabled() { + return generalTintEnabled; } - public void setEnableNpcTint(boolean enableNpcTint) { - this.enableNpcTint = enableNpcTint; + public void setGeneralTintEnabled(boolean generalTintEnabled) { + this.generalTintEnabled = generalTintEnabled; } - public int getColorNpcTintAlpha() { - return colorNpcTintAlpha; + public int getGeneralAlpha() { + return generalAlpha; } - public void setColorNpcTintAlpha(int colorNpcTintAlpha) { - this.colorNpcTintAlpha = colorNpcTintAlpha; + public void setGeneralAlpha(int generalAlpha) { + this.generalAlpha = generalAlpha; } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4ff9d4b68..2d4b3f8e7 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -223,6 +223,7 @@ display.overlay=Overlay display.player=Player display.selectTexture=Select Texture display.livingAnimation=Has a living animation +display.collides=Collides With Entities display.visible=Visible display.bossbar=BossBar display.squareTexture=Square Texture @@ -244,6 +245,7 @@ display.top=Top display.fixed=Fixed display.glow=Glow display.solid=Solid +display.tintsettings=Tint Settings inv.minExp=Min Exp inv.maxExp=Max Exp @@ -1177,9 +1179,9 @@ mark.skull=Skull mark.cross=Cross mark.star=Star -tint.enablecustom=Enable Custom Tint -tint.enablenpc=Enable NPC Tint +tint.enable=Enable Custom Tint +tint.enablegeneral=Enable General Tint tint.enablehurt=Enable Hurt Tint -tint.tint=Tint +tint.tint=General Tint tint.alpha=Alpha tint.hurt=Hurt Tint