From 2ad3f48f15236c08c20145e2813c605909859165 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 6 Oct 2024 18:26:44 +0100 Subject: [PATCH] Fixed muffins and rocks appearing invisible when thrown --- .../unicopia/item/HeavyProjectileItem.java | 5 +++-- .../PhysicsBodyProjectileEntity.java | 20 ++++++++++--------- .../unicopia/projectile/Projectile.java | 10 +++++----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java b/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java index 16797e43..e76a2920 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java @@ -18,12 +18,13 @@ public class HeavyProjectileItem extends ProjectileItem { @Override public PhysicsBodyProjectileEntity createProjectile(ItemStack stack, World world, @Nullable PlayerEntity player) { - PhysicsBodyProjectileEntity projectile = player == null ? new PhysicsBodyProjectileEntity(world) : new PhysicsBodyProjectileEntity(world, player); + PhysicsBodyProjectileEntity projectile = player == null + ? new PhysicsBodyProjectileEntity(world, stack.copyWithCount(1)) + : new PhysicsBodyProjectileEntity(world, player, stack.copyWithCount(1)); if (player != null) { projectile.setVelocity(player, player.getPitch(), player.getYaw(), 0, 1.5F, 1); } projectile.pickupType = PersistentProjectileEntity.PickupPermission.ALLOWED; - projectile.setStack(stack.copy().split(1)); return projectile; } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java index 19b3c2bc..a831c804 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java @@ -55,16 +55,18 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl private RegistryKey damageType = UDamageTypes.ROCK; + public PhysicsBodyProjectileEntity(World world, ItemStack stack) { + super(UEntities.MUFFIN, world); + setStack(stack); + } + public PhysicsBodyProjectileEntity(EntityType type, World world) { super(type, world); } - public PhysicsBodyProjectileEntity(World world) { - this(UEntities.MUFFIN, world); - } - - public PhysicsBodyProjectileEntity(World world, @Nullable LivingEntity thrower) { + public PhysicsBodyProjectileEntity(World world, @Nullable LivingEntity thrower, ItemStack stack) { super(UEntities.MUFFIN, thrower, world); + setStack(stack); } @Override @@ -75,7 +77,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl } public void setStack(ItemStack stack) { - getDataTracker().set(ITEM, stack); + getDataTracker().set(ITEM, stack.copy()); } @Override @@ -89,7 +91,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl @Override protected ItemStack asItemStack() { - return getStack(); + return getStack().copy(); } public void setBouncy() { @@ -273,7 +275,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl super.writeCustomDataToNbt(nbt); ItemStack stack = getStack(); if (!stack.isEmpty()) { - nbt.put("Item", stack.writeNbt(new NbtCompound())); + nbt.put("item", stack.writeNbt(new NbtCompound())); } nbt.putString("damageType", damageType.getValue().toString()); } @@ -281,7 +283,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl @Override public void readCustomDataFromNbt(NbtCompound nbt) { super.readCustomDataFromNbt(nbt); - setStack(ItemStack.fromNbt(nbt.getCompound("Item"))); + setStack(ItemStack.fromNbt(nbt.getCompound("item"))); if (nbt.contains("damageType", NbtElement.STRING_TYPE)) { Optional.ofNullable(Identifier.tryParse(nbt.getString("damageType"))).ifPresent(id -> { setDamageType(RegistryKey.of(RegistryKeys.DAMAGE_TYPE, id)); diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java b/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java index c8b0c2a2..34f831ea 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java @@ -38,12 +38,12 @@ public interface Projectile extends ItemConvertible { default TypedActionResult triggerThrow(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); - SoundEmitter.playSoundAt(player, - getThrowSound(stack), SoundCategory.NEUTRAL, - 0.5F, - 0.4F / (world.random.nextFloat() * 0.4F + 0.8F)); - if (!world.isClient) { + SoundEmitter.playSoundAt(player, + getThrowSound(stack), SoundCategory.NEUTRAL, + 0.5F, + 0.4F / (world.random.nextFloat() * 0.4F + 0.8F)); + world.spawnEntity(createProjectile(stack.copyWithCount(1), world, player)); }