Posted May 23, 201510 yr Hi everyone, So I want to set up a dynamic link between a series of entities and the player so that the player has each spawned entities position data (that updates dynamically as the entity moves) and all of the entities properties also. I have a player that has the NBT data for a party of entities. This player can use the data that is stores in his IEEP to spawn these entities at will and can despawn them/update the NBT that is saved to the IEEP also. I now want to establish a link dynamic link between the player and the entity that is spawned in the world so that the player has stuff like the position and all properties of the entity at all times during which the entity is spawned in the world. How would you go about doing this? any ideas? Also as a side question, should I update to 1.8 or is it a pain, I understand that rendering changed like crazy and from what ive been reading a lot is a pain to fix but is it worth it? As always any input is greatly appreciated
May 23, 201510 yr Author This is my working party class where I store my entity data for the party members that the player has acquired. I want to somehow establish a dynamic link between the entities that the player spawns into the world and the player himself so that the player knows the position of each entity and their stats etc etc... I was wondering how would be a good way to go about doing this. Any ideas? FYI atm I use a pretty bad method to check whether or not each entity is spawned in the world using arrays (and im trying to come up with a better method for determining if a party member is spawned in the world or not but for now the one I have seems to work). I use an int array that sets the value of the array slot to my party NBT[] slot # when the mob is spawned and resets it to -1 when the mob is not spawned, I then get the mobs NBT from the value of the slots spawnedSelectedSlot[]), but if I create a dynamic link between the entities and the NBT data that is saved here then I wont have to use the inefficient system i dont think). public class PlayerParty implements IExtendedEntityProperties { protected EntityPlayer entityPlayer; protected EntityPlayer ownerName; public static final int NUM_SLOTS = 6; public int currentSelectedSlot = 0; //default slot is the first slot public int[] spawnedSelectedSlot = new int[6]; public boolean partyFull = false; // Used in EventTryToAddMobToParty in the tryToAddMobToParty it allows for one to get a spawnegg item if party is full that contains the mob private static final String EXTENDED_ENTITY_PROPERTIES_TAGNAME = "PlayerParty"; protected NBTTagCompound[] customMobPartyNbt = new NBTTagCompound[NUM_SLOTS]; public PlayerParty(EntityPlayer player) { this.entityPlayer = player; spawnedSelectedSlot[0] = -1; //A value of -1 should mean that the mob in slot 0 is not spawned spawnedSelectedSlot[1] = -1; spawnedSelectedSlot[2] = -1; spawnedSelectedSlot[3] = -1; spawnedSelectedSlot[4] = -1; spawnedSelectedSlot[5] = -1; } //sets the customMob in the specified slot. Stores only the NBT data, which is enough to recreate the customMob later. // doesnt seem to be explicitly called but without it customMob dont go into the party public void setCustomMob(int slot, EntityCustomMob customMob, NBTTagCompound caughtTag){ NBTTagCompound compound = new NBTTagCompound(); customMob.writeToNBT(compound); customMobPartyNbt[slot] = compound; } public void setCustomMobInSlot(int slot, NBTTagCompound customMob, int mobID, String ownerName){ customMobPartyNbt[slot] = customMob; //the NBTTagCompound that is being passed here from tryToAddMobToParty() method inside EventTryToAddMobToParty class doesnt have a key ie (customMob.hasKey("caughtCustomMob") = false) here dunno y but we need it to be true customMobPartyNbt[slot].setInteger("MobID", mobID); System.out.println("ownerName "+ ownerName); customMobPartyNbt[slot].setString("ownerName", ownerName); } public void setSelectedSlot(int slot){ currentSelectedSlot = slot; } public int getSelectedSlot(){ return currentSelectedSlot; } public int getSpawnedSlot(){ for(int i = 0; i < NUM_SLOTS; i++){ if(this.spawnedSelectedSlot[i] !=-1) return i; } return -1; } //returns true if the player has a free party slot public boolean hasFreeSlot(){ return (this.getNextFreeSlot() >= 0); } //gets the first free slot in the player's party. The NBT tag compound that slot position should //be null. public int getNextFreeSlot(){ for(int i = 0; i < NUM_SLOTS; i++){ if(this.customMobPartyNbt[i] == null) return i; } return -1; } public int getNextFullSlot(){ for(int i = 0; i < NUM_SLOTS; i++){ if(this.customMobPartyNbt[i] != null) return i; } return -1; } public NBTTagCompound getCustomMobNBTFromSlot(int slot){ return customMobPartyNbt[slot]; } public void swapCustomMobn(int slotOne, int slotTwo, boolean wasPressed){ if(slotOne != -1 && slotTwo!=-1){ NBTTagCompound tempSlot = customMobPartyNbt[slotOne]; customMobPartyNbt[slotOne] = customMobPartyNbt[slotTwo]; customMobPartyNbt[slotTwo] = tempSlot; } } /** * Used to register these extended properties for the player during EntityConstructing event */ public static final void register(EntityPlayer player) { player.registerExtendedProperties(EXTENDED_ENTITY_PROPERTIES_TAGNAME, new PlayerParty(player)); } /** * Copies additional player data from the given BattleMobExtendedPlayerHelper instance * Avoids NBT disk I/O overhead when cloning a player after respawn */ public void copy(PlayerParty properties) { customMobPartyNbt = properties.customMobPartyNbt.clone(); } /** * Returns BattleMobExtendedPlayerHelper properties for player */ public static final PlayerParty get(EntityPlayer player) { return (PlayerParty) player.getExtendedProperties(EXTENDED_ENTITY_PROPERTIES_TAGNAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); for(int i=0; i < NUM_SLOTS; i++){ if(customMobPartyNbt[i] != null){ properties.setTag("Slot"+ i, customMobPartyNbt[i]); } } compound.setTag(EXTENDED_ENTITY_PROPERTIES_TAGNAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXTENDED_ENTITY_PROPERTIES_TAGNAME); if(properties != null){ for(int i=0; i < NUM_SLOTS; i++){ if(properties.hasKey("Slot"+i)){ customMobPartyNbt[i] = properties.getCompoundTag("Slot"+i); } } } } public void updatePlayerPartyServerToClient(){ PacketOverlord.sendTo(new PacketSyncPlayerParty((EntityPlayer) entityPlayer),(EntityPlayerMP) entityPlayer); } @Override public void init(Entity entity, World world) { } }
May 23, 201510 yr Author I got this Idea from digging around to use the PlayerEvent.StartTracking event to establish the link between the entity and the player as long as both are tracking each other. Im not sure if this is the best approach but I think it should work, if I do the appropriate checks and get the exact entity I want then somehow send packets to update each about the others position and what not. @SubscribeEvent(priority=EventPriority.NORMAL) public void onTracking(PlayerEvent.StartTracking event) { //Establish the link here } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.