diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index 5ce64cd92..befd353fc 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -1,9 +1,6 @@ package noppes.npcs; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.UUID; +import java.util.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; @@ -13,6 +10,8 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.nbt.NBTUtil; import net.minecraft.server.MinecraftServer; import net.minecraft.util.StringUtils; +import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.util.ValueUtil; @@ -37,17 +36,10 @@ public class DataDisplay { public String texture = "customnpcs:textures/entity/humanmale/Steve.png"; public String cloakTexture = ""; - public String glowTexture = ""; - public float overlaySize = 1.0F; - public float overlayScaleX = 1.0F; - public float overlayScaleY = 1.0F; + public HashMap skinOverlays = new HashMap<>(); + public long overlayRenderTicks = 0; - public String poweredTexture = ""; - public float poweredSize = 1.0F; - public float poweredSpeedX = 1.0F; - public float poweredSpeedY = 1.0F; - public float poweredScaleX = 1.0F; - public float poweredScaleY = 1.0F; + public String glowTexture = ""; public int visible = 0; //0:visible 1:Invisible 2:semi-invisible @@ -76,6 +68,30 @@ public class DataDisplay { return CustomNpcs.MARKOV_GENERATOR[markovGeneratorId].fetch(markovGender); } + public NBTTagCompound writeOverlaysToNBT(NBTTagCompound nbttagcompound) { + NBTTagList overlayList = new NBTTagList(); + if (!npc.display.skinOverlays.isEmpty()) { + for (Map.Entry overlayData : npc.display.skinOverlays.entrySet()) { + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("SkinOverlayID", overlayData.getKey()); + compound.setString("SkinOverlayTexture", overlayData.getValue().directory); + compound.setBoolean("SkinOverlayGlow", overlayData.getValue().glow); + compound.setFloat("SkinOverlayAlpha", overlayData.getValue().alpha); + compound.setFloat("SkinOverlaySize", overlayData.getValue().size); + compound.setFloat("SkinOverlaySpeedX", overlayData.getValue().speedX); + compound.setFloat("SkinOverlaySpeedY", overlayData.getValue().speedY); + compound.setFloat("SkinOverlayScaleX", overlayData.getValue().scaleX); + compound.setFloat("SkinOverlayScaleY", overlayData.getValue().scaleY); + compound.setFloat("SkinOverlayOffsetX", overlayData.getValue().offsetX); + compound.setFloat("SkinOverlayOffsetY", overlayData.getValue().offsetY); + compound.setFloat("SkinOverlayOffsetZ", overlayData.getValue().offsetZ); + overlayList.appendTag(compound); + } + } + nbttagcompound.setTag("SkinOverlayData",overlayList); + return nbttagcompound; + } + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setString("Name", name); nbttagcompound.setInteger("MarkovGeneratorId", markovGeneratorId); @@ -85,18 +101,9 @@ public class DataDisplay { nbttagcompound.setString("Texture", texture); nbttagcompound.setString("CloakTexture", cloakTexture); nbttagcompound.setByte("UsingSkinUrl", skinType); - nbttagcompound.setString("GlowTexture", glowTexture); - nbttagcompound.setFloat("OverlaySize", overlaySize); - nbttagcompound.setFloat("OverlayScaleX", overlayScaleX); - nbttagcompound.setFloat("OverlayScaleY", overlayScaleY); - nbttagcompound.setString("PoweredTexture", poweredTexture); - nbttagcompound.setFloat("PoweredSize", poweredSize); - nbttagcompound.setFloat("PoweredSpeedX", poweredSpeedX); - nbttagcompound.setFloat("PoweredSpeedY", poweredSpeedY); - nbttagcompound.setFloat("PoweredScaleX", poweredScaleX); - nbttagcompound.setFloat("PoweredScaleY", poweredScaleY); + nbttagcompound = writeOverlaysToNBT(nbttagcompound); if (this.playerProfile != null) { @@ -152,26 +159,50 @@ public class DataDisplay { texture = nbttagcompound.getString("Texture"); cloakTexture = nbttagcompound.getString("CloakTexture"); - - overlayScaleX = overlayScaleX == 0 ? 1.0F : overlayScaleX; - overlayScaleY = overlayScaleY == 0 ? 1.0F : overlayScaleY; - overlaySize = overlaySize == 0 ? 1.0F : overlaySize; glowTexture = nbttagcompound.getString("GlowTexture"); - overlaySize = nbttagcompound.getFloat("OverlaySize"); - overlayScaleX = nbttagcompound.getFloat("OverlayScaleX"); - overlayScaleY = nbttagcompound.getFloat("OverlayScaleY"); - poweredScaleX = poweredScaleX == 0 ? 1.0F : poweredScaleX; - poweredScaleY = poweredScaleY == 0 ? 1.0F : poweredScaleY; - poweredSpeedX = poweredSpeedX == 0 ? 1.0F : poweredSpeedX; - poweredSpeedY = poweredSpeedY == 0 ? 1.0F : poweredSpeedY; - poweredSize = poweredSize == 0 ? 1.0F : poweredSize; - poweredTexture = nbttagcompound.getString("PoweredTexture"); - poweredSize = nbttagcompound.getFloat("PoweredSize"); - poweredSpeedX = nbttagcompound.getFloat("PoweredSpeedX"); - poweredSpeedY = nbttagcompound.getFloat("PoweredSpeedY"); - poweredScaleX = nbttagcompound.getFloat("PoweredScaleX"); - poweredScaleY = nbttagcompound.getFloat("PoweredScaleY"); + if (!nbttagcompound.hasKey("SkinOverlayData") && !glowTexture.isEmpty()) { + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("SkinOverlayID", 0); //unique glow texture ID + compound.setString("SkinOverlayTexture", glowTexture); + compound.setBoolean("SkinOverlayGlow", true); + compound.setFloat("SkinOverlayAlpha", 1.0F); + compound.setFloat("SkinOverlaySize", 1.0F); + compound.setFloat("SkinOverlaySpeedX", 0.0F); + compound.setFloat("SkinOverlaySpeedY", 0.0F); + compound.setFloat("SkinOverlayScaleX", 1.0F); + compound.setFloat("SkinOverlayScaleY", 1.0F); + compound.setFloat("SkinOverlayOffsetX", 0.0F); + compound.setFloat("SkinOverlayOffsetY", 0.0F); + compound.setFloat("SkinOverlayOffsetZ", 0.0F); + + if (!nbttagcompound.hasKey("SkinOverlayData")) { + NBTTagList tagList = new NBTTagList(); + tagList.appendTag(compound); + nbttagcompound.setTag("SkinOverlayData", tagList); + } else if (!glowTexture.isEmpty()) { + nbttagcompound.getTagList("SkinOverlayData", 10).appendTag(compound); + glowTexture = ""; + } + } + + NBTTagList skinOverlayList = nbttagcompound.getTagList("SkinOverlayData",10); + for (int i = 0; i < skinOverlayList.tagCount(); i++) { + int tagID = skinOverlayList.getCompoundTagAt(i).getInteger("SkinOverlayID"); + String tagString = skinOverlayList.getCompoundTagAt(i).getString("SkinOverlayTexture"); + boolean glow = skinOverlayList.getCompoundTagAt(i).getBoolean("SkinOverlayGlow"); + float alpha = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayAlpha"); + float size = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlaySize"); + float speedX = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlaySpeedX"); + float speedY = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlaySpeedY"); + float scaleX = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayScaleX"); + float scaleY = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayScaleY"); + float offsetX = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayOffsetX"); + float offsetY = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayOffsetY"); + float offsetZ = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayOffsetZ"); + + skinOverlays.put(tagID,new SkinOverlayData(tagString,glow,alpha,size,speedX,speedY,scaleX,scaleY,offsetX,offsetY,offsetZ)); + } modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE); if(modelSize > CustomNpcs.NpcSizeLimit) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 576d69ffb..aa478c0ed 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -148,7 +148,7 @@ public class PacketHandlerServer{ public void updateSkinOverlays(EntityPlayerMP player) { NBTTagCompound data = new NBTTagCompound(); data.setTag("SkinOverlayData",player.getEntityData().getTagList("SkinOverlayData",10)); - Server.sendData(player, EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS, data); + Server.sendData(player, EnumPacketClient.PLAYER_UPDATE_SKIN_OVERLAYS, data); } private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 75d81209a..529013059 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -439,7 +439,7 @@ public class ScriptPlayerEventHandler { if (playerMP.getEntityData().hasKey("SkinOverlayData")) { NBTTagCompound data = new NBTTagCompound(); data.setTag("SkinOverlayData",playerMP.getEntityData().getTagList("SkinOverlayData",10)); - Server.sendData(playerMP, EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS, data); + Server.sendData(playerMP, EnumPacketClient.PLAYER_UPDATE_SKIN_OVERLAYS, data); } } } diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index c29fabf27..2dfd659bd 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -13,6 +13,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -37,6 +39,7 @@ import noppes.npcs.controllers.Dialog; import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.Quest; import noppes.npcs.controllers.data.SkinOverlayData; +import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.Sys; @@ -90,7 +93,7 @@ public class NoppesUtil { float offsetY = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayOffsetY"); float offsetZ = skinOverlayList.getCompoundTagAt(i).getFloat("SkinOverlayOffsetZ"); - skinOverlays.put(tagID,new SkinOverlayData(new ResourceLocation(tagString),glow,alpha,size,speedX,speedY,scaleX,scaleY,offsetX,offsetY,offsetZ)); + skinOverlays.put(tagID,new SkinOverlayData(tagString,glow,alpha,size,speedX,speedY,scaleX,scaleY,offsetX,offsetY,offsetZ)); } Client.skinOverlays.put(player.getUniqueID(), skinOverlays); } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index d9921ea53..f7baf4fba 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -273,7 +273,7 @@ public class PacketHandlerClient extends PacketHandlerServer{ else if(type == EnumPacketClient.SWING_PLAYER_ARM){ Minecraft.getMinecraft().thePlayer.swingItem(); } - else if(type == EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS) { + else if(type == EnumPacketClient.PLAYER_UPDATE_SKIN_OVERLAYS) { NoppesUtil.updateSkinOverlayData(player, Server.readNBT(buffer)); } } diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java index d701bc72e..7c89bd03d 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java @@ -4,23 +4,27 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; public class GuiNpcTextureOverlays extends GuiNpcSelectionInterface{ public GuiNpcTextureOverlays(EntityNPCInterface npc,GuiScreen parent){ - super(npc, parent, npc.display.glowTexture.isEmpty()?"customnpcs:textures/overlays/":npc.display.glowTexture); - title = "Select Overlay"; + //super(npc, parent, npc.display.glowTexture.isEmpty()?"customnpcs:textures/overlays/":npc.display.glowTexture); + super(npc, parent, npc.display.skinOverlays.containsKey(0) ? npc.display.skinOverlays.get(0).directory : ""); + title = "Select Overlay"; this.parent = parent; } public void initGui(){ super.initGui(); - int index = npc.display.glowTexture.lastIndexOf("/"); + String str = npc.display.skinOverlays.containsKey(0) ? npc.display.skinOverlays.get(0).directory : ""; + int index = str.lastIndexOf("/"); if(index > 0){ - String asset = npc.display.glowTexture.substring(index + 1); - if(npc.display.glowTexture.equals(assets.getAsset(asset))) + String asset = str.substring(index + 1); + if(str.equals(assets.getAsset(asset))) slot.selected = asset; } } @@ -73,8 +77,13 @@ public class GuiNpcTextureOverlays extends GuiNpcSelectionInterface{ @Override public void elementClicked(){ if(dataTextures.contains(slot.selected) && slot.selected != null){ - npc.display.glowTexture = assets.getAsset(slot.selected); + //npc.display.glowTexture = assets.getAsset(slot.selected); npc.textureGlowLocation = null; + + npc.display.skinOverlays.put(0,new SkinOverlayData( + assets.getAsset(slot.selected), true, 0.8F, 1.0F, 0.0F, 0.0F, + 1.0F, 1.0F, 0.0F, 0.0F, 0.0F + )); } } 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 ca2055e63..fa4492ebc 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -4,6 +4,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomNpcs; import noppes.npcs.DataDisplay; import noppes.npcs.client.Client; @@ -15,6 +16,7 @@ import noppes.npcs.client.gui.SubGuiNpcName; import noppes.npcs.client.gui.model.GuiCreationScreen; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -76,7 +78,8 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene y+=23; addLabel(new GuiNpcLabel(9,"display.overlay", guiLeft + 5, y + 5)); - addTextField(new GuiNpcTextField(9,this, fontRendererObj, guiLeft + 80, y, 200, 20, display.glowTexture)); + + addTextField(new GuiNpcTextField(9,this, fontRendererObj, guiLeft + 80, y, 200, 20, npc.display.skinOverlays.containsKey(0) ? npc.display.skinOverlays.get(0).directory : "")); this.addButton(new GuiNpcButton(9, guiLeft + 283, y, 80, 20, "display.selectTexture")); y+=23; @@ -128,7 +131,11 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene } else if(textfield.id == 9){ npc.textureGlowLocation = null; - display.glowTexture = textfield.getText(); + //display.glowTexture = textfield.getText(); + npc.display.skinOverlays.put(0,new SkinOverlayData( + textfield.getText(), true, 0.8F, 1.0F, 0.0F, 0.0F, + 1.0F, 1.0F, 0.0F, 0.0F, 0.0F + )); } else if(textfield.id == 11){ display.title = textfield.getText(); diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java b/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java index 8abf61f8a..6af7252db 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java @@ -21,6 +21,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import noppes.npcs.client.Client; import noppes.npcs.client.gui.util.GuiCustomScroll; @@ -30,6 +31,7 @@ import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.ICustomScrollListener; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityFakeLiving; import noppes.npcs.entity.EntityNPCInterface; @@ -229,7 +231,8 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol npc.display.texture = NPCRendererHelper.getTexture(render,entity); } } - npc.display.glowTexture = ""; + //npc.display.glowTexture = ""; + npc.display.skinOverlays.remove(0); npc.textureLocation = null; npc.textureGlowLocation = null; npc.updateHitbox(); @@ -336,7 +339,8 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol else{ npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; } - npc.display.glowTexture = ""; + //npc.display.glowTexture = ""; + npc.display.skinOverlays.remove(0); npc.textureLocation = null; npc.textureGlowLocation = null; npc.updateHitbox(); diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java index 727cd19ba..c0eb3228f 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java @@ -12,11 +12,13 @@ import net.minecraft.client.renderer.entity.NPCRendererHelper; import net.minecraft.client.renderer.entity.RendererLivingEntity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; import noppes.npcs.ModelData; import noppes.npcs.client.EntityUtil; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNPCStringSlot; import noppes.npcs.client.gui.util.GuiNpcButton; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityCustomNpc; import org.lwjgl.opengl.GL11; @@ -127,7 +129,8 @@ public class GuiEntitySelection extends GuiNPCInterface else{ npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; } - npc.display.glowTexture = ""; + //npc.display.glowTexture = ""; + npc.display.skinOverlays.remove(0); npc.textureLocation = null; npc.textureGlowLocation = null; npc.updateHitbox(); diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java index d15e5df01..ae2a5bbf8 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java @@ -93,6 +93,15 @@ public class RenderCNPCPlayer extends RenderPlayer { if (Client.skinOverlays.containsKey(player.getUniqueID())) { for (SkinOverlayData overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) { + if (overlayData.location == null) { + overlayData.location = new ResourceLocation(overlayData.directory); + } else { + String str = overlayData.location.getResourceDomain()+":"+overlayData.location.getResourcePath(); + if (!str.equals(overlayData.directory)) { + overlayData.location = new ResourceLocation(overlayData.directory); + } + } + if (!preRenderOverlay(false, player, overlayData.location, overlayData.glow, overlayData.alpha, overlayData.size, overlayData.speedX, overlayData.speedY, overlayData.scaleX, overlayData.scaleY, overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ @@ -135,6 +144,15 @@ public class RenderCNPCPlayer extends RenderPlayer { if (Client.skinOverlays.containsKey(player.getUniqueID())) { for (SkinOverlayData overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) { + if (overlayData.location == null) { + overlayData.location = new ResourceLocation(overlayData.directory); + } else { + String str = overlayData.location.getResourceDomain()+":"+overlayData.location.getResourcePath(); + if (!str.equals(overlayData.directory)) { + overlayData.location = new ResourceLocation(overlayData.directory); + } + } + if (!preRenderOverlay(false, player, overlayData.location, overlayData.glow, overlayData.alpha, overlayData.size, overlayData.speedX, overlayData.speedY, overlayData.scaleX, overlayData.scaleY, overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 01deba024..3a5c93c1d 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -24,6 +24,7 @@ import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.constants.EnumAnimation; import noppes.npcs.constants.EnumStandingType; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -208,115 +209,69 @@ public class RenderNPCInterface extends RenderLiving{ super.doRender(entityliving, d, d1, d2, f, f1); } - protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7){ + protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7) { super.renderModel(entityliving, par2, par3, par4, par5, par6, par7); EntityNPCInterface npc = (EntityNPCInterface) entityliving; - if (!npc.display.glowTexture.isEmpty() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer)) - { - if(npc.textureGlowLocation == null){ - npc.textureGlowLocation = new ResourceLocation(npc.display.glowTexture); - } else { - String locationString = npc.textureGlowLocation.getResourceDomain() + ":" + npc.textureGlowLocation.getResourcePath(); - if (!locationString.equals(npc.display.glowTexture)) { - npc.textureGlowLocation = new ResourceLocation(npc.display.glowTexture); + + if (!npc.display.skinOverlays.isEmpty()) { + for (SkinOverlayData overlayData : npc.display.skinOverlays.values()) { + try { + if (overlayData.location == null) { + overlayData.location = new ResourceLocation(overlayData.directory); + } else { + String str = npc.display.skinOverlays.get(0).location.getResourceDomain()+":"+npc.display.skinOverlays.get(0).location.getResourcePath(); + if (!str.equals(overlayData.directory)) { + overlayData.location = new ResourceLocation(overlayData.directory); + } + } + + this.bindTexture(overlayData.location); + + // Overlay & Glow + if (overlayData.glow) { + GL11.glDepthFunc(GL11.GL_LEQUAL); + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA); + Minecraft.getMinecraft().entityRenderer.disableLightmap((double) 0); + } + + GL11.glColor4f(1.0F, 1.0F, 1.0F, overlayData.alpha); + + GL11.glDepthMask(!npc.isInvisible()); + + GL11.glPushMatrix(); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + GL11.glTranslatef(npc.display.overlayRenderTicks * 0.001F * overlayData.speedX, npc.display.overlayRenderTicks * 0.001F * overlayData.speedY, 0.0F); + GL11.glScalef(overlayData.scaleX, overlayData.scaleY, 1.0F); + + GL11.glMatrixMode(GL11.GL_MODELVIEW); + float scale = 1.005f * overlayData.size; + GL11.glTranslatef(overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ); + GL11.glScalef(scale, scale, scale); + if(mainModel instanceof ModelMPM){ + ((ModelMPM)mainModel).isArmor = true; + mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); + ((ModelMPM)mainModel).isArmor = false; + } + else + mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); + GL11.glPopMatrix(); + + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDepthFunc(GL11.GL_LEQUAL); + GL11.glDisable(GL11.GL_BLEND); + Minecraft.getMinecraft().entityRenderer.enableLightmap((double) 0); + } catch (Exception ignored) { } } - - bindTexture((ResourceLocation) npc.textureGlowLocation); - float f1 = 1.0F; - - // Overlay & Glow - GL11.glDepthFunc(GL11.GL_LEQUAL); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); - GL11.glDisable(GL11.GL_LIGHTING); - Minecraft.getMinecraft().entityRenderer.disableLightmap((double)0); - - GL11.glDepthMask(!npc.isInvisible()); - GL11.glColor4f(1.0F, 1.0F, 1.0F, npc.isInvisible() ? 0.2F : 1.0F); - - GL11.glPushMatrix(); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glLoadIdentity(); - GL11.glScalef(npc.display.overlayScaleX, npc.display.overlayScaleY, 1.0F); - - GL11.glMatrixMode(GL11.GL_MODELVIEW); - float scale = 1.001f * npc.display.overlaySize; - GL11.glScalef(scale, scale, scale); - if(mainModel instanceof ModelMPM){ - ((ModelMPM)mainModel).isArmor = true; - mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); - ((ModelMPM)mainModel).isArmor = false; - } - else - mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); - GL11.glPopMatrix(); - - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glLoadIdentity(); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glColor4f(1.0F, 1.0F, 1.0F, f1); - GL11.glDepthFunc(GL11.GL_LEQUAL); - GL11.glDisable(GL11.GL_BLEND); - Minecraft.getMinecraft().entityRenderer.enableLightmap((double)0); - } - - if (!npc.display.poweredTexture.isEmpty() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer)) - { - if(npc.texturePoweredLocation == null){ - npc.texturePoweredLocation = new ResourceLocation(npc.display.poweredTexture); - } else { - String locationString = npc.texturePoweredLocation.getResourceDomain() + ":" + npc.texturePoweredLocation.getResourcePath(); - if (!locationString.equals(npc.display.poweredTexture)) { - npc.texturePoweredLocation = new ResourceLocation(npc.display.poweredTexture); - } - } - - bindTexture((ResourceLocation) npc.texturePoweredLocation); - float f1 = 1.0F; - - // Overlay & Glow - GL11.glDepthFunc(GL11.GL_LEQUAL); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); - GL11.glDisable(GL11.GL_LIGHTING); - Minecraft.getMinecraft().entityRenderer.disableLightmap((double)0); - - GL11.glDepthMask(!npc.isInvisible()); - GL11.glColor4f(1.0F, 1.0F, 1.0F, npc.isInvisible() ? 0.2F : 1.0F); - - GL11.glPushMatrix(); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glLoadIdentity(); - GL11.glTranslatef(npc.renderTicksPowered * 0.001F * npc.display.poweredSpeedX, npc.renderTicksPowered * 0.001F * npc.display.poweredSpeedY, 0.0F); - GL11.glScalef(npc.display.poweredScaleX, npc.display.poweredScaleY, 1.0F); - - GL11.glMatrixMode(GL11.GL_MODELVIEW); - float scale = 1.001f * npc.display.poweredSize; - GL11.glScalef(scale, scale, scale); - GL11.glEnable(GL11.GL_BLEND); - if(mainModel instanceof ModelMPM){ - ((ModelMPM)mainModel).isArmor = true; - mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); - ((ModelMPM)mainModel).isArmor = false; - } - else - mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); - GL11.glPopMatrix(); - - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glLoadIdentity(); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glColor4f(1.0F, 1.0F, 1.0F, f1); - GL11.glDepthFunc(GL11.GL_LEQUAL); - GL11.glDisable(GL11.GL_BLEND); - Minecraft.getMinecraft().entityRenderer.enableLightmap((double)0); - - npc.renderTicksPowered++; + npc.display.overlayRenderTicks++; } } @Override diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 044959ccc..3ab209708 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -38,5 +38,5 @@ public enum EnumPacketClient { OVERLAY_CLOSE, SWING_PLAYER_ARM, UPDATE_ITEM, - CLIENT_UPDATE_SKIN_OVERLAYS + PLAYER_UPDATE_SKIN_OVERLAYS } diff --git a/src/main/java/noppes/npcs/controllers/data/SkinOverlayData.java b/src/main/java/noppes/npcs/controllers/data/SkinOverlayData.java index 8b6f0bdc7..2b201e419 100644 --- a/src/main/java/noppes/npcs/controllers/data/SkinOverlayData.java +++ b/src/main/java/noppes/npcs/controllers/data/SkinOverlayData.java @@ -3,7 +3,8 @@ package noppes.npcs.controllers.data; import net.minecraft.util.ResourceLocation; public class SkinOverlayData { - public ResourceLocation location; + public ResourceLocation location = null; + public String directory; public boolean glow; public float alpha = 1.0F; public float size = 1.0F; @@ -18,9 +19,9 @@ public class SkinOverlayData { public float offsetY = 0.0F; public float offsetZ = 0.0F; - public SkinOverlayData(ResourceLocation location, boolean glow, float alpha, float size, float speedX, float speedY, + public SkinOverlayData(String directory, boolean glow, float alpha, float size, float speedX, float speedY, float scaleX, float scaleY, float offsetX, float offsetY, float offsetZ) { - this.location = location; + this.directory = directory; this.glow = glow; this.alpha = alpha; this.size = size; diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 164b7c95c..d576c5e8e 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -120,7 +120,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public long totalTicksAlive = 0; private int taskCount = 1; public int lastInteract = 0; - public long renderTicksPowered = 0; public Faction faction; //should only be used server side @@ -131,7 +130,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public ResourceLocation textureLocation = null; public ResourceLocation textureGlowLocation = null; - public ResourceLocation texturePoweredLocation = null; public ResourceLocation textureCloakLocation = null; public EnumAnimation currentAnimation = EnumAnimation.NONE; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java index 8d0b237d8..6d983b834 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java @@ -6,9 +6,11 @@ package noppes.npcs.entity.old; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import noppes.npcs.ModelData; import noppes.npcs.constants.EnumAnimation; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityCustomNpc; public class EntityNPCEnderman extends EntityNpcEnderchibi @@ -17,7 +19,11 @@ public class EntityNPCEnderman extends EntityNpcEnderchibi { super(world); display.texture = "customnpcs:textures/entity/enderman/enderman.png"; - display.glowTexture = "customnpcs:textures/overlays/ender_eyes.png"; + //display.glowTexture = ; + display.skinOverlays.put(0,new SkinOverlayData( + "customnpcs:textures/overlays/ender_eyes.png", true, 0.8F, 1.0F, 0.0F, 0.0F, + 1.0F, 1.0F, 0.0F, 0.0F, 0.0F + )); this.width = 0.6F; this.height = 2.9F; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 58f416ad2..da46cd42b 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -1,13 +1,20 @@ package noppes.npcs.scripted.entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.Server; import noppes.npcs.constants.*; import noppes.npcs.controllers.Line; +import noppes.npcs.controllers.data.SkinOverlayData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.ScriptFaction; +import noppes.npcs.scripted.ScriptSkinOverlay; +import noppes.npcs.scripted.interfaces.ISkinOverlay; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.item.IItemStack; @@ -34,6 +41,7 @@ import noppes.npcs.scripted.NpcAPI; import noppes.npcs.util.ValueUtil; import java.util.ArrayList; +import java.util.HashMap; import java.util.UUID; public class ScriptNpc extends ScriptLiving implements ICustomNpc { @@ -1095,47 +1103,28 @@ public class ScriptNpc extends ScriptLiving imp } public void setOverlayTexture(String overlayTexture) { - npc.display.glowTexture = overlayTexture; - npc.script.clientNeedsUpdate = true; + this.setSkinOverlay(0, NpcAPI.Instance().createSkinOverlay(overlayTexture)); } - public String getOverlayTexture() {return npc.display.glowTexture;} + public String getOverlayTexture() { + if (!npc.display.skinOverlays.containsKey(0)) + return ""; - public void setOverlaySize(float size) { - npc.display.overlaySize = size; + return npc.display.skinOverlays.get(0).directory; } - public float getOverlaySize() {return npc.display.overlaySize;} - public void setOverlayScale(float scaleX, float scaleY) { - npc.display.overlayScaleX = scaleX; - npc.display.overlayScaleY = scaleY; + public void setSkinOverlay(int id, ISkinOverlay overlay) { + if (overlay != null) { + npc.display.skinOverlays.put(id, new SkinOverlayData( + overlay.getTexture(),overlay.getGlow(),overlay.getAlpha(),overlay.getSize(), + overlay.getSpeedX(),overlay.getSpeedY(),overlay.getScaleX(),overlay.getScaleY(), + overlay.getOffsetX(),overlay.getOffsetY(),overlay.getOffsetZ() + )); + } } - public float getOverlayTextureScaleX() {return npc.display.overlayScaleX;} - public float getOverlayTextureScaleY() {return npc.display.overlayScaleY;} - public void setPoweredTexture(String poweredTexture) { - npc.display.poweredTexture = poweredTexture; - npc.script.clientNeedsUpdate = true; + public void removeSkinOverlay(int id) { + npc.display.skinOverlays.remove(id); } - public String getPoweredTexture() {return npc.display.poweredTexture;} - - public void setPoweredSize(float size) { - npc.display.poweredSize = size; - } - public float getPoweredSize() {return npc.display.poweredSize;} - - public void setPoweredScale(float scaleX, float scaleY) { - npc.display.poweredScaleX = scaleX; - npc.display.poweredScaleY = scaleY; - } - public float getPoweredTextureScaleX() {return npc.display.poweredScaleX;} - public float getPoweredTextureScaleY() {return npc.display.poweredScaleY;} - - public void setPoweredSpeed(float speedX, float speedY) { - npc.display.poweredSpeedX = speedX; - npc.display.poweredSpeedY = speedY; - } - public float getPoweredSpeedX() {return npc.display.poweredSpeedX;} - public float getPoweredSpeedY() {return npc.display.poweredSpeedY;} public void setCollisionType(int type){ npc.display.collidesWith = type; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index f787d8821..5fe85514b 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -527,7 +527,11 @@ public class ScriptPlayer extends ScriptLivingBase Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.OVERLAY_CLOSE, id, new NBTTagCompound()); } - public void setSkinOverlay(int id, ScriptSkinOverlay overlay) { + public void setSkinOverlay(int id, ISkinOverlay overlay) { + if (id < 0) { + throw new CustomNPCsException("Skin overlay ID must be greater than 0."); + } + if (overlay != null) { NBTTagCompound data = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound(); @@ -559,7 +563,7 @@ public class ScriptPlayer extends ScriptLivingBase player.getEntityData().getTagList("SkinOverlayData", 10).appendTag(compound); } data.setTag("SkinOverlayData",player.getEntityData().getTagList("SkinOverlayData",10)); - Server.sendData((EntityPlayerMP) this.entity, EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS, data); + Server.sendData((EntityPlayerMP) this.entity, EnumPacketClient.PLAYER_UPDATE_SKIN_OVERLAYS, data); } } @@ -573,7 +577,7 @@ public class ScriptPlayer extends ScriptLivingBase } } data.setTag("SkinOverlayData",player.getEntityData().getTagList("SkinOverlayData",10)); - Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS, data); + Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.PLAYER_UPDATE_SKIN_OVERLAYS, data); } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java index 7d3fef7fd..8b9efff78 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java @@ -738,10 +738,6 @@ public interface ICustomNpc extends IEntityLiving { String getOverlayTexture(); - void setPoweredTexture(String poweredTexture); - - String getPoweredTexture(); - void setCollisionType(int type); int getCollisionType();