mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-12 06:54:27 -04:00
Biome modification API small enhancements (#2789)
* Allow OptionalInt in BiomeModificationContext
For some reason, vanilla uses `Optional<Integer>` instead of
the preferred `OptionalInt`. Add an override that allows passing
`OptionalInt`. For consistency with vanilla, the old method is NOT
deprecated.
* Do not rely on Identifier identity when checking registration
`Identifier` is a value-based class and should never be compared
using `==`. Luckily, this does not cause bugs right now.
(Using `equals` is worse, since it'll prevent spawning pigs.)
Instead use the proper method of checking if an entry is registered.
* Fix #2079
(cherry picked from commit b5d379b004
)
This commit is contained in:
parent
2d2baf4bf6
commit
82db024a24
2 changed files with 26 additions and 2 deletions
fabric-biome-api-v1/src/main/java/net/fabricmc/fabric
|
@ -17,6 +17,7 @@
|
|||
package net.fabricmc.fabric.api.biome.v1;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -129,6 +130,14 @@ public interface BiomeModificationContext {
|
|||
setFoliageColor(Optional.of(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BiomeEffects#getFoliageColor()
|
||||
* @see BiomeEffects.Builder#foliageColor(int)
|
||||
*/
|
||||
default void setFoliageColor(OptionalInt color) {
|
||||
color.ifPresentOrElse(this::setFoliageColor, this::clearFoliageColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BiomeEffects#getFoliageColor()
|
||||
* @see BiomeEffects.Builder#foliageColor(int)
|
||||
|
@ -151,6 +160,14 @@ public interface BiomeModificationContext {
|
|||
setGrassColor(Optional.of(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BiomeEffects#getGrassColor()
|
||||
* @see BiomeEffects.Builder#grassColor(int)
|
||||
*/
|
||||
default void setGrassColor(OptionalInt color) {
|
||||
color.ifPresentOrElse(this::setGrassColor, this::clearGrassColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BiomeEffects#getGrassColor()
|
||||
* @see BiomeEffects.Builder#grassColor(int)
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.google.common.base.Suppliers;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
|
@ -302,7 +303,11 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
|
|||
@Override
|
||||
public boolean removeCarver(GenerationStep.Carver step, RegistryKey<ConfiguredCarver<?>> configuredCarverKey) {
|
||||
ConfiguredCarver<?> carver = carvers.getOrThrow(configuredCarverKey);
|
||||
List<RegistryEntry<ConfiguredCarver<?>>> genCarvers = new ArrayList<>(generationSettings.carvers.get(step).stream().toList());
|
||||
RegistryEntryList<ConfiguredCarver<?>> carvers = generationSettings.carvers.get(step);
|
||||
|
||||
if (carvers == null) return false;
|
||||
|
||||
List<RegistryEntry<ConfiguredCarver<?>>> genCarvers = new ArrayList<>(carvers.stream().toList());
|
||||
|
||||
if (genCarvers.removeIf(entry -> entry.value() == carver)) {
|
||||
generationSettings.carvers.put(step, RegistryEntryList.of(genCarvers));
|
||||
|
@ -312,7 +317,9 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
|
|||
return false;
|
||||
}
|
||||
|
||||
private <T> RegistryEntryList<T> plus(RegistryEntryList<T> values, RegistryEntry<T> entry) {
|
||||
private <T> RegistryEntryList<T> plus(@Nullable RegistryEntryList<T> values, RegistryEntry<T> entry) {
|
||||
if (values == null) return RegistryEntryList.of(entry);
|
||||
|
||||
List<RegistryEntry<T>> list = new ArrayList<>(values.stream().toList());
|
||||
list.add(entry);
|
||||
return RegistryEntryList.of(list);
|
||||
|
|
Loading…
Add table
Reference in a new issue