diff --git a/CHANGELOG.md b/CHANGELOG.md index ddd1c9d48..83968dd44 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/gradle.properties b/gradle.properties index 64d18adc4..b944c6fc1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ min_loader_version=0.16.7 # 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 444096818..5518a4001 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) { } 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 b97fc71f4..e00eac138 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 0e227b622..66846a7fa 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; @@ -48,6 +49,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; @@ -63,12 +65,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 @@ -76,15 +77,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)); } /** @@ -108,7 +109,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); @@ -128,7 +129,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"); } @@ -172,7 +174,7 @@ private void loadSoundOverwrites() { profiler.pop(); } - private void addOverwrite(ResourceLocation id, Resource resource) { + private void addOverwrite(ResourceLocation id, @NotNull Resource resource) { BufferedReader reader; try { reader = resource.openAsReader(); @@ -190,7 +192,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()); } } 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 5d3b8ac6f..da48c6f91 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 d628fdc50..84976eb3a 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" ] }