Jump to content

Entity is not saved


Bedrock_Miner

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! My friends and I were attempting to add a few extra mods to the Create Chronicles modpack, and all was well until people started crashing when they opened their inventories. Any help finding the culprit would be MUCH appreciated, I've been scratching my head for the past few days on what went wrong. https://paste.ee/p/8pajP
    • >>>KLIK LOGIN DISINI SAYANG<<< >>>KLIK DAFTAR DISINI SAYANG<<< Pendahuluan Dalam dunia perjudian online, slot menjadi salah satu permainan yang paling diminati. Dengan munculnya berbagai platform, Togel2Win hadir sebagai salah satu pilihan menarik, terutama dengan fitur anti rungkad yang dijanjikan. Artikel ini akan membahas tentang Togel2Win, keunggulan slot terbaru, dan bagaimana server Thailand berperan dalam meningkatkan pengalaman bermain. Apa Itu Togel2Win? Togel2Win adalah platform permainan yang menawarkan berbagai jenis permainan, termasuk slot dan togel. Dengan antarmuka yang ramah pengguna dan beragam pilihan permainan, situs ini bertujuan untuk memberikan pengalaman bermain yang menyenangkan dan menguntungkan bagi para pemain. Keunggulan Slot Togel2Win Fitur Anti Rungkad: Salah satu keunggulan utama dari Togel2Win adalah fitur anti rungkad yang dirancang untuk mengurangi kemungkinan gangguan saat bermain. Ini memastikan bahwa pemain dapat menikmati permainan tanpa gangguan teknis, meningkatkan kenyamanan dan fokus. Beragam Pilihan Slot: Togel2Win menawarkan berbagai jenis slot, dari yang klasik hingga yang modern dengan grafis menawan dan tema yang menarik. Ini memberikan variasi yang cukup bagi pemain untuk menemukan permainan yang sesuai dengan preferensi mereka. Server Thailand yang Stabil: Server yang berlokasi di Thailand memberikan koneksi yang cepat dan stabil. Ini sangat penting untuk pengalaman bermain yang lancar, terutama saat bermain slot yang memerlukan respons cepat. Bonus dan Promosi Menarik: Togel2Win sering menawarkan bonus dan promosi yang menarik untuk menarik pemain baru dan mempertahankan loyalitas pemain yang sudah ada. Ini bisa berupa bonus deposit, putaran gratis, atau program loyalitas. Tips untuk Pemain Slot di Togel2Win Pilih Slot dengan RTP Tinggi: Sebelum memulai permainan, pastikan untuk memilih slot dengan tingkat pengembalian pemain (RTP) yang tinggi untuk meningkatkan peluang menang. Kelola Anggaran: Tentukan batasan anggaran sebelum bermain dan patuhi itu. Ini membantu mencegah kerugian besar dan menjaga pengalaman bermain tetap menyenangkan. Manfaatkan Bonus: Jangan ragu untuk memanfaatkan bonus dan promosi yang ditawarkan. Ini bisa memberikan tambahan modal untuk bermain lebih lama. Kesimpulan Togel2Win merupakan pilihan menarik bagi para penggemar slot, terutama dengan fitur anti rungkad dan server yang stabil. Dengan berbagai pilihan permainan dan bonus yang menggiurkan, Togel2Win siap memberikan pengalaman bermain yang tak terlupakan. Jika Anda mencari platform slot yang andal dan menyenangkan, Togel2Win bisa menjadi solusi yang tepat.
    • I'm trying to make my own modpack, but sometimes, in certain areas of the world, the game just says "server closed". Minecraft doesn't close, it just returns to the menu. When I tried to figure it out on my own and understand the logs, I didn't understand anything (English is not my native language, so it's difficult for me). I've been trying to solve the problem for the third month. So I ask if anyone is good at this and it's not difficult for you, to help me with this. If you need details, ask. I'll describe everything. What it looks like Logs
  • Topics

×
×
  • Create New...

Important Information

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