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 5, 2025
2 parents 16b2146 + 448010c commit 601acec
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package net.frozenblock.lib.worldgen.feature.api;

import java.util.Iterator;
import lombok.experimental.UtilityClass;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -48,20 +47,19 @@ public static boolean isAirOrWaterNearby(WorldGenLevel level, @NotNull BlockPos
pos.offset(searchDistance, searchDistance, searchDistance)
);
for (BlockPos blockPos : poses) {
if (BlockPredicate.ONLY_IN_AIR_OR_WATER_PREDICATE.test(level, blockPos)) {
return true;
}
if (BlockPredicate.ONLY_IN_AIR_OR_WATER_PREDICATE.test(level, blockPos)) return true;
}
return false;
}

public static boolean isWaterNearby(WorldGenLevel level, @NotNull BlockPos blockPos, int searchArea) {
Iterator<BlockPos> poses = BlockPos.betweenClosed(blockPos.offset(-searchArea, -searchArea, -searchArea), blockPos.offset(searchArea, searchArea, searchArea)).iterator();
BlockPos blockPos2;
do {
if (!poses.hasNext()) return false;
blockPos2 = poses.next();
} while (!level.getBlockState(blockPos2).is(Blocks.WATER));
return true;
public static boolean isWaterNearby(WorldGenLevel level, @NotNull BlockPos pos, int searchDistance) {
Iterable<BlockPos> poses = BlockPos.betweenClosed(
pos.offset(-searchDistance, -searchDistance, -searchDistance),
pos.offset(searchDistance, searchDistance, searchDistance)
);
for (BlockPos blockPos : poses) {
if (level.getBlockState(blockPos).is(Blocks.WATER)) return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static java.util.Objects.requireNonNull;
import net.frozenblock.lib.datafix.api.BlockStateRenameFix;
import net.frozenblock.lib.math.api.AdvancedMath;
import net.minecraft.Util;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.util.datafix.fixes.BlockRenameFix;
Expand Down Expand Up @@ -56,9 +59,13 @@ private SimpleFixes() {
* @param schema the schema this fixer should be a part of
* @see BlockRenameFix
*/
public static void addBlockRenameFix(@NotNull DataFixerBuilder builder, @NotNull String name,
@NotNull ResourceLocation oldId, @NotNull ResourceLocation newId,
@NotNull Schema schema) {
public static void addBlockRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull ResourceLocation oldId,
@NotNull ResourceLocation newId,
@NotNull Schema schema
) {
requireNonNull(builder, "DataFixerBuilder cannot be null");
requireNonNull(name, "Fix name cannot be null");
requireNonNull(oldId, "Old identifier cannot be null");
Expand All @@ -70,6 +77,38 @@ public static void addBlockRenameFix(@NotNull DataFixerBuilder builder, @NotNull
Objects.equals(NamespacedSchema.ensureNamespaced(inputName), oldIdStr) ? newIdStr : inputName));
}

/**
* Adds a block rename fix to the builder, choosing a random new id from a list.
*
* @param builder the builder
* @param name the fix's name
* @param oldId the block's old identifier
* @param newIds the new ids to randomly pick from
* @param schema the schema this fixer should be a part of
* @see BlockRenameFix
*/
public static void addRandomBlockRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull ResourceLocation oldId,
List<ResourceLocation> newIds,
@NotNull Schema schema
) {
Objects.requireNonNull(builder, "DataFixerBuilder cannot be null");
Objects.requireNonNull(name, "Fix name cannot be null");
Objects.requireNonNull(oldId, "Old identifier cannot be null");
Objects.requireNonNull(newIds, "New identifiers cannot be null");
Objects.requireNonNull(schema, "Schema cannot be null");
String oldIdStr = oldId.toString();
builder.addFixer(
BlockRenameFix.create(
schema,
name,
(inputName) -> Objects.equals(NamespacedSchema.ensureNamespaced(inputName), oldIdStr) ? Util.getRandom(newIds, AdvancedMath.random()).toString() : inputName
)
);
}

/**
* Adds an entity rename fix to the builder, in case an entity's identifier is changed.
*
Expand All @@ -80,9 +119,13 @@ public static void addBlockRenameFix(@NotNull DataFixerBuilder builder, @NotNull
* @param schema the schema this fix should be a part of
* @see SimplestEntityRenameFix
*/
public static void addEntityRenameFix(@NotNull DataFixerBuilder builder, @NotNull String name,
@NotNull ResourceLocation oldId, @NotNull ResourceLocation newId,
@NotNull Schema schema) {
public static void addEntityRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull ResourceLocation oldId,
@NotNull ResourceLocation newId,
@NotNull Schema schema
) {
requireNonNull(builder, "DataFixerBuilder cannot be null");
requireNonNull(name, "Fix name cannot be null");
requireNonNull(oldId, "Old identifier cannot be null");
Expand All @@ -108,9 +151,13 @@ protected String rename(String inputName) {
* @param schema the schema this fix should be a part of
* @see ItemRenameFix
*/
public static void addItemRenameFix(@NotNull DataFixerBuilder builder, @NotNull String name,
@NotNull ResourceLocation oldId, @NotNull ResourceLocation newId,
@NotNull Schema schema) {
public static void addItemRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull ResourceLocation oldId,
@NotNull ResourceLocation newId,
@NotNull Schema schema
) {
requireNonNull(builder, "DataFixerBuilder cannot be null");
requireNonNull(name, "Fix name cannot be null");
requireNonNull(oldId, "Old identifier cannot be null");
Expand All @@ -122,6 +169,38 @@ public static void addItemRenameFix(@NotNull DataFixerBuilder builder, @NotNull
Objects.equals(NamespacedSchema.ensureNamespaced(inputName), oldIdStr) ? newIdStr : inputName));
}

/**
* Adds an item rename fix to the builder, choosing a random new id from a list.
*
* @param builder the builder
* @param name the fix's name
* @param oldId the item's old identifier
* @param newIds the new ids to randomly pick from
* @param schema the schema this fix should be a part of
* @see ItemRenameFix
*/
private static void addRandomItemRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull ResourceLocation oldId,
List<ResourceLocation> newIds,
@NotNull Schema schema
) {
Objects.requireNonNull(builder, "DataFixerBuilder cannot be null");
Objects.requireNonNull(name, "Fix name cannot be null");
Objects.requireNonNull(oldId, "Old identifier cannot be null");
Objects.requireNonNull(newIds, "New identifiers cannot be null");
Objects.requireNonNull(schema, "Schema cannot be null");
String oldIdStr = oldId.toString();
builder.addFixer(
ItemRenameFix.create(
schema,
name,
(inputName) -> Objects.equals(NamespacedSchema.ensureNamespaced(inputName), oldIdStr) ? Util.getRandom(newIds, AdvancedMath.random()).toString() : inputName
)
);
}

/**
* Adds a blockstate rename fix to the builder, in case a blockstate's name is changed.
*
Expand All @@ -134,10 +213,15 @@ public static void addItemRenameFix(@NotNull DataFixerBuilder builder, @NotNull
* @param schema the schema this fixer should be a part of
* @see BlockStateRenameFix
*/
public static void addBlockStateRenameFix(@NotNull DataFixerBuilder builder, @NotNull String name,
@NotNull ResourceLocation blockId, @NotNull String oldState,
@NotNull String defaultValue, @NotNull String newState,
@NotNull Schema schema) {
public static void addBlockStateRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull ResourceLocation blockId,
@NotNull String oldState,
@NotNull String defaultValue,
@NotNull String newState,
@NotNull Schema schema
) {
requireNonNull(builder, "DataFixerBuilder cannot be null");
requireNonNull(name, "Fix name cannot be null");
requireNonNull(blockId, "Block Id cannot be null");
Expand All @@ -159,9 +243,13 @@ public static void addBlockStateRenameFix(@NotNull DataFixerBuilder builder, @No
* @param schema the schema this fixer should be a part of
* @see NamespacedTypeRenameFix
*/
public static void addBiomeRenameFix(@NotNull DataFixerBuilder builder, @NotNull String name,
@NotNull Map<ResourceLocation, ResourceLocation> changes,
@NotNull Schema schema) {
public static void addBiomeRenameFix(
@NotNull DataFixerBuilder builder,
@NotNull String name,
@NotNull Map<ResourceLocation,
ResourceLocation> changes,
@NotNull Schema schema
) {
requireNonNull(builder, "DataFixerBuilder cannot be null");
requireNonNull(name, "Fix name cannot be null");
requireNonNull(changes, "Changes cannot be null");
Expand Down

0 comments on commit 601acec

Please sign in to comment.