Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • Author

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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.