Jump to content

Recommended Posts

Posted

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);
}
}

Posted

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.

Posted

So that would involve getting the direction the player is looking etc. I trust you have got that bit sorted then :P 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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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());
}

Posted

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

Posted

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

Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.