From 653fc0bcf7c65c1bbe2bae953fc100136f5f4c54 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 1 Nov 2024 14:01:58 +0000 Subject: [PATCH] Make horseshoes, muffins, and rocks produce intangible projectiles when thrown by creative players. Closes #510 --- .../unicopia/item/HeavyProjectileItem.java | 2 -- .../unicopia/projectile/Projectile.java | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java b/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java index 08240df2..34b6109c 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java @@ -6,7 +6,6 @@ import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.projectile.PhysicsBodyProjectileEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.PersistentProjectileEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvent; @@ -25,7 +24,6 @@ public class HeavyProjectileItem extends ProjectileItem { if (player != null) { projectile.setVelocity(player, player.getPitch(), player.getYaw(), 0, 1.5F, 1); } - projectile.pickupType = PersistentProjectileEntity.PickupPermission.ALLOWED; return projectile; } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java b/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java index 2978ef3d..1281d66c 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java @@ -6,7 +6,9 @@ import com.minelittlepony.unicopia.util.SoundEmitter; import net.minecraft.block.DispenserBlock; import net.minecraft.block.dispenser.ProjectileDispenserBehavior; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.PersistentProjectileEntity; import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; @@ -16,6 +18,7 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.stat.Stats; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; +import net.minecraft.util.Unit; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Position; import net.minecraft.world.World; @@ -32,7 +35,12 @@ public interface Projectile extends ItemConvertible, ProjectileItem { @Override default ProjectileEntity createEntity(World world, Position pos, ItemStack stack, Direction direction) { - return createProjectile(stack, world, null); + ProjectileEntity entity = createProjectile(stack.copyWithCount(1), world, null); + entity.setPosition(pos.getX(), pos.getY(), pos.getZ()); + if (entity instanceof PersistentProjectileEntity p) { + p.pickupType = PersistentProjectileEntity.PickupPermission.ALLOWED; + } + return entity; } @Override @@ -49,7 +57,12 @@ public interface Projectile extends ItemConvertible, ProjectileItem { 0.5F, 0.4F / (world.random.nextFloat() * 0.4F + 0.8F)); - world.spawnEntity(createProjectile(stack.copyWithCount(1), world, player)); + ItemStack projectileStack = stack.splitUnlessCreative(1, player); + if (player.isCreative()) { + projectileStack.set(DataComponentTypes.INTANGIBLE_PROJECTILE, Unit.INSTANCE); + } + + world.spawnEntity(createProjectile(projectileStack, world, player)); } player.incrementStat(Stats.USED.getOrCreateStat(asItem()));