feat: update mod platforms to Minecraft 26.3

This commit is contained in:
Zoe Gidiere committed 2026-11-07 15:57:40 -07:00
1 parent 4b3dd2b692
commit b8d8807ae8
45 files changed
+250 -402

No files matched your search

@@ -3,6 +3,7 @@ package com.dfsek.terra.mod.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
@@ -27,7 +28,7 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
}
public SpawnerData getSpawnEntry() {
return new SpawnerData(type, groupSize.getMin(), groupSize.getMax());
return new SpawnerData(type, UniformInt.of(groupSize.getMin(), groupSize.getMax()));
}
@Override
@@ -28,15 +28,15 @@ public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
for(SpawnTypeConfig spawn : spawns) {
MobCategory group = spawn.getGroup();
for(SpawnEntryConfig entry : spawn.getEntries()) {
builder.addSpawn(group, entry.getWeight(), entry.getSpawnEntry());
MobSpawnSettings.SpawnerData spawnEntry = entry.getSpawnEntry();
builder.addSpawn(spawnEntry.type(), group, entry.getWeight(), spawnEntry.count());
}
}
for(SpawnCostConfig cost : costs) {
builder.addMobCharge(cost.getType(), cost.getMass(), cost.getGravity());
}
if(probability != null) {
builder.creatureGenerationProbability(probability);
builder.addMobSpawnCost(cost.getType(), cost.getMass(), cost.getGravity());
}
// TODO: environment attributes. Creature generation probability is now the
// gameplay/creature_world_gen_spawn_probability biome attribute, so it is ignored here.
return builder.build();
}
@@ -73,8 +73,8 @@ public final class Codecs {
public static final MapCodec<TerraIntProvider> TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE = RecordCodecBuilder.mapCodec(
range -> range.group(
Codec.INT.fieldOf("min").stable().forGetter(TerraIntProvider::getMinValue),
Codec.INT.fieldOf("max").stable().forGetter(TerraIntProvider::getMaxValue))
Codec.INT.fieldOf("min").stable().forGetter(TerraIntProvider::minInclusive),
Codec.INT.fieldOf("max").stable().forGetter(TerraIntProvider::maxInclusive))
.apply(range, range.stable((min, max) -> new TerraIntProvider(new ConstantRange(
min, max)))));
}
@@ -35,17 +35,18 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.Beardifier;
import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.RandomSupport;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.blending.Blender;
import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import com.dfsek.terra.api.block.state.BlockStateExtended;
@@ -61,7 +62,6 @@ import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.mod.data.Codecs;
import com.dfsek.terra.mod.mixin.access.StructureManagerAccessor;
import com.dfsek.terra.mod.util.MinecraftAdapter;
import com.dfsek.terra.mod.util.SeedHack;
public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.chunk.ChunkGenerator implements GeneratorWrapper {
@@ -89,29 +89,25 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
return Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER;
}
@Override
public void buildSurface(WorldGenRegion region, StructureManager structures, RandomState noiseConfig, ChunkAccess chunk) {
// no op
}
@Override
public void spawnOriginalMobs(WorldGenRegion region) {
if(this.settings.mobGeneration()) {
ChunkPos chunkPos = region.getCenter();
Holder<Biome> registryEntry = region.getBiome(chunkPos.getWorldPosition().atY(region.getMaxY() - 1));
BlockPos sourcePos = chunkPos.getWorldPosition().atY(region.getMaxY() - 1);
WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
chunkRandom.setDecorationSeed(region.getSeed(), chunkPos.getMinBlockX(), chunkPos.getMinBlockZ());
NaturalSpawner.spawnMobsForChunkGeneration(region, registryEntry, chunkPos, chunkRandom);
NaturalSpawner.spawnMobsForChunkGeneration(region, sourcePos, chunkPos, chunkRandom);
}
}
@Override
public CompletableFuture<ChunkAccess> fillFromNoise(Blender blender, RandomState noiseConfig, StructureManager structureAccessor,
ChunkAccess chunk) {
public CompletableFuture<ChunkAccess> buildTerrain(ChunkAccess chunk, Blender blender, RandomState noiseConfig,
StructureManager structureAccessor, BiomeManager biomeAccess,
WorldGenRegion carverBiomeRegion, Set<Holder<Biome>> possibleBiomes) {
return CompletableFuture.supplyAsync(() -> {
ProtoWorld world = (ProtoWorld) ((StructureManagerAccessor) structureAccessor).getLevel();
BiomeProvider biomeProvider = pack.getBiomeProvider();
delegate.generateChunkData((ProtoChunk) chunk, world, biomeProvider, chunk.getPos().x, chunk.getPos().z);
delegate.generateChunkData((ProtoChunk) chunk, world, biomeProvider, chunk.getPos().x(), chunk.getPos().z());
PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
if(compatibilityOptions.isBeard()) {
@@ -127,13 +123,13 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
chunk.getPos());
double threshold = compatibilityOptions.getBeardThreshold();
double airThreshold = compatibilityOptions.getAirThreshold();
int xi = chunk.getPos().x << 4;
int zi = chunk.getPos().z << 4;
int xi = chunk.getPos().x() << 4;
int zi = chunk.getPos().z() << 4;
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
int depth = 0;
for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) {
double noise = structureWeightSampler.compute(new SinglePointContext(x + xi, y, z + zi));
double noise = structureWeightSampler.sampleValue(SamplerContext.EMPTY_UNCACHED, x + xi, y, z + zi);
if(noise > threshold) {
com.dfsek.terra.api.block.state.BlockState data = delegate.getPalette(x + xi, y, z + zi, world, biomeProvider).get(
depth, x + xi, y, z + zi, world.getSeed());
@@ -190,7 +186,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
@Override
public int getBaseHeight(int x, int z, Types heightmap, LevelHeightAccessor height, RandomState noiseConfig) {
WorldProperties properties = MinecraftAdapter.adapt(height, SeedHack.getSeed(noiseConfig.sampler()));
WorldProperties properties = MinecraftAdapter.adapt(height, noiseConfig.seed());
BiomeProvider biomeProvider = pack.getBiomeProvider();
int min = height.getMinY();
for(int y = height.getMaxY() - 1; y >= min; y--) {
@@ -207,7 +203,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
@Override
public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height, RandomState noiseConfig) {
BlockState[] array = new BlockState[height.getHeight()];
WorldProperties properties = MinecraftAdapter.adapt(height, SeedHack.getSeed(noiseConfig.sampler()));
WorldProperties properties = MinecraftAdapter.adapt(height, noiseConfig.seed());
BiomeProvider biomeProvider = pack.getBiomeProvider();
for(int y = height.getMaxY() - 1; y >= height.getMinY(); y--) {
com.dfsek.terra.api.block.state.BlockState terraBlockState = delegate.getBlock(properties, x, y, z, biomeProvider);
@@ -219,7 +215,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
}
@Override
public void addDebugScreenInfo(List<String> text, RandomState noiseConfig, BlockPos pos) {
public void addDebugScreenInfo(List<String> text, RandomState noiseConfig, BlockPos pos, SamplerContext samplerContext) {
// no op
}
@@ -235,13 +231,6 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
logger.debug("Loading world with config pack {}", pack.getID());
}
@Override
public void applyCarvers(WorldGenRegion chunkRegion, long seed, RandomState noiseConfig, BiomeManager biomeAccess,
StructureManager structureAccessor, ChunkAccess chunk) {
//no op
}
@Override
public ChunkGenerator getHandle() {
return delegate;
@@ -20,6 +20,7 @@ package com.dfsek.terra.mod.generation;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeResolver;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate.Sampler;
import org.slf4j.Logger;
@@ -61,10 +62,15 @@ public class TerraBiomeSource extends BiomeSource {
}
@Override
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Sampler Sampler) {
public BiomeResolver createResolver(Sampler sampler) {
long seed = SeedHack.getSeed(sampler);
return (biomeX, biomeY, biomeZ) -> getNoiseBiome(biomeX, biomeY, biomeZ, seed);
}
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, long seed) {
return ((ProtoPlatformBiome) pack
.getBiomeProvider()
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(Sampler))
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, seed)
.getPlatformBiome()).getDelegate();
}
@@ -58,7 +58,7 @@ public class MinecraftItemHandle implements ItemHandle {
public <T> Optional<RegistryLookup<T>> lookup(ResourceKey<? extends Registry<? extends T>> registryRef) {
return Optional.of(CommonPlatform.get().getServer().registryAccess().lookupOrThrow(registryRef));
}
}).parse(new StringReader(data)).getItem();
}).parse(new StringReader(data)).item().value();
} catch(CommandSyntaxException e) {
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
}
@@ -1,8 +1,8 @@
package com.dfsek.terra.mod.implmentation;
import com.mojang.serialization.MapCodec;
import net.minecraft.util.RandomSource;
import net.minecraft.util.valueproviders.IntProvider;
import net.minecraft.util.valueproviders.IntProviderType;
import java.util.HashMap;
import java.util.Map;
@@ -11,8 +11,8 @@ import com.dfsek.terra.api.util.range.Range;
import com.dfsek.terra.mod.util.MinecraftAdapter;
public class TerraIntProvider extends IntProvider {
public static final Map<Class, IntProviderType> TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE = new HashMap<>();
public class TerraIntProvider implements IntProvider {
public static final Map<Class, MapCodec<? extends IntProvider>> TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE = new HashMap<>();
public Range delegate;
@@ -26,17 +26,17 @@ public class TerraIntProvider extends IntProvider {
}
@Override
public int getMinValue() {
public int minInclusive() {
return delegate.getMin();
}
@Override
public int getMaxValue() {
public int maxInclusive() {
return delegate.getMax();
}
@Override
public IntProviderType<?> getType() {
public MapCodec<? extends IntProvider> codec() {
return TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE.get(delegate.getClass());
}
}
@@ -1,35 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.mod.mixin.access;
import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.Property;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
import java.util.function.Function;
@Mixin(StateHolder.class)
public interface StateHolderAccessor {
@Accessor("PROPERTY_ENTRY_TO_STRING_FUNCTION")
static Function<Map.Entry<Property<?>, Comparable<?>>, String> getPropertyMapPrinter() {
throw new UnsupportedOperationException();
}
}
@@ -1,7 +1,6 @@
package com.dfsek.terra.mod.mixin.generalize;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
@@ -9,7 +8,7 @@ import net.minecraft.server.level.progress.LevelLoadListener;
import net.minecraft.world.RandomSequences;
import net.minecraft.world.level.CustomSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.ServerLevelData;
@@ -34,11 +33,8 @@ public abstract class ServerLevelMixin extends Level {
@Redirect(method = "<init>",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/core/Holder;is(Lnet/minecraft/resources/ResourceKey;)Z"))
public <T> boolean matchesKeyProxy(Holder<T> instance, ResourceKey<T> tRegistryKey) {
if(tRegistryKey == BuiltinDimensionTypes.END) {
return (this.dimension() == Level.END);
}
return instance.is(tRegistryKey);
target = "Lnet/minecraft/world/level/dimension/DimensionType;hasEnderDragonFight()Z"))
public boolean hasEnderDragonFightProxy(DimensionType instance) {
return this.dimension() == Level.END;
}
}
@@ -1,7 +1,7 @@
package com.dfsek.terra.mod.mixin.implementations.compat;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
@@ -19,14 +19,14 @@ import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
@Mixin(BiomeGenerationSettings.class)
@Implements(@Interface(iface = FloraFeatureHolder.class, prefix = "terra$"))
public class BiomeGenerationSettingsFloraFeaturesMixin {
private List<ConfiguredFeature<?, ?>> flora;
private List<Feature> flora;
public void terra$setFloraFeatures(List<ConfiguredFeature<?, ?>> features) {
public void terra$setFloraFeatures(List<Feature> features) {
this.flora = features;
}
@Inject(method = "getFlowerFeatures()Ljava/util/List;", cancellable = true, at = @At("HEAD"))
public void inject(CallbackInfoReturnable<List<ConfiguredFeature<?, ?>>> cir) {
@Inject(method = "getBoneMealFeatures()Ljava/util/List;", cancellable = true, at = @At("HEAD"))
public void inject(CallbackInfoReturnable<List<Feature>> cir) {
if(flora != null) {
cir.setReturnValue(flora);
}
@@ -20,12 +20,15 @@ package com.dfsek.terra.mod.mixin.implementations.terra.block.entity;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.world.level.block.entity.SignText;
import net.minecraft.world.level.block.entity.SignTextSlot;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
import com.dfsek.terra.api.block.entity.SerialState;
import com.dfsek.terra.api.block.entity.Sign;
@@ -37,23 +40,23 @@ public abstract class SignBlockEntityMixin {
private SignText frontText;
@Shadow
public abstract boolean setText(SignText text, boolean front);
public abstract void setText(SignText text, SignTextSlot slot);
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
setText(frontText.setMessage(index, Component.literal(line)), true);
setText(frontText.asMutable().setLine(index, Component.literal(line)).asImmutable(), SignTextSlot.FRONT);
}
public @NotNull String[] terra$getLines() {
Component[] texts = frontText.getMessages(false);
String[] lines = new String[texts.length];
for(int i = 0; i < texts.length; i++) {
lines[i] = texts[i].getString();
List<Component> texts = frontText.getMessages(false);
String[] lines = new String[texts.size()];
for(int i = 0; i < texts.size(); i++) {
lines[i] = texts.get(i).getString();
}
return lines;
}
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
return frontText.getMessage(index, false).getString();
return frontText.getMessages(false).get(index).getString();
}
public void terra$applyState(String state) {
@@ -1,8 +1,6 @@
package com.dfsek.terra.mod.mixin.implementations.terra.block.state;
import com.mojang.serialization.MapCodec;
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour.BlockStateBase;
@@ -18,15 +16,14 @@ import java.util.stream.Collectors;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.state.properties.Property;
import com.dfsek.terra.mod.mixin.access.StateHolderAccessor;
@Mixin(BlockStateBase.class)
@Implements(@Interface(iface = BlockState.class, prefix = "terra$"))
public abstract class BlockStateBaseMixin extends StateHolder<Block, net.minecraft.world.level.block.state.BlockState> {
private BlockStateBaseMixin(Block owner, Reference2ObjectArrayMap<net.minecraft.world.level.block.state.properties.Property<?>, Comparable<?>> entries,
MapCodec<net.minecraft.world.level.block.state.BlockState> codec) {
super(owner, entries, codec);
private BlockStateBaseMixin(Block owner, net.minecraft.world.level.block.state.properties.Property<?>[] propertyKeys,
Comparable<?>[] propertyValues) {
super(owner, propertyKeys, propertyValues);
}
@Shadow
@@ -67,10 +64,10 @@ public abstract class BlockStateBaseMixin extends StateHolder<Block, net.minecra
@Intrinsic
public String terra$getAsString(boolean properties) {
StringBuilder data = new StringBuilder(BuiltInRegistries.BLOCK.getKey(getBlock()).toString());
if(properties && !getValues().isEmpty()) {
if(properties && !isSingletonState()) {
data.append('[');
data.append(
getValues().entrySet().stream().map(StateHolderAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
getValues().map(net.minecraft.world.level.block.state.properties.Property.Value::toString).collect(Collectors.joining(",")));
data.append(']');
}
return data.toString();
@@ -88,11 +88,11 @@ public abstract class LevelChunkMixin {
}
public int terra$getX() {
return ((net.minecraft.world.level.chunk.ChunkAccess) (Object) this).getPos().x;
return ((net.minecraft.world.level.chunk.ChunkAccess) (Object) this).getPos().x();
}
public int terra$getZ() {
return ((net.minecraft.world.level.chunk.ChunkAccess) (Object) this).getPos().z;
return ((net.minecraft.world.level.chunk.ChunkAccess) (Object) this).getPos().z();
}
public ServerWorld terra$getWorld() {
@@ -72,8 +72,8 @@ public abstract class WorldGenRegionMixin implements WorldGenLevel {
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockState data, boolean physics) {
ChunkPos pos = center.getPos();
BlockPos blockPos = new BlockPos(CoordFunctions.chunkAndRelativeToAbsolute(pos.x, x), y,
CoordFunctions.chunkAndRelativeToAbsolute(pos.z, z));
BlockPos blockPos = new BlockPos(CoordFunctions.chunkAndRelativeToAbsolute(pos.x(), x), y,
CoordFunctions.chunkAndRelativeToAbsolute(pos.z(), z));
net.minecraft.world.level.block.state.BlockState state;
boolean isExtended = MinecraftUtil.isCompatibleBlockStateExtended(data);
@@ -97,14 +97,14 @@ public abstract class WorldGenRegionMixin implements WorldGenLevel {
public @NotNull BlockState terraChunk$getBlock(int x, int y, int z) {
return (BlockState) ((WorldGenRegion) (Object) this).getBlockState(
new BlockPos(x + (center.getPos().x << 4), y, z + (center.getPos().z << 4)));
new BlockPos(x + (center.getPos().x() << 4), y, z + (center.getPos().z() << 4)));
}
public int terraChunk$getX() {
return center.getPos().x;
return center.getPos().x();
}
public int terraChunk$getZ() {
return center.getPos().z;
return center.getPos().z();
}
}
@@ -24,6 +24,7 @@ import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntitySpawnRequest;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.dimension.DimensionType;
@@ -75,7 +76,7 @@ public abstract class ServerLevelMixin extends Level {
if(isExtended) {
MinecraftEntityTypeExtended type = ((MinecraftEntityTypeExtended) data);
CompoundTag nbt = (CompoundTag) ((Object) type.getData());
entity = net.minecraft.world.entity.EntityType.loadEntityRecursive(nbt, this, EntitySpawnReason.CHUNK_GENERATION, (entityx) -> {
entity = net.minecraft.world.entity.EntityType.loadEntityRecursive(nbt, this, new EntitySpawnRequest(EntitySpawnReason.CHUNK_GENERATION, false), (entityx) -> {
entityx.snapTo(x, y, z, entityx.getYRot(), entityx.getXRot());
return entityx;
});
@@ -23,6 +23,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.util.StaticCache2D;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntitySpawnRequest;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.chunk.ChunkAccess;
@@ -151,7 +152,7 @@ public abstract class WorldGenRegionMixin implements WorldGenLevel {
if(isExtended) {
MinecraftEntityTypeExtended type = ((MinecraftEntityTypeExtended) data);
CompoundTag nbt = (CompoundTag) ((Object) type.getData());
entity = net.minecraft.world.entity.EntityType.loadEntityRecursive(nbt, level, EntitySpawnReason.CHUNK_GENERATION, (entityx) -> {
entity = net.minecraft.world.entity.EntityType.loadEntityRecursive(nbt, level, new EntitySpawnRequest(EntitySpawnReason.CHUNK_GENERATION, false), (entityx) -> {
entityx.snapTo(x, y, z, entityx.getYRot(), entityx.getXRot());
return entityx;
});
@@ -166,11 +167,11 @@ public abstract class WorldGenRegionMixin implements WorldGenLevel {
}
public int terraWorld$centerChunkX() {
return center.getPos().x;
return center.getPos().x();
}
public int terraWorld$centerChunkZ() {
return center.getPos().z;
return center.getPos().z();
}
public ServerWorld terraWorld$getWorld() {
@@ -1,10 +1,10 @@
package com.dfsek.terra.mod.mixin_ifaces;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import java.util.List;
public interface FloraFeatureHolder {
void setFloraFeatures(List<ConfiguredFeature<?, ?>> features);
void setFloraFeatures(List<Feature> features);
}
@@ -1,21 +1,15 @@
package com.dfsek.terra.mod.util;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
import com.dfsek.terra.mod.mixin.access.BiomeAccessor;
public class BiomeUtil {
@@ -23,82 +17,7 @@ public class BiomeUtil {
TERRA_BIOME_MAP = new HashMap<>();
public static Biome createBiome(Biome vanilla, VanillaBiomeProperties vanillaBiomeProperties) {
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
net.minecraft.world.level.biome.Biome.BiomeBuilder builder = new BiomeBuilder();
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor()))
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()))
.grassColorModifier(
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.getSpecialEffects().getGrassColorModifier()))
.musicVolume(Objects.requireNonNullElse(vanillaBiomeProperties.getMusicVolume(), vanilla.getMusicVolume()));
if(vanillaBiomeProperties.getGrassColor() == null) {
vanilla.getSpecialEffects().getGrassColor().ifPresent(effects::grassColorOverride);
} else {
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
}
if(vanillaBiomeProperties.getFoliageColor() == null) {
vanilla.getSpecialEffects().getFoliageColor().ifPresent(effects::foliageColorOverride);
} else {
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
}
if(vanillaBiomeProperties.getDryFoliageColor() == null) {
vanilla.getSpecialEffects().getDryFoliageColor().ifPresent(effects::dryFoliageColorOverride);
} else {
effects.dryFoliageColorOverride(vanillaBiomeProperties.getDryFoliageColor());
}
if(vanillaBiomeProperties.getParticleConfig() == null) {
vanilla.getSpecialEffects().getParticleConfig().ifPresent(effects::particleConfig);
} else {
effects.particleConfig(vanillaBiomeProperties.getParticleConfig());
}
if(vanillaBiomeProperties.getLoopSound() == null) {
vanilla.getSpecialEffects().getLoopSound().ifPresent(effects::loopSound);
} else {
effects.loopSound(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(vanillaBiomeProperties.getLoopSound()));
}
if(vanillaBiomeProperties.getMoodSound() == null) {
vanilla.getSpecialEffects().getMoodSound().ifPresent(effects::moodSound);
} else {
effects.moodSound(vanillaBiomeProperties.getMoodSound());
}
if(vanillaBiomeProperties.getAdditionsSound() == null) {
vanilla.getSpecialEffects().getAdditionsSound().ifPresent(effects::additionsSound);
} else {
effects.additionsSound(vanillaBiomeProperties.getAdditionsSound());
}
if(vanillaBiomeProperties.getMusic() == null) {
vanilla.getSpecialEffects().getMusic().ifPresent(effects::music);
} else {
effects.music(vanillaBiomeProperties.getMusic());
}
builder.hasPrecipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.hasPrecipitation()));
builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getBaseTemperature()));
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(),
((BiomeAccessor) ((Object) vanilla)).getWeather().downfall()));
builder.temperatureAdjustment(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(),
((BiomeAccessor) ((Object) vanilla)).getWeather().temperatureModifier()));
builder.mobSpawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getMobSettings()));
return builder
.specialEffects(effects.build())
.generationSettings(new BiomeGenerationSettings.PlainBuilder().build())
.build();
throw new UnsupportedOperationException("TODO: environment attributes");
}
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
@@ -1,75 +1,22 @@
package com.dfsek.terra.mod.util;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.DimensionType.MonsterSettings;
import org.jetbrains.annotations.NotNull;
import java.util.OptionalLong;
import com.dfsek.terra.mod.ModPlatform;
import com.dfsek.terra.mod.config.MonsterSettingsConfig;
import com.dfsek.terra.mod.config.VanillaWorldProperties;
import com.dfsek.terra.mod.implmentation.TerraIntProvider;
public class DimensionUtil {
public static DimensionType createDimension(VanillaWorldProperties vanillaWorldProperties, DimensionType defaultDimension,
ModPlatform platform) {
MonsterSettingsConfig monsterSettingsConfig;
if(vanillaWorldProperties.getMonsterSettings() != null) {
monsterSettingsConfig = vanillaWorldProperties.getMonsterSettings();
} else {
monsterSettingsConfig = new MonsterSettingsConfig();
}
MonsterSettings monsterSettings = getMonsterSettings(defaultDimension, monsterSettingsConfig);
return new DimensionType(
vanillaWorldProperties.getFixedTime() == null ? defaultDimension.fixedTime() : OptionalLong.of(
vanillaWorldProperties.getFixedTime()),
vanillaWorldProperties.getHasSkyLight() == null ? defaultDimension.hasSkyLight() : vanillaWorldProperties.getHasSkyLight(),
vanillaWorldProperties.getHasCeiling() == null ? defaultDimension.hasCeiling() : vanillaWorldProperties.getHasCeiling(),
vanillaWorldProperties.getUltraWarm() == null ? defaultDimension.ultrawarm() : vanillaWorldProperties.getUltraWarm(),
vanillaWorldProperties.getNatural() == null ? defaultDimension.natural() : vanillaWorldProperties.getNatural(),
vanillaWorldProperties.getCoordinateScale() == null
? defaultDimension.coordinateScale()
: vanillaWorldProperties.getCoordinateScale(),
vanillaWorldProperties.getBedWorks() == null ? defaultDimension.bedWorks() : vanillaWorldProperties.getBedWorks(),
vanillaWorldProperties.getRespawnAnchorWorks() == null
? defaultDimension.respawnAnchorWorks()
: vanillaWorldProperties.getRespawnAnchorWorks(),
vanillaWorldProperties.getHeight() == null ? defaultDimension.minY() : vanillaWorldProperties.getHeight().getMin(),
vanillaWorldProperties.getHeight() == null ? defaultDimension.height() : vanillaWorldProperties.getHeight().getRange(),
vanillaWorldProperties.getLogicalHeight() == null
? defaultDimension.logicalHeight()
: vanillaWorldProperties.getLogicalHeight(),
vanillaWorldProperties.getInfiniburn() == null
? defaultDimension.infiniburn()
: TagKey.create(Registries.BLOCK, vanillaWorldProperties.getInfiniburn()),
vanillaWorldProperties.getEffects() == null ? defaultDimension.effects() : vanillaWorldProperties.getEffects(),
vanillaWorldProperties.getAmbientLight() == null ? defaultDimension.ambientLight() : vanillaWorldProperties.getAmbientLight(),
vanillaWorldProperties.getCloudHeight() == null
? defaultDimension.cloudHeight()
: vanillaWorldProperties.getCloudHeight().describeConstable(),
monsterSettings
);
throw new UnsupportedOperationException("TODO: environment attributes");
}
@NotNull
private static MonsterSettings getMonsterSettings(DimensionType defaultDimension, MonsterSettingsConfig monsterSettingsConfig) {
MonsterSettings defaultMonsterSettings = defaultDimension.monsterSettings();
return new MonsterSettings(
monsterSettingsConfig.getPiglinSafe() == null ? defaultMonsterSettings.piglinSafe() : monsterSettingsConfig.getPiglinSafe(),
monsterSettingsConfig.getHasRaids() == null ? defaultMonsterSettings.hasRaids() : monsterSettingsConfig.getHasRaids(),
monsterSettingsConfig.getMonsterSpawnLight() == null ? defaultMonsterSettings.monsterSpawnLightTest() : new TerraIntProvider(
monsterSettingsConfig.getMonsterSpawnLight()),
monsterSettingsConfig.getMonsterSpawnBlockLightLimit() == null
? defaultMonsterSettings.monsterSpawnBlockLightLimit()
: monsterSettingsConfig.getMonsterSpawnBlockLightLimit()
);
throw new UnsupportedOperationException("TODO: environment attributes");
}
}
@@ -1,14 +1,15 @@
package com.dfsek.terra.mod.util;
import com.mojang.serialization.MapCodec;
import net.minecraft.commands.arguments.blocks.BlockInput;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.valueproviders.IntProviderType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.Biome;
@@ -20,7 +21,7 @@ import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.ticks.ScheduledTick;
import net.minecraft.world.ticks.TickAccess;
@@ -107,7 +108,7 @@ public final class MinecraftUtil {
}
public static void registerIntProviderTypes() {
IntProviderType<TerraIntProvider> CONSTANT = IntProviderType.register("terra:constant_range",
MapCodec<TerraIntProvider> CONSTANT = Registry.register(BuiltInRegistries.INT_PROVIDER_TYPE, "terra:constant_range",
Codecs.TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE);
TerraIntProvider.TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE.put(ConstantRange.class, CONSTANT);
@@ -135,9 +136,9 @@ public final class MinecraftUtil {
Identifier terraBiomeIdentifier = Identifier.fromNamespaceAndPath("terra", BiomeUtil.createBiomeID(pack, id));
biomeRegistry.getOptional(terraBiomeIdentifier).ifPresentOrElse(
terraBiome -> {
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
List<Feature> flowerFeatures = List.copyOf(
vanillaBiome.getGenerationSettings()
.getFlowerFeatures());
.getBoneMealFeatures());
logger.debug("Injecting flora into biome" +
" {} : {}", terraBiomeIdentifier,
flowerFeatures);
@@ -1,29 +1,28 @@
package com.dfsek.terra.mod.util;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import com.google.common.collect.MapMaker;
import net.minecraft.world.level.biome.Climate.Sampler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ConcurrentMap;
/**
* Holder for hacky biome source seed workaround
* Maps climate samplers to world seeds.
* <p>
* {@link net.minecraft.world.level.levelgen.RandomState} creates a new {@link Sampler} for every sampling context.
*/
public class SeedHack {
private static final Logger LOGGER = LoggerFactory.getLogger(SeedHack.class);
private static final Object2LongMap<Sampler> seedMap = new Object2LongOpenHashMap<>();
private static final ConcurrentMap<Sampler, Long> seedMap = new MapMaker().weakKeys().makeMap();
public static long getSeed(Sampler sampler) {
if(!seedMap.containsKey(sampler)) {
Long seed = seedMap.get(sampler);
if(seed == null) {
throw new IllegalArgumentException("Sampler is not registered: " + sampler);
}
return seedMap.getLong(sampler);
return seed;
}
public static void register(Sampler sampler, long seed) {
LOGGER.info("Registered seed {} to sampler {}", seed, sampler.hashCode());
seedMap.put(sampler, seed);
}
}
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_ashen_tame",
"wild": "minecraft:entity/wolf/wolf_ashen"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_ashen_angry_baby",
"tame": "minecraft:entity/wolf/wolf_ashen_tame_baby",
"wild": "minecraft:entity/wolf/wolf_ashen_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_black_tame",
"wild": "minecraft:entity/wolf/wolf_black"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_black_angry_baby",
"tame": "minecraft:entity/wolf/wolf_black_tame_baby",
"wild": "minecraft:entity/wolf/wolf_black_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_chestnut_tame",
"wild": "minecraft:entity/wolf/wolf_chestnut"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_chestnut_angry_baby",
"tame": "minecraft:entity/wolf/wolf_chestnut_tame_baby",
"wild": "minecraft:entity/wolf/wolf_chestnut_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_tame",
"wild": "minecraft:entity/wolf/wolf"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_angry_baby",
"tame": "minecraft:entity/wolf/wolf_tame_baby",
"wild": "minecraft:entity/wolf/wolf_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_rusty_tame",
"wild": "minecraft:entity/wolf/wolf_rusty"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_rusty_angry_baby",
"tame": "minecraft:entity/wolf/wolf_rusty_tame_baby",
"wild": "minecraft:entity/wolf/wolf_rusty_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_snowy_tame",
"wild": "minecraft:entity/wolf/wolf_snowy"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_snowy_angry_baby",
"tame": "minecraft:entity/wolf/wolf_snowy_tame_baby",
"wild": "minecraft:entity/wolf/wolf_snowy_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_spotted_tame",
"wild": "minecraft:entity/wolf/wolf_spotted"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_spotted_angry_baby",
"tame": "minecraft:entity/wolf/wolf_spotted_tame_baby",
"wild": "minecraft:entity/wolf/wolf_spotted_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_striped_tame",
"wild": "minecraft:entity/wolf/wolf_striped"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_striped_angry_baby",
"tame": "minecraft:entity/wolf/wolf_striped_tame_baby",
"wild": "minecraft:entity/wolf/wolf_striped_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -4,6 +4,11 @@
"tame": "minecraft:entity/wolf/wolf_woods_tame",
"wild": "minecraft:entity/wolf/wolf_woods"
},
"baby_assets": {
"angry": "minecraft:entity/wolf/wolf_woods_angry_baby",
"tame": "minecraft:entity/wolf/wolf_woods_tame_baby",
"wild": "minecraft:entity/wolf/wolf_woods_baby"
},
"spawn_conditions": [
{
"condition": {
@@ -1,7 +1,6 @@
accessWidener v1 named
accessWidener v2 official
accessible class net/minecraft/world/level/biome/Biome$ClimateSettings
accessible class net/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap
accessible field net/minecraft/world/level/levelgen/WorldDimensions BUILTIN_ORDER Ljava/util/Set;
accessible class net/minecraft/resources/RegistryDataLoader$Loader
extendable class net/minecraft/nbt/Tag
accessible field net/minecraft/world/level/block/entity/BlockEntity TYPE_CODEC Lcom/mojang/serialization/Codec;
@@ -2,11 +2,10 @@
"required": true,
"minVersion": "0.8",
"package": "com.dfsek.terra.mod.mixin",
"compatibilityLevel": "JAVA_21",
"compatibilityLevel": "JAVA_25",
"mixins": [
"access.BiomeAccessor",
"access.BaseSpawnerAccessor",
"access.StateHolderAccessor",
"access.StructureManagerAccessor",
"access.VillagerTypeAccessor",
"access.LevelChunkAccessor",
@@ -48,6 +47,5 @@
],
"injectors": {
"defaultRequire": 1
},
"refmap": "terra.common.refmap.json"
}
}