From 0788b2750fe0b98e667b7be18d0e0667ae841ab1 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 20 Jan 2022 00:15:21 -0600 Subject: [PATCH 1/4] Quick fix for custom GUI textured rectangles, now with working x and y offsets. --- .../noppes/npcs/client/fx/EntityCustomFX.java | 72 +++++++++++++++++-- .../components/CustomGuiTexturedRect.java | 2 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java index 318cf8152..3ba3a02d6 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -74,6 +74,15 @@ public class EntityCustomFX extends EntityFX { location = new ResourceLocation(directory); } + /* + par2 = partial tick time + par3 = ActiveRenderInfo.rotationX; + par4 = ActiveRenderInfo.rotationZ; + par5 = ActiveRenderInfo.rotationYZ; + par6 = ActiveRenderInfo.rotationXY; + par7 = ActiveRenderInfo.rotationXZ; + */ + @Override public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) { @@ -121,12 +130,16 @@ public class EntityCustomFX extends EntityFX { Minecraft minecraft = Minecraft.getMinecraft(); EntityPlayer player = minecraft.thePlayer; - double yaw = (player.rotationYaw/180)*Math.PI; - double pitch = (player.rotationPitch/180)*Math.PI; - double angle = Minecraft.getMinecraft().theWorld.getWorldTime()%360; double angleRad = (angle/180)*Math.PI; + double diffX = player.posX - this.startX; + double diffY = player.posY - player.getYOffset() - this.startY; + double diffZ = player.posZ - this.startZ; + + double yaw = (player.rotationYaw/180)*Math.PI; + double pitch = (player.rotationPitch/180)*Math.PI; + double angleX = Math.sin(yaw)*Math.cos(pitch); if(Math.abs(angleX) < 0.0001){ angleX = 0.0D; @@ -140,13 +153,62 @@ public class EntityCustomFX extends EntityFX { angleZ = 0.0D; } - double translateX = 0; + double angleXtranslateX = 0.0D; + double angleXtranslateY = 0.0D;//(-diffY + Math.cos(angleRad)*diffY) + (-Math.sin(angleRad)*diffZ); + double angleXtranslateZ = 0.0D;//(Math.sin(angleRad)*diffY) + (-diffZ + Math.cos(angleRad)*diffZ); + + double angleYtranslateX = 0.0D;//(-diffX + Math.cos(angleRad)*diffX) + (Math.sin(angleRad)*diffZ); + double angleYtranslateY = 0.0D; + double angleYtranslateZ = 0.0D;//(-Math.sin(angleRad)*diffX) + (-diffZ + Math.cos(angleRad)*diffZ); + + double angleZtranslateX = 0.0D;//(-diffX + Math.cos(angleRad)*diffX) + (-Math.sin(angleRad)*diffY); + double angleZtranslateY = 0.0D;//(Math.sin(angleRad)*diffX) + (-diffY + Math.cos(angleRad)*diffY); + double angleZtranslateZ = 0.0D; + + double translateX = angleXtranslateX + angleYtranslateX + angleZtranslateX; + double translateY = angleXtranslateY + angleYtranslateY + angleZtranslateY; + double translateZ = angleXtranslateZ + angleYtranslateZ + angleZtranslateZ; + + //distance in the X & Z plane + double distXZ = Math.sqrt(Math.pow(diffX,2) + Math.pow(diffZ,2)); + //distance in the X & Y plane + double distXY = Math.sqrt(Math.pow(diffX,2) + Math.pow(diffY,2)); + //distance in the Y & Z plane + double distYZ = Math.sqrt(Math.pow(diffY,2) + Math.pow(diffZ,2)); + + double signDiffX = Math.signum(diffX); + double signDiffY = Math.signum(diffY); + double signDiffZ = Math.signum(diffZ); + + double angleXtoNorm = Math.sin(Math.acos(diffX/distXZ)); + double angleZtoNorm = Math.sin(Math.acos(diffZ/distXZ)); + + double angleDiffX = (Math.abs(Math.cos(yaw))-angleXtoNorm); + double angleDiffZ = (Math.abs(Math.cos(yaw))-angleZtoNorm); + + double translateX = -Math.abs(angleDiffX*angleZ*distXZ)*signDiffX; double translateY = 0; - double translateZ = 0; + double translateZ = -Math.abs(angleDiffX*angleX*distXZ)*signDiffZ + Math.cos(angleRad)*Math.abs(angleDiffX*angleX*distXZ)*signDiffZ; + + if(minecraft.currentScreen == null) { + System.out.println(); + //System.out.printf("diffX: %f, diffY: %f, diffZ: %f\n", diffX, diffY, diffZ); + //System.out.printf("angleX: %f, angleY: %f, angleZ: %f\n", angleX, angleY, angleZ); + //System.out.printf("angleXtoNorm: %f, angleZtoNorm: %f\n", angleXtoNorm, angleZtoNorm); + System.out.printf("Math.sin(yaw): %f\n", Math.sin(yaw)); + System.out.printf("Math.cos(yaw): %f\n", Math.cos(yaw)); + //System.out.printf("Math.sin(pitch): %f\n", Math.sin(pitch)); + //System.out.printf("Math.cos(pitch): %f\n", Math.cos(pitch)); + System.out.printf("angleDiffX: %f\n", angleDiffX); + System.out.printf("angleDiffZ: %f\n", angleDiffZ); + System.out.printf("translateX: %f\n", Math.cos(angleRad)*Math.abs(angleDiffX*angleZ*distXZ)*signDiffX); + System.out.printf("translateZ: %f\n", Math.cos(angleRad)*Math.abs(angleDiffX*angleX*distXZ)*signDiffZ); + } */ GL11.glPushMatrix(); GL11.glColor4f(1, 1, 1, 1.0F); + //GL11.glTranslated(translateX,translateY,translateZ); //GL11.glRotated(angle, angleX, angleY, angleZ); diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index 229e8e311..f81de23ce 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -56,7 +56,7 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { boolean hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; mc.getTextureManager().bindTexture(this.texture); - this.drawTexturedModalRect(this.x + this.textureX, this.y + this.textureY, 0, 0, (int)(this.width*this.scale), (int)(this.height*this.scale)); + this.drawTexturedModalRect(this.x, this.y, this.textureX, this.textureY, (int)(this.width*this.scale), (int)(this.height*this.scale)); if (hovered && this.hoverText != null && this.hoverText.length > 0) { this.parent.hoverText = this.hoverText; From 83756381e4b00ae81db0b2befd9cc3f0b63243d0 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 20 Jan 2022 20:27:26 -0600 Subject: [PATCH 2/4] Added toggleable shadows and scaling to custom GUI labels. --- .../gui/custom/components/CustomGuiLabel.java | 19 ++++++++++++++----- .../npcs/scripted/gui/ScriptGuiLabel.java | 12 ++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index 32a1321fd..31eb61e01 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -28,6 +28,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { int id; int border = 2; boolean labelBgEnabled = true; + boolean labelShadowEnabled = false; protected int field_146167_a; protected int field_146161_f; @@ -45,13 +46,14 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { private int field_146163_s; private static final String __OBFID = "CL_00000671"; - public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height){ + public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ this.id = id; this.fullLabel = fullLabel; this.x = x; this.y = y; this.width = width; this.height = height; + this.labelShadowEnabled = shadow; } public void setParent(GuiCustom parent) { @@ -75,7 +77,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { } public static CustomGuiLabel fromComponent(ScriptGuiLabel component) { - CustomGuiLabel lbl = new CustomGuiLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight()); + CustomGuiLabel lbl = new CustomGuiLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight(), component.hasShadow()); lbl.scale = 1.0F; lbl.color = component.getColor(); lbl.field_146172_j = true; @@ -83,6 +85,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { if (component.hasHoverText()) { lbl.hoverText = component.getHoverText(); } + lbl.labelShadowEnabled = component.hasShadow(); return lbl; } @@ -90,6 +93,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { public ICustomGuiComponent toComponent() { ScriptGuiLabel component = new ScriptGuiLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); component.setHoverText(this.hoverText); + component.enableShadow(this.labelShadowEnabled); return component; } @@ -100,8 +104,13 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + this.drawLabelBackground(); - this.drawString(Minecraft.getMinecraft().fontRenderer, fullLabel, this.x, this.y, this.color); + GL11.glPushMatrix(); + GL11.glTranslatef(this.x,this.y,0.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + GL11.glPopMatrix(); } } @@ -109,8 +118,8 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { { if (this.labelBgEnabled) { - int k = this.width + this.border * 2; - int l = this.height + this.border * 2; + int k = (int)(this.width*this.scale) + this.border * 2; + int l = (int)(this.height*this.scale) + this.border * 2; int i1 = this.x - this.border; int j1 = this.y - this.border; drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java index fb2d22609..6467f60f8 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java @@ -9,6 +9,7 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { int height; int color; float scale; + boolean shadow; public ScriptGuiLabel() { this.color = 16777215; @@ -22,6 +23,7 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { this.setText(label); this.setPos(x, y); this.setSize(width, height); + this.enableShadow(false); } public ScriptGuiLabel(int id, String label, int x, int y, int width, int height, int color) { @@ -70,6 +72,14 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { return this; } + public boolean hasShadow(){ + return this.shadow; + } + + public void enableShadow(boolean shadow){ + this.shadow = shadow; + } + public int getType() { return 1; } @@ -80,6 +90,7 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { nbt.setIntArray("size", new int[]{this.width, this.height}); nbt.setInteger("color", this.color); nbt.setFloat("scale", this.scale); + nbt.setBoolean("shadow",this.shadow); return nbt; } @@ -89,6 +100,7 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); this.setColor(nbt.getInteger("color")); this.setScale(nbt.getFloat("scale")); + this.enableShadow(this.shadow); return this; } } From 06c730b166caf0545c4f7894aed44e0284caea01 Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 21 Jan 2022 01:15:21 -0600 Subject: [PATCH 3/4] Fixed scale & color issues for custom GUI textured rectangles. --- .../client/gui/custom/components/CustomGuiTexturedRect.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index f81de23ce..992e024ca 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -56,7 +56,11 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { boolean hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; mc.getTextureManager().bindTexture(this.texture); - this.drawTexturedModalRect(this.x, this.y, this.textureX, this.textureY, (int)(this.width*this.scale), (int)(this.height*this.scale)); + GL11.glPushMatrix(); + GL11.glColor4f(1.0F,1.0F,1.0F,1.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height)); + GL11.glPopMatrix(); if (hovered && this.hoverText != null && this.hoverText.length > 0) { this.parent.hoverText = this.hoverText; From 092b3ce0c12a60ff7cd819f97004fb12b6e73936 Mon Sep 17 00:00:00 2001 From: luisc Date: Sat, 22 Jan 2022 22:50:01 -0600 Subject: [PATCH 4/4] Fixed overloaded hurt(damage,entity) function not working when an entity is to be hurt by a player --- src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 4 ++-- .../java/noppes/npcs/scripted/entity/ScriptLivingBase.java | 5 ++++- .../java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 4c7aed224..2d029b97c 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -472,10 +472,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public boolean attackEntityFrom(DamageSource damagesource, float i) { - if (this.worldObj.isRemote || CustomNpcs.FreezeNPCs || damagesource.damageType.equals("inWall")){ + if (this.worldObj.isRemote || CustomNpcs.FreezeNPCs || (damagesource.damageType != null && damagesource.damageType.equals("inWall"))){ return false; } - if(damagesource.damageType.equals("outOfWorld") && isKilled()){ + if(damagesource.damageType != null && damagesource.damageType.equals("outOfWorld") && isKilled()){ reset(); } i = stats.resistances.applyResistance(damagesource, i); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 843a402fd..e6ef07d7d 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -41,7 +41,10 @@ public class ScriptLivingBase extends ScriptEntity