Posted June 9, 201411 yr Heyho Guys! I created a Entity which actually only spawns particles to show that its there (going to add a function soon), but it is not saved. I registered it like this: EntityRegistry.registerModEntity(EntityMagic.class, "magic_entity", EntityRegistry.findGlobalUniqueEntityId(), Main.instance, 128, 1, true); I already tried to replace EntityRegistry.findGlobalUniqueEntityId() with a constant value (0) but with no effect. The entity is configured in a way that it automatically mounts its owner in order to stay at the same place with him. Maybe I'll change this later too. What I'm wondering about is that the entity isn't shown in the list of summonable objects. Entity class: package com.bedrockminer.magicum.entity.magic; import java.util.List; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import com.bedrockminer.magicum.Main; import com.bedrockminer.magicum.client.particle.ParticleEffect; import com.bedrockminer.magicum.element.ElementNBTHelper; import com.bedrockminer.magicum.element.Elements; public class EntityMagic extends Entity { public List<Elements> elements; public EntityMagic(World world) { super(world); } public EntityMagic(World world, EntityLivingBase owner) { this(world); this.mountEntity(owner); } public EntityMagic setElements(List<Elements> elements) { this.elements = elements; return this; } @Override protected void entityInit() { } @Override protected void readEntityFromNBT(NBTTagCompound comp) { this.elements = ElementNBTHelper.loadElementList(comp, "elements"); } @Override protected void writeEntityToNBT(NBTTagCompound comp) { ElementNBTHelper.saveElementList(comp, "elements", this.elements); Main.log("saved"); //NEVER CALLED! } @Override public double getYOffset() { //PLAN: Make this one entity sensitive (use entities getMounted..offset) if (this.ridingEntity != null) return -1.75F; return super.getYOffset(); } @Override public void onEntityUpdate() { super.onEntityUpdate(); ParticleEffect.spawnElementParticle(Elements.Bio, this.posX, this.posY, this.posZ, 0.1F, 0.0F, 0.0F); } } http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr Author I think the problem is because of the riding. Is there another way to save a special player in a way that you can load it later? How would I do this? http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr From my interpretation, it sound like you are wanting to extend the player? If so and if not, have you looked into IExtendedEntityProperties (something like that. maybe its aiEntityExtendedProperties. Check for those and stuff similar). We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author No, actually I don't want to extend the player (I did this before ) but I want to create an entity which can be controlled by the player: It should point anywhere a player (its owner) looks. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr So that would involve getting the direction the player is looking etc. I trust you have got that bit sorted then so what exactly is the problem? Just the saving? Is it NBT stuff then? We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author The problem is: If I make the entity riding the player, it is not saved. If I just place it in the world it is saved. I thought about another method, namely saving the player's uuid (or EntityID?) to get the player object if its loaded again; then the entity doesn't have to ride the player, but I don't know how to do this exactly. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr So yes, you do want to have an IExtendedEntityProperties. In this, have a variable equal to the entity that is riding the player. That way, when the player is initialized you can add the entity back on again. I think. So.ething along those lines anyway... 'tis an interesting problem We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author Sounds logical to me. But how do I save the Entity in the ExtendedProperties? With the UUID? With the EntityID? Or another way? http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr That seems to be the question doesn't it. Not being near my testing environment, I can't try much. But it seems you may have to store all the entities data that you need into the extended properties and then when the player constructs, add a new entity with all the stored data... Probably an easier way, but try that to start with? We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author You mean I shouldn't save the entity in the world but instead in the extended properties? http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr Sort of. If the entity is riding the player - save via extended properties. If the entity is in the world - save it in the world. Does that make sense? Don't stop researching because you have this way to do it. There is most definitely a better way. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author OK, basically the saving process worked. @Override public void saveNBTData(NBTTagCompound compound) { if (this.activeMagic != null) { NBTTagCompound nbt = new NBTTagCompound(); this.activeMagic.writeToNBT(nbt); nbt.setString("id", EntityList.getEntityString(this.activeMagic)); compound.setTag("activeMagic", nbt); } } @Override public void loadNBTData(NBTTagCompound compound) { if (compound.hasKey("activeMagic")) { NBTTagCompound nbt = compound.getCompoundTag("activeMagic"); Entity e = EntityList.createEntityFromNBT(nbt, this.thePlayer.worldObj); this.thePlayer.worldObj.spawnEntityInWorld(e); } } But now I'm wondering how I can disable the saving of the entity in the world if its saved by the ExtendedProperties. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr Didn't you say the entity wasn't being saved in the world if it was riding the player anyway? If that's the case, problem solved We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author Ok, my mistake. I thought about completely replacing the riding with the extended properties. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr Interesting this popped up actually. It will come in handy for my current project. Thank you for this. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author But actually I don't think it's useful if you do it with the riding because it would destroy any other riding entities which are maybe added by other mods. Can't I just disable the normal saving and only use the one in the ExtProps? Or can I save a reference to the corresponding player in the entity itself and save it the normal way? I think this would be better. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr Yes, that is another possibility. And yes, that does seem easier. Give it a try and tell me what happens We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 10, 201411 yr Author OK, new problem: I can get a persistant UUID from a entity but I don't know how to get the entity from its UUID. @Override protected void readEntityFromNBT(NBTTagCompound comp) { if (comp.hasKey("ownerMost") && comp.hasKey("ownerLeast")) { UUID id = new UUID(comp.getLong("ownerMost"), comp.getLong("ownerLeast")); //Got the UUID; but now..? } } @Override protected void writeEntityToNBT(NBTTagCompound comp) { Main.log("uuid:" + this.owner.getPersistentID().toString()); comp.setLong("ownerMost", this.owner.getPersistentID().getMostSignificantBits()); comp.setLong("ownerLeast", this.owner.getPersistentID().getLeastSignificantBits()); } http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr I'm not sure from reading this, excactly what you are doing. If you really want a seperate entity, just set it to have no BB and each tick, have it set its position to yoru target player. Teleporting is goign to be a bit painfull. If you could describe why you want this, it would make it easier to offer you alternatives or help. Long time Bukkit & Forge Programmer Happy to try and help
June 10, 201411 yr Author I want to make a kind of a flamethrower where the player is constantly firing entities in his viewing direction which cause damage and ignite the hit entities. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr I'm going to suggest you do not use an Entity for that. In your mod, create a class to track players and wehther they ahve this ability or not. Setup a tickhandler to fire a routine in the class on whatever frequency you like. Then with that routine, fire your flamethrower effect. If you need to save the data as to whether a player should ahve the effect or not have the effect, just use the player's NBT data. You can either check on player login if they should be added to the list or check on some frequency all the players and see if your list is accurate. Long time Bukkit & Forge Programmer Happy to try and help
June 10, 201411 yr Author Sound quite logical, although I have no Idea how to create the Player tracker. Is this just a kind of extendedProperties? http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
June 10, 201411 yr Your PlayerTracker is just a class. In it you would have a list of players 'List<Players>' that would be the ones of interest. In your main class set up a reference to the Playertrack and initialize it so you can find it later. // In the top declare variables public PlayerTracker playertracker; // In your init section playertracker = new PlayerTracker(); Then from your tick method, you can alwasy get to it with instance.PlayerTracker.onTick (where instance is your mod). Inside playertracker have the method 'public void onTick()' In it, check to see if someone should be added or removed from list of players. Also execute your flame code for those in it. If you need to know how to cycle through players logged in // Get all players List players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; // cycle through list for (int i = 0; i < players.size(); i++) { } Long time Bukkit & Forge Programmer Happy to try and help
June 10, 201411 yr Author Thanks! I think I can work with this! http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
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.