Jump to content

Recommended Posts

Posted

 

I got this in mi head

 

 

well not so in mi head alredy much of the code is done

 

i been creating mercenary entityes, you buy their loyalty whith gold

so they help you, follow you and, well at least not kill you 

 

soo i also make a radio item that is sopused (not finish yet) to be used to call the mercenaries, to set target entitys to kill, and to manage the mercernaries equipment

 

well the trouble comes when you close the game, the radio has a Mercenarys List

this entity list i can'not save it as nbt

ad if where posible the entityes are just references dont gonna works when reload the world

 

ArrayList<aldeanoMercenario00> mercenaryList = new ArrayList<aldeanoMercenario00>();

if the radio dont'n have the entitye list the it could not recall my mercenaryes

 

i made an ExtendedPropertieEntityLiving the mercenaryes save the value of "OwnerUUID"

String OwnerUUID = theEntitycompound.getString("OwnerUUID");

 

soo they are still loyal to me

but the radio dont works when reopen minecraft

 

i need a way to save the entityes to the radio item

an was tinking in the pokeball mod from grim3212

this pockeball item is capable of save not only vainilla but also moded entityes

 

i wanna know the idea of how this pockeball works, to see if i can adapt it to mi mercenary radio 

 

some one knows how goes the pockeball code ??

 

thanks for reading

is a little hard to espress complex ideas in english

Posted

e  nop 

the entityes are smart enough to use guns

but dumb to use the radio

 

the radio is an item in the player inventory to manage the mercenaryes

so it must be a list in the radio item of the mercenaries loyal to the player

so it could call and teleport this entities next to the player even those to far or in a unloaded chunck in the world

 

 

Posted

 

hey wait

there is alot of little troubles when i try to do that before.

 

- first of all the entityes continued existence is just an illusion, when you close the game everything dieded and disapear, when you reopen the minecraft it just create new entityes whith the data stored but this entityes has diferents uuid and id's values so you can'not just save entity uuid or id to the players data

it will point to other entityes of to nothing at all

 

- second i can take note of the vainilla entityes classes and save their data

soo if i have a sheep i can save this entity asigning a nunmber to the classes

per example  sheep is number 2    wolf is number 3

 

so if i wana save a sheep

int entiType = 2;

float entiHeal = 10f;

BlockPos entiPos = wever;

 

so later in the load i can say is entiType 2  so this must be a sheep and create a new sheep whith this healt  and pos values

 

but moded entityes clases how i could save a moded entity class to later recreate it

 

#####

 

Or there is and absolutly diferent an easy way to do this, an i not aware ??

 

 

for now this is mi actual IEEP saving some data and here is where sava and recreate the fantasmaMercenario Entity

 

 

 

package mercenarymod.entidades;

import java.util.UUID;

import mercenarymod.utilidades.util;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityGolem;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ExtendedPropertiesMercenary implements IExtendedEntityProperties {
public final static String extendedPropertiesName = "extendedFantasmaMercenario";
protected EntityLivingBase theEntity;
protected World theWorld;

@Override
public void saveNBTData(NBTTagCompound parCompound) {
	// DEBUG
	//System.out.println(("ExtendedProperties EntityLivingBase saveNBTData()"));

	// good idea to keep your extended properties in a sub-compound to
	// avoid conflicts with other possible extended properties,
	// even from other mods (like if a mod extends all EntityAnimal)

	if ( (theEntity instanceof EntityLivingBase) & !(theEntity instanceof fantasmaMercenario) )   {


		EntityLivingBase shootingEntity = (EntityLivingBase) theEntity;

		if (shootingEntity != null) {

			NBTTagCompound theEntitycompound = theEntity.getEntityData();


			boolean hasStS = theEntitycompound.getBoolean("hasStS"); //has something to save 

			if (hasStS)
			{
			System.out.println("hasStS=true");

			boolean hasGHOST = theEntitycompound.getBoolean("hasGHOST");
			boolean hasFULTON = theEntitycompound.getBoolean("hasFULTON");
			boolean hasC4 = theEntitycompound.getBoolean("hasC4");
			boolean hasRCbullet = theEntitycompound.getBoolean("hasRCbullet");

			int OwnerID = theEntitycompound.getInteger("OwnerID"); 
			String OwnerUUID = theEntitycompound.getString("OwnerUUID");

			int radioSerial = theEntitycompound.getInteger("radioSerial");
			int radioDialN = theEntitycompound.getInteger("radioDialN");

			System.out.println("hasGHOST="+hasGHOST+ theEntity.getName()+" pos="+theEntity.getPosition());


			NBTTagCompound compound = new NBTTagCompound();

                         // the entity has relevant data to save 
			compound.setBoolean("hasStS", true);

                         // the entity has a MercenaryGhost whatching over it 
			compound.setBoolean("hasGHOST", hasGHOST);

                        //the entity is atached to a fulton device WIP
			compound.setBoolean("hasFULTON", hasFULTON);

                        //the entity has atached to c4 WIP
			compound.setBoolean("hasC4", hasC4);

                        //the entity has been damage for redclub munition
			compound.setBoolean("hasRCbullet", hasRCbullet);

                        //the owner id of this entity
			compound.setInteger("OwnerID", OwnerID);

                        //the owner UUid of this entity				
			compound.setString("OwnerUUID", OwnerUUID);


			parCompound.setTag(extendedPropertiesName, compound); // set as sub-compound

			}

		}
	}
}

@Override
public void loadNBTData(NBTTagCompound parCompound)

{
	// DEBUG
	//System.out.println(("ExtendedPropertiesH EntityLivingBase loadNBTData()"));


	// Get the sub-compound
	NBTTagCompound compound = (NBTTagCompound) parCompound.getTag(extendedPropertiesName);

	if (compound != null) {

		NBTTagCompound theEntitycompound = theEntity.getEntityData();




		boolean hasStS = theEntitycompound.getBoolean("hasStS");

		boolean hasGHOST = theEntitycompound.getBoolean("hasGHOST");
		boolean hasFULTON = theEntitycompound.getBoolean("hasFULTON");
		boolean hasC4 = theEntitycompound.getBoolean("hasC4");
		boolean hasRCbullet = theEntitycompound.getBoolean("hasRCbullet");

		int OwnerID = theEntitycompound.getInteger("OwnerID"); 
		String OwnerUUID = theEntitycompound.getString("OwnerUUID");


		if ( OwnerID != 0) //then this has a master, set the UUID 
		{

		theEntitycompound.setString("OwnerUUID", OwnerUUID);	

		theEntitycompound.setInteger("OwnerID", 0);

//get the master ID for this this sesion and save it to entity
		util.getEntityOwnerID(theEntity); 
		System.out.println("OwnerID set to="+util.getEntityOwnerID(theEntity));	
		}


		if (hasGHOST){

		// i notice that loadNBTData() some times run 2  or 3 times over the same creature
		// so this check if the entity has already a ghost before conjuring a new one  

		util.getFantasma(theEntity, null);

		System.out.println("hasGHOST=Conjured for"+ theEntity.getName()+" pos="+theEntity.getPosition() );
		}

	}




}

// ########################################################################################################################3
// conjurar espirito
// @SubscribeEvent


// ########################################################################################################################3
@Override
public void init(Entity entity, World world) {
	// DEBUG
	// System.out.println(("ExtendedProperties EntityLivingBase init()");
	theEntity = (EntityLivingBase) entity;
	theWorld = world;
}

}

 

 

 

 

 

Posted

The entity UUID will NOT change, but the id from #getEntityID will.

 

However, the entities will not exist until the chunk that they are in is loaded, so they will likely be null for a while after loading the game. One way around that is to store their last known coordinates and load that chunk (if not already loaded) when searching for them, but even that's not foolproof - the entity may have moved, died, etc.

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.