From 5a7a35b3cc44ac7adfce02379590b8bc610fbe9f Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 26 Jun 2021 10:40:10 -0700 Subject: [PATCH] Sounds in the right places and no stacking --- .../java/com/simibubi/create/AllItems.java | 1 + .../com/simibubi/create/AllSoundEvents.java | 19 ++++++++++++++----- .../weapons/PotatoCannonRenderHandler.java | 2 +- .../weapons/PotatoProjectileEntity.java | 2 +- .../weapons/PotatoProjectileRenderMode.java | 11 ++++++++--- .../curiosities/zapper/ShootGadgetPacket.java | 11 +++++------ .../zapper/ShootableGadgetRenderHandler.java | 8 ++++---- .../zapper/ZapperRenderHandler.java | 3 +-- 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index c7d7521d6..0c12df01c 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -232,6 +232,7 @@ public class AllItems { public static final ItemEntry POTATO_CANNON = REGISTRATE.item("potato_cannon", PotatoCannonItem::new) + .properties(p -> p.maxStackSize(1)) .transform(CreateRegistrate.customRenderedItem(() -> PotatoCannonModel::new)) .model(AssetLookup.itemModelWithPartials()) .register(); diff --git a/src/main/java/com/simibubi/create/AllSoundEvents.java b/src/main/java/com/simibubi/create/AllSoundEvents.java index 9056afc59..8682a553e 100644 --- a/src/main/java/com/simibubi/create/AllSoundEvents.java +++ b/src/main/java/com/simibubi/create/AllSoundEvents.java @@ -25,6 +25,7 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.registries.IForgeRegistry; @@ -231,7 +232,7 @@ public class AllSoundEvents { // return; // if (soundLocation.getPath().contains("_compounded_") // event.setResultSound(); -// +// // } private static class SoundEntryProvider implements IDataProvider { @@ -377,10 +378,18 @@ public class AllSoundEvents { play(world, entity, pos.getX(), pos.getY(), pos.getZ(), volume, pitch); } - abstract void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch); + public void play(World world, PlayerEntity entity, Vector3d pos, float volume, float pitch) { + play(world, entity, pos.getX(), pos.getY(), pos.getZ(), volume, pitch); + } + + public abstract void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch); public void playAt(World world, BlockPos pos, float volume, float pitch, boolean fade) { - playAt(world, pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, volume, pitch, fade); + playAt(world, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, volume, pitch, fade); + } + + public void playAt(World world, Vector3d pos, float volume, float pitch, boolean fade) { + playAt(world, pos.getX(), pos.getY(), pos.getZ(), volume, pitch, fade); } public abstract void playAt(World world, double x, double y, double z, float volume, float pitch, boolean fade); @@ -445,7 +454,7 @@ public class AllSoundEvents { } @Override - void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch) { + public void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch) { for (Pair> pair : compiledEvents) { Couple volPitch = pair.getSecond(); world.playSound(entity, x, y, z, pair.getFirst(), category, volPitch.getFirst() * volume, @@ -498,7 +507,7 @@ public class AllSoundEvents { } @Override - void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch) { + public void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch) { world.playSound(entity, x, y, z, event, category, volume, pitch); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonRenderHandler.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonRenderHandler.java index 4cec8dcc2..81009bc54 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonRenderHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonRenderHandler.java @@ -22,7 +22,7 @@ public class PotatoCannonRenderHandler extends ShootableGadgetRenderHandler { private float nextPitch; @Override - protected void playSound(Hand hand, BlockPos position) { + protected void playSound(Hand hand, Vector3d position) { PotatoProjectileEntity.playLaunchSound(Minecraft.getInstance().world, position, nextPitch); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java index 0ee33981f..36dd46492 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java @@ -167,7 +167,7 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements AllSoundEvents.POTATO_HIT.playOnServer(world, new BlockPos(location)); } - public static void playLaunchSound(World world, BlockPos location, float pitch) { + public static void playLaunchSound(World world, Vector3d location, float pitch) { AllSoundEvents.FWOOMP.playAt(world, location, 1, pitch, true); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java index 46ab4fa99..9fb0c04e3 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java @@ -5,6 +5,7 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.api.distmarker.Dist; @@ -41,8 +42,8 @@ public abstract class PotatoProjectileRenderMode { public void transform(MatrixStack ms, PotatoProjectileEntity entity, float pt) { super.transform(ms, entity, pt); MatrixStacker.of(ms) - .rotateZ((entity.ticksExisted + pt) * 2 * (entity.getEntityId() % 16)) - .rotateX((entity.ticksExisted + pt) * (entity.getEntityId() % 32)); + .rotateZ((entity.ticksExisted + pt) * 2 * entityRandom(entity, 16)) + .rotateX((entity.ticksExisted + pt) * entityRandom(entity, 32)); } } @@ -65,10 +66,14 @@ public abstract class PotatoProjectileRenderMode { .rotateX(270 + AngleHelper.deg(MathHelper.atan2(diff.y, -MathHelper.sqrt(diff.x * diff.x + diff.z * diff.z)))); MatrixStacker.of(ms) - .rotateY((entity.ticksExisted + pt) * 20 * spin) + .rotateY((entity.ticksExisted + pt) * 20 * spin + entityRandom(entity, 360)) .rotateZ(-spriteAngleOffset); } } + public static int entityRandom(Entity entity, int maxValue) { + return (System.identityHashCode(entity) * 31) % maxValue; + } + } diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootGadgetPacket.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootGadgetPacket.java index 370cbf401..12a204775 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootGadgetPacket.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootGadgetPacket.java @@ -8,7 +8,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.network.PacketBuffer; import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -45,13 +44,13 @@ public abstract class ShootGadgetPacket extends SimplePacketBase { protected abstract void readAdditional(PacketBuffer buffer); protected abstract void writeAdditional(PacketBuffer buffer); - + @OnlyIn(Dist.CLIENT) protected abstract void handleAdditional(); @OnlyIn(Dist.CLIENT) protected abstract ShootableGadgetRenderHandler getHandler(); - + @Override @OnlyIn(Dist.CLIENT) public final void handle(Supplier context) { @@ -64,13 +63,13 @@ public abstract class ShootGadgetPacket extends SimplePacketBase { if (renderViewEntity.getPositionVec() .distanceTo(location) > 100) return; - + ShootableGadgetRenderHandler handler = getHandler(); handleAdditional(); if (self) - handler.shoot(hand); + handler.shoot(hand, location); else - handler.playSound(hand, new BlockPos(location)); + handler.playSound(hand, location); }); context.get() .setPacketHandled(true); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootableGadgetRenderHandler.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootableGadgetRenderHandler.java index 82ed26ba6..11b7c2b5e 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootableGadgetRenderHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ShootableGadgetRenderHandler.java @@ -13,8 +13,8 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; import net.minecraft.util.HandSide; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3f; import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.eventbus.api.IEventBus; @@ -44,7 +44,7 @@ public abstract class ShootableGadgetRenderHandler { return 0.8f; } - public void shoot(Hand hand) { + public void shoot(Hand hand, Vector3d location) { ClientPlayerEntity player = Minecraft.getInstance().player; boolean rightHand = hand == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT; if (rightHand) { @@ -54,10 +54,10 @@ public abstract class ShootableGadgetRenderHandler { leftHandAnimation = .2f; dontReequipLeft = false; } - playSound(hand, player.getBlockPos()); + playSound(hand, location); } - protected abstract void playSound(Hand hand, BlockPos position); + protected abstract void playSound(Hand hand, Vector3d position); protected abstract boolean appliesTo(ItemStack stack); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java index 90875e628..5d370e8de 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java @@ -14,7 +14,6 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.item.ItemStack; import net.minecraft.particles.ParticleTypes; import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3f; @@ -58,7 +57,7 @@ public class ZapperRenderHandler extends ShootableGadgetRenderHandler { protected void transformHand(MatrixStack ms, float flip, float equipProgress, float recoil, float pt) {} @Override - protected void playSound(Hand hand, BlockPos position) { + protected void playSound(Hand hand, Vector3d position) { float pitch = hand == Hand.MAIN_HAND ? 0.1f : 0.9f; Minecraft mc = Minecraft.getInstance(); AllSoundEvents.WORLDSHAPER_PLACE.play(mc.world, mc.player, position, 0.1f, pitch);