Skip to content

Commit

Permalink
Merge branch '1.21.2' into 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Feb 4, 2025
2 parents 07b5f84 + 5565b9a commit 382fe5e
Show file tree
Hide file tree
Showing 51 changed files with 468 additions and 784 deletions.
15 changes: 5 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ Put changelog here:

-----------------
- Revamped the Block Sound Type API entirely, fixing a few glaring issues.
- Code-defined overwrites can now define:
- Individual Blocks.
- Arrays of Blocks.
- Lists of ResourceLocations.
- Block Tags.
- Data-drive overwrites can now define:
- Lists of ResourceLocations.
- Block Tags.
- Overwrites that list multiple blocks no longer create one instance per-block, saving space in RAM.
- Block Tags now actually work in overwrites.
- Block sound type overrides now use a `HolderSet` to define which blocks are affected.
- This allows tags and lists to work properly with this system, saving space in RAM.
- The new field for blocks is named `blocks`.
- The data-driven directory for block sound type overrides has been changed from `blocksoundoverwrites` to `block_sound_overwrites`.
- All Fading Disk features check if surrounding blocks are replaceable, instead of strictly Air.
- Potentially fixed an issue with C2ME during structure generation.
- `BlockStateRespectingProcessorRule` now maintains water if a waterlogged block is replaced with air.
Expand All @@ -31,5 +25,6 @@ Put changelog here:
- Removed a few unnecessary APIs.
- Added the `requires_air_or_water_in_area_noise_path_feature,` which only places blocks when Air or Water is within a certain distance.
- Removed many duplicate worldgen feature implementations, now just relying on HolderSets.
- Cleaned up existing worldgen feature configurations and features.
- Disconnecting from a FrozenLib server and joining a non-FrozenLib server afterwards no longer leaves client Wind running.
- Wind can no longer return any non-zero value when on a non-FrozenLib server without the config option to override this behavior enabled.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.frozenblock.lib.block.api.sculk;

import java.util.Collection;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
Expand All @@ -30,8 +31,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

/**
* A {@link SculkBehaviour} that sets a specified {@link BooleanProperty} to a defined value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
public class BlockSoundTypeOverwrites {
private static final BlockSoundTypeManager MANAGER = BlockSoundTypeManager.INSTANCE;

public static Optional<SoundType> getSoundType(Block block) {
return MANAGER.getSoundType(block);
}

public static Optional<SoundType> getSoundType(BlockState blockState) {
return MANAGER.getSoundType(blockState);
}
Expand All @@ -66,6 +62,10 @@ public static void addBlock(ResourceLocation location, SoundType sounds, Boolean
MANAGER.addBuiltInOverwrite(location, sounds, condition);
}

public static void addBlock(BlockState blockState, SoundType sounds, BooleanSupplier condition) {
MANAGER.addBuiltInOverwrite(blockState, sounds, condition);
}

public static void addBlock(Block block, SoundType sounds, BooleanSupplier condition) {
MANAGER.addBuiltInOverwrite(block, sounds, condition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@

package net.frozenblock.lib.block.sound.api;

import com.google.common.collect.ImmutableList;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.List;
import lombok.experimental.UtilityClass;
import net.frozenblock.lib.block.sound.impl.overwrite.AbstractBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.ResourceLocationBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.ResourceLocationListBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.TagBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.HolderSetBlockSoundTypeOverwrite;
import net.minecraft.core.RegistryCodecs;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.SoundType;

@UtilityClass
Expand All @@ -46,34 +40,10 @@ public class SoundTypeCodecs {
).apply(instance, SoundType::new)
);

public static final Codec<ResourceLocationBlockSoundTypeOverwrite> RESOURCE_LOCATION_BLOCK_SOUND_TYPE_OVERWRITE_CODEC = RecordCodecBuilder.create(instance ->
public static final Codec<HolderSetBlockSoundTypeOverwrite> HOLDER_SET_BLOCK_SOUND_TYPE_OVERWRITE_CODEC = RecordCodecBuilder.create(instance ->
instance.group(
ResourceLocation.CODEC.fieldOf("id").forGetter(ResourceLocationBlockSoundTypeOverwrite::getValue),
SOUND_TYPE.fieldOf("sound_type").forGetter(ResourceLocationBlockSoundTypeOverwrite::getSoundType)
).apply(instance, (id, soundType) -> new ResourceLocationBlockSoundTypeOverwrite(id, soundType, () -> true))
RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("blocks").forGetter(HolderSetBlockSoundTypeOverwrite::getValue),
SOUND_TYPE.fieldOf("sound_type").forGetter(HolderSetBlockSoundTypeOverwrite::getSoundType)
).apply(instance, (tag, soundType) -> new HolderSetBlockSoundTypeOverwrite(tag, soundType, () -> true))
);

public static final Codec<ResourceLocationListBlockSoundTypeOverwrite> RESOURCE_LOCATION_LIST_BLOCK_SOUND_TYPE_OVERWRITE_CODEC = RecordCodecBuilder.create(instance ->
instance.group(
ResourceLocation.CODEC.listOf().fieldOf("ids").forGetter(ResourceLocationListBlockSoundTypeOverwrite::getValue),
SOUND_TYPE.fieldOf("sound_type").forGetter(ResourceLocationListBlockSoundTypeOverwrite::getSoundType)
).apply(instance, (ids, soundType) -> new ResourceLocationListBlockSoundTypeOverwrite(ids, soundType, () -> true))
);

public static final Codec<TagBlockSoundTypeOverwrite> TAG_BLOCK_SOUND_TYPE_OVERWRITE_CODEC = RecordCodecBuilder.create(instance ->
instance.group(
TagKey.codec(Registries.BLOCK).fieldOf("tag").forGetter(TagBlockSoundTypeOverwrite::getValue),
SOUND_TYPE.fieldOf("sound_type").forGetter(TagBlockSoundTypeOverwrite::getSoundType)
).apply(instance, (tag, soundType) -> new TagBlockSoundTypeOverwrite(tag, soundType, () -> true))
);

private static final List<Codec<? extends AbstractBlockSoundTypeOverwrite<?>>> CODECS = ImmutableList.of(
RESOURCE_LOCATION_LIST_BLOCK_SOUND_TYPE_OVERWRITE_CODEC,
RESOURCE_LOCATION_BLOCK_SOUND_TYPE_OVERWRITE_CODEC,
TAG_BLOCK_SOUND_TYPE_OVERWRITE_CODEC
);

public List<Codec<? extends AbstractBlockSoundTypeOverwrite<?>>> possibleCodecs() {
return CODECS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -36,10 +36,10 @@
import net.frozenblock.lib.FrozenLibConstants;
import net.frozenblock.lib.block.sound.api.SoundTypeCodecs;
import net.frozenblock.lib.block.sound.impl.overwrite.AbstractBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.BlockArrayBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.BlockBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.ResourceLocationBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.TagBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.BlockStateBlockSoundTypeOverwrite;
import net.frozenblock.lib.block.sound.impl.overwrite.HolderSetBlockSoundTypeOverwrite;
import net.minecraft.core.HolderSet;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
Expand All @@ -55,41 +55,82 @@

@ApiStatus.Internal
public class BlockSoundTypeManager implements SimpleResourceReloadListener<BlockSoundTypeManager.SoundTypeLoader> {
private static final Logger LOGGER = LoggerFactory.getLogger("FrozenLib Block Sound Type Manager");
private static final String DIRECTORY = "blocksoundoverwrites";
private static final Logger LOGGER = LoggerFactory.getLogger("Block Sound Type Override Manager");
private static final String DIRECTORY = "block_sound_overwrites";

public static final BlockSoundTypeManager INSTANCE = new BlockSoundTypeManager();

private final List<AbstractBlockSoundTypeOverwrite<?>> builtInOverwrites = new ArrayList<>();
private final List<AbstractBlockSoundTypeOverwrite<?>> overwrites = new ArrayList<>();

public void addBuiltInOverwrite(Block block, SoundType soundType, BooleanSupplier condition) {
this.builtInOverwrites.add(new BlockBlockSoundTypeOverwrite(block, soundType, condition));
public void addBuiltInOverwrite(@NotNull BlockState blockState, SoundType soundType, BooleanSupplier condition) {
this.builtInOverwrites.add(
new BlockStateBlockSoundTypeOverwrite(
blockState,
soundType,
condition
)
);
}

public void addBuiltInOverwrite(@NotNull Block block, SoundType soundType, BooleanSupplier condition) {
this.builtInOverwrites.add(
new HolderSetBlockSoundTypeOverwrite(
HolderSet.direct(block.builtInRegistryHolder()),
soundType,
condition
)
);
}

public void addBuiltInOverwrite(Block[] blocks, SoundType soundType, BooleanSupplier condition) {
this.builtInOverwrites.add(new BlockArrayBlockSoundTypeOverwrite(blocks, soundType, condition));
List<Block> blockList = Arrays.stream(blocks).toList();

if (!blockList.isEmpty()) {
this.builtInOverwrites.add(
new HolderSetBlockSoundTypeOverwrite(
HolderSet.direct(
Block::builtInRegistryHolder,
Arrays.stream(blocks).toList()
),
soundType,
condition
)
);
}
}

public void addBuiltInOverwrite(TagKey<Block> tagKey, SoundType soundType, BooleanSupplier condition) {
this.builtInOverwrites.add(new TagBlockSoundTypeOverwrite(tagKey, soundType, condition));
this.builtInOverwrites.add(
new HolderSetBlockSoundTypeOverwrite(
new HolderSet.Named<>(
BuiltInRegistries.BLOCK,
tagKey
),
soundType,
condition
)
);
}

public void addBuiltInOverwrite(ResourceLocation resourceLocation, SoundType soundType, BooleanSupplier condition) {
this.builtInOverwrites.add(new ResourceLocationBlockSoundTypeOverwrite(resourceLocation, soundType, condition));
Optional<Block> optionalBlock = BuiltInRegistries.BLOCK.getOptional(resourceLocation);
optionalBlock.ifPresent(block -> this.builtInOverwrites.add(
new HolderSetBlockSoundTypeOverwrite(
HolderSet.direct(block.builtInRegistryHolder()),
soundType,
condition
)
));
}

public void addFinalizedOverwrite(AbstractBlockSoundTypeOverwrite<?> overwrite) {
this.overwrites.add(overwrite);
}

public Optional<SoundType> getSoundType(@NotNull BlockState state) {
return this.getSoundType(state.getBlock());
}

public Optional<SoundType> getSoundType(Block block) {
for (AbstractBlockSoundTypeOverwrite<?> overwrite : this.overwrites) {
if (overwrite.getSoundCondition().getAsBoolean() && overwrite.matches(block)) {
if (overwrite.getSoundCondition().getAsBoolean() && overwrite.matches(state)) {
return Optional.of(overwrite.getSoundType());
}
}
Expand Down Expand Up @@ -118,7 +159,7 @@ public CompletableFuture<Void> apply(@NotNull SoundTypeLoader prepared, Resource

@NotNull
public ResourceLocation getFabricId() {
return FrozenLibConstants.id("block_sound_type_reloader");
return FrozenLibConstants.id("block_sound_type_overwrites");
}

public static class SoundTypeLoader {
Expand All @@ -143,27 +184,16 @@ private void addOverwrite(ResourceLocation location, @NotNull Resource resource)
try {
reader = resource.openAsReader();
} catch (IOException e) {
LOGGER.error(String.format("Unable to open BufferedReader for id %s", location), e);
LOGGER.error("Unable to open BufferedReader for file: `{}`", location);
return;
}

JsonObject json = GsonHelper.parse(reader);
Optional<Pair<? extends AbstractBlockSoundTypeOverwrite<?>, JsonElement>> result = Optional.empty();

for (Codec<? extends AbstractBlockSoundTypeOverwrite<?>> codec : SoundTypeCodecs.possibleCodecs()) {
DataResult<? extends Pair<? extends AbstractBlockSoundTypeOverwrite<?>, JsonElement>> possibleResult = codec.decode(JsonOps.INSTANCE, json);
if (possibleResult.isSuccess()) {
result = Optional.of(possibleResult.getOrThrow());
break;
}
}

if (result.isEmpty()) {
LOGGER.error(String.format("Unable to parse sound overwrite file %s.", location));
return;
}
DataResult<? extends Pair<? extends AbstractBlockSoundTypeOverwrite<?>, JsonElement>> dataResult
= SoundTypeCodecs.HOLDER_SET_BLOCK_SOUND_TYPE_OVERWRITE_CODEC.decode(JsonOps.INSTANCE, json);

this.parsedOverwrites.add(result.get().getFirst());
dataResult.resultOrPartial((string) -> LOGGER.error("Failed to parse sound override for file: '{}'", location))
.ifPresent(overwrite -> parsedOverwrites.add(overwrite.getFirst()));
}

public List<AbstractBlockSoundTypeOverwrite<?>> getOverwrites() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.function.BooleanSupplier;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
Expand All @@ -46,5 +47,5 @@ public BooleanSupplier getSoundCondition() {
return this.soundCondition;
}

public abstract boolean matches(Block block);
public abstract boolean matches(BlockState blockState);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
package net.frozenblock.lib.block.sound.impl.overwrite;

import java.util.function.BooleanSupplier;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

@ApiStatus.Internal
public class BlockBlockSoundTypeOverwrite extends AbstractBlockSoundTypeOverwrite<Block> {
public class BlockStateBlockSoundTypeOverwrite extends AbstractBlockSoundTypeOverwrite<BlockState> {

public BlockBlockSoundTypeOverwrite(Block value, SoundType soundType, BooleanSupplier soundCondition) {
public BlockStateBlockSoundTypeOverwrite(BlockState value, SoundType soundType, BooleanSupplier soundCondition) {
super(value, soundType, soundCondition);
}

@Override
public boolean matches(@NotNull Block block) {
return block == this.getValue();
public boolean matches(@NotNull BlockState blockState) {
return blockState.equals(this.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@

package net.frozenblock.lib.block.sound.impl.overwrite;

import java.util.Arrays;
import java.util.function.BooleanSupplier;
import net.minecraft.core.HolderSet;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

@ApiStatus.Internal
public class BlockArrayBlockSoundTypeOverwrite extends AbstractBlockSoundTypeOverwrite<Block[]> {
public class HolderSetBlockSoundTypeOverwrite extends AbstractBlockSoundTypeOverwrite<HolderSet<Block>> {

public BlockArrayBlockSoundTypeOverwrite(Block[] value, SoundType soundType, BooleanSupplier soundCondition) {
public HolderSetBlockSoundTypeOverwrite(HolderSet<Block> value, SoundType soundType, BooleanSupplier soundCondition) {
super(value, soundType, soundCondition);
}

@Override
public boolean matches(@NotNull Block block) {
return Arrays.stream(this.getValue()).anyMatch(currentBlock -> currentBlock == block);
public boolean matches(@NotNull BlockState blockState) {
return blockState.is(this.getValue());
}
}
Loading

0 comments on commit 382fe5e

Please sign in to comment.