mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-11-28 00:45:03 +00:00
feat: update mod platforms to Minecraft 26.3
This commit is contained in:
1 parent
4b3dd2b692
commit
b8d8807ae8
45 files changed
+250
-402
No files matched your search
@@ -32,8 +32,8 @@ object Versions {
|
||||
}
|
||||
|
||||
object Fabric {
|
||||
const val fabricAPI = "0.140.0+${Mod.minecraft}"
|
||||
const val cloud = "2.0.0-beta.13"
|
||||
const val fabricAPI = "0.165.2+${Mod.minecraft}"
|
||||
const val cloud = "2.1.0"
|
||||
}
|
||||
//
|
||||
// object Quilt {
|
||||
@@ -42,14 +42,14 @@ object Versions {
|
||||
// }
|
||||
|
||||
object Mod {
|
||||
const val mixin = "0.16.5+mixin.0.8.7"
|
||||
const val mixinExtras = "0.5.0"
|
||||
const val mixin = "0.17.5+mixin.0.8.7"
|
||||
const val mixinExtras = "0.5.5"
|
||||
|
||||
const val minecraft = "1.21.11"
|
||||
const val fabricLoader = "0.18.3"
|
||||
const val minecraft = "26.3"
|
||||
const val fabricLoader = "0.20.1"
|
||||
|
||||
const val architecturyLoom = "1.13.463"
|
||||
const val architecturyPlugin = "3.4.162"
|
||||
const val architecturyLoom = "1.17.493"
|
||||
const val architecturyPlugin = "3.5.170"
|
||||
|
||||
}
|
||||
//
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
id("dev.architectury.loom") version Versions.Mod.architecturyLoom
|
||||
id("dev.architectury.loom-no-remap") version Versions.Mod.architecturyLoom
|
||||
id("architectury-plugin") version Versions.Mod.architecturyPlugin
|
||||
}
|
||||
|
||||
@@ -13,45 +13,49 @@ architectury {
|
||||
dependencies {
|
||||
shadedApi(project(":common:implementation:base"))
|
||||
|
||||
implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
"developmentFabric"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
implementation(project(":platforms:mixin-common")) { isTransitive = false }
|
||||
"developmentFabric"(project(":platforms:mixin-common")) { isTransitive = false }
|
||||
shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionFabric")) { isTransitive = false }
|
||||
implementation(project(path = ":platforms:mixin-lifecycle", configuration = "namedElements")) { isTransitive = false }
|
||||
"developmentFabric"(project(path = ":platforms:mixin-lifecycle", configuration = "namedElements")) { isTransitive = false }
|
||||
implementation(project(":platforms:mixin-lifecycle")) { isTransitive = false }
|
||||
"developmentFabric"(project(":platforms:mixin-lifecycle")) { isTransitive = false }
|
||||
shaded(project(path = ":platforms:mixin-lifecycle", configuration = "transformProductionFabric")) { isTransitive = false }
|
||||
|
||||
|
||||
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
|
||||
mappings(loom.officialMojangMappings())
|
||||
|
||||
modImplementation("net.fabricmc:fabric-loader:${Versions.Mod.fabricLoader}")
|
||||
implementation("net.fabricmc:fabric-loader:${Versions.Mod.fabricLoader}")
|
||||
|
||||
modImplementation("org.incendo", "cloud-fabric", Versions.Fabric.cloud) {
|
||||
implementation("org.incendo", "cloud-fabric", Versions.Fabric.cloud) {
|
||||
exclude("me.lucko", "fabric-permissions-api")
|
||||
}
|
||||
include("org.incendo", "cloud-fabric", Versions.Fabric.cloud)
|
||||
|
||||
modRuntimeOnly("net.fabricmc.fabric-api", "fabric-api", Versions.Fabric.fabricAPI)
|
||||
runtimeOnly("net.fabricmc.fabric-api", "fabric-api", Versions.Fabric.fabricAPI)
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath.set(project(":platforms:mixin-common").file("src/main/resources/terra.accesswidener"))
|
||||
|
||||
mixin {
|
||||
defaultRefmapName.set("terra.fabric.refmap.json")
|
||||
}
|
||||
|
||||
// Minecraft 26.x is unobfuscated: no remapJar, the shaded jar is the release jar.
|
||||
nestJars(tasks.shadowJar, configurations.include)
|
||||
injectAccessWidener(tasks.shadowJar)
|
||||
}
|
||||
|
||||
|
||||
addonDir(project.file("./run/config/Terra/addons"), tasks.named("configureLaunch").get())
|
||||
|
||||
tasks {
|
||||
remapJar {
|
||||
dependsOn("installAddons")
|
||||
jar {
|
||||
archiveClassifier.set("dev")
|
||||
}
|
||||
|
||||
injectAccessWidener.set(true)
|
||||
inputFile.set(shadowJar.get().archiveFile)
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
archiveFileName.set("${rootProject.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}-fabric-${project.version}.jar")
|
||||
manifest.attributes("Fabric-Mapping-Namespace" to "official")
|
||||
}
|
||||
|
||||
withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@
|
||||
"terra.common.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.10",
|
||||
"java": ">=21",
|
||||
"minecraft": "1.21.10",
|
||||
"fabric": "*"
|
||||
"fabricloader": ">=0.20.1",
|
||||
"java": ">=25",
|
||||
"minecraft": "~26.3",
|
||||
"fabric-api": "*"
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.dfsek.terra.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
val platformOverrides = mapOf(
|
||||
"fabric" to "remapJar"
|
||||
"fabric" to "shadowJar"
|
||||
)
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
plugins {
|
||||
id("dev.architectury.loom") version Versions.Mod.architecturyLoom
|
||||
id("dev.architectury.loom-no-remap") version Versions.Mod.architecturyLoom
|
||||
id("architectury-plugin") version Versions.Mod.architecturyPlugin
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath.set(file("src/main/resources/terra.accesswidener"))
|
||||
|
||||
mixin {
|
||||
defaultRefmapName.set("terra.common.refmap.json")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
shadedApi(project(":common:implementation:base"))
|
||||
|
||||
compileOnly("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}")
|
||||
annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}")
|
||||
annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecturyLoom}")
|
||||
|
||||
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
|
||||
mappings(loom.officialMojangMappings())
|
||||
}
|
||||
|
||||
architectury {
|
||||
@@ -27,3 +20,6 @@ architectury {
|
||||
minecraft = Versions.Mod.minecraft
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
+2
-1
@@ -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
|
||||
|
||||
+5
-5
@@ -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)))));
|
||||
}
|
||||
+14
-25
@@ -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;
|
||||
|
||||
+8
-2
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+6
-6
@@ -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());
|
||||
}
|
||||
}
|
||||
-35
@@ -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();
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -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;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -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);
|
||||
}
|
||||
|
||||
+10
-7
@@ -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) {
|
||||
|
||||
+5
-8
@@ -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();
|
||||
|
||||
+2
-2
@@ -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() {
|
||||
|
||||
+5
-5
@@ -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();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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;
|
||||
});
|
||||
|
||||
+4
-3
@@ -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() {
|
||||
|
||||
+2
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("dev.architectury.loom") version Versions.Mod.architecturyLoom
|
||||
id("dev.architectury.loom-no-remap") version Versions.Mod.architecturyLoom
|
||||
id("architectury-plugin") version Versions.Mod.architecturyPlugin
|
||||
}
|
||||
|
||||
@@ -8,15 +8,12 @@ dependencies {
|
||||
|
||||
compileOnly("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}")
|
||||
compileOnly("io.github.llamalad7:mixinextras-common:${Versions.Mod.mixinExtras}")
|
||||
annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}")
|
||||
annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecturyLoom}")
|
||||
|
||||
implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
implementation(project(":platforms:mixin-common")) { isTransitive = false }
|
||||
|
||||
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
|
||||
mappings(loom.officialMojangMappings())
|
||||
|
||||
modImplementation("org.incendo", "cloud-fabric", Versions.Fabric.cloud) {
|
||||
implementation("org.incendo", "cloud-fabric", Versions.Fabric.cloud) {
|
||||
exclude("net.fabricmc")
|
||||
exclude("net.fabricmc.fabric-api")
|
||||
exclude("me.lucko", "fabric-permissions-api")
|
||||
@@ -25,19 +22,13 @@ dependencies {
|
||||
|
||||
loom {
|
||||
accessWidenerPath.set(project(":platforms:mixin-common").file("src/main/resources/terra.accesswidener"))
|
||||
|
||||
mixin {
|
||||
defaultRefmapName.set("terra.lifecycle.refmap.json")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
remapJar {
|
||||
inputFile.set(shadowJar.get().archiveFile)
|
||||
}
|
||||
}
|
||||
|
||||
architectury {
|
||||
common("fabric")
|
||||
minecraft = Versions.Mod.minecraft
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
+7
-11
@@ -1,16 +1,14 @@
|
||||
package com.dfsek.terra.lifecycle.mixin;
|
||||
|
||||
import net.minecraft.core.HolderGetter;
|
||||
import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||
import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.dfsek.terra.mod.util.SeedHack;
|
||||
|
||||
@@ -22,13 +20,11 @@ import com.dfsek.terra.mod.util.SeedHack;
|
||||
public class RandomStateMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private Sampler sampler;
|
||||
private long seed;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/level/levelgen/NoiseGeneratorSettings;Lnet/minecraft/core/HolderGetter;J)V",
|
||||
at = @At("TAIL"))
|
||||
private void mapMultiNoise(NoiseGeneratorSettings chunkGeneratorSettings,
|
||||
HolderGetter<NormalNoise.NoiseParameters> noiseParametersLookup, long seed,
|
||||
CallbackInfo ci) {
|
||||
SeedHack.register(sampler, seed);
|
||||
@Inject(method = "createClimateSampler(Lnet/minecraft/world/level/levelgen/densityfunction/SamplerContext;)Lnet/minecraft/world/level/biome/Climate$Sampler;",
|
||||
at = @At("RETURN"))
|
||||
private void mapMultiNoise(SamplerContext context, CallbackInfoReturnable<Sampler> cir) {
|
||||
SeedHack.register(cir.getReturnValue(), seed);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.dfsek.terra.lifecycle.mixin;
|
||||
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.resources.RegistryLoadTask;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
|
||||
@Mixin(RegistryLoadTask.class)
|
||||
public interface RegistryLoadTaskAccessor {
|
||||
@Accessor("registry")
|
||||
WritableRegistry<?> getRegistry();
|
||||
}
|
||||
+5
-12
@@ -1,29 +1,22 @@
|
||||
package com.dfsek.terra.lifecycle.mixin.lifecycle;
|
||||
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.server.WorldStem;
|
||||
import net.minecraft.server.level.progress.LevelLoadListener;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.net.Proxy;
|
||||
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
@Inject(method = "<init>(Ljava/lang/Thread;Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lnet/minecraft/server/packs/repository/PackRepository;Lnet/minecraft/server/WorldStem;Ljava/net/Proxy;Lcom/mojang/datafixers/DataFixer;Lnet/minecraft/server/Services;Lnet/minecraft/server/level/progress/LevelLoadListener;)V",
|
||||
@Inject(method = "<init>(Ljava/lang/Thread;Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;" +
|
||||
"Lnet/minecraft/server/packs/repository/PackRepository;Lnet/minecraft/server/WorldStem;Ljava/util/Optional;" +
|
||||
"Ljava/net/Proxy;Lcom/mojang/datafixers/DataFixer;Lnet/minecraft/server/Services;" +
|
||||
"Lnet/minecraft/server/level/progress/LevelLoadListener;ZLnet/minecraft/server/notifications/NotificationManager;)V",
|
||||
at = @At("RETURN"))
|
||||
private void injectConstructor(Thread serverThread, LevelStorageSource.LevelStorageAccess session, PackRepository dataPackManager,
|
||||
WorldStem saveLoader, Proxy proxy, DataFixer dataFixer, Services apiServices,
|
||||
LevelLoadListener chunkLoadProgress, CallbackInfo ci) {
|
||||
private void injectConstructor(CallbackInfo ci) {
|
||||
LifecyclePlatform.setServer((MinecraftServer) (Object) this);
|
||||
}
|
||||
}
|
||||
+25
-42
@@ -1,35 +1,31 @@
|
||||
package com.dfsek.terra.lifecycle.mixin.lifecycle;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.RegistryLoadTask;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.resources.ResourceManagerRegistryLoadTask;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterList;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
import com.dfsek.terra.lifecycle.mixin.RegistryLoadTaskAccessor;
|
||||
import com.dfsek.terra.lifecycle.util.LifecycleUtil;
|
||||
import com.dfsek.terra.lifecycle.util.RegistryHack;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
@@ -38,44 +34,26 @@ import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
@Mixin(RegistryDataLoader.class)
|
||||
public class RegistryDataLoaderMixin {
|
||||
|
||||
@Unique
|
||||
private static final AtomicBoolean LOADING_DYNAMIC_REGISTRIES = new AtomicBoolean(false);
|
||||
@Shadow
|
||||
@Final
|
||||
private static Logger LOGGER;
|
||||
|
||||
@Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/List;Ljava/util/List;)Lnet/minecraft/core/RegistryAccess$Frozen;",
|
||||
at = @At("HEAD"))
|
||||
private static void loadFromResources(ResourceManager resourceManager, List<HolderLookup.RegistryLookup<?>> registries,
|
||||
List<RegistryDataLoader.RegistryData<?>> entries,
|
||||
CallbackInfoReturnable<RegistryAccess.Frozen> cir) {
|
||||
LOADING_DYNAMIC_REGISTRIES.set(entries.stream().anyMatch(entry -> entry.key() == Registries.BIOME));
|
||||
}
|
||||
|
||||
// The thenApplyAsync callback in load(LoaderFactory, List, List, Executor): every registry populated, none frozen.
|
||||
@Inject(
|
||||
method = "load(Lnet/minecraft/resources/RegistryDataLoader$LoadingFunction;Ljava/util/List;Ljava/util/List;)" +
|
||||
"Lnet/minecraft/core/RegistryAccess$Frozen;",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V",
|
||||
ordinal = 1
|
||||
)
|
||||
method = "lambda$load$2(Ljava/util/List;Ljava/util/Map;Ljava/lang/Void;)Lnet/minecraft/core/RegistryAccess$Frozen;",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private static void beforeFreeze(@Coerce Object loadable, List<HolderLookup.RegistryLookup<?>> wrappers, List<RegistryDataLoader.RegistryData<?>> entries,
|
||||
CallbackInfoReturnable<RegistryAccess.Frozen> cir,
|
||||
@Local(ordinal = 2) List<RegistryDataLoader.Loader<?>> registriesList) {
|
||||
if(LOADING_DYNAMIC_REGISTRIES.getAndSet(false)) {
|
||||
private static void beforeFreeze(List<RegistryLoadTask<?>> loadTasks, Map<ResourceKey<?>, Exception> loadingErrors, Void ignored,
|
||||
CallbackInfoReturnable<RegistryAccess.Frozen> cir) {
|
||||
boolean loadingDynamicRegistries = loadTasks.stream().anyMatch(
|
||||
task -> task instanceof ResourceManagerRegistryLoadTask<?> && getRegistry(task).key() == Registries.BIOME);
|
||||
if(loadingDynamicRegistries) {
|
||||
ModPlatform platform = CommonPlatform.get();
|
||||
platform.getRawConfigRegistry().clear();
|
||||
WritableRegistry<Biome> biomes = extractRegistry(registriesList, Registries.BIOME).orElseThrow();
|
||||
WritableRegistry<DimensionType> dimensionTypes = extractRegistry(registriesList, Registries.DIMENSION_TYPE).orElseThrow();
|
||||
WritableRegistry<WorldPreset> worldPresets = extractRegistry(registriesList, Registries.WORLD_PRESET).orElseThrow();
|
||||
WritableRegistry<NoiseGeneratorSettings> chunkGeneratorSettings = extractRegistry(registriesList,
|
||||
WritableRegistry<Biome> biomes = extractRegistry(loadTasks, Registries.BIOME).orElseThrow();
|
||||
WritableRegistry<DimensionType> dimensionTypes = extractRegistry(loadTasks, Registries.DIMENSION_TYPE).orElseThrow();
|
||||
WritableRegistry<WorldPreset> worldPresets = extractRegistry(loadTasks, Registries.WORLD_PRESET).orElseThrow();
|
||||
WritableRegistry<NoiseGeneratorSettings> chunkGeneratorSettings = extractRegistry(loadTasks,
|
||||
Registries.NOISE_SETTINGS).orElseThrow();
|
||||
WritableRegistry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterLists = extractRegistry(registriesList,
|
||||
WritableRegistry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterLists = extractRegistry(loadTasks,
|
||||
Registries.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST).orElseThrow();
|
||||
WritableRegistry<Enchantment> enchantments = extractRegistry(registriesList, Registries.ENCHANTMENT).orElseThrow();
|
||||
WritableRegistry<Enchantment> enchantments = extractRegistry(loadTasks, Registries.ENCHANTMENT).orElseThrow();
|
||||
|
||||
LifecyclePlatform.setRegistries(biomes, dimensionTypes, chunkGeneratorSettings, multiNoiseBiomeSourceParameterLists,
|
||||
enchantments);
|
||||
@@ -83,12 +61,17 @@ public class RegistryDataLoaderMixin {
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static WritableRegistry<?> getRegistry(RegistryLoadTask<?> task) {
|
||||
return ((RegistryLoadTaskAccessor) task).getRegistry();
|
||||
}
|
||||
|
||||
@Unique
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> Optional<WritableRegistry<T>> extractRegistry(List<RegistryDataLoader.Loader<?>> instance,
|
||||
private static <T> Optional<WritableRegistry<T>> extractRegistry(List<RegistryLoadTask<?>> instance,
|
||||
ResourceKey<Registry<T>> key) {
|
||||
List<? extends WritableRegistry<?>> matches = instance
|
||||
.stream().map(RegistryDataLoader.Loader::registry)
|
||||
.stream().map(RegistryDataLoaderMixin::getRegistry)
|
||||
.filter(r -> r.key().equals(key))
|
||||
.toList();
|
||||
if(matches.size() > 1) {
|
||||
|
||||
+6
-1
@@ -14,7 +14,12 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
@Mixin(WorldLoader.class)
|
||||
public class WorldLoaderMixin {
|
||||
@ModifyArg(
|
||||
method = "load(Lnet/minecraft/server/WorldLoader$InitConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;Lnet/minecraft/server/WorldLoader$ResultFactory;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;",
|
||||
// The innermost thenComposeAsync callback of WorldLoader.load, which builds the server resources.
|
||||
method = "lambda$load$2(Lcom/mojang/datafixers/util/Pair;Ljava/util/List;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;" +
|
||||
"Lnet/minecraft/server/packs/resources/CloseableResourceManager;Lnet/minecraft/core/LayeredRegistryAccess;" +
|
||||
"Lnet/minecraft/core/RegistryAccess$Frozen;Ljava/util/List;Lnet/minecraft/server/WorldLoader$InitConfig;" +
|
||||
"Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Lnet/minecraft/server/WorldLoader$ResultFactory;" +
|
||||
"Lnet/minecraft/core/RegistryAccess$Frozen;)Ljava/util/concurrent/CompletionStage;",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/ReloadableServerResources;loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/LayeredRegistryAccess;Ljava/util/List;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;Lnet/minecraft/server/permissions/PermissionSet;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"),
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.dfsek.terra.lifecycle.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"mixins": [
|
||||
"RandomStateMixin",
|
||||
"HolderReferenceInvoker",
|
||||
"RegistryLoadTaskAccessor",
|
||||
"BuiltInRegistriesMixin",
|
||||
"MappedRegistryMixin",
|
||||
"lifecycle.MinecraftServerMixin",
|
||||
@@ -16,6 +17,5 @@
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"refmap": "terra.lifecycle.refmap.json"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user