Skip to content

Commit

Permalink
Merge branch 'master' into 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Nov 2, 2024
2 parents cfe021f + e1a3e33 commit 5535066
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -38,7 +41,6 @@ public class BlockSoundGroupOverwrites {

private static final BlockSoundGroupManager MANAGER = BlockSoundGroupManager.INSTANCE;

@Nullable
public static List<BlockSoundGroupOverwrite> getOverwrites() {
return MANAGER.getOverwrites();
}
Expand All @@ -48,6 +50,16 @@ public static BlockSoundGroupOverwrite getOverwrite(ResourceLocation id) {
return MANAGER.getOverwrite(id);
}

public static @NotNull Optional<BlockSoundGroupOverwrite> getOverwrite(Block block) {
ResourceLocation id = BuiltInRegistries.BLOCK.getKey(block);
return MANAGER.getOverwrites().stream().filter(overwrite -> overwrite.blockId().equals(id)).findFirst();
}

public static Optional<BlockSoundGroupOverwrite> 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -63,28 +65,27 @@ public class BlockSoundGroupManager implements SimpleResourceReloadListener<Bloc
private Map<ResourceLocation, BlockSoundGroupOverwrite> overwrites;
private final Map<ResourceLocation, BlockSoundGroupOverwrite> queuedOverwrites = new Object2ObjectOpenHashMap<>();

@Nullable
public List<BlockSoundGroupOverwrite> getOverwrites() {
if (this.overwrites != null) {
return this.overwrites.values().stream().toList();
}
return null;
return List.of();
}

@Nullable
public BlockSoundGroupOverwrite getOverwrite(ResourceLocation id) {
return this.overwrites.get(id);
}

public Optional<BlockSoundGroupOverwrite> 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));
}

/**
Expand All @@ -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);
Expand All @@ -128,7 +129,8 @@ public void addBlockTag(TagKey<Block> 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");
}

Expand Down Expand Up @@ -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();
Expand All @@ -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());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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;
Expand All @@ -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<SoundType> 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<SoundType> info) {
BlockSoundGroupOverwrites.getOverwriteIfConditionIsMet(state.getBlock())
.ifPresent(blockSoundGroupOverwrite -> info.setReturnValue(blockSoundGroupOverwrite.soundOverwrite()));
}

}
6 changes: 2 additions & 4 deletions src/main/resources/mixin/frozenlib.sound.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
},
"mixins": [
"EntityMixin",
"PlayerMixin"
],
"client": [
"client.BlockBehaviourMixin"
"PlayerMixin",
"BlockBehaviourMixin"
]
}

0 comments on commit 5535066

Please sign in to comment.