Jump to content

Recommended Posts

Posted

I am trying to make an event that will spawn armor stands with arms whenever an armor stand is spawned but I cannot get it to work.

I included a logger to see if it gets past the if statement that checks if the entity spawned was an armor stand and it does not log anything so I am assuming that is the problem(I put one outside of the if statement and it does log when things spawn).

Any ideas?

 

package com.chaoticsoul.evolate.events;
import com.chaoticsoul.evolate.Evolate;

import net.minecraft.entity.item.ArmorStandEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@Mod.EventBusSubscriber(modid = Evolate.MOD_ID, bus = Bus.FORGE)
public class SpawnArmorStandEvent {

	@SubscribeEvent
	public static void spawnArmorStandEvent(LivingSpawnEvent event)
	{
		if (event.getEntityLiving() instanceof ArmorStandEntity)
		{
			Evolate.LOGGER.info("test");
			ArmorStandEntity stand = (ArmorStandEntity) event.getEntityLiving();
			CompoundNBT compound = new CompoundNBT();
			compound.putBoolean("ShowArms", true);
			stand.writeAdditional(compound);
		}
	}
	

}

Also, I am new to nbt data so that part may be wrong as well.

Posted (edited)

Thanks, it now works

For anyone else trying to do this, the final code is:

package com.chaoticsoul.evolate.events;
import com.chaoticsoul.evolate.Evolate;

import net.minecraft.entity.item.ArmorStandEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@Mod.EventBusSubscriber(modid = Evolate.MOD_ID, bus = Bus.FORGE)
public class SpawnArmorStandEvent {
	@SubscribeEvent
	public static void spawnArmorStandEvent(EntityJoinWorldEvent event)
	{
		if (event.getEntity() instanceof ArmorStandEntity)
		{
			ArmorStandEntity stand = (ArmorStandEntity) event.getEntity();
			CompoundNBT compound = new CompoundNBT();
			compound.putBoolean("ShowArms", true);
			stand.readAdditional(compound);
		}
	}
	

}

 

Edited by clearcut
mistake in code
Posted

Ah, I didn't know about the overwriting.

			stand.writeAdditional(compound);
			compound.putBoolean("ShowArms", true);

Adding the lines above before the readAdditional method seems to work but does it fix the overwriting issue?

I wanted to find a work around using setShowArms since I did not know how to use it.

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.