Jump to content

How do I store the dragon's uuid in the item if the dragon dies


TheRPGAdventurer

Recommended Posts

	/**
	 * Called when the mob's health reaches 0.
	 */
	public void onDeath(DamageSource src) {
		super.onDeath(src);
		if (dragonInv != null && !this.world.isRemote && !isEgg()) {
			for (int i = 0; i < dragonInv.getSizeInventory(); ++i) {
				ItemStack itemstack = dragonInv.getStackInSlot(i);
				if (!itemstack.isEmpty()) {
					this.entityDropItem(itemstack, 0.0F);
				}
			}
		}
		
		if(!this.world.isRemote) {
				if(this.isTamed()) {
		  	ItemDragonEssence essence = dragonEssence();
			  essence.setDragonNBT(this);
			  entityDropItem(new ItemStack(essence), 1);
			}
		}
	}

 

 

	public void setDragonNBT(EntityTameableDragon dragon) {
		 ItemStack stack = new ItemStack(this);
	 	NBTTagCompound nbt = stack.getTagCompound();		
   if (stack.hasTagCompound()) {
     nbt = stack.getTagCompound(); 
   } else {
     nbt = new NBTTagCompound();
   }
 				
   stack.setTagCompound(nbt);
   
   if(stack.getTagCompound() != null) {
   	nbt.setUniqueId("essenceDragonId", dragon.getUniqueID());
   	nbt.setUniqueId("essenceOwnerId" , dragon.getOwnerId ());
   	if(dragon.hasCustomName())	nbt.setString("name", dragon.getCustomNameTag());
   }
	}

 

So if a dragon is tamed and it dies, it will store its uuid and owner uuid so that players can respawn it.

Link to comment
Share on other sites

somehow it doesnt work when it dies, you can respawn it by right clicking it on the ground

	public void setDragonNBT(EntityTameableDragon dragon) {
		 ItemStack stack = new ItemStack(this);
	 	NBTTagCompound nbt = stack.getTagCompound();		
   if (stack.hasTagCompound()) {
     nbt = stack.getTagCompound(); 
   } else {
     nbt = new NBTTagCompound();
   }
 				
   stack.setTagCompound(nbt);
   
   if(stack.getTagCompound() != null) {
   	nbt.setUniqueId("essenceDragonId", dragon.getUniqueID());
   	nbt.setUniqueId("essenceOwnerId" , dragon.getOwnerId ());
   	if(dragon.hasCustomName())	nbt.setString("name", dragon.getCustomNameTag());
   }
	}

 

Link to comment
Share on other sites

Just now, diesieben07 said:

Your setDragonNBT does nothing. Well, it does, but nothing useful. It creates an ItemStack, writes some data to it and then discards it, leaving it completely unused.

Your onDeath then goes and creates a new ItemStack of the essence (without any data written to it) and drops that into the world.

ohhhh, so what should I do?

Link to comment
Share on other sites

    public void setDragonNBT(EntityTameableDragon dragon, ItemStack stack) {
         NBTTagCompound nbt = stack.getTagCompound();        
   if (stack.hasTagCompound()) {
     nbt = stack.getTagCompound(); 
   } else {
     nbt = new NBTTagCompound();
   }
                 
   stack.setTagCompound(nbt);
   
   if(stack.getTagCompound() != null) {
       nbt.setUniqueId("essenceDragonId", dragon.getUniqueID());
       nbt.setUniqueId("essenceOwnerId" , dragon.getOwnerId ());
       if(dragon.hasCustomName())    nbt.setString("name", dragon.getCustomNameTag());
   }
    }

 

like this, they drop but they wont spawn

Link to comment
Share on other sites

Just now, diesieben07 said:

Post the code where you actually drop the item.

And please use the code option in the editor.

	/**
	 * Called when the mob's health reaches 0.
	 */
	public void onDeath(DamageSource src) {
		super.onDeath(src);
		if (dragonInv != null && !this.world.isRemote && !isEgg()) {
			for (int i = 0; i < dragonInv.getSizeInventory(); ++i) {
				ItemStack itemstack = dragonInv.getStackInSlot(i);
				if (!itemstack.isEmpty()) {
					this.entityDropItem(itemstack, 0.0F);
				}
			}
		}
		
		if(!this.world.isRemote) {
				if(this.isTamed()) {
		  	ItemDragonEssence essence = dragonEssence();
		  	ItemStack essence1 = new ItemStack(essence);
			  essence.setDragonNBT(this, essence1);
			  entityDropItem(essence1, 1);
			}
		}
	}

 

Link to comment
Share on other sites

Also away from this I have a new truble is EntityAITasks.EntityAITAskEntry became private?

java.lang.BootstrapMethodError: java.lang.IllegalAccessError: Class 'com.TheRPGAdventurer.ROTD.server.entity.helper.DragonBrain' no access to: class 'net.minecraft.entity.ai.EntityAITasks$EntityAITaskEntry'
 

I get this error from this

    public void clearTasks() {
        clearTasks(tasks);
        clearTasks(targetTasks);
    }
    
    public void clearTasks(EntityAITasks tasks) {
        List<EntityAITaskEntry> taskEntries = new ArrayList<>(tasks.taskEntries);
        taskEntries.forEach(entry -> tasks.removeTask(entry.action));
    }

 

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.