mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-01 01:30:00 -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
This commit is contained in:
parent
5b9a588bfd
commit
b5d379b004
3 changed files with 33 additions and 9 deletions
fabric-biome-api-v1/src/main/java/net/fabricmc/fabric
api/biome/v1
impl/biome/modification
|
@ -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;
|
||||
|
@ -127,6 +128,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)
|
||||
|
@ -149,6 +158,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)
|
||||
|
|
|
@ -79,7 +79,7 @@ public final class BiomeModifications {
|
|||
|
||||
// We need the entity type to be registered, or we cannot deduce an ID otherwise
|
||||
Identifier id = Registries.ENTITY_TYPE.getId(entityType);
|
||||
Preconditions.checkState(id != Registries.ENTITY_TYPE.getDefaultId(), "Unregistered entity type: %s", entityType);
|
||||
Preconditions.checkState(Registries.ENTITY_TYPE.getKey(entityType).isPresent(), "Unregistered entity type: %s", entityType);
|
||||
|
||||
create(id).add(ModificationPhase.ADDITIONS, biomeSelector, context -> {
|
||||
context.getSpawnSettings().addSpawn(spawnGroup, new SpawnSettings.SpawnEntry(entityType, weight, minGroupSize, maxGroupSize));
|
||||
|
|
|
@ -31,20 +31,21 @@ 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.registry.RegistryKeys;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.entry.RegistryEntryList;
|
||||
import net.minecraft.sound.BiomeAdditionsSound;
|
||||
import net.minecraft.sound.BiomeMoodSound;
|
||||
import net.minecraft.sound.MusicSound;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.collection.Pool;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.entry.RegistryEntryList;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.BiomeParticleConfig;
|
||||
|
@ -301,7 +302,11 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
|
|||
@Override
|
||||
public boolean removeCarver(GenerationStep.Carver step, RegistryKey<ConfiguredCarver<?>> configuredCarverKey) {
|
||||
ConfiguredCarver<?> carver = getEntry(carvers, configuredCarverKey).value();
|
||||
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));
|
||||
|
@ -311,7 +316,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