MarkData to NPCs [1.12 Backport]

This commit is contained in:
Kam committed 2024-02-21 03:02:39 -05:00
1 parent 7f2a375323
commit 8ec795c98a
22 files changed
+473 -17

No files matched your search

@@ -23,6 +23,7 @@ import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumGuiType;
@@ -40,6 +41,7 @@ import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptSound;
import noppes.npcs.scripted.event.DialogEvent;
import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
@@ -862,6 +864,18 @@ public class NoppesUtilServer {
return null;
}
public static Entity getEntityFromUUID(World world, UUID uuid) {
for (Object obj : world.loadedEntityList) {
if (obj instanceof Entity) {
Entity entity = (Entity) obj;
if (entity.getUniqueID().equals(uuid)) {
return entity;
}
}
}
return null;
}
static public EntityPlayer getPlayerByName(String playername){
return MinecraftServer.getServer().getConfigurationManager().func_152612_a(playername);
}
@@ -3,6 +3,9 @@ package noppes.npcs;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemEditableBook;
@@ -25,9 +28,10 @@ import noppes.npcs.roles.RoleCompanion;
import java.io.IOException;
import java.util.Iterator;
import java.util.UUID;
public class PacketHandlerPlayer{
@SubscribeEvent
public void onServerPacket(ServerCustomPacketEvent event) {
EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity;
@@ -40,7 +44,17 @@ public class PacketHandlerPlayer{
}
private void player(ByteBuf buffer, EntityPlayerMP player, EnumPlayerPacket type) throws IOException {
if(type == EnumPlayerPacket.CompanionTalentExp){
if(type == EnumPlayerPacket.MarkData){
String uuid = Server.readString(buffer);
if(uuid == null)
return;
Entity entity = NoppesUtilServer.getEntityFromUUID(player.worldObj, UUID.fromString(uuid));
if(!(entity instanceof EntityNPCInterface))
return;
MarkData data = MarkData.get((EntityNPCInterface) entity);
}
else if(type == EnumPlayerPacket.CompanionTalentExp){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
return;
@@ -202,7 +216,7 @@ public class PacketHandlerPlayer{
long time = buffer.readLong();
String username = Server.readString(buffer);
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Iterator<PlayerMail> it = data.playermail.iterator();
while(it.hasNext()){
PlayerMail mail = it.next();
@@ -220,7 +234,7 @@ public class PacketHandlerPlayer{
NoppesUtilServer.sendGuiError(player, 0);
return;
}
PlayerMail mail = new PlayerMail();
//String s = player.func_145748_c_().getFormattedText();
String s = player.getDisplayName();
@@ -235,7 +249,7 @@ public class PacketHandlerPlayer{
return;
}
PlayerDataController.Instance.addPlayerMessage(username, mail);
NBTTagCompound comp = new NBTTagCompound();
comp.setString("username", username);
NoppesUtilServer.sendGuiClose(player, 1,comp);
@@ -245,7 +259,7 @@ public class PacketHandlerPlayer{
String username = Server.readString(buffer);
player.closeContainer();
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Iterator<PlayerMail> it = data.playermail.iterator();
while(it.hasNext()){
PlayerMail mail = it.next();
@@ -260,7 +274,7 @@ public class PacketHandlerPlayer{
long time = buffer.readLong();
String username = Server.readString(buffer);
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Iterator<PlayerMail> it = data.playermail.iterator();
while(it.hasNext()){
PlayerMail mail = it.next();
@@ -1000,6 +1000,11 @@ public class PacketHandlerServer{
npc.updateAI = true;
npc.updateClient = true;
}
else if(type == EnumPacketServer.MainmenuAdvancedMarkData){
MarkData data = MarkData.get(npc);
data.setNBT(Server.readNBT(buffer));
data.syncClients();
}
else if(type == EnumPacketServer.JobSave){
NBTTagCompound original = npc.jobInterface.writeToNBT(new NBTTagCompound());
NBTTagCompound compound = Server.readNBT(buffer);
@@ -403,4 +403,15 @@ public class ServerEventsHandler {
public void populateChunk(PopulateChunkEvent.Post event){
NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand);
}
@SubscribeEvent
public void playerTracking(PlayerEvent.StartTracking event){
if(!(event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote)
return;
MarkData data = MarkData.get((EntityNPCInterface) event.target);
if(data.marks.isEmpty())
return;
Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT());
}
}
@@ -15,11 +15,14 @@ import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.renderer.MarkRenderer;
import noppes.npcs.client.renderer.RenderCNPCPlayer;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.MarkType;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.entity.EntityNPCInterface;
import java.lang.reflect.Field;
@@ -93,6 +96,16 @@ public class ClientEventHandler {
AnimationData data = null;
if (event.entity instanceof EntityNPCInterface) {
data = ClientEventHandler.renderingNpc.display.animationData;
MarkData markData = MarkData.get((EntityNPCInterface) event.entity);
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
for(MarkData.Mark m : markData.marks){
if(m.getType() != MarkType.NONE && m.availability.isAvailable(player)){
MarkRenderer.render(event.entity, event.x, event.y, event.z, m);
break;
}
}
} else if (event.entity instanceof EntityPlayer) {
if (ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) {
data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID());
@@ -118,6 +131,7 @@ public class ClientEventHandler {
animation.increaseTime();
}
}
ClientEventHandler.renderingNpc = null;
}
@@ -8,6 +8,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.achievement.GuiAchievement;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@@ -35,6 +36,7 @@ import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.controllers.data.RecipeCarpentry;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.entity.EntityNPCInterface;
@@ -103,6 +105,13 @@ public class PacketHandlerClient extends PacketHandlerServer{
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.MARK_DATA){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(!(entity instanceof EntityNPCInterface))
return;
MarkData data = MarkData.get((EntityNPCInterface) entity);
data.setNBT(Server.readNBT(buffer));
}
else if(type == EnumPacketClient.DIALOG){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
@@ -0,0 +1,84 @@
package noppes.npcs.client.gui.advanced;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.SubGuiColorSelector;
import noppes.npcs.client.gui.SubGuiNpcAvailability;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.constants.MarkType;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.entity.EntityNPCInterface;
public class GuiNPCMarks extends GuiNPCInterface2 implements ISubGuiListener {
private final String[] marks = new String[]{"gui.none", "mark.question", "mark.exclamation", "mark.pointer", "mark.skull", "mark.cross", "mark.star"};
private MarkData data;
private MarkData.Mark selectedMark;
public GuiNPCMarks(EntityNPCInterface npc){
super(npc);
this.data = MarkData.get(npc);
}
@Override
public void initGui(){
super.initGui();
int y = guiTop + 14;
for(int i = 0; i < data.marks.size(); i++){
MarkData.Mark mark = data.marks.get(i);
this.addButton(new GuiButtonBiDirectional(1 + i * 10, guiLeft + 6, y, 120, 20, marks, mark.type));
String color = Integer.toHexString(mark.color);
while(color.length() < 6)
color = "0" + color;
addButton(new GuiNpcButton(2 + i * 10, guiLeft + 128, y, 60, 20, color));
getButton(2 + i * 10).setTextColor(mark.color);
this.addButton(new GuiNpcButton(3 + i * 10, guiLeft + 190, y, 120, 20, "availability.options"));
this.addButton(new GuiNpcButton(4 + i * 10, guiLeft + 312, y, 40, 20, "X"));
y += 22;
}
if(data.marks.size() < 9){
this.addButton(new GuiNpcButton(101 , guiLeft + 6, y + 2, 60, 20, "gui.add"));
}
}
@Override
public void buttonEvent(GuiButton button){
if(button.id < 90){
selectedMark = data.marks.get(button.id / 10);
if(button.id % 10 == 1){
selectedMark.type = ((GuiNpcButton)button).getValue();
}
if(button.id % 10 == 2){
this.setSubGui(new SubGuiColorSelector(selectedMark.color));
}
if(button.id % 10 == 3){
setSubGui(new SubGuiNpcAvailability(selectedMark.availability));
}
if(button.id % 10 == 4){
data.marks.remove(selectedMark);
initGui();
}
}
if(button.id == 101){
data.addMark(MarkType.NONE);
initGui();
}
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if(subgui instanceof SubGuiColorSelector){
selectedMark.color = ((SubGuiColorSelector)subgui).color;
initGui();
}
}
@Override
public void save() {
Client.sendData(EnumPacketServer.MainmenuAdvancedMarkData, data.getNBT());
}
}
@@ -45,7 +45,9 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
this.addButton(new GuiNpcButton(12, guiLeft + 85, y += gap, 214, 20, "advanced.night"));
this.addButton(new GuiNpcButton(13, guiLeft + 85, y += gap, 214, 20, "global.linked"));
this.addButton(new GuiNpcButton(14, guiLeft + 85, y += gap, 214, 20, "menu.tags"));
// FIX THIS KAM
this.addButton(new GuiNpcButton(15, guiLeft + 208, y, 190, 20, "advanced.marks"));
}
@Override
@@ -68,7 +70,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
if(button.id == 5){
hasChanges = true;
npc.advanced.setJob(button.getValue());
getButton(4).setEnabled(npc.advanced.job != EnumJobType.None && npc.advanced.job != EnumJobType.ChunkLoader);
}
if(button.id == 9){
@@ -99,6 +101,10 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
save();
NoppesUtil.openGUI(player, new GuiNPCTagSetup(npc));
}
if(button.id == 15){
save();
NoppesUtil.openGUI(player, new GuiNPCMarks(npc));
}
}
@Override
@@ -106,7 +112,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
if(compound.hasKey("RoleData")){
if(npc.roleInterface != null)
npc.roleInterface.readFromNBT(compound);
if(npc.advanced.role == EnumRoleType.Trader)
NoppesUtil.requestOpenGUI(EnumGuiType.SetupTrader);
else if(npc.advanced.role == EnumRoleType.Follower)
@@ -121,7 +127,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
else if(compound.hasKey("JobData")){
if(npc.jobInterface != null)
npc.jobInterface.readFromNBT(compound);
if(npc.advanced.job == EnumJobType.Bard)
NoppesUtil.openGUI(player, new GuiNpcBard(npc));
else if(npc.advanced.job == EnumJobType.Healer)
@@ -142,7 +148,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
initGui();
}
}
@Override
public void save() {
if(hasChanges){
@@ -150,6 +156,6 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
hasChanges = false;
}
}
}
@@ -88,4 +88,81 @@ public class Model2DRenderer extends ModelRenderer {
GL11.glEndList();
this.compiledModel = true;
}
public static void renderItemIn2D(float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, int p_78439_5_, int p_78439_6_, float p_78439_7_) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, p_78439_1_, p_78439_4_);
tessellator.addVertexWithUV(1.0D, 0.0D, 0.0D, p_78439_3_, p_78439_4_);
tessellator.addVertexWithUV(1.0D, 1.0D, 0.0D, p_78439_3_, p_78439_2_);
tessellator.addVertexWithUV(0.0D, 1.0D, 0.0D, p_78439_1_, p_78439_2_);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1.0F);
tessellator.addVertexWithUV(0.0D, 1.0D, 0.0F - p_78439_7_, p_78439_1_, p_78439_2_);
tessellator.addVertexWithUV(1.0D, 1.0D, 0.0F - p_78439_7_, p_78439_3_, p_78439_2_);
tessellator.addVertexWithUV(1.0D, 0.0D, 0.0F - p_78439_7_, p_78439_3_, p_78439_4_);
tessellator.addVertexWithUV(0.0D, 0.0D, 0.0F - p_78439_7_, p_78439_1_, p_78439_4_);
tessellator.draw();
float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float) p_78439_5_;
float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float) p_78439_6_;
tessellator.startDrawingQuads();
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
for (int k = 0; k < p_78439_5_; ++k) {
float f7 = (float) k / (float) p_78439_5_;
float f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5;
tessellator.addVertexWithUV(f7, 0.0D, 0.0F - p_78439_7_, f8, p_78439_4_);
tessellator.addVertexWithUV(f7, 0.0D, 0.0D, f8, p_78439_4_);
tessellator.addVertexWithUV(f7, 1.0D, 0.0D, f8, p_78439_2_);
tessellator.addVertexWithUV(f7, 1.0D, 0.0F - p_78439_7_, f8, p_78439_2_);
}
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
for (int k = 0; k < p_78439_5_; ++k) {
float f7 = (float) k / (float) p_78439_5_;
float f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5;
float f9 = f7 + 1.0F / (float) p_78439_5_;
tessellator.addVertexWithUV(f9, 1.0D, 0.0F - p_78439_7_, f8, p_78439_2_);
tessellator.addVertexWithUV(f9, 1.0D, 0.0D, f8, p_78439_2_);
tessellator.addVertexWithUV(f9, 0.0D, 0.0D, f8, p_78439_4_);
tessellator.addVertexWithUV(f9, 0.0D, 0.0F - p_78439_7_, f8, p_78439_4_);
}
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
for (int k = 0; k < p_78439_6_; ++k) {
float f7 = (float) k / (float) p_78439_6_;
float f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6;
float f9 = f7 + 1.0F / (float) p_78439_6_;
tessellator.addVertexWithUV(0.0D, f9, 0.0D, p_78439_1_, f8);
tessellator.addVertexWithUV(1.0D, f9, 0.0D, p_78439_3_, f8);
tessellator.addVertexWithUV(1.0D, f9, 0.0F - p_78439_7_, p_78439_3_, f8);
tessellator.addVertexWithUV(0.0D, f9, 0.0F - p_78439_7_, p_78439_1_, f8);
}
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1.0F, 0.0F);
for (int k = 0; k < p_78439_6_; ++k) {
float f7 = (float) k / (float) p_78439_6_;
float f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6;
tessellator.addVertexWithUV(1.0D, f7, 0.0D, p_78439_3_, f8);
tessellator.addVertexWithUV(0.0D, f7, 0.0D, p_78439_1_, f8);
tessellator.addVertexWithUV(0.0D, f7, 0.0F - p_78439_7_, p_78439_1_, f8);
tessellator.addVertexWithUV(1.0D, f7, 0.0F - p_78439_7_, p_78439_3_, f8);
}
tessellator.draw();
}
}
@@ -0,0 +1,59 @@
package noppes.npcs.client.renderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.model.util.Model2DRenderer;
import noppes.npcs.constants.MarkType;
import noppes.npcs.controllers.data.MarkData;
import org.lwjgl.opengl.GL11;
public class MarkRenderer {
public static ResourceLocation markExclamation = new ResourceLocation("customnpcs", "textures/marks/exclamation.png");
public static ResourceLocation markQuestion = new ResourceLocation("customnpcs", "textures/marks/question.png");
public static ResourceLocation markPointer = new ResourceLocation("customnpcs", "textures/marks/pointer.png");
public static ResourceLocation markCross = new ResourceLocation("customnpcs", "textures/marks/cross.png");
public static ResourceLocation markSkull = new ResourceLocation("customnpcs", "textures/marks/skull.png");
public static ResourceLocation markStar = new ResourceLocation("customnpcs", "textures/marks/star.png");
public static int displayList = -1;
public static void render(EntityLivingBase entity, double x, double y, double z, MarkData.Mark mark){
GL11.glPushMatrix();
int color = mark.color;
float red = (float)(color >> 16 & 255) / 255.0F;
float blue = (float)(color >> 8 & 255) / 255.0F;
float green = (float)(color & 255) / 255.0F;
GL11.glColor4f(red, blue, green, 1);
GL11.glTranslatef((float) x, (float) (y + entity.height + 0.6), (float) z);
GL11.glRotatef(-entity.rotationYawHead, 0, 1, 0);
if(mark.type == MarkType.EXCLAMATION)
Minecraft.getMinecraft().getTextureManager().bindTexture(markExclamation);
else if(mark.type == MarkType.QUESTION)
Minecraft.getMinecraft().getTextureManager().bindTexture(markQuestion);
else if(mark.type == MarkType.POINTER)
Minecraft.getMinecraft().getTextureManager().bindTexture(markPointer);
else if(mark.type == MarkType.CROSS)
Minecraft.getMinecraft().getTextureManager().bindTexture(markCross);
else if(mark.type == MarkType.SKULL)
Minecraft.getMinecraft().getTextureManager().bindTexture(markSkull);
else if(mark.type == MarkType.STAR)
Minecraft.getMinecraft().getTextureManager().bindTexture(markStar);
if(displayList >= 0){
GL11.glCallList(displayList);
}
else{
displayList = GLAllocation.generateDisplayLists(1);
GL11.glNewList(displayList, GL11.GL_COMPILE);
GL11.glTranslatef((float) -0.5, 0, 0);
Model2DRenderer.renderItemIn2D(0f, 0f, 1f, 1f, 32, 32, 0.0625F);
GL11.glEndList();
}
GL11.glPopMatrix();
}
}
@@ -53,5 +53,6 @@ public enum EnumPacketClient {
PAUSE_SOUNDS,
CONTINUE_SOUNDS,
STOP_SOUNDS,
SYNC_WEAPON
SYNC_WEAPON,
MARK_DATA
}
@@ -20,7 +20,7 @@ public enum EnumPacketServer {
MainmenuDisplaySave(CustomNpcsPermissions.NPC_DISPLAY, true), MainmenuDisplayGet(true),
ModelDataSave(CustomNpcsPermissions.NPC_DISPLAY, true),
MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true),
MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true), MainmenuAdvancedMarkData(CustomNpcsPermissions.NPC_ADVANCED,true),
DialogNpcSet(CustomNpcsPermissions.NPC_ADVANCED),
DialogNpcRemove(CustomNpcsPermissions.NPC_ADVANCED, true),
FactionSet(CustomNpcsPermissions.NPC_ADVANCED, true),
@@ -1,5 +1,9 @@
package noppes.npcs.constants;
public enum EnumPlayerPacket {
FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, MouseClicked, CompanionTalentExp, ScreenSize
FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade,
Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet,
MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail,
SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed,
MouseClicked, CompanionTalentExp, ScreenSize, MarkData
}
@@ -0,0 +1,11 @@
package noppes.npcs.constants;
public class MarkType {
public static final int NONE = 0;
public static final int QUESTION = 1;
public static final int EXCLAMATION = 2;
public static final int POINTER = 3;
public static final int SKULL = 4;
public static final int CROSS = 5;
public static final int STAR = 6;
}
@@ -0,0 +1,147 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import noppes.npcs.Server;
import noppes.npcs.api.entity.data.IMark;
import noppes.npcs.api.handler.data.IAvailability;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.MarkType;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.List;
public class MarkData implements IExtendedEntityProperties {
private static final String CNPCMARK = "cnpcmark";
private EntityLivingBase entity;
public List<Mark> marks = new ArrayList<Mark>();
public void setNBT(NBTTagCompound compound){
List<Mark> marks = new ArrayList<Mark>();
NBTTagList list = compound.getTagList("marks", 10);
for(int i = 0; i < list.tagCount(); i++){
NBTTagCompound c = list.getCompoundTagAt(i);
Mark m = new Mark();
m.type = c.getInteger("type");
m.color = c.getInteger("color");
m.availability.readFromNBT(c.getCompoundTag("availability"));
marks.add(m);
}
this.marks = marks;
}
public NBTTagCompound getNBT() {
NBTTagCompound compound = new NBTTagCompound();
NBTTagList list = new NBTTagList();
for(Mark m : marks){
NBTTagCompound c = new NBTTagCompound();
c.setInteger("type", m.type);
c.setInteger("color", m.color);
c.setTag("availability", m.availability.writeToNBT(new NBTTagCompound()));
list.appendTag(c);
}
compound.setTag("marks", list);
return compound;
}
public static boolean has(EntityLivingBase entity) {
return entity.getExtendedProperties(CNPCMARK) != null;
}
public static MarkData get(EntityNPCInterface npc){
if(!MarkData.has(npc)){
npc.registerExtendedProperties(CNPCMARK, new MarkData());
}
MarkData data = (MarkData) npc.getExtendedProperties(CNPCMARK);
if(data.entity == null){
data.entity = npc;
data.setNBT(npc.getEntityData().getCompoundTag(CNPCMARK));
}
return data;
}
public IMark addMark(int type) {
Mark m = new Mark();
m.type = type;
marks.add(m);
if (!entity.worldObj.isRemote)
syncClients();
return m;
}
public IMark addMark(int type, int color) {
Mark m = new Mark();
m.type = type;
m.color = color;
marks.add(m);
if (!entity.worldObj.isRemote)
syncClients();
return m;
}
@Override
public void saveNBTData(NBTTagCompound compound) {
if (!(this.entity instanceof EntityNPCInterface)) {
return;
}
this.entity.getEntityData().setTag(CNPCMARK, this.getNBT());
}
@Override
public void loadNBTData(NBTTagCompound compound) {}
@Override
public void init(Entity entity, World world) {}
public void syncClients() {
Server.sendToAll(EnumPacketClient.MARK_DATA, entity.getEntityId(), getNBT());
}
public class Mark implements IMark {
public int type = MarkType.NONE;
public Availability availability = new Availability();
public int color = 0xFFED51;
@Override
public IAvailability getAvailability() {
return availability;
}
@Override
public int getColor() {
return color;
}
@Override
public void setColor(int color) {
this.color = color;
}
@Override
public int getType() {
return type;
}
@Override
public void setType(int type) {
this.type = type;
}
@Override
public void update() {
MarkData.this.syncClients();
}
}
}