mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 15:24:46 +00:00
Players can now have multiple skin overlays, just like GUI overlays.
This commit is contained in:
1 parent
9a0aae50e0
commit
dbfbab7be2
10 files changed
+162
-76
No files matched your search
@@ -128,6 +128,8 @@ public class PacketHandlerServer{
|
||||
itemScriptPackets(type, buffer, player);
|
||||
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
|
||||
getScriptsEnabled(type, buffer, player);
|
||||
else if (type == EnumPacketServer.SERVER_UPDATE_SKIN_OVERLAYS)
|
||||
updateSkinOverlays(player);
|
||||
else if (item.getItem() == CustomItems.scripter)
|
||||
scriptPackets(type, buffer, player, npc);
|
||||
else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock))
|
||||
@@ -143,6 +145,12 @@ public class PacketHandlerServer{
|
||||
NoppesUtilServer.isGUIOpen(buffer, player);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
||||
if (type == EnumPacketServer.ScriptGlobalGuiDataGet) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
||||
@@ -12,7 +12,10 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
@@ -26,6 +29,7 @@ import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.player.*;
|
||||
import net.minecraftforge.event.world.*;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
@@ -33,6 +37,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptPlayerEventHandler {
|
||||
public ScriptPlayerEventHandler() {
|
||||
}
|
||||
@@ -426,6 +432,16 @@ public class ScriptPlayerEventHandler {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.player);
|
||||
EventHooks.onPlayerLogin(handler, scriptPlayer);
|
||||
|
||||
//Loads other players' and own player's skin overlays if they have them
|
||||
List<EntityPlayerMP> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
|
||||
for (EntityPlayerMP playerMP : list) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
@@ -12,10 +13,11 @@ import noppes.npcs.Server;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import noppes.npcs.controllers.data.SkinOverlayData;
|
||||
|
||||
public class Client {
|
||||
public static HashMap<Integer, OverlayCustom> customOverlays = new HashMap<>();
|
||||
public static ResourceLocation playerOverlay = null;
|
||||
public static HashMap<UUID, HashMap<Integer, SkinOverlayData>> skinOverlays = new HashMap<>();
|
||||
|
||||
public static void sendData(EnumPacketServer enu, Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
@@ -35,6 +36,7 @@ import noppes.npcs.constants.EnumPlayerPacket;
|
||||
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.EntityNPCInterface;
|
||||
|
||||
import org.lwjgl.Sys;
|
||||
@@ -70,6 +72,19 @@ public class NoppesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateSkinOverlayData(EntityPlayer player, NBTTagCompound compound) {
|
||||
HashMap<Integer, SkinOverlayData> skinOverlays = new HashMap<>();
|
||||
NBTTagList skinOverlayList = compound.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");
|
||||
|
||||
skinOverlays.put(tagID,new SkinOverlayData(new ResourceLocation(tagString)));
|
||||
}
|
||||
Client.skinOverlays.put(player.getUniqueID(), skinOverlays);
|
||||
}
|
||||
|
||||
public static void spawnScriptedParticle(ByteBuf buffer){
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
@@ -274,11 +273,8 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
else if(type == EnumPacketClient.SWING_PLAYER_ARM){
|
||||
Minecraft.getMinecraft().thePlayer.swingItem();
|
||||
}
|
||||
else if(type == EnumPacketClient.PLAYER_OVERLAY) {
|
||||
String overlayString = Server.readString(buffer);
|
||||
if (overlayString != null) {
|
||||
Client.playerOverlay = new ResourceLocation(overlayString);
|
||||
}
|
||||
else if(type == EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS) {
|
||||
NoppesUtil.updateSkinOverlayData(player, Server.readNBT(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,54 +3,76 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.data.SkinOverlayData;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RenderCNPCPlayer extends RenderPlayer {
|
||||
|
||||
public RenderCNPCPlayer() {
|
||||
}
|
||||
|
||||
private boolean preRenderOverlay(EntityPlayer player, ResourceLocation overlayLocation) {
|
||||
try {
|
||||
this.bindTexture(overlayLocation);
|
||||
} catch (Exception exception) {
|
||||
return false;
|
||||
}
|
||||
// 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);
|
||||
|
||||
GL11.glDepthMask(!player.isInvisible());
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glMatrixMode(GL11.GL_TEXTURE);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glScalef(1.0F, 1.0F, 1.0F);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
float scale = 1.001f;
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
|
||||
return true;
|
||||
}
|
||||
public void postRenderOverlay(EntityPlayer player) {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderModel(EntityLivingBase p_77036_1_, float p_77036_2_, float p_77036_3_, float p_77036_4_, float p_77036_5_, float p_77036_6_, float p_77036_7_) {
|
||||
EntityPlayer player = (EntityPlayer) p_77036_1_;
|
||||
this.bindEntityTexture(p_77036_1_);
|
||||
|
||||
if (!p_77036_1_.isInvisible())
|
||||
{
|
||||
this.mainModel.render(p_77036_1_, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, p_77036_7_);
|
||||
|
||||
if (Client.playerOverlay != null) {
|
||||
try {
|
||||
this.bindTexture(Client.playerOverlay);
|
||||
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);
|
||||
|
||||
GL11.glDepthMask(!p_77036_1_.isInvisible());
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glMatrixMode(GL11.GL_TEXTURE);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glScalef(1.0F, 1.0F, 1.0F);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
float scale = 1.001f;
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
if (Client.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlayData overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (!preRenderOverlay(player, overlayData.location))
|
||||
return;
|
||||
this.mainModel.render(p_77036_1_, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, p_77036_7_);
|
||||
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);
|
||||
} catch (Exception ignored) {}
|
||||
postRenderOverlay(player);
|
||||
}
|
||||
} else if(player.getEntityData().hasKey("SkinOverlayData")) {
|
||||
Client.sendData(EnumPacketServer.SERVER_UPDATE_SKIN_OVERLAYS, new Object[0]);
|
||||
}
|
||||
}
|
||||
else if (!p_77036_1_.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer))
|
||||
@@ -73,49 +95,26 @@ public class RenderCNPCPlayer extends RenderPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
public void renderFirstPersonArm(EntityPlayer p_82441_1_)
|
||||
public void renderFirstPersonArm(EntityPlayer player)
|
||||
{
|
||||
float f = 1.0F;
|
||||
GL11.glColor3f(f, f, f);
|
||||
this.modelBipedMain.onGround = 0.0F;
|
||||
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, p_82441_1_);
|
||||
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, player);
|
||||
this.modelBipedMain.bipedRightArm.render(0.0625F);
|
||||
|
||||
if (Client.playerOverlay != null) {
|
||||
try {
|
||||
this.bindTexture(Client.playerOverlay);
|
||||
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);
|
||||
|
||||
GL11.glDepthMask(!p_82441_1_.isInvisible());
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glMatrixMode(GL11.GL_TEXTURE);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glScalef(1.0F, 1.0F, 1.0F);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
float scale = 1.001f;
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
if (Client.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlayData overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (!preRenderOverlay(player, overlayData.location))
|
||||
return;
|
||||
GL11.glColor3f(1.0F, 1.0F, 1.0F);
|
||||
this.modelBipedMain.onGround = 0.0F;
|
||||
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, p_82441_1_);
|
||||
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, player);
|
||||
this.modelBipedMain.bipedRightArm.render(0.0625F);
|
||||
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);
|
||||
} catch (Exception ignored) {}
|
||||
postRenderOverlay(player);
|
||||
}
|
||||
} else if(player.getEntityData().hasKey("SkinOverlayData")) {
|
||||
Client.sendData(EnumPacketServer.SERVER_UPDATE_SKIN_OVERLAYS, new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,5 +38,5 @@ public enum EnumPacketClient {
|
||||
OVERLAY_CLOSE,
|
||||
SWING_PLAYER_ARM,
|
||||
UPDATE_ITEM,
|
||||
PLAYER_OVERLAY
|
||||
CLIENT_UPDATE_SKIN_OVERLAYS
|
||||
}
|
||||
@@ -87,7 +87,9 @@ public enum EnumPacketServer {
|
||||
NaturalSpawnGetAll, MailOpenSetup,
|
||||
DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen,
|
||||
|
||||
CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused;
|
||||
CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused,
|
||||
|
||||
SERVER_UPDATE_SKIN_OVERLAYS;
|
||||
|
||||
public CustomNpcsPermissions.Permission permission = null;
|
||||
public boolean needsNpc = false;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class SkinOverlayData {
|
||||
public ResourceLocation location;
|
||||
|
||||
public SkinOverlayData(ResourceLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.stats.StatBase;
|
||||
import net.minecraft.stats.StatList;
|
||||
@@ -526,8 +527,44 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.OVERLAY_CLOSE, id, new NBTTagCompound());
|
||||
}
|
||||
|
||||
public void setPlayerOverlay(String texture) {
|
||||
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.PLAYER_OVERLAY, texture);
|
||||
public void addSkinOverlay(int id, String overlayString) {
|
||||
if (overlayString != null) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
||||
compound.setString("SkinOverlayTexture", overlayString);
|
||||
compound.setInteger("SkinOverlayID", id);
|
||||
|
||||
if (!player.getEntityData().hasKey("SkinOverlayData")) {
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
tagList.appendTag(compound);
|
||||
player.getEntityData().setTag("SkinOverlayData", tagList);
|
||||
} else {
|
||||
for (int i = 0; i < player.getEntityData().getTagList("SkinOverlayData", 10).tagCount(); i++) {
|
||||
int tagID = player.getEntityData().getTagList("SkinOverlayData", 10).getCompoundTagAt(i).getInteger("SkinOverlayID");
|
||||
if (tagID == id) {
|
||||
player.getEntityData().getTagList("SkinOverlayData", 10).removeTag(i);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSkinOverlay(int id) {
|
||||
if (player.getEntityData().hasKey("SkinOverlayData")) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
for (int i = 0; i < player.getEntityData().getTagList("SkinOverlayData",10).tagCount(); i++) {
|
||||
int tagID = player.getEntityData().getTagList("SkinOverlayData",10).getCompoundTagAt(i).getInteger("SkinOverlayID");
|
||||
if (tagID == id) {
|
||||
player.getEntityData().getTagList("SkinOverlayData",10).removeTag(i);
|
||||
}
|
||||
}
|
||||
data.setTag("SkinOverlayData",player.getEntityData().getTagList("SkinOverlayData",10));
|
||||
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.CLIENT_UPDATE_SKIN_OVERLAYS, data);
|
||||
}
|
||||
}
|
||||
|
||||
public IQuest[] getFinishedQuests() {
|
||||
|
||||
Reference in new issue
Block a user