Jump to content

[1.8] save ShootingEntity reference as an NBT value in a watcher entity ?


perromercenary00

Recommended Posts

Goo days

 

during the last weeks i been working in an custom entity (fantasmaMercenario) that watch over others (vanilla or modded) entities

  healing then over time if their are hurt  and shooting the guns from mi mod for them, this is the only way i found to make vanilla skeletons to use mi rifles and guns.

 

several troubles i find and the most important is : if you close/save the world the wacherEntity(fantasmaMercenario) lost the values from the shootingEntity it is watching for 

 

for example this (fantasmaMercenario) is watching an vanilla skeleton raging around the village  in the norther part, inside the code of fantasmamercenario the skeleton reference is saved as "shootingEntity"  the code from the ghost its working properly, the ghost is causing regeneration over the skeleton and if i put some herb in a tactical vest and put it on the skeleton chest slot the ghost use them to health the skeleton if life goes under 25%

 

but if i close/reopen the minecraft game , the ghost and the skeleton still exist in nortern part of the village but the ghost is watching no more the skeleton coz has lost the variable values and betwin them the shootingEntity reference to the skeleton is now null. 

private EntityLiving Base shootingEntity =  thisWachedEntity;

 

###

i could save all the variables to nbts/datawacher in the ghost no trouble with it ,  but the reference to an entity is other thing.

 

 

*first i try saving the UUID from  shootingEntity but because shooting entity is a mob and not a player i have to make mi own method to check the area around the ghost and search for an entity with a maching UUID this works but i don't want use it coz when the game gets thousens of watched entities its gonna lags ugly at the load of the world. 

 

//#########################################################################3
public static Entity getEntityFromUUID(World worldIn, EntityLivingBase referenceEntity ,UUID euuid){


//System.out.println("\n\n#####################################################################################");
//System.out.println("getEntityFromUUID");
//System.out.println("referenceEntity="+referenceEntity.getName());

//List entidadesTodas =  worldIn.loadedEntityList;

//int entidadesTodasSize = entidadesTodas.size();

//System.out.println("entidadesTodas="+entidadesTodasSize );

EntityLivingBase uuu = null; 
UUID uuuid = null;

BlockPos nucleo = referenceEntity.getPosition();

   	List entidades=null; 

int f=5;  //reach

BlockPos posMin = nucleo.add( -f, -f, -f);
BlockPos posMax = nucleo.add( f, f, f);
      

AxisAlignedBB boundingBox=new AxisAlignedBB(posMin, posMax);
entidades = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox);

int entidadesSize=entidades.size();


for (int u = 0 ; u < entidadesSize ; u ++)
{
	uuu =  (EntityLivingBase) entidades.get(u);

	//System.out.println("entidades["+u+"]="+uuu.getName());

	if ( (euuid.compareTo(uuu.getUniqueID()) == 0 ) )
	{
		return uuu;
	}


}

return null;
}
//#########################################################################3

 

 

* the other thing  i try was to use events to set dead the fantasmamercenario when the world close/save

and make another event to cast a brand new ghost when  "LivingSpawnEvent event", but this fail becoze LivingSpawnEvent event only hapens once when the skeleton is first time casted  unto the world, not everytime the world loads 

 

//########################################################################################################################3
// conjurar espiritu
@SubscribeEvent
public void onEntitySpawnsConjureGhost(LivingSpawnEvent event) {

	if ( (event.entity instanceof EntityLivingBase) & !(event.entity instanceof fantasmaMercenario) ) {

		NBTTagCompound compound = event.entity.getEntityData();
		Boolean hasGHOST = compound.getBoolean("hasGHOST");

		if (hasGHOST) {

			System.out.println("\n\n######\n onEntityConjureGhost");

			World worldIn = event.entity.getEntityWorld();
			EntityLivingBase shootingEntity = (EntityLivingBase) event.entity;

			if (!worldIn.isRemote) {

				mercenarymod.entidades.fantasmaMercenario fantasma = new mercenarymod.entidades.fantasmaMercenario(worldIn);

				fantasma.setShootingEntity(shootingEntity);

				double x = shootingEntity.posX;
				double y = shootingEntity.posY + shootingEntity.height;// shootingEntity.getEyeHeight();
				double z = shootingEntity.posZ;

				float yaw = shootingEntity.rotationYaw; // getRotationYawHead();
														// rotationYaw;
				float pitch = shootingEntity.rotationPitch;

				fantasma.setPositionAndRotation(x, y, z, yaw, pitch);

				fantasma.setShootingEntity(shootingEntity);

				int fantasmaID = fantasma.getEntityId();
				String fantasmaUUID = fantasma.getUniqueID().toString();

				shootingEntity.getEntityData().setString("GhostUUID", fantasmaUUID);
				shootingEntity.getEntityData().setInteger("GhostID", fantasmaID);
				shootingEntity.getEntityData().setBoolean("hasGHOST", true);

				worldIn.spawnEntityInWorld(fantasma);
			}
		}
	}
}

//########################################################################################################################3	

 

 

someOne has try some like this before, or well know how to store an entity reference, not all the entity to an nbt soo you could recalled again even if the worlds close/save and the entityes ID's change.  but not searching the entity again every time using whith UUID's

 

other thing im curious is that i have declared in the ghost constructor 

this.isEntityInvulnerable(DamageSource.inWall);

but the entity is still taken damage when in wall

 

 

 

fantasmaMercenario.class


package mercenarymod.entidades;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import mercenarymod.Mercenary;
import mercenarymod.eventos.mensajeMercenarioalServidor;
import mercenarymod.gui.NotificationMercenaria;
import mercenarymod.items.MercenaryModItems;
import mercenarymod.items.armasdefuego.cargadormf9x.cargadorFM9X;
import mercenarymod.utilidades.chat;
import mercenarymod.utilidades.util;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.BlockPos;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class fantasmaMercenario extends EntityTameable {


private int ticksExisted;

private int texturajson = 0;
private int accion = 0;
private boolean leftClick = false;
private boolean rigthClick = false;

private int ticksMaximos = 0;
private EntityLivingBase shootingEntity;
private int shootingEntityId = 0;

private float maxHealth = 0.0F;
private float health = 0.0F;

private Entity targetEntity;
private int targetEntityId = 0;

private int fantasmaId = 0;

private ItemStack heldItemStack;
private Item heldItem;

private ItemStack subArma;
private Item subArmaItem;

private ItemStack pistola00;
private Item pistolaItem00;

private ItemStack pistola01;
private Item pistolaItem01;

private String OwnerUUID = "";
private String ShootUUID = "";

private int tipoDePistola = 0;
private int numerodeserie = 0;

private int lmuniciondisponible = 0;
private int municiondisponible = 0;

private int municion = 0;
private int municionmaxima = 0;

private int tipodisparo = 0;
private int tipomunicion = 0;
private int tipocargador = 0;
private int tipocargadorcambio = 0;

private int lmunicion = 0;
private int lmunicionmaxima = 0;

private int ltipodisparo = 0;
private int ltipomunicion = 0;
private int ltipocargador = 0;
private int ltipocargadorcambio = 0;

private int nDeDisparos = 0;

private int cuantosDisparos;

private boolean hacerNada = false;
private boolean exorcisar = false;
private boolean eselhumano = false;
private boolean recargar = false;

private boolean stapp = false;

private int comandos[] = { 0, 0, 0 };

private int[] ignorar = { 0 };

// inventario de la armadura
private int inventarioSize = 36;
private ItemStack[] inventario = new ItemStack[inventarioSize];

private ItemStack chestItem = null;

// inventario de la shootingEntity
private int mainInventorySize = 36;
private ItemStack[] mainInventory = new ItemStack[mainInventorySize];

private int ghostInventorySize = 36;
private ItemStack[] ghostInventory = new ItemStack[mainInventorySize];

private int conteodeEtiquetas = 0;
private World worldIn = null;

private String customName = "algo";

static Item cargadoresCompatibles[] = { MercenaryModItems.cargador55645 };
static Item municionesCompatibles[] = { MercenaryModItems.bala55645mm_Standar, MercenaryModItems.bala55645mm_Redstone, MercenaryModItems.bala55645mm_Obsidiana };
// static Item curativasCompatibles[] = { MercenaryModItems.hierba,
// MercenaryModItems.hierbaVerdePlanta, MercenaryModItems.papa_cocida,
// MercenaryModItems.yuca_cocida };

private int cargadorListo = -1;
private int cargadorVacio = -1;
private int MunicionLista = -1;
private int hierba = -1;

// private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this,
// 1.0D, 20, 10, 30.0F);
private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityMob.class, 1.2D, false);

// #################################################################################################################
public fantasmaMercenario(World worldIn) {
	super(worldIn);
	this.setSize(0.0F, 0.0F);

	this.isEntityInvulnerable(DamageSource.drown);
	this.isEntityInvulnerable(DamageSource.fall);
	this.isEntityInvulnerable(DamageSource.generic);
	this.isEntityInvulnerable(DamageSource.inWall);
	this.isEntityInvulnerable(DamageSource.lava);
	this.isEntityInvulnerable(DamageSource.fallingBlock);


}

// #################################################################################################################
@Override
protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.0D);
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(9999.0D);
	this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(2.0D);
}

// #################################################################################################################

@Override
protected void entityInit() {
	super.entityInit();
	ticksExisted = 0;

	// 0 1 2 3 4 6 7 8 9 12 15 16 17

	this.dataWatcher.addObject(5, 0); // int R 000Municion

	this.dataWatcher.addObject(10, 0); // R int 0tipodisparo 0tipomunicion
										// 0cargador 0cargadordereemplazo
										// 000municionMax 000municionMin,
										// tipoDeArma_BCMG

	this.dataWatcher.addObject(11, 0); // int L 000Municion

	this.dataWatcher.addObject(13, 0); // L int 0tipodisparo 0tipomunicion
										// 0cargador 0cargadordereemplazo
										// 000municionMax 000municionMin

	this.dataWatcher.addObject(14, 0); // Booleans

	this.dataWatcher.addObject(31, ""); // "ShootUUID"
	// this.dataWatcher.addObject(17, ""); // "OwnerUUID"

	this.dataWatcher.addObject(18, Byte.valueOf((byte) 0));

	this.dataWatcher.addObject(19, 0.0F); // this.posX
	this.dataWatcher.addObject(20, 0.0F); // this.posY
	this.dataWatcher.addObject(21, 0.0F); // this.posZ

	this.dataWatcher.addObject(22, 0.0F); // this.rotationPitch
	this.dataWatcher.addObject(23, 0.0F); // this.rotationYaw

	this.dataWatcher.addObject(24, 0); // this.hacerNada
	this.dataWatcher.addObject(25, 0); // this.exorcisar

	this.dataWatcher.addObject(26, 0.0F); // MotionX
	this.dataWatcher.addObject(27, 0.0F); // MotionY
	this.dataWatcher.addObject(28, 0.0F); // MotionZ

	this.dataWatcher.addObject(29, 0); // this.ShootingEntityId

	this.dataWatcher.addObject(30, 0); // this.TargetEntityId

}

// #################################################################################################################
// actualiza shooting entity y extrae el arma que sostiene
void actualizarValoresEstablesDesdeShootingEntity() {

	// System.out.println("actualizarValoresEstablesDesdeShootingEntity()");



	if (shootingEntity != null & !this.worldObj.isRemote) {

		this.getEntityData().setString("ShootUUID", shootingEntity.getUniqueID().toString() );

		ShootUUID = shootingEntity.getUniqueID().toString();

		eselhumano = false;
		if (shootingEntity instanceof EntityPlayer) {
			OwnerUUID = ShootUUID;
			eselhumano = true;
		} 
		else
		{
			OwnerUUID = util.getEntityOwnerUUID(shootingEntity);
		}			

		this.dataWatcher.updateObject(31, ShootUUID);// "ShootUUID"
		this.dataWatcher.updateObject(17, OwnerUUID);// "OwnerUUID"

		shootingEntityId = shootingEntity.getEntityId();
		this.dataWatcher.updateObject(29, shootingEntityId); // this.ShootingEntityId

		heldItemStack = shootingEntity.getHeldItem();
		heldItem = null;
	}

	if (this.worldObj.isRemote) {

		ShootUUID = this.dataWatcher.getWatchableObjectString(31);// "ShootUUID"

		OwnerUUID = this.dataWatcher.getWatchableObjectString(17);// "OwnerUUID"

		shootingEntityId = this.dataWatcher.getWatchableObjectInt(29); // this.ShootingEntityId

		shootingEntity = null;

		if (shootingEntityId > 0) {

			Entity tempEntity00 = this.worldObj.getEntityByID(shootingEntityId);

			if (tempEntity00 != null) {

				if (tempEntity00 instanceof EntityLivingBase) {
					shootingEntity = (EntityLivingBase) tempEntity00;
					heldItemStack = shootingEntity.getHeldItem();
					heldItem = null;

				}

			}
		}

	}

	if (shootingEntity != null) {
		shootingEntity.getEntityData().setString("OwnerUUID", OwnerUUID);

		eselhumano = false;
		if (shootingEntity instanceof EntityPlayer) {
			eselhumano = true;
		}
	}

	if (heldItemStack != null) {
		heldItem = heldItemStack.getItem();

		boolean esDisparable = armasDisparables.esDisparable(heldItemStack);

		if (esDisparable) {

			pistola00 = heldItemStack;
			pistolaItem00 = pistola00.getItem();

			tipoDePistola = armasDisparables.tipodePistola(pistola00);

			numerodeserie = util.getInttag(pistola00, "numerodeserie");

			municiondisponible = util.getInttag(pistola00, "municiondisponible");
			lmuniciondisponible = util.getInttag(pistola00, "lmuniciondisponible");

			municion = util.getInttag(pistola00, "municion");
			municionmaxima = util.getInttag(pistola00, "municionmaxima");

			tipodisparo = util.getInttag(pistola00, "tipodisparo");
			tipomunicion = util.getInttag(pistola00, "tipomunicion");
			tipocargador = util.getInttag(pistola00, "tipocargador");
			tipocargadorcambio = util.getInttag(pistola00, "tipocargadorcambio");

			lmunicion = util.getInttag(pistola00, "lmunicion");
			lmunicionmaxima = util.getInttag(pistola00, "lmunicionmaxima");

			ltipodisparo = util.getInttag(pistola00, "ltipodisparo");
			ltipomunicion = util.getInttag(pistola00, "ltipomunicion");
			ltipocargador = util.getInttag(pistola00, "ltipocargador");
			ltipocargadorcambio = util.getInttag(pistola00, "ltipocargadorcambio");

			util.setInttag(pistola00, "fantasmaID", this.getEntityId());

		}

	}

}

// #################################################################################################################
// actualiza todos los valores del arma y la posicion del fantasma
void leerEscribirElDatawacherTodo() {

	if (!this.worldObj.isRemote) {

		this.dataWatcher.updateObject(5, municion); // int R 000Municion

		int BCMG = 0;

		BCMG = tipoDePistola;

		BCMG = BCMG + (tipodisparo * 100);

		BCMG = BCMG + (tipomunicion * 1000);

		BCMG = BCMG + (tipocargador * 10000);

		BCMG = BCMG + (tipocargadorcambio * 100000);

		BCMG = BCMG + (municionmaxima * 1000000);

		this.dataWatcher.updateObject(10, BCMG); // R int 00tipoDePistola
													// 0tipodisparo
													// 0tipomunicion
													// 0tipocargador
													// 0tipocargadorcambio
													// 000municionmaxima ,

		this.dataWatcher.updateObject(11, lmunicion); // int L 000Municion

		int LBCMG = 0;

		LBCMG = tipoDePistola;

		LBCMG = LBCMG + (ltipodisparo * 100);

		LBCMG = LBCMG + (ltipomunicion * 1000);

		LBCMG = LBCMG + (ltipocargador * 10000);

		LBCMG = LBCMG + (ltipocargadorcambio * 100000);

		LBCMG = LBCMG + (lmunicionmaxima * 1000000);

		this.dataWatcher.updateObject(13, LBCMG); // L int 0tipodisparo
													// 0tipomunicion
													// 0cargador
													// 0cargadordereemplazo
													// 000municionMax
													// 000municionMin

		int BOOL = 0;
		if (stapp) {
			BOOL = 1;
		}

		this.dataWatcher.updateObject(14, BOOL); // Booleans

		if (hacerNada) {
			this.dataWatcher.updateObject(24, 1); // this.hacerNada
		} else {
			this.dataWatcher.updateObject(24, 0); // this.hacerNada
		}

		if (exorcisar) {
			this.dataWatcher.updateObject(25, 1); // this.exorcisar
		} else {
			this.dataWatcher.updateObject(25, 0); // this.exorcisar
		}

		this.dataWatcher.updateObject(17, "OwnerUUID"); // "OwnerUUID"

		if (shootingEntity != null & ticksExisted < 20) {
			shootingEntityId = shootingEntity.getEntityId();
			heldItemStack = shootingEntity.getHeldItem();
		}

		this.dataWatcher.updateObject(29, shootingEntityId); // this.ShootingEntityId

		if (shootingEntity != null) {
			double x = shootingEntity.posX;
			double y = shootingEntity.posY + shootingEntity.height;// shootingEntity.getEyeHeight();//
																	// shootingEntity.posY
			double z = shootingEntity.posZ;

			float yaw = shootingEntity.rotationYaw; // getRotationYawHead();
													// rotationYaw;
			float pitch = shootingEntity.rotationPitch;

			if (pitch < 0) {
				y = shootingEntity.posY;
			}

			this.motionX = shootingEntity.motionX;
			this.motionY = shootingEntity.motionY;
			this.motionZ = shootingEntity.motionZ;

			this.setPositionAndRotation(x, y, z, yaw, pitch);

			this.dataWatcher.updateObject(19, (float) x); // this.posX
			this.dataWatcher.updateObject(20, (float) y); // this.posY
			this.dataWatcher.updateObject(21, (float) z); // this.posZ

			this.dataWatcher.updateObject(22, (float) pitch); // this.rotationPitch
			this.dataWatcher.updateObject(23, (float) yaw); // this.rotationYaw

			this.dataWatcher.updateObject(26, (float) this.motionX); // MotionX
			this.dataWatcher.updateObject(27, (float) this.motionY); // MotionY
			this.dataWatcher.updateObject(28, (float) this.motionZ); // MotionZ

		}

	}

	else

	{

		municion = this.dataWatcher.getWatchableObjectInt(5); // int R
																// 000Municion

		int BCMG = this.dataWatcher.getWatchableObjectInt(10);// R int
																// 00tipoDePistola
																// 0tipodisparo
																// 0tipomunicion
																// 0tipocargador
																// 0tipocargadorcambio
																// 000municionmaxima
																// ,

		tipoDePistola = (BCMG % 100);

		tipodisparo = (BCMG % 1000) / 100;

		tipomunicion = (BCMG % 10000) / 1000;

		tipocargador = (BCMG % 100000) / 10000;

		tipocargadorcambio = (BCMG % 100000) / 10000;

		municionmaxima = (BCMG / 1000000);

		lmunicion = this.dataWatcher.getWatchableObjectInt(11); // int l
																// 000Municion

		int LBCMG = this.dataWatcher.getWatchableObjectInt(13);// L int
																// 0tipodisparo
																// 0tipomunicion
																// 0cargador
																// 0cargadordereemplazo
																// 000municionMax
																// 000municionMin

		// tipoDePistola = (BCMG % 100);

		ltipodisparo = (LBCMG % 1000) / 100;

		ltipomunicion = (LBCMG % 10000) / 1000;

		ltipocargador = (LBCMG % 100000) / 10000;

		ltipocargadorcambio = (LBCMG % 100000) / 10000;

		lmunicionmaxima = (LBCMG / 1000000);

		int BOOL = this.dataWatcher.getWatchableObjectInt(14);// Booleans

		stapp = false;
		if ((BOOL % 10) == 1) {
			stapp = true;
		}

		hacerNada = false;
		if (this.dataWatcher.getWatchableObjectInt(24) > 0) {
			hacerNada = true;
		}

		exorcisar = false;
		if (this.dataWatcher.getWatchableObjectInt(25) > 0) {
			exorcisar = true;
		}

		OwnerUUID = this.dataWatcher.getWatchableObjectString(17);// "OwnerUUID"

		shootingEntityId = this.dataWatcher.getWatchableObjectInt(29); // this.ShootingEntityId

		if (shootingEntity == null & shootingEntityId > 0 & ticksExisted < 20) {

			Entity tempEntity00 = this.worldObj.getEntityByID(shootingEntityId);

			if (tempEntity00 != null) {
				if (tempEntity00 instanceof EntityLivingBase) {
					shootingEntity = (EntityLivingBase) tempEntity00;
					heldItemStack = shootingEntity.getHeldItem();
				}
			}
		}

		this.posX = (float) this.dataWatcher.getWatchableObjectFloat(19); // this.posX
		this.posY = (float) this.dataWatcher.getWatchableObjectFloat(20); // this.posY
		this.posZ = (float) this.dataWatcher.getWatchableObjectFloat(21); // this.posZ

		this.rotationPitch = (float) this.dataWatcher.getWatchableObjectFloat(22);
		this.rotationYaw = (float) this.dataWatcher.getWatchableObjectFloat(23);

		this.motionX = (float) this.dataWatcher.getWatchableObjectFloat(26); // MotionX
		this.motionY = (float) this.dataWatcher.getWatchableObjectFloat(27); // MotionY
		this.motionZ = (float) this.dataWatcher.getWatchableObjectFloat(28); // MotionZ

	}

}

// #################################################################################################################
// solo actualiza cantidad de municion y posicion del fantasma
void leerEscribirElDatawacher() {

	if (!this.worldObj.isRemote) {

		this.dataWatcher.updateObject(5, municion); // int R 000Municion

		this.dataWatcher.updateObject(11, lmunicion); // int L 000Municion

		int BOOL = 0;
		if (stapp) {
			BOOL = 1;
		}

		this.dataWatcher.updateObject(14, BOOL); // Booleans

		if (hacerNada) {
			this.dataWatcher.updateObject(24, 1); // this.hacerNada
		} else {
			this.dataWatcher.updateObject(24, 0); // this.hacerNada
		}

		if (exorcisar) {
			this.dataWatcher.updateObject(25, 1); // this.exorcisar
		} else {
			this.dataWatcher.updateObject(25, 0); // this.exorcisar
		}

		if (shootingEntity != null) {

			double x = shootingEntity.posX;
			double y = shootingEntity.posY + 2; //shootingEntity.height ;// shootingEntity.getEyeHeight();//
			double z = shootingEntity.posZ;

			float yaw = shootingEntity.rotationYaw; // getRotationYawHead();
			float pitch = shootingEntity.rotationPitch;

			if (pitch < 0) {
				y = shootingEntity.posY;
			}

			this.motionX = shootingEntity.motionX;
			this.motionY = shootingEntity.motionY;
			this.motionZ = shootingEntity.motionZ;

			this.setPositionAndRotation(x, y, z, yaw, pitch);

			this.dataWatcher.updateObject(19, (float) x); // this.posX
			this.dataWatcher.updateObject(20, (float) y); // this.posY
			this.dataWatcher.updateObject(21, (float) z); // this.posZ

			this.dataWatcher.updateObject(22, (float) pitch); // this.rotationPitch
			this.dataWatcher.updateObject(23, (float) yaw); // this.rotationYaw

			this.dataWatcher.updateObject(26, (float) this.motionX); // MotionX
			this.dataWatcher.updateObject(27, (float) this.motionY); // MotionY
			this.dataWatcher.updateObject(28, (float) this.motionZ); // MotionZ

			this.fallDistance = 0;

		}

	}

	else

	{

		municion = this.dataWatcher.getWatchableObjectInt(5); // int R
																// 000Municion

		lmunicion = this.dataWatcher.getWatchableObjectInt(11); // int l
																// 000Municion

		int BOOL = this.dataWatcher.getWatchableObjectInt(14);// Booleans

		stapp = false;
		if ((BOOL % 10) == 1) {
			stapp = true;
		}

		hacerNada = false;
		if (this.dataWatcher.getWatchableObjectInt(24) > 0) {
			hacerNada = true;
		}

		exorcisar = false;
		if (this.dataWatcher.getWatchableObjectInt(25) > 0) {
			exorcisar = true;
		}

		this.posX = (float) this.dataWatcher.getWatchableObjectFloat(19); // this.posX
		this.posY = (float) this.dataWatcher.getWatchableObjectFloat(20); // this.posY
		this.posZ = (float) this.dataWatcher.getWatchableObjectFloat(21); // this.posZ

		this.rotationPitch = (float) this.dataWatcher.getWatchableObjectFloat(22);
		this.rotationYaw = (float) this.dataWatcher.getWatchableObjectFloat(23);

		this.motionX = (float) this.dataWatcher.getWatchableObjectFloat(26); // MotionX
		this.motionY = (float) this.dataWatcher.getWatchableObjectFloat(27); // MotionY
		this.motionZ = (float) this.dataWatcher.getWatchableObjectFloat(28); // MotionZ

		this.fallDistance = 0;
	}

}

// #################################################################################################################
public String getOwnerId() {
	return this.dataWatcher.getWatchableObjectString(17);
}

public void setOwnerId(String ownerUuid) {
	this.dataWatcher.updateObject(17, ownerUuid);
}

// #################################################################################################################
@Override
/**
 * Called when the mob's health reaches 0.
 */
public void onDeath(DamageSource cause) {

	System.out.println("\n\n########################################################");
	System.out.println("cause ="+cause.getDamageType());
	//System.out.println("cause ="+cause.getEntity().getName());

}

// #################################################################################################################
@Override
/**
 * Returns the sound this mob makes when it is hurt.
 */
protected String getHurtSound() {
	return null;//"mob.wolf.hurt"
}

// #################################################################################################################
@Override
/**
 * Returns the sound this mob makes on death.
 */
protected String getDeathSound() {
	return "mob.wolf.death";
}

// #################################################################################################################
@Override
/**
 * Returns the volume for the sounds this mob makes.
 */
protected float getSoundVolume() {
	return 0.4F;
}

// #################################################################################################################
@Override
protected Item getDropItem() {
	return Item.getItemById(-1);
}

// #################################################################################################################
@Override
/**
 * Called frequently so the entity can update its state every tick as
 * required. For example, zombies and skeletons use this to react to
 * sunlight and start to burn.
 */
public void onLivingUpdate() {
	super.onLivingUpdate();

}

// #################################################################################################################

/**
 * sets this entity's combat AI.
 */

public void setCombatTask() {
}

// #################################################################################################################

/**
 * sets this entity's combat AI.
 */

boolean getTarget() {

	if (shootingEntity != null) {

		ArrayList<Entity> entidades = util.getAquienLeEstoyApuntando(this.worldObj, shootingEntity, 15, 3);

		if (entidades.size() > 0) {

			if (OwnerUUID.length() > 0) {

				// //System.out.println("###################
				// entidades.size("+entidades.size()+")");

				for (int e = 0; e < entidades.size(); e++) {

					if ((entidades.get(e) != null) & (entidades.get(e) instanceof EntityLivingBase)) {

						EntityLivingBase entityE = (EntityLivingBase) entidades.get(e);

						String EOwnerUUID = util.getEntityOwnerUUID(entityE);

						if ((OwnerUUID.equals(EOwnerUUID))) {
							targetEntity = null;
							return false;
						}

					}

				}

			}

			if (entidades.get(0) != null) {
				targetEntity = entidades.get(0);
			} else {
				targetEntity = null;
			}
			return true;
		}
		targetEntity = null;
		return true;
	}
	targetEntity = null;
	return false;

}

// #################################################################################################################
@Override
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
	super.onUpdate();


	if ( ticksExisted < 2 || shootingEntity == null  ) { // ticksExisted == 0
		//System.out.println(">>> actualizarValoresEstablesDesdeShootingEntity()");
                        //updates the values form server side to client side using the ghost Datawacher
		actualizarValoresEstablesDesdeShootingEntity();

	}

                //actualiza the ghost position to match shootinEntity position  
	leerEscribirElDatawacher();


	if ( ((ticksExisted % 40) == 0)) {


		System.out.println("\n######");
		System.out.println("Mundo=" + this.worldObj.isRemote + " ticksExisted"+ticksExisted);

		System.out.println("Ghostpos X=" + this.posX + " Y"+ this.posY + " Z"+ this.posZ);

		System.out.println("this.getHealth()=" + this.getHealth() );

		if (this.getHealth() < 5000)
		{
			this.setHealth(9999);
		}
		if (shootingEntity != null)
		{
			System.out.println("shootingEntity()=" + shootingEntity.getName() );
		}

		getTarget();

		if (targetEntity != null)
		{
			System.out.println("targetEntity()=" + targetEntity.getName() );
		}


	}

	// Show the shootingEntity Heal
	if (shootingEntity != null & ((ticksExisted % 20) == 0)) {
		maxHealth = shootingEntity.getMaxHealth();
		health = shootingEntity.getHealth();

		//System.out.println("\nMundo=" + this.worldObj.isRemote + " ticksExisted"+ticksExisted);
		//System.out.println("entity=" + shootingEntity.getName() + " HP=" + health + "/" + maxHealth);
	}

	hacerNada = true;

	if (shootingEntity != null) {

		if (heldItemStack != null) {
			hacerNada = false;
		} 

		eselhumano = false;

		// Heal the shootingEntity if it has whith it a curative item 
		if (!eselhumano & !this.worldObj.isRemote) {
			if ((ticksExisted % 40) == 0) {
				maxHealth = shootingEntity.getMaxHealth();
				health = shootingEntity.getHealth();

				if (health < (maxHealth / 4)) {
					// buscar healtItem
					this.readFromNBT();
					this.buscar();

					//System.out.println("hierba=" + hierba);

					if (hierba > -1) {

						if (ghostInventory[hierba] != null) {

							float curar = armasDisparables.esCurativo(ghostInventory[hierba]);

							if (curar > 9) {
								curar = curar - 10;
								shootingEntity.curePotionEffects(new ItemStack(Items.milk_bucket, 1, 0));
							}

							float nhealth = shootingEntity.getHealth() + (maxHealth * curar);
							if (nhealth > maxHealth) {
								nhealth = maxHealth;
							}

							shootingEntity.setHealth(nhealth);

							if (shootingEntity instanceof EntityPlayer) {
								((EntityPlayer) shootingEntity).getFoodStats().addStats((int) (10 * curar), (int) (10 * curar));
							}

							//System.out.println("hierba=" + ghostInventory[hierba].getUnlocalizedName());

							decrStackSize(hierba, 1);

						}
					}

				}

			}

			// regeng 1/4 hearth every two minutes
			if ((ticksExisted % 2400) == 0) {

				maxHealth = shootingEntity.getMaxHealth();
				health = shootingEntity.getHealth();

				if (health < maxHealth) {
					shootingEntity.setHealth(shootingEntity.getHealth() + 0.5F);
				}

			}

		}

	}



	/*
	accion
	0 estandBy

	1 shoot R
	2 unload R
	3 reload R
	4 unload/reload R

	5 shoot L
	6 unload L
	7 reload L
	8 unload/reload L
	*/

	// detener la accion
	if (stapp) {
		texturajson = 0;
		accion = 0;
		stapp = false;
	}

//		System.out.println("hacerNada="+hacerNada);
//		System.out.println("rigthClick="+rigthClick);
//		System.out.println("leftClick="+leftClick);


	if (!hacerNada) {

		if (rigthClick) {
			accion = 1;
			texturajson = 0;

			System.out.println("rigthClick###");
			// if (!this.worldObj.isRemote)
			{

				if (getTarget()) {
					accion = 1;
				} else {
					stapp = true;
				}

				if (targetEntity != null) {
					//System.out.println("targetEntity=" + targetEntity.getName());
				} else {
					//System.out.println("targetEntity=NULL");
				}

			}

			if (this.worldObj.isRemote) {
				NotificationMercenaria.setconteo100Zero();
			}

			rigthClick = false;

		}

		// Accion 1 rafaga de 5 disaparos
		if (accion == 1) {

			int conteo = 0;
			if (this.worldObj.isRemote) {
				conteo = NotificationMercenaria.getconteo100();
			}

			// //System.out.println("ConteoLocal=" + conteo);

			if (conteo % 2 == 0) {
				texturajson = 0;

			} else {
				texturajson = 1;
			}

			if (conteo > 10) {
				if (this.worldObj.isRemote) {
					Mercenary.network.sendToServer(new mensajeMercenarioalServidor("stapp_" + this.getEntityId()));
				}
			}

		}

		if (leftClick) {
			accion = 2;
			texturajson = 9;

			System.out.println("leftClick###");

			if (this.worldObj.isRemote) {
				NotificationMercenaria.setconteo100Zero();
			}

			leftClick = false;

		}

		// Accion 2 Sierra de redstone por 2 seg
		if (accion == 2) {

			int conteo = 0;
			if (this.worldObj.isRemote) {
				conteo = NotificationMercenaria.getconteo100();
			}

			// //System.out.println("ConteoLocal=" + conteo);

			texturajson = 9;

			if (this.worldObj.isRemote) {

				int lconteo = NotificationMercenaria.getlconteo();
				// //System.out.println("lconteo=" + lconteo);

				if (lconteo < 1 & conteo > 20) {
					texturajson = 0;

					{
						Mercenary.network.sendToServer(new mensajeMercenarioalServidor("stapp_" + this.getEntityId()));
					}
				}
			}

		}

	} // fin de hacerAlgo

	// terminar la entidad si contados  180 ticks no a sido inicializado shooting entity o esta muerto
	if (ticksExisted > 180 & !this.worldObj.isRemote) {
		if (shootingEntity == null) {
			//System.out.println("entity is NULL");
			exorcisar = true;
		} else if (!shootingEntity.isEntityAlive()) {
			//System.out.println("Entity is Not Alive");
			exorcisar = true;
		}

	}

	if (exorcisar) {

		System.out.println("\nMundo=" + this.worldObj.isRemote);
		System.out.println("######This has been killled likke kenny t=" + ticksExisted );
		System.out.println("Dead UUID=" + this.entityUniqueID.toString());
		this.setDead();
	}

	ticksExisted++;

}



// #################################################################################################################
void sacarCargador() {

}

// #################################################################################################################
void meterCargador() {

}

// #################################################################################################################
void searchValues() {

}

// #################################################################################################################
//Shoot bullet
public static void disparo(World worldIn, EntityLivingBase shooter, int shootingEntityId, ItemStack pistola, int tipomunicion, int tipocargador, int municion, int tipoDePistola, int[] ignorar) {

	// World worldIn = shootingEntity.getEntityWorld();

	Item bala = null;
	// bala = MercenaryModItems.bala9mm_Standar;
	// bala = MercenaryModItems.bala9mm_Standar;

	int spell0 = 0;
	int spell1 = 0;
	int spell2 = 0;
	int spell3 = 0;
	int spell4 = 0;
	int R = 0;

	int knockback = 0;
	float f = 0.0F;
	boolean modo = false;
	boolean flame = false;
	boolean poison = false;
	boolean headShoot = false;

	int cantDeEntidadesAfectadas = 1;
	float damageM = 0.0F;
	float damageI = 0.0F;
	float precision = 8.0F;

	switch (tipomunicion) {
	default:
		damageM = 0.0F;
		damageI = 0.0F;
		cantDeEntidadesAfectadas = 0;
		break; // Empty bullet
	case 1:
		damageM = 2.55F;
		damageI = 0.0F;
		cantDeEntidadesAfectadas = 1;
		break; // bala9mm_Hierro
	case 2:
		damageM = 3.00F;
		damageI = 0.0F;
		cantDeEntidadesAfectadas = 1;
		break; // bala9mm_redstone
	case 3:
		damageM = 3.50F;
		damageI = 0.0F;
		cantDeEntidadesAfectadas = 1;
		break; // bala9mm_obisidana
	}

	// conjuros
	if (!worldIn.isRemote) {

		spell0 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, pistola);
		spell1 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, pistola);
		spell2 = EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, pistola);
		spell3 = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, pistola);
		spell4 = EnchantmentHelper.getEnchantmentLevel(Enchantment.knockback.effectId, pistola);

		R = ((int) (Math.random() * 20)) + spell3;

		// power
		if (spell0 > 0) {
			damageM = damageM + (float) spell0 * 0.5F + 0.5F;
		}

		// punch and knockback
		if ((spell1 > 0) | (spell4 > 0)) {
			knockback = (spell1 + spell4);
		}

		if (tipomunicion == 2 & EnchantmentHelper.getEnchantmentLevel(Enchantment.fireAspect.effectId, pistola) > 0) {
			flame = true;
		}

		if (tipomunicion == 2 & EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, pistola) > 0) {
			flame = true;
		}

	}

	// fuerza del disparo y modo de disparo

	if (R > 15) {
		damageM = damageM * 2.0F;
	}

	if (damageM > 26.1F) {
		damageM = 26.1F;
	}

	mercenarymod.items.armasdefuego.balas.bala9mm_entity bala9mm = new mercenarymod.items.armasdefuego.balas.bala9mm_entity(worldIn, shooter, 10F, precision);

	if (R < 15) {
		bala9mm.setHeadShoot(false);
	}

	bala9mm.setKnockbackStrength(knockback);
	bala9mm.setIsOnFire(flame);
	bala9mm.setIsVenomus(poison);

	bala9mm.setPrecision(precision);
	bala9mm.setDamage(damageM);
	bala9mm.setDamageI(damageI);
	bala9mm.setCantDamage(cantDeEntidadesAfectadas);
	bala9mm.setSEntityB(shootingEntityId);
	bala9mm.setIgnorar(ignorar);

	if (tipoDePistola == 2) {
		worldIn.playSoundAtEntity(shooter, "modmercenario:subfusilMP5T5_disparo", 0.4F, 0.4F);
	} else {
		worldIn.playSoundAtEntity(shooter, "modmercenario:pistolaFM92_disparo", 0.4F, 0.4F);
	}

	worldIn.spawnEntityInWorld(bala9mm);

	if (!worldIn.isRemote) {
		municion = util.getInttag(pistola, "municion") - 1;
		if (municion < 0) {
			municion = 0;
		}
		util.setInttag(pistola, "municion", municion);
	}

} // fin de disparar

// #################################################################################################################
@Override
public float getEyeHeight() {
	return 1.74F;
}

// #########################################################################3
public static ArrayList<Integer> cuantosHayCuantosCaben(EntityPlayer playerIn, Item cosa) {
	ArrayList<Integer> salida = new ArrayList<Integer>();
	ArrayList<Integer> vacio = new ArrayList<Integer>();
	ArrayList<Integer> conteos = new ArrayList<Integer>();
	conteos.clear();

	vacio.clear();
	vacio.add(0);

	salida.clear();
	salida.add(0);
	int cantidad = 0;

	int invSize = (playerIn.inventory.getSizeInventory()) - 4;
	ItemStack invStack = null;
	Item invItem = null;

	for (int invSlot = 0; invSlot < invSize; invSlot++) {
		invStack = playerIn.inventory.getStackInSlot(invSlot);

		if (invStack != null) {
			invItem = invStack.getItem();

			if (invItem.equals(cosa)) {
				salida.add(invSlot);
				cantidad += (invStack.stackSize);
			}

		} else {
			vacio.add(invSlot);
		}

	}

	salida.set(0, cantidad);
	vacio.set(0, (vacio.size() - 1));

	int maxStaacksize = cosa.getItemStackLimit();
	int cantidadUbicable = (((salida.size() - 1) * maxStaacksize) - cantidad) + (maxStaacksize * (vacio.get(0)));

	// chat.chatda(playerIn, "cantidadUbicable="+cantidadUbicable );
	// chat.chatda(playerIn, "vacios="+(vacio.get(0)) );

	conteos.add(cantidad);
	conteos.add(cantidadUbicable);

	return conteos;
}

// #################################################################################################################
// se ejecuta cuando hace ataque intercambio fisico normal a una criatura
@Override
public boolean attackEntityAsMob(Entity p_70652_1_) {
	boolean flag = p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float) ((int) this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue()));

	if (flag) {
		this.func_174815_a(this, p_70652_1_);
	}

	p_70652_1_.setFire(10);

	return flag;
}

// #################################################################################################################
@Override
public void setTamed(boolean tamed) {
	super.setTamed(tamed);

	if (tamed) {
		this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
	} else {
		this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
	}

	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(4.0D);
}

// #################################################################################################################
@Override
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow,
 * gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer player) {

	return super.interact(player);
}

// #################################################################################################################
@Override
/**
 * Will return how many at most can spawn in a chunk at once.
 */
public int getMaxSpawnedInChunk() {
	return 20;
}

// #################################################################################################################
@Override
/**
 * Determines if an entity can be despawned, used on idle far away entities
 */
protected boolean canDespawn() {

	return true;
}

@Override
public EntityAgeable createChild(EntityAgeable ageable) {
	// TODO Auto-generated method stub
	return null;
}

// #################################################################################################################
public boolean func_70922_bv() {
	return this.dataWatcher.getWatchableObjectByte(19) == 1;
}
// ###################################################################################################

/**
 * Returns the number of slots in the inventory.
 */

public int getinventarioSize() // ItemStack pistola
{

	return inventarioSize;// inventarioSize;
}

// ###################################################################################################
public void setinventarioSize(int z) // ItemStack pistola
{
	this.inventarioSize = z;// inventarioSize;
}
// ###################################################################################################

public int getMainInventorySize() // ItemStack pistola
{

	return mainInventorySize;// inventarioSize;
}

// ###################################################################################################
public void setMainInventorySize(int z) // ItemStack pistola
{
	this.mainInventorySize = z;// inventarioSize;
}
// ###################################################################################################

public NBTTagCompound getthisCompound() {

	NBTTagCompound compound = new NBTTagCompound();

	NBTTagList nbttaglist = new NBTTagList();

	for (int i = 0; i < inventario.length; ++i) {
		if (inventario[i] != null) {
			NBTTagCompound nbttagcompound1 = new NBTTagCompound();
			nbttagcompound1.setByte("Slot", (byte) i);
			inventario[i].writeToNBT(nbttagcompound1);
			nbttaglist.appendTag(nbttagcompound1);
		}
	}

	compound.setTag("Inventory", nbttaglist);

	// this.pistola.setTagCompound(compound);

	if (this.hasCustomName()) {
		compound.setString("CustomName", this.customName);
	}

	return compound;

}

// #########################################################################3
// @Override
ItemStack decrStackSize(int index, int count) {

	if (ghostInventory[index] != null) {
		ItemStack itemstack;

		if (ghostInventory[index].stackSize <= count) {
			itemstack = ghostInventory[index];
			ghostInventory[index] = null;
			this.writeToNBT();
			return itemstack;

		} else {
			itemstack = ghostInventory[index].splitStack(count);

			if (ghostInventory[index].stackSize <= 0) {
				ghostInventory[index] = null;
			} else {
				// Just to show that changes happened
				// this.setInventorySlotContents(index,
				// this.getStackInSlot(index));
			}

			this.writeToNBT();
			return itemstack;
		}
	} else {
		return null;
	}
}

// #########################################################################3
// @Override
public void clear() {

	for (int i = 0; i < inventario.length; ++i) {
		inventario[i] = null;
	}

	for (int i = 0; i < mainInventory.length; ++i) {
		mainInventory[i] = null;
	}

	// //System.out.println("$$$ clear()");

}

// #########################################################################3
// @Override
void buscar() {

	MunicionLista = -1;
	cargadorVacio = -1;
	cargadorListo = -1;
	hierba = -1;

	for (int i = 0; i < ghostInventorySize; ++i) {

		// #####
		ItemStack ghostItemStack = ghostInventory[i];
		Item ghostItem = null;

		if (ghostItemStack != null) {

			ghostItem = ghostItemStack.getItem();

			// ######

			for (int pc = 0; pc < municionesCompatibles.length; pc++) {

				if (ghostItem == municionesCompatibles[pc]) {
					MunicionLista = i;
				}
			}

			// ######
			for (int pc = 0; pc < cargadoresCompatibles.length; pc++) {

				if (ghostItem == cargadoresCompatibles[pc]) {

					cargadorVacio = i;
					municion = util.getInttag(ghostItemStack, "municion");

					if (municion > 0) {
						cargadorListo = i;
					}
				}
			}

			// ######

			if (armasDisparables.esCurativo(ghostItemStack) > 0.0F) {
				hierba = i;
			}

			/*
			 * for (int pc = 0; pc < curativasCompatibles.length; pc++) {
			 * 
			 * if (ghostItem == curativasCompatibles[pc]) {
			 * 
			 * if (pc == 0) { int ghostmeta = ghostItemStack.getMetadata();
			 * 
			 * if (ghostmeta > 2) { hierba = i; } } else { hierba = i; }
			 * 
			 * } }
			 */

			// ######
		}
	}

}

// #########################################################################3
// @Override
public void readFromNBT() {
	this.clear();

	// Shoting Entity Inventory

	if (shootingEntity != null) {

		NBTTagCompound compound3 = shootingEntity.getEntityData();

		if (shootingEntity instanceof EntityPlayer) {
			EntityPlayer playerIn = (EntityPlayer) shootingEntity;

			mainInventorySize = playerIn.inventory.getSizeInventory();

			this.mainInventory = new ItemStack[mainInventorySize];// playerIn.Inventory.mainInventory;

			for (int i = 0; i < mainInventorySize; ++i) {

				ItemStack plInvStack = playerIn.inventory.getStackInSlot(i);
				mainInventory[i] = plInvStack;

				if (mainInventory[i] != null) {

					// //System.out.println("inventario[" + i + "]" +
					// mainInventory[i].getUnlocalizedName());
					// chat.chatga(shootingEntity, "mainInventory[" + i +
					// "]" + mainInventory[i].getUnlocalizedName());
				}

			}

		} else {
			// 33
			if (compound3 != null) {

				mainInventorySize = 36;
				this.mainInventory = new ItemStack[mainInventorySize];

				NBTTagList nbttaglist3 = compound3.getTagList("Inventory", 10);

				for (int i = 0; i < nbttaglist3.tagCount(); ++i) {

					NBTTagCompound nbttagcompound3 = nbttaglist3.getCompoundTagAt(i);
					int j = nbttagcompound3.getByte("Slot") & 255;

					if (j >= 0 && j < mainInventorySize) {
						mainInventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound3);

						if (mainInventory[j] != null) {
							// //System.out.println("mainInventory[" + j + "]"
							// + mainInventory[j].getUnlocalizedName());
							// chat.chatga(shootingEntity, "mainInventory["
							// + j + "]" +
							// mainInventory[j].getUnlocalizedName());
						}

					}

				}

			}

			// 33

		}

		chestItem = this.shootingEntity.getEquipmentInSlot(3);// getCurrentArmor(2);chest

		// inventario en la armadura
		if (chestItem != null) {
			//System.out.println("===> chestItem=" + chestItem.getUnlocalizedName());
			NBTTagCompound compound2 = chestItem.getTagCompound();

			if (compound2 != null) {

				inventarioSize = armasDisparables.tieneBolsillos(chestItem) + 5;
				inventario = new ItemStack[inventarioSize];

				NBTTagList nbttaglist2 = compound2.getTagList("Items", 10);

				for (int i = 0; i < nbttaglist2.tagCount(); ++i) {

					NBTTagCompound nbttagcompound1 = nbttaglist2.getCompoundTagAt(i);
					int j = nbttagcompound1.getByte("Slot") & 255;

					if (j >= 0 && j < inventarioSize) {
						inventario[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);

						if (inventario[j] != null) {
							// //System.out.println("inventario[" + j + "]" +
							// inventario[j].getUnlocalizedName());
							// chat.chatga(shootingEntity, "inventario[" + j
							// + "]" + inventario[j].getUnlocalizedName());
						}

					}
				}

			}

		}

		ghostInventorySize = inventarioSize + mainInventorySize;
		ghostInventory = new ItemStack[ghostInventorySize];

		for (int i = 0; i < ghostInventorySize; ++i) {

			if (i < inventarioSize) {
				ghostInventory[i] = inventario[i];
			}

			else

			{
				ghostInventory[i] = mainInventory[i - inventarioSize];
			}
		}

	}

}

// #########################################################################3
// @Override
public void writeToNBT() {

	if (shootingEntity != null) {

		// ghostInventorySize = inventarioSize + mainInventorySize;
		// ghostInventory = new ItemStack[ghostInventorySize];

		for (int i = 0; i < ghostInventorySize; ++i) {

			if (i < inventarioSize) {
				inventario[i] = ghostInventory[i];
			}

			else

			{
				mainInventory[i - inventarioSize] = ghostInventory[i];
			}
		}

		// mainInventory

		if (shootingEntity instanceof EntityPlayer) {
			EntityPlayer playerIn = (EntityPlayer) shootingEntity;

			int playerInvSize = playerIn.inventory.getSizeInventory();
			int mainInvSize = mainInventory.length;

			if (playerInvSize < mainInvSize) {
				mainInvSize = playerInvSize;
			}

			for (int i = 0; i < mainInvSize; ++i) {

				playerIn.inventory.setInventorySlotContents(i, mainInventory[i]);

				if (mainInventory[i] != null) {

					// //System.out.println("inventario[" + i + "]" +
					// mainInventory[i].getUnlocalizedName());
					// chat.chatga(shootingEntity, "mainInventory[" + i +
					// "]" + mainInventory[i].getUnlocalizedName());
				}

			}

			// playerIn.inventory.mainInventory = this.mainInventory;

		} else {

			NBTTagList nbttaglist3 = new NBTTagList();

			for (int i = 0; i < mainInventory.length; ++i) {
				if (mainInventory[i] != null) {

					NBTTagCompound nbttagcompound3 = new NBTTagCompound();
					nbttagcompound3.setByte("Slot", (byte) i);
					inventario[i].writeToNBT(nbttagcompound3);
					nbttaglist3.appendTag(nbttagcompound3);

				}
			}

			NBTTagCompound shootingEntityData = shootingEntity.getEntityData();

			shootingEntityData.setTag("Inventory", nbttaglist3);

		}

		// inventario en la armadura

		chestItem = this.shootingEntity.getEquipmentInSlot(3);// getCurrentArmor(2);chest

		if (chestItem != null) {

			NBTTagList nbttaglist = new NBTTagList();

			for (int i = 0; i < inventario.length; ++i) {
				if (inventario[i] != null) {

					NBTTagCompound nbttagcompound1 = new NBTTagCompound();
					nbttagcompound1.setByte("Slot", (byte) i);
					inventario[i].writeToNBT(nbttagcompound1);
					nbttaglist.appendTag(nbttagcompound1);

				}
			}

			NBTTagCompound chestcompound = chestItem.getTagCompound();
			if (chestcompound == null) {
				chestcompound = new NBTTagCompound();
			}

			chestcompound.setTag("Items", nbttaglist);
			chestItem.setTagCompound(chestcompound);

			this.inventario[3] = chestItem;

			this.shootingEntity.setCurrentItemOrArmor(3, inventario[3]);

		}

	}

}

// #########################################################################3

// #########################################################################3
public void setShootingEntity(EntityLivingBase entidad) {

	shootingEntity = entidad;
}

// #########################################################################3
public Entity getShootingEntity() {

	return shootingEntity;
}

// #########################################################################3
public Entity getTargetEntity() {

	return targetEntity;
}

// #########################################################################3
public void setTargetEntity(EntityLivingBase entidad) {
	targetEntity = entidad;
}

// #########################################################################3
public void setHeldItemStack(ItemStack p) {
	heldItemStack = p;
}

// #########################################################################3
public ItemStack getHeldItemStack() {
	return heldItemStack;
}

// #########################################################################3
public int getTicksExisted() {
	return this.ticksExisted;
}

// #########################################################################3
public int getTexturajson() {
	return texturajson;
}

// #########################################################################3
public void setTexturajson(int t) {
	texturajson = t;
}

// #########################################################################3
public int getAccion() {
	return accion;
}

// #########################################################################3
public void setAccion(int t) {
	accion = t;
}

// #########################################################################3
public boolean getLeftClick() {
	return leftClick;
}

// #########################################################################3
public void setLeftClick(boolean l) {
	leftClick = l;
}

// #########################################################################3
public boolean getRigthClick() {
	return rigthClick;
}

// #########################################################################3
public void setRigthClick(boolean r) {
	rigthClick = r;
}

// #########################################################################3
public boolean getStapp() {
	return stapp;
}

// #########################################################################3
public void setStapp(boolean s) {
	stapp = s;
}

// ##########################################################################3
public String getOwnerUUID() {
	return OwnerUUID;
}

// ##########################################################################3
public void setOwnerUUID(String uu) {
	OwnerUUID = uu;
}

// ##########################################################################3
public String getShootUUID() {
	return ShootUUID;
}

// ##########################################################################3
public void setShootUUID(String uu) {
	ShootUUID = uu;
}

// #################################################################################################################
}

 

 

Thanks for reading

 

 

 

 

Link to comment
Share on other sites

1. Save ghost INTO Entity's IEEP (no problem with that. I for e.g have IEEP on all LivingEntityBase).

2. "Ghost" entity will be save/loaded in some entity IEEP. You simply load that NBT.

- If constructed entity is new (not loaded from world's NBT) - your IEEP's "ghost" field (NBTTagCompound of ghost) will be null.

- If constructed entity is loaded - you can read Ghost data from entity's NBT.

3. Use EntityJoinedWorld event - there are 2 scenarios:

- IEEP's Ghost field is null:

---> Spawn new ghost if needed (some boolean?)

---> Don't do anything, since entity doesn't have ghost.

- IEEP's Ghost field is not null - therefore you can use createEntityFromNBT (something like that), and spawn ghost into the world.

---> Doing that you can auto-make entity-to-entity bind (via direct reference).

4. To be on a safe side - use ticking (LivingUpdateEvent) and:

4.1. Check if mentioned entity-to-entity reference is not null, and if it is - try to re-bind it by looking for entity by UUID (which will either find one, and if not - stop looking, there is no entity like that).

 

Simple as that. Also (you alredy asked in other thread) - to make it work properly you need to NOT save ghosts to world, but to entity.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

hay thanks i take the idea to full fill needs but find another trouble

 

the basic idea is to save the fantasmaMercenario  values to the the watched entity in the save part of an IExtendedEntityProperties class

 

to later when the load part is called and is the turn for the watched entity, get back the values from the watched, create a new fantasmaMercenario entity and load the values and set again the shooting entity and all the other stuff.

 

but for some reason the entity fantasmaMercenario don't spawn in the world, but its is triyng i see the output in console   

 

package mercenarymod.entidades;

import java.util.UUID;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
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 ExtendedPropertiesEntityLiving 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 fantasmaMercenario)) {

		fantasmaMercenario fantasma = (fantasmaMercenario) theEntity;
		EntityLivingBase shootingEntity = (EntityLivingBase) fantasma.getShootingEntity();

		if (shootingEntity != null) {
			theEntity.getEntityData().setBoolean("hasGHOST", true);
			NBTTagCompound compound = new NBTTagCompound();
			// not relevant for now
			// compound.setString("OwnerUUID",
			// theEntity.getEntityData().getString("OwnerUUID") );
			// compound.setString("GhostUUID",
			// theEntity.getEntityData().getString("GhostUUID") );
			// compound.setString("ShootUUID",
			// theEntity.getEntityData().getString("ShootUUID") );
			// compound.setBoolean("hasGHOST",
			// theEntity.getEntityData().getBoolean("hasGHOST") );
			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) {

		theEntity.getEntityData().setBoolean("hasGHOST", true);

		NBTTagCompound entityNBT = theEntity.getEntityData();

		//the new fantasmaMercenario entity is conjured here
		onEntityConjureGhost(theEntity);



	}
}

// ########################################################################################################################3
// conjurar espiritu
// @SubscribeEvent
public void onEntityConjureGhost(EntityLivingBase shootingEntity) {

	NBTTagCompound compound = shootingEntity.getEntityData();

	System.out.println("\n\n######\n on IEEP Conjuring Ghost");

	World worldIn = shootingEntity.getEntityWorld();

	System.out.println("### Mundo=" + worldIn.isRemote );

	if (!worldIn.isRemote) {

		String GhostUUID = compound.getString("GhostUUID");
		int GhostID = compound.getInteger("GhostID");
		boolean doSomething = true;

		Entity oldGhost = worldIn.getEntityByID(GhostID);


		//check is there an ghost to avoid multiple watchers over the same entity 
		if (oldGhost != null) {
			if (oldGhost instanceof fantasmaMercenario) {

				fantasmaMercenario oldFantasma = (fantasmaMercenario) oldGhost;
				EntityLivingBase ghostShootingEntity = (EntityLivingBase) oldFantasma.getShootingEntity();

				if (ghostShootingEntity != null) {
					int comparacion = ghostShootingEntity.getUniqueID().compareTo(shootingEntity.getUniqueID());
					if (comparacion == 0) {
						doSomething = false;

						System.out.println("### El fantasma ya existe "); //there is an alredy loaded ghost

					}

				}
			}
		}



		//###############
		if (doSomething){
                         //if reach this is because
                         //there is no ghost and its gona create a new one
		System.out.println("### El fantasma no existe y va a crear uno nuevo"); 


		mercenarymod.entidades.fantasmaMercenario fantasma = new mercenarymod.entidades.fantasmaMercenario(worldIn);
		fantasma.setShootingEntity(shootingEntity);

		double x = shootingEntity.posX;
		double y = shootingEntity.posY + shootingEntity.height;// shootingEntity.getEyeHeight();
		double z = shootingEntity.posZ;

		float yaw = shootingEntity.rotationYaw; // getRotationYawHead();
												// rotationYaw;
		float pitch = shootingEntity.rotationPitch;

		if (pitch < 0) {
			y = shootingEntity.posY;
		}

		fantasma.setPositionAndRotation(x, y, z, yaw, pitch);


                        //Main point the shoting entity 
		fantasma.setShootingEntity(shootingEntity);

		int fantasmaID = fantasma.getEntityId();
		String fantasmaUUID = fantasma.getUniqueID().toString();

                        //   \/ \/ \/
		//i could se this in the console 
		System.out.println("### El fantasma fue Creado con ID="+fantasmaID);


		compound.setString("GhostUUID", fantasmaUUID);
		compound.setInteger("GhostID", fantasmaID);


		//Here  \/ \/ \/ \/
		//but this spawn is not happend and dont see any error  
		worldIn.spawnEntityInWorld(fantasma);


		}
	}
}

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

}

 

 

all this becase is heavy load  to resinc wathed entity whit watcher entity 

 

thanks for reading

 

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



×
×
  • Create New...

Important Information

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