From 9613a21049168fb6fdf0b8fc81bc1771c5018fd3 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Thu, 31 Oct 2024 04:43:19 -0400 Subject: [PATCH 1/3] fix .local server --- gradle.properties | 2 +- .../java/net/frozenblock/lib/networking/FrozenNetworking.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 919846da..0bbd11ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ min_loader_version=0.16.0 # Mod Properties - mod_version = 1.9.1 + mod_version = 1.9.2 maven_group = net.frozenblock archives_base_name = FrozenLib diff --git a/src/main/java/net/frozenblock/lib/networking/FrozenNetworking.java b/src/main/java/net/frozenblock/lib/networking/FrozenNetworking.java index 44409681..5518a400 100644 --- a/src/main/java/net/frozenblock/lib/networking/FrozenNetworking.java +++ b/src/main/java/net/frozenblock/lib/networking/FrozenNetworking.java @@ -152,7 +152,7 @@ public static void registerNetworking() { } else { if (!FrozenLibConfig.FILE_TRANSFER_SERVER) return; try { - Path path = ctx.server().getServerDirectory().resolve(packet.transferPath()).resolve(packet.fileName()); + Path path = ctx.server().getServerDirectory().resolve(packet.transferPath().replace(".local/", "")).resolve(packet.fileName()); FileUtils.copyInputStreamToFile(new ByteArrayInputStream(packet.bytes()), path.toFile()); } catch (IOException ignored) { } From 012b1ed2d597ad475d5b98a05685b4eb4b944945 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:29:32 -0400 Subject: [PATCH 2/3] fix sound overwrites --- CHANGELOG.md | 5 ++- .../BlockSoundGroupOverwrites.java | 14 +++++++- .../BlockSoundGroupManager.java | 36 ++++++++++--------- .../{client => }/BlockBehaviourMixin.java | 22 +++--------- .../mixin/frozenlib.sound.mixins.json | 6 ++-- 5 files changed, 41 insertions(+), 42 deletions(-) rename src/main/java/net/frozenblock/lib/sound/mixin/{client => }/BlockBehaviourMixin.java (59%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddd1c9d4..83968dd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,5 @@ Make sure to clear this after each release Put changelog here: ----------------- -- Updated to Kotlin 2.0.21 -- Block sound overwrites now work on servers. -- FrozenLib's `fabric.mod.json` no longer requires a specific Fabric API. +- Block sound overwrites now actually work on servers, unlike last time. +- Fixed `.local` directories not being accounted for in transfer packets received by the server. diff --git a/src/main/java/net/frozenblock/lib/sound/api/block_sound_group/BlockSoundGroupOverwrites.java b/src/main/java/net/frozenblock/lib/sound/api/block_sound_group/BlockSoundGroupOverwrites.java index b97fc71f..e00eac13 100644 --- a/src/main/java/net/frozenblock/lib/sound/api/block_sound_group/BlockSoundGroupOverwrites.java +++ b/src/main/java/net/frozenblock/lib/sound/api/block_sound_group/BlockSoundGroupOverwrites.java @@ -18,13 +18,16 @@ package net.frozenblock.lib.sound.api.block_sound_group; import java.util.List; +import java.util.Optional; import java.util.function.BooleanSupplier; import lombok.experimental.UtilityClass; import net.frozenblock.lib.sound.impl.block_sound_group.BlockSoundGroupManager; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -38,7 +41,6 @@ public class BlockSoundGroupOverwrites { private static final BlockSoundGroupManager MANAGER = BlockSoundGroupManager.INSTANCE; - @Nullable public static List getOverwrites() { return MANAGER.getOverwrites(); } @@ -48,6 +50,16 @@ public static BlockSoundGroupOverwrite getOverwrite(ResourceLocation id) { return MANAGER.getOverwrite(id); } + public static @NotNull Optional getOverwrite(Block block) { + ResourceLocation id = BuiltInRegistries.BLOCK.getKey(block); + return MANAGER.getOverwrites().stream().filter(overwrite -> overwrite.blockId().equals(id)).findFirst(); + } + + public static Optional getOverwriteIfConditionIsMet(Block block) { + ResourceLocation id = BuiltInRegistries.BLOCK.getKey(block); + return MANAGER.getOverwrites().stream().filter(overwrite -> overwrite.blockId().equals(id) && overwrite.condition().getAsBoolean()).findFirst(); + } + /** * This will only work with vanilla blocks. */ diff --git a/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java b/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java index 35747a15..7fb8b2c5 100644 --- a/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java +++ b/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.BooleanSupplier; @@ -46,6 +47,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -61,12 +63,11 @@ public class BlockSoundGroupManager implements SimpleResourceReloadListener overwrites; private final Map queuedOverwrites = new Object2ObjectOpenHashMap<>(); - @Nullable public List getOverwrites() { if (this.overwrites != null) { return this.overwrites.values().stream().toList(); } - return null; + return List.of(); } @Nullable @@ -74,15 +75,15 @@ public BlockSoundGroupOverwrite getOverwrite(ResourceLocation id) { return this.overwrites.get(id); } + public Optional getOptionalOverwrite(ResourceLocation id) { + return Optional.ofNullable(this.overwrites.get(id)); + } + /** * Adds a block with the specified {@link ResourceLocation}. */ public void addBlock(ResourceLocation key, SoundType sounds, BooleanSupplier condition) { - if (!BuiltInRegistries.BLOCK.containsKey(key)) { - FrozenLogUtils.log("Error whilst adding a block to BlockSoundGroupOverwrites: The specified block id has not been added to the Registry", true); - } else { - this.queuedOverwrites.put(getPath(key), new BlockSoundGroupOverwrite(key, sounds, condition)); - } + this.queuedOverwrites.put(getPath(key), new BlockSoundGroupOverwrite(key, sounds, condition)); } /** @@ -106,7 +107,7 @@ public void addBlock(Block block, SoundType sounds, BooleanSupplier condition) { addBlock(key, sounds, condition); } - public void addBlocks(Block[] blocks, SoundType sounds, BooleanSupplier condition) { + public void addBlocks(Block @NotNull [] blocks, SoundType sounds, BooleanSupplier condition) { for (Block block : blocks) { var key = BuiltInRegistries.BLOCK.getKey(block); addBlock(key, sounds, condition); @@ -126,7 +127,8 @@ public void addBlockTag(TagKey tag, SoundType sounds, BooleanSupplier con } } - public static ResourceLocation getPath(ResourceLocation blockId) { + @Contract("_ -> new") + public static @NotNull ResourceLocation getPath(@NotNull ResourceLocation blockId) { return ResourceLocation.fromNamespaceAndPath(blockId.getNamespace(), DIRECTORY + "/" + blockId.getPath() + ".json"); } @@ -136,10 +138,10 @@ public CompletableFuture load(ResourceManager manager, Profile } @Override - public CompletableFuture apply(SoundGroupLoader prepared, ResourceManager manager, ProfilerFiller profiler, Executor executor) { - this.overwrites = prepared.getOverwrites(); - this.overwrites.putAll(this.queuedOverwrites); + public CompletableFuture apply(@NotNull SoundGroupLoader prepared, ResourceManager manager, ProfilerFiller profiler, Executor executor) { return CompletableFuture.runAsync(() -> { + this.overwrites = prepared.getOverwrites(); + this.overwrites.putAll(this.queuedOverwrites); }); } @@ -161,16 +163,16 @@ public SoundGroupLoader(ResourceManager manager, ProfilerFiller profiler) { } private void loadSoundOverwrites() { - profiler.push("Load Sound Overwrites"); - Map resources = manager.listResources(DIRECTORY, id -> id.getPath().endsWith(".json")); + this.profiler.push("Load Sound Overwrites"); + Map resources = this.manager.listResources(DIRECTORY, id -> id.getPath().endsWith(".json")); var entrySet = resources.entrySet(); for (Map.Entry entry : entrySet) { this.addOverwrite(entry.getKey(), entry.getValue()); } - profiler.pop(); + this.profiler.pop(); } - private void addOverwrite(ResourceLocation id, Resource resource) { + private void addOverwrite(ResourceLocation id, @NotNull Resource resource) { BufferedReader reader; try { reader = resource.openAsReader(); @@ -188,7 +190,7 @@ private void addOverwrite(ResourceLocation id, Resource resource) { } ResourceLocation overwriteId = ResourceLocation.fromNamespaceAndPath(id.getNamespace(), id.getPath().substring((DIRECTORY + "/").length())); - overwrites.put(overwriteId, result.result().orElseThrow().getFirst()); + this.overwrites.put(overwriteId, result.result().orElseThrow().getFirst()); } public Map getOverwrites() { diff --git a/src/main/java/net/frozenblock/lib/sound/mixin/client/BlockBehaviourMixin.java b/src/main/java/net/frozenblock/lib/sound/mixin/BlockBehaviourMixin.java similarity index 59% rename from src/main/java/net/frozenblock/lib/sound/mixin/client/BlockBehaviourMixin.java rename to src/main/java/net/frozenblock/lib/sound/mixin/BlockBehaviourMixin.java index 5d3b8ac6..da48c6f9 100644 --- a/src/main/java/net/frozenblock/lib/sound/mixin/client/BlockBehaviourMixin.java +++ b/src/main/java/net/frozenblock/lib/sound/mixin/BlockBehaviourMixin.java @@ -15,13 +15,9 @@ * along with this program. If not, see . */ -package net.frozenblock.lib.sound.mixin.client; +package net.frozenblock.lib.sound.mixin; -import net.frozenblock.lib.sound.api.block_sound_group.BlockSoundGroupOverwrite; import net.frozenblock.lib.sound.api.block_sound_group.BlockSoundGroupOverwrites; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; @@ -33,18 +29,10 @@ @Mixin(BlockBehaviour.class) public final class BlockBehaviourMixin { - @Inject(method = "getSoundType", at = @At("RETURN"), cancellable = true) - private void getSoundGroupOverride(BlockState state, CallbackInfoReturnable info) { - Block block = state.getBlock(); - ResourceLocation id = BuiltInRegistries.BLOCK.getKey(block); - var overwrites = BlockSoundGroupOverwrites.getOverwrites(); - if (overwrites != null) { - for (BlockSoundGroupOverwrite overwrite : overwrites) { - if (overwrite.blockId().equals(id) && overwrite.condition().getAsBoolean()) { - info.setReturnValue(overwrite.soundOverwrite()); - } - } - } + @Inject(method = "getSoundType", at = @At("HEAD"), cancellable = true) + private void frozenLib$getSoundGroupOverride(BlockState state, CallbackInfoReturnable info) { + BlockSoundGroupOverwrites.getOverwriteIfConditionIsMet(state.getBlock()) + .ifPresent(blockSoundGroupOverwrite -> info.setReturnValue(blockSoundGroupOverwrite.soundOverwrite())); } } diff --git a/src/main/resources/mixin/frozenlib.sound.mixins.json b/src/main/resources/mixin/frozenlib.sound.mixins.json index d628fdc5..84976eb3 100644 --- a/src/main/resources/mixin/frozenlib.sound.mixins.json +++ b/src/main/resources/mixin/frozenlib.sound.mixins.json @@ -8,9 +8,7 @@ }, "mixins": [ "EntityMixin", - "PlayerMixin" - ], - "client": [ - "client.BlockBehaviourMixin" + "PlayerMixin", + "BlockBehaviourMixin" ] } From e1a3e33c08104e56373afb37d9ff8fa7caa21749 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:31:05 -0400 Subject: [PATCH 3/3] Update BlockSoundGroupManager.java --- .../sound/impl/block_sound_group/BlockSoundGroupManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java b/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java index 7fb8b2c5..159dec4e 100644 --- a/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java +++ b/src/main/java/net/frozenblock/lib/sound/impl/block_sound_group/BlockSoundGroupManager.java @@ -139,9 +139,9 @@ public CompletableFuture load(ResourceManager manager, Profile @Override public CompletableFuture apply(@NotNull SoundGroupLoader prepared, ResourceManager manager, ProfilerFiller profiler, Executor executor) { + this.overwrites = prepared.getOverwrites(); + this.overwrites.putAll(this.queuedOverwrites); return CompletableFuture.runAsync(() -> { - this.overwrites = prepared.getOverwrites(); - this.overwrites.putAll(this.queuedOverwrites); }); }