diff --git a/gradle.properties b/gradle.properties index c5281aa..4d52158 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ authors=HavenKing, ModFest contributors=Chai, Sisby folk, ShiroJR, Superkat32, maximumpower55, CallMeEcho, quaternary, comp500, LemmaEOF, acikek, TheEpicBlock, SkyNotTheLimit, Patbox, AmyMialee license=CC0-1.0 # Mod Version -baseVersion=1.7.3 +baseVersion=1.7.4 # Branch Metadata branch=1.21 tagBranch=1.21 diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/SoundPlayerBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/SoundPlayerBlockEntity.java index dc641b4..305a76f 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/SoundPlayerBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/SoundPlayerBlockEntity.java @@ -40,6 +40,7 @@ public class SoundPlayerBlockEntity extends BlockEntity { public float distance = 16; public boolean relative = false; public Vec3d soundPosition; + public boolean cancelOthers = false; public PositionedSoundLoop nowPlaying = null; @@ -133,12 +134,16 @@ public static void clientTick(World world, BlockPos pos, BlockState state, Sound player, entity.getPos() ); - LOGGER.info("done? " + (entity.nowPlaying == null ? "null" : entity.nowPlaying.isDone())); + +// LOGGER.info("done? " + (entity.nowPlaying == null ? "null" : entity.nowPlaying.isDone())); if (entity.nowPlaying == null || entity.nowPlaying.isDone() || entity.nowPlaying.isDifferentFrom(sound)) { mc.getSoundManager().stop(entity.nowPlaying); - mc.getSoundManager().play(sound); - LOGGER.info("playing"); - entity.nowPlaying = sound; +// LOGGER.info("playing"); + if (sound.inRange()) { + if (entity.cancelOthers) mc.getSoundManager().stopSounds(null, entity.category); + mc.getSoundManager().play(sound); + entity.nowPlaying = sound; + } } } } @@ -184,12 +189,16 @@ public void setDone() { @Override public void tick() { // stops track-stacking when reloading the block - if (!(this.player.squaredDistanceTo(this.soundBlockPos.toCenterPos()) <= this.squaredDistance) || + if (!inRange() || !(this.player.getWorld().getBlockEntity(this.soundBlockPos) instanceof SoundPlayerBlockEntity be && !this.isDifferentFrom(be.nowPlaying))) { setDone(); } } + public boolean inRange() { + return this.player.squaredDistanceTo(this.soundBlockPos.toCenterPos()) <= this.squaredDistance; + } + // @Override // public boolean canPlay() { // return this.player.squaredDistanceTo(this.soundBlockPos.toCenterPos()) <= this.squaredDistance; diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SoundPlayerBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SoundPlayerBlockEditScreen.java index a143d7d..1607a8b 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SoundPlayerBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SoundPlayerBlockEditScreen.java @@ -18,6 +18,7 @@ public class SoundPlayerBlockEditScreen extends GlowcaseScreen { private TextFieldWidget soundId; private ButtonWidget categoryButton; + private ButtonWidget cancelOthersButton; private TextFieldWidget volume; private TextFieldWidget pitch; @@ -52,6 +53,12 @@ protected void init() { }).dimensions(7 * width / 10, 20, 2 * width / 10, 20).build(); this.addDrawableChild(this.categoryButton); + this.cancelOthersButton = new ButtonWidget.Builder(Text.of(Boolean.toString(soundBlock.cancelOthers)), (action) -> { + soundBlock.cancelOthers = !soundBlock.cancelOthers; + this.cancelOthersButton.setMessage(Text.of(Boolean.toString(soundBlock.cancelOthers))); + }).dimensions(7 * width / 10, 50, 2 * width / 10, 20).build(); + this.addDrawableChild(this.cancelOthersButton); + this.volume = new TextFieldWidget( this.client.textRenderer, width / 10, 110, diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SoundPlayerBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SoundPlayerBlockEntityRenderer.java index 6e29309..d93084b 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SoundPlayerBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SoundPlayerBlockEntityRenderer.java @@ -14,7 +14,7 @@ public record SoundPlayerBlockEntityRenderer(BlockEntityRendererFactory.Context @Override public void render(SoundPlayerBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { - //if (BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) + if (BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 1.0F, matrices, vertexConsumers, context.getRenderDispatcher().camera); } } diff --git a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSoundBlock.java b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSoundBlock.java index e7b4a36..0170430 100644 --- a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSoundBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSoundBlock.java @@ -24,7 +24,7 @@ public record C2SEditSoundBlock(SoundInfo soundInfo, PositionalInfo positionalIn public static C2SEditSoundBlock of(SoundPlayerBlockEntity be) { return new C2SEditSoundBlock( - new SoundInfo(be.soundId, be.category.toString(), be.volume, be.pitch, be.repeatDelay), + new SoundInfo(be.soundId, be.category.toString(), be.volume, be.pitch, be.repeatDelay, be.cancelOthers), new PositionalInfo(be.distance, be.relative, be.soundPosition), be.getPos() ); @@ -49,6 +49,7 @@ public void receive(ServerWorld world, BlockEntity blockEntity) { be.volume = soundInfo.volume; be.pitch = soundInfo.pitch; be.repeatDelay = soundInfo.repeatDelay; + be.cancelOthers = soundInfo.cancelOthers; be.distance = positionalInfo.distance; be.relative = positionalInfo.relative; @@ -58,13 +59,14 @@ public void receive(ServerWorld world, BlockEntity blockEntity) { be.dispatch(); } - public record SoundInfo(Identifier id, String category, float volume, float pitch, int repeatDelay) { + public record SoundInfo(Identifier id, String category, float volume, float pitch, int repeatDelay, boolean cancelOthers) { public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( Identifier.PACKET_CODEC, SoundInfo::id, PacketCodecs.STRING, SoundInfo::category, PacketCodecs.FLOAT, SoundInfo::volume, PacketCodecs.FLOAT, SoundInfo::pitch, PacketCodecs.INTEGER, SoundInfo::repeatDelay, + PacketCodecs.BOOL, SoundInfo::cancelOthers, SoundInfo::new ); }