From ba392395a4d814d69ba40cc8cd54da7bf6ee7f5e Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 1 Jun 2023 18:22:48 -0400 Subject: [PATCH 1/4] Fix DBC Render Error --- .../noppes/npcs/mixin/MixinModelRenderer.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 1d731a98c..6c462c638 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -112,12 +112,18 @@ public abstract class MixinModelRenderer { } if (ClientEventHandler.renderingPlayer != null && Client.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) { animData = Client.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID()); - EnumAnimationPart mainPartType = this.getPlayerPartType((ModelRenderer) (Object) this); - EnumAnimationPart pivotEqualPart = null; - if (mainPartType == null) { - pivotEqualPart = this.pivotEqualPart((ModelRenderer) (Object) this); + + EnumAnimationPart mainPartType = null; + try{ + EnumAnimationPart pivotEqualPart = null; + mainPartType = this.getPlayerPartType((ModelRenderer) (Object) this); + if (mainPartType == null) { + pivotEqualPart = this.pivotEqualPart((ModelRenderer) (Object) this); + } + partType = mainPartType != null ? mainPartType : pivotEqualPart; } - partType = mainPartType != null ? mainPartType : pivotEqualPart; + catch (Exception ignored){} + if (partType != null && animData != null) { if (!ClientEventHandler.originalValues.containsKey((ModelRenderer) (Object) this)) { FramePart part = new FramePart(); From 598e8ede7ca78f2db31d556daead15017fb4bba5 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 1 Jun 2023 17:29:35 -0500 Subject: [PATCH 2/4] CustomFX: -Now uses image caching, commit copied from dev without using the new ClientCacheHandler class. --- .../java/noppes/npcs/client/fx/CustomFX.java | 184 +++++++----------- .../client/renderer/customitem/ImageData.java | 4 + 2 files changed, 76 insertions(+), 112 deletions(-) diff --git a/src/main/java/noppes/npcs/client/fx/CustomFX.java b/src/main/java/noppes/npcs/client/fx/CustomFX.java index 86d207fc4..cc425d4cb 100644 --- a/src/main/java/noppes/npcs/client/fx/CustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/CustomFX.java @@ -5,27 +5,21 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.client.resources.IResource; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import noppes.npcs.client.Client; import noppes.npcs.client.ClientProxy; -import noppes.npcs.client.ImageDownloadAlt; -import noppes.npcs.client.renderer.ImageBufferDownloadAlt; +import noppes.npcs.client.renderer.customitem.ImageData; import noppes.npcs.scripted.ScriptParticle; import org.lwjgl.opengl.GL11; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; - public class CustomFX extends EntityFX { private final Entity entity; - private final ResourceLocation location; + private final String directory; + private final ImageData imageData; private static final ResourceLocation resource = new ResourceLocation("textures/particle/particles.png"); private float startX = 0, startY = 0, startZ = 0; @@ -65,7 +59,6 @@ public class CustomFX extends EntityFX { public boolean facePlayer = true; public boolean glows = true; - private int totalWidth, totalHeight; public int width, height; public int offsetX, offsetY; @@ -81,16 +74,13 @@ public class CustomFX extends EntityFX { public float HEXColorRate = 0.0F; public int HEXColorStart = 0; - private ImageDownloadAlt imageDownloadAlt = null; - private boolean isUrl = false; - private boolean gotWidthHeight = false; - double renderPosX, renderPosY, renderPosZ; public CustomFX(World worldObj, Entity entity, String directory, double x, double y, double z, double motionX, double motionY, double motionZ) { super(worldObj, x, y, z, motionX, motionY, motionZ); this.entity = entity; - this.location = new ResourceLocation(directory); + this.directory = directory; + this.imageData = Client.getImageData(this.directory); } public static CustomFX fromScriptedParticle(ScriptParticle particle, World worldObj, Entity entity) { @@ -171,19 +161,6 @@ public class CustomFX extends EntityFX { if(customFX.animEnd < customFX.animStart) customFX.animEnd = customFX.animStart + customFX.particleMaxAge; - if(particle.directory.startsWith("https://")){ - customFX.isUrl = true; - TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); - customFX.imageDownloadAlt = new ImageDownloadAlt(null, particle.directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true,false)); - texturemanager.loadTexture(customFX.location, customFX.imageDownloadAlt); - } else { - try { - customFX.getWidthHeight(); - } catch (IOException e) { - e.printStackTrace(); - } - } - customFX.facePlayer = particle.facePlayer; customFX.glows = particle.glows; @@ -192,6 +169,10 @@ public class CustomFX extends EntityFX { @Override public void onUpdate() { + if (!this.imageLoaded()) { + return; + } + ++this.timeSinceStart; if (this.timeSinceStart == this.particleMaxAge) @@ -206,12 +187,12 @@ public class CustomFX extends EntityFX { this.motionY -= 0.04D * (double)this.particleGravity; this.moveEntity(this.motionX, this.motionY, this.motionZ); - if(animRate > 0 && timeSinceStart%animRate == 0 && timeSinceStart > 0 && gotWidthHeight && timeSinceStart >= animStart && timeSinceStart <= animEnd && (animLoop || animPosY <= totalHeight)){ + if (animRate > 0 && timeSinceStart % animRate == 0 && timeSinceStart > 0 && timeSinceStart >= animStart && timeSinceStart <= animEnd && (animLoop || animPosY <= imageData.getTotalHeight())) { animPosX += width; - if (animPosX + width > totalWidth) { + if (animPosX + width > imageData.getTotalWidth()) { animPosX = offsetX; animPosY += height; - if (animPosY > totalHeight && animLoop) { + if (animPosY > imageData.getTotalHeight() && animLoop) { animPosY = offsetY; } } @@ -228,11 +209,14 @@ public class CustomFX extends EntityFX { @Override public void renderParticle(Tessellator tessellator, float partialTick, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch) { - tessellator.draw(); - ClientProxy.bindTexture(location); + if (!this.imageLoaded()) { + return; + } - if(imageDownloadAlt != null && isUrl && !gotWidthHeight){ - getURLWidthHeight(); + tessellator.draw(); + imageData.bindTexture(); + if (imageData.invalid()) { + setDead(); } if(entity != null){ @@ -286,6 +270,9 @@ public class CustomFX extends EntityFX { } public void renderParticleSide(boolean front, Tessellator tessellator, float partialTick){ + int totalWidth = imageData.getTotalWidth(); + int totalHeight = imageData.getTotalHeight(); + float u1 = (float)offsetX/(float)totalWidth + (float)animPosX/(float)totalWidth; float u2 = u1 + (float)width/(float)totalWidth; float v1 = (float)offsetY/(float)totalHeight + (float)animPosY/(float)totalHeight; @@ -297,49 +284,49 @@ public class CustomFX extends EntityFX { float posZ = (float)((prevPosZ + (this.posZ - prevPosZ) * (double)partialTick) - interpPosZ) + startZ; GL11.glPushMatrix(); - renderPosX = startX + posX + this.posX; - renderPosY = startY + posY + this.posY; - renderPosZ = startZ + posZ + this.posZ; + renderPosX = startX + posX + this.posX; + renderPosY = startY + posY + this.posY; + renderPosZ = startZ + posZ + this.posZ; - GL11.glTranslated(posX,posY,posZ); - if(facePlayer) { - GL11.glRotated(180 - player.rotationYaw, 0.0, 1.0, 0.0); - GL11.glRotated(-player.rotationPitch + 90, 1.0, 0.0, 0.0); + GL11.glTranslated(posX,posY,posZ); + if(facePlayer) { + GL11.glRotated(180 - player.rotationYaw, 0.0, 1.0, 0.0); + GL11.glRotated(-player.rotationPitch + 90, 1.0, 0.0, 0.0); - GL11.glRotated(rotationX, 1.0, 0.0, 0.0); - GL11.glRotated(rotationZ, 0.0, 1.0, 0.0); - GL11.glRotated(rotationY + (!front ? 180 : 0), 0.0, 0.0, 1.0); - } else { - GL11.glRotated(rotationX, 1.0, 0.0, 0.0); - GL11.glRotated(rotationY, 0.0, 1.0, 0.0); - GL11.glRotated(rotationZ + (!front ? 180 : 0), 0.0, 0.0, 1.0); - } + GL11.glRotated(rotationX, 1.0, 0.0, 0.0); + GL11.glRotated(rotationZ, 0.0, 1.0, 0.0); + GL11.glRotated(rotationY + (!front ? 180 : 0), 0.0, 0.0, 1.0); + } else { + GL11.glRotated(rotationX, 1.0, 0.0, 0.0); + GL11.glRotated(rotationY, 0.0, 1.0, 0.0); + GL11.glRotated(rotationZ + (!front ? 180 : 0), 0.0, 0.0, 1.0); + } - tessellator.startDrawingQuads(); - if (!this.glows) { - tessellator.setBrightness(this.getBrightnessForRender(partialTick)); - } else { - tessellator.setBrightness(240); - } + tessellator.startDrawingQuads(); + if (!this.glows) { + tessellator.setBrightness(this.getBrightnessForRender(partialTick)); + } else { + tessellator.setBrightness(240); + } - float textureXScale = 1.0F, textureYScale = 1.0F; - if (totalWidth > totalHeight) { - textureYScale = (float) totalHeight/totalWidth; - GL11.glScalef(1/textureYScale/2,1/textureYScale/2,1/textureYScale/2); - } else if(totalHeight > totalWidth) { - textureXScale = (float) totalWidth/totalHeight; - GL11.glScalef(1/textureXScale/2,1/textureXScale/2,1/textureXScale/2); - } - textureXScale *= scaleX1/10.0F; - textureYScale *= scaleY1/10.0F; + float textureXScale = 1.0F, textureYScale = 1.0F; + if (totalWidth > totalHeight) { + textureYScale = (float) totalHeight/totalWidth; + GL11.glScalef(1/textureYScale/2,1/textureYScale/2,1/textureYScale/2); + } else if(totalHeight > totalWidth) { + textureXScale = (float) totalWidth/totalHeight; + GL11.glScalef(1/textureXScale/2,1/textureXScale/2,1/textureXScale/2); + } + textureXScale *= scaleX1/10.0F; + textureYScale *= scaleY1/10.0F; - tessellator.setColorOpaque_F(1, 1, 1); - tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha); - tessellator.addVertexWithUV( textureXScale * (u2-u1)/2, 0, textureYScale * (v2-v1)/2, u2, v2); - tessellator.addVertexWithUV( textureXScale * (u2-u1)/2, 0, textureYScale * -(v2-v1)/2, u2, v1); - tessellator.addVertexWithUV( textureXScale * -(u2-u1)/2, 0, textureYScale * -(v2-v1)/2, u1, v1); - tessellator.addVertexWithUV( textureXScale * -(u2-u1)/2, 0, textureYScale * (v2-v1)/2, u1, v2); - tessellator.draw(); + tessellator.setColorOpaque_F(1, 1, 1); + tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha); + tessellator.addVertexWithUV( textureXScale * (u2-u1)/2, 0, textureYScale * (v2-v1)/2, u2, v2); + tessellator.addVertexWithUV( textureXScale * (u2-u1)/2, 0, textureYScale * -(v2-v1)/2, u2, v1); + tessellator.addVertexWithUV( textureXScale * -(u2-u1)/2, 0, textureYScale * -(v2-v1)/2, u1, v1); + tessellator.addVertexWithUV( textureXScale * -(u2-u1)/2, 0, textureYScale * (v2-v1)/2, u1, v2); + tessellator.draw(); GL11.glPopMatrix(); } @@ -361,42 +348,6 @@ public class CustomFX extends EntityFX { } } - public void getWidthHeight() throws IOException { - InputStream inputstream = null; - - try { - IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(this.location); - inputstream = iresource.getInputStream(); - BufferedImage bufferedimage = ImageIO.read(inputstream); - gotWidthHeight = true; - this.totalWidth = bufferedimage.getWidth(); - this.totalHeight = bufferedimage.getHeight(); - correctWidthHeight(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (inputstream != null) { - inputstream.close(); - } - } - } - - public void getURLWidthHeight(){ - if(imageDownloadAlt.getBufferedImage() != null) { - gotWidthHeight = true; - this.totalWidth = imageDownloadAlt.getBufferedImage().getWidth(); - this.totalHeight = imageDownloadAlt.getBufferedImage().getHeight(); - correctWidthHeight(); - } - } - - public void correctWidthHeight(){ - totalWidth = Math.max(totalWidth, 1); - totalHeight = Math.max(totalHeight, 1); - this.width = width < 0 ? totalWidth : width; - this.height = height < 0 ? totalHeight : height; - } - public int lerpColor(int from, int to, float ratio) { float ar = (from & 0xFF0000) >> 16; float ag = (from & 0x00FF00) >> 8; @@ -412,8 +363,17 @@ public class CustomFX extends EntityFX { return (int)(((int)rr << 16) + ((int)rg << 8) + (rb)); } - + public int getFXLayer(){ - return 0; + return 0; + } + + public boolean imageLoaded() { + if (imageData.imageLoaded()) { + this.width = width < 0 ? imageData.getTotalWidth() : width; + this.height = height < 0 ? imageData.getTotalHeight() : height; + return true; + } + return false; } } diff --git a/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java b/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java index 2e1e69172..b0f9bf445 100644 --- a/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java +++ b/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java @@ -48,6 +48,10 @@ public class ImageData { return !this.invalid && this.location != null && this.gotWidthHeight; } + public boolean invalid() { + return this.invalid; + } + public void bindTexture() { ResourceLocation location = this.getLocation(); if (location != null && !this.invalid) { From 9c5d5a8d73758a2b9b7fa19043894c0e9cf7fc41 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 1 Jun 2023 17:53:08 -0500 Subject: [PATCH 3/4] PacketHandlerServer: -Fixed custom items not updating scripted data --- src/main/java/noppes/npcs/PacketHandlerServer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 069091f56..917dfc390 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -306,9 +306,8 @@ public class PacketHandlerServer{ NBTTagCompound compound = Server.readNBT(buffer); ScriptCustomItem wrapper = (ScriptCustomItem) NpcAPI.Instance().getIItemStack(player.getHeldItem()); wrapper.setMCNbt(compound); - wrapper.loadScriptData(); - wrapper.loaded = false; wrapper.saveScriptData(); + wrapper.loaded = false; player.sendContainerToPlayer(player.inventoryContainer); } } From 6febeeea02af1476561b40a633debe8caf2a8c69 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:12:15 -0500 Subject: [PATCH 4/4] ScriptCustomItem: -Fixed custom item visually disappearing after editing a script. --- src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java b/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java index 3ef35244f..54edba07e 100644 --- a/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java +++ b/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java @@ -439,7 +439,7 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS public void loadItemData() { NBTTagCompound c = this.item.getTagCompound(); - if (c != null){ + if (c != null && !c.getCompoundTag("ItemData").hasNoTags()){ this.setItemNBT(c.getCompoundTag("ItemData")); } }