From f16e2402a6142d550503969503afade9ab8e1c55 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Wed, 4 May 2022 18:08:54 -0500 Subject: [PATCH] ScriptEntityParticle: -Added scripted particles which can not face the player, having their angles be absolute in the world instead of relative to the camera. -set/getFacePlayer() functions added. --- .../java/noppes/npcs/NoppesUtilServer.java | 2 + .../java/noppes/npcs/client/NoppesUtil.java | 4 +- .../noppes/npcs/client/fx/EntityCustomFX.java | 37 ++++++++---- .../npcs/scripted/ScriptEntityParticle.java | 6 ++ .../npcs/scripted/entity/ScriptEntity.java | 6 ++ .../npcs/scripted/interfaces/IEntity.java | 56 ------------------- 6 files changed, 44 insertions(+), 67 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index eff4322f9..2141f5d83 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -320,6 +320,7 @@ public class NoppesUtilServer { float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart, float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart, float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart, + boolean facePlayer, int entityID ){ Server.sendToAll(EnumPacketClient.SCRIPTED_PARTICLE, @@ -331,6 +332,7 @@ public class NoppesUtilServer { rotationX1, rotationX2, rotationXRate, rotationXRateStart, rotationY1, rotationY2, rotationYRate, rotationYRateStart, rotationZ1, rotationZ2, rotationZRate, rotationZRateStart, + facePlayer, entityID ); } diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index d9aee3bf3..035478c4d 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -113,6 +113,8 @@ public class NoppesUtil { float rotationZRate = buffer.readFloat(); int rotationZRateStart = buffer.readInt(); + boolean facePlayer = buffer.readBoolean(); + int entityID = buffer.readInt(); World worldObj = Minecraft.getMinecraft().theWorld; @@ -131,7 +133,7 @@ public class NoppesUtil { rotationX1, rotationX2, rotationXRate, rotationXRateStart, rotationY1, rotationY2, rotationYRate, rotationYRateStart, rotationZ1, rotationZ2, rotationZRate, rotationZRateStart, - maxAge + maxAge, facePlayer ); for(int i = 0; i < amount; i++){ diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java index 8f8ce3861..39f8e4b68 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -44,6 +44,8 @@ public class EntityCustomFX extends EntityFX { public float rotationZRate = 0.0F; public int rotationZRateStart = 0; + public boolean facePlayer = true; + public EntityCustomFX(Entity entity, String directory, int HEXColor, double x, double y, double z, double motionX, double motionY, double motionZ, float gravity, float scale1, float scale2, float scaleRate, int scaleRateStart, @@ -51,7 +53,7 @@ public class EntityCustomFX extends EntityFX { float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart, float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart, float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart, - int age) { + int age, boolean facePlayer) { super(entity.worldObj, x, y, z, motionX, motionY, motionZ); this.scale1 = scale1; @@ -116,6 +118,8 @@ public class EntityCustomFX extends EntityFX { } location = new ResourceLocation(directory); + + this.facePlayer = facePlayer; } @Override @@ -178,16 +182,29 @@ public class EntityCustomFX extends EntityFX { double yaw = (player.rotationYaw/180)*Math.PI; double pitch = (player.rotationPitch/180)*Math.PI; - if(Math.abs(rotationX%360) >= 90 && Math.abs(rotationX%360) < 270) { - rotationX += 180*Math.signum(rotationX); - } - if(Math.abs(rotationY%360) >= 90 && Math.abs(rotationY%360) < 270) { - rotationY += 180*Math.signum(rotationY); - } + if(facePlayer) { + if (Math.abs(rotationX % 360) >= 90 && Math.abs(rotationX % 360) < 270) { + rotationX += 180 * Math.signum(rotationX); + } + if (Math.abs(rotationY % 360) >= 90 && Math.abs(rotationY % 360) < 270) { + rotationY += 180 * Math.signum(rotationY); + } - GL11.glRotated(rotationX, Math.cos(yaw)*Math.cos(pitch),0.0,Math.sin(yaw)*Math.cos(pitch)); - GL11.glRotated(rotationY, -Math.sin(yaw)*Math.sin(pitch), Math.cos(pitch), Math.cos(yaw)*Math.sin(pitch)); - GL11.glRotated(rotationZ, Math.sin(yaw)*Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw)*Math.cos(pitch)); + GL11.glRotated(rotationX, Math.cos(yaw) * Math.cos(pitch), 0.0, Math.sin(yaw) * Math.cos(pitch)); + GL11.glRotated(rotationY, -Math.sin(yaw) * Math.sin(pitch), Math.cos(pitch), Math.cos(yaw) * Math.sin(pitch)); + GL11.glRotated(rotationZ, Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw) * Math.cos(pitch)); + } else { + GL11.glRotated(player.rotationYaw % 360, 0.0, 1.0, 0.0); + GL11.glRotated(rotationY, 0.0, 1.0, 0.0); + GL11.glRotated(rotationX, Math.cos(yaw), 0.0, Math.sin(yaw)); + GL11.glRotated(rotationZ, Math.sin(yaw), 0.0, -Math.cos(yaw)); + GL11.glRotated((90 - player.rotationPitch), Math.cos(yaw), 0.0, Math.sin(yaw)); + } + /* + if(Minecraft.getMinecraft().currentScreen == null){ + System.out.println(); + } + */ tessellator.startDrawingQuads(); tessellator.setBrightness(240); diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java index 01d913d13..c81aac693 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java @@ -33,6 +33,8 @@ public class ScriptEntityParticle { public float rotationZRate = 0.0F; public int rotationZRateStart = 0; + public boolean facePlayer = true; + public ScriptEntityParticle(String directory){ this.directory = directory; } @@ -47,10 +49,14 @@ public class ScriptEntityParticle { rotationX1, rotationX2, rotationXRate, rotationXRateStart, rotationY1, rotationY2, rotationYRate, rotationYRateStart, rotationZ1, rotationZ2, rotationZRate, rotationZRateStart, + facePlayer, entityID ); } + public boolean getFacePlayer() { return facePlayer; } + public void setFacePlayer(boolean facePlayer) { this.facePlayer = facePlayer; } + public String getDirectory() { return directory; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 4989d6e1c..09bb5b4dc 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -82,6 +82,7 @@ public class ScriptEntity implements IEntity { rotationX1, rotationX2, rotationXRate, rotationXRateStart, rotationY1, rotationY2, rotationYRate, rotationYRateStart, rotationZ1, rotationZ2, rotationZRate, rotationZRateStart, + true, entityID ); } @@ -100,6 +101,7 @@ public class ScriptEntity implements IEntity { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + true, entityID ); } @@ -117,6 +119,7 @@ public class ScriptEntity implements IEntity { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + true, entityID ); } @@ -133,6 +136,7 @@ public class ScriptEntity implements IEntity { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + true, entityID ); } @@ -148,6 +152,7 @@ public class ScriptEntity implements IEntity { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + true, entityID ); } @@ -162,6 +167,7 @@ public class ScriptEntity implements IEntity { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + true, entityID ); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index a806676d9..895e6b242 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -10,62 +10,6 @@ import noppes.npcs.scripted.entity.ScriptEntity; import noppes.npcs.scripted.ScriptItemStack; public interface IEntity { - /** - * @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" - * @param HEXcolor The particle's color as a HEX integer - * @param amount The amount of particles to spawn - * @param maxAge The particle's maximum age in MC ticks - - * @param x The particle's x position - * @param y The particle's y position - * @param z The particle's z position - - * @param motionX The particle's speed in the x axis - * @param motionY The particle's speed in the y axis - * @param motionZ The particle's speed in the z axis - * @param gravity The particle's gravity - - * @param scale1 The particle's starting scale - * @param scale2 The particle's ending scale - * @param scaleRate Multiplier for the particle's scale growth rate - * @param scaleRateStart The time at which the particle begins growing/shrinking - - * @param alpha1 The particle's starting transparency - * @param alpha2 The particle's ending transparency - * @param scaleRate Multiplier for the particle's transparency growth rate - * @param alphaRateStart The time at which the particle begins appearing/fading - * - * @param rotation1 The particle's starting rotation angle with respect to the player's vision - * @param rotation2 The particle's final rotation angle with respect to the player's vision - * @param rotationRate The rate at which the particle rotates with respect to the player's vision - * @param rotationRateStart The time at which the particle begins rotating - - * @param rotationX1 The particle's starting rotation angle with respect to the X-axis - * @param rotationX2 The particle's final rotation angle with respect to the X-axis - * @param rotationXRate The rate at which the particle rotates with respect to the X-axis - * @param rotationXRateStart The time at which the particle begins rotating over the X-axis - - * @param rotationY1 The particle's starting rotation angle with respect to the Y-axis - * @param rotationY2 The particle's final rotation angle with respect to the Y-axis - * @param rotationYRate The rate at which the particle rotates with respect to the Y-axis - * @param rotationYRateStart The time at which the particle begins rotating over the Y-axis - - * @param rotationZ1 The particle's starting rotation angle with respect to the Z-axis - * @param rotationZ2 The particle's final rotation angle with respect to the Z-axis - * @param rotationZRate The rate at which the particle rotates with respect to the Z-axis - * @param rotationZRateStart The time at which the particle begins rotating over the Z-axis - */ - void spawnParticle(String directory, int HEXcolor, int amount, int maxAge, - double x, double y, double z, - double motionX, double motionY, double motionZ, float gravity, - float scale1, float scale2, float scaleRate, int scaleRateStart, - float alpha1, float alpha2, float alphaRate, int alphaRateStart, - float rotation1, float rotation2, float rotationRate, int rotationRateStart, - float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart, - float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart, - float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart - ); - public double getYOffset(); /**