Jump to content

[1.15.2] Entity yaw incorrect upon spawning - fixes after reloading world


Recommended Posts

I'm working on an entity - very similar to that of an armor stand - as of current. A lot of what I have gone off is abstracted from the armor stand classes. I am, however, experiencing issues with the yaw of this upon being spawned into the world.


The same as armor stands - the intended effect is for the entity to face the player upon being placed (players yaw, flipped and rounded to face a 45 degree angle). When placed, however, the entity rotates to the incorrect angle - while hitboxes show that they are facing south (even if they aren't). Reloading the world then causes them to face the correct direction. An image to better illustrate my point:




As can be seen, before they are appearing to all face sotuh via hitboxes. The yaw property is definitely set and getting the values from them shows them to be correct. They don't reflect this change on the client until the world is reloaded, however. I'll include relevant code samples below.


Item class (used to spawn entity into the world):

public class TrainingDummyItem extends Item {

	public TrainingDummyItem(Properties properties) {
	public ActionResultType onItemUse(ItemUseContext context) {
		Direction direction = context.getFace();
		if (direction == Direction.DOWN) {
			return ActionResultType.FAIL;
		} else {
			World world = context.getWorld();
			BlockItemUseContext blockitemusecontext = new BlockItemUseContext(context);
			BlockPos blockpos = blockitemusecontext.getPos();
			BlockPos blockpos1 = blockpos.up();
			if (blockitemusecontext.canPlace() && world.getBlockState(blockpos1).isReplaceable(blockitemusecontext)) {
				double d0 = (double) blockpos.getX();
				double d1 = (double) blockpos.getY();
				double d2 = (double) blockpos.getZ();
				List<Entity> list = world.getEntitiesWithinAABBExcludingEntity((Entity) null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));
				if (!list.isEmpty()) {
					return ActionResultType.FAIL;
				} else {
					ItemStack itemstack = context.getItem();
					if (!world.isRemote) {
						world.removeBlock(blockpos, false);
						world.removeBlock(blockpos1, false);
						TrainingDummyEntity trainingDummyEntity = new TrainingDummyEntity(world, d0 + 0.5D, d1, d2 + 0.5D);
						float f = (float)MathHelper.floor((MathHelper.wrapDegrees(context.getPlacementYaw() - 180.0F) + 22.5F) / 45.0F) * 45.0F;
						trainingDummyEntity.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
						EntityType.applyItemNBT(world, context.getPlayer(), trainingDummyEntity, itemstack.getTag());
						world.playSound((PlayerEntity) null, trainingDummyEntity.func_226277_ct_(), trainingDummyEntity.func_226278_cu_(), trainingDummyEntity.func_226281_cx_(), SoundEvents.ENTITY_ARMOR_STAND_PLACE, SoundCategory.BLOCKS, 0.75F, 0.8F);

					return ActionResultType.SUCCESS;
			} else {
				return ActionResultType.FAIL;


Entity class (stripped it down to the bare essentials to check nothing I was doing was causing issues):

public class TrainingDummyEntity extends LivingEntity {
	private final NonNullList<ItemStack> armorItems = NonNullList.withSize(4, ItemStack.EMPTY);

	public TrainingDummyEntity(EntityType<? extends LivingEntity> type, World world) {
		super(type, world);
	public TrainingDummyEntity(World worldIn, double posX, double posY, double posZ) {
		this(EntityInit.TRAINING_DUMMY_ENTITY.get(), worldIn);
		this.setPosition(posX, posY, posZ);

	public Iterable<ItemStack> getArmorInventoryList() {
		return armorItems;

	public ItemStack getItemStackFromSlot(EquipmentSlotType slotIn) {
		return ItemStack.EMPTY;

	public void setItemStackToSlot(EquipmentSlotType slotIn, ItemStack stack) { }

	public HandSide getPrimaryHand() {
		return HandSide.RIGHT;



As far as I am aware the issue should be in these files. There's nothing to suggest it's anything to do with the renderer, model or registering (although I can add these upon request if any issue is not visible).


Thanks in advance.

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.

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.


  • Create New...

Important Information

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