1.19 fabric compiles now

This commit is contained in:
dfsek
2022-05-30 20:44:04 -07:00
parent 9d131a8992
commit 9c9487ced6
18 changed files with 117 additions and 328 deletions
@@ -29,7 +29,6 @@ import net.minecraft.MinecraftVersion;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.biome.Biome.Precipitation; import net.minecraft.world.biome.Biome.Precipitation;
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier; import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -39,6 +38,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import com.dfsek.terra.AbstractPlatform; import com.dfsek.terra.AbstractPlatform;
import com.dfsek.terra.addon.EphemeralAddon; import com.dfsek.terra.addon.EphemeralAddon;
@@ -68,6 +68,10 @@ public class PlatformImpl extends AbstractPlatform {
this.server = server; this.server = server;
} }
public MinecraftServer getServer() {
return server;
}
@Override @Override
public boolean reload() { public boolean reload() {
getTerraConfig().load(this); getTerraConfig().load(this);
@@ -157,9 +161,10 @@ public class PlatformImpl extends AbstractPlatform {
throw new LoadException("Invalid identifier: " + o, depthTracker); throw new LoadException("Invalid identifier: " + o, depthTracker);
return identifier; return identifier;
}) })
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.byName((String) o)) .registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
.registerLoader(Category.class, (type, o, loader, depthTracker) -> Category.byName((String) o)) Locale.ROOT)))
.registerLoader(GrassColorModifier.class, (type, o, loader, depthTracker) -> GrassColorModifier.byName((String) o)); .registerLoader(GrassColorModifier.class, (type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)));
} }
@@ -3,7 +3,6 @@ package com.dfsek.terra.fabric.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate; import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Default; 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.annotations.Value;
import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.biome.Biome.Precipitation; import net.minecraft.world.biome.Biome.Precipitation;
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier; import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
@@ -43,10 +42,6 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Default @Default
private Precipitation precipitation = null; private Precipitation precipitation = null;
@Value("climate.category")
@Default
private Category category = null;
public Integer getFogColor() { public Integer getFogColor() {
return fogColor; return fogColor;
} }
@@ -71,10 +66,6 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
return skyColor; return skyColor;
} }
public Category getCategory() {
return category;
}
public Precipitation getPrecipitation() { public Precipitation getPrecipitation() {
return precipitation; return precipitation;
} }
@@ -13,11 +13,12 @@ import net.minecraft.util.Util;
import net.minecraft.util.math.BlockBox; import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.StructureWeightType; import net.minecraft.world.gen.StructureTerrainAdaptation;
import net.minecraft.world.gen.StructureWeightSampler;
import net.minecraft.world.gen.StructureWeightSampler.class_7301;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator; import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
@@ -30,14 +31,13 @@ public class BeardGenerator {
for(int i = 0; i < 24; ++i) { for(int i = 0; i < 24; ++i) {
for(int j = 0; j < 24; ++j) { for(int j = 0; j < 24; ++j) {
for(int k = 0; k < 24; ++k) { for(int k = 0; k < 24; ++k) {
array[i * 24 * 24 + j * 24 + k] = (float) calculateStructureWeight(j - 12, k - 12, i - 12); array[i * 24 * 24 + j * 24 + k] = (float)calculateStructureWeight(j - 12, k - 12, i - 12);
} }
} }
} }
}); });
private final ObjectList<StructurePiece> pieces;
private final ObjectList<JigsawJunction> junctions; private final ObjectListIterator<StructureWeightSampler.class_7301> pieceIterator;
private final ObjectListIterator<StructurePiece> pieceIterator;
private final ObjectListIterator<JigsawJunction> junctionIterator; private final ObjectListIterator<JigsawJunction> junctionIterator;
private final Chunk chunk; private final Chunk chunk;
private final int minY; private final int minY;
@@ -51,36 +51,50 @@ public class BeardGenerator {
ChunkPos chunkPos = chunk.getPos(); ChunkPos chunkPos = chunk.getPos();
int i = chunkPos.getStartX(); int i = chunkPos.getStartX();
int j = chunkPos.getStartZ(); int j = chunkPos.getStartZ();
this.junctions = new ObjectArrayList<>(32); ObjectList<JigsawJunction> junctions = new ObjectArrayList<>(32);
this.pieces = new ObjectArrayList<>(10); ObjectList<class_7301> pieces = new ObjectArrayList<>(10);
int minY = chunk.getBottomY(); int minY = chunk.getBottomY();
int maxY = chunk.getTopY(); int maxY = chunk.getTopY();
for(StructureStart start : structureAccessor.method_41035(ChunkSectionPos.from(chunk), for(StructureStart structureStart : structureAccessor.method_41035(chunkPos,
configuredStructureFeature -> configuredStructureFeature.field_37144)) { structureType -> structureType.getTerrainAdaptation() !=
for(StructurePiece structurePiece : start.getChildren()) { StructureTerrainAdaptation.NONE)) {
if(!structurePiece.intersectsChunk(chunkPos, 12)) continue; StructureTerrainAdaptation structureTerrainAdaptation = structureStart.getFeature().getTerrainAdaptation();
for(StructurePiece structurePiece : structureStart.getChildren()) {
if(structurePiece.intersectsChunk(chunkPos, 12)) {
if(structurePiece instanceof PoolStructurePiece poolStructurePiece) { if(structurePiece instanceof PoolStructurePiece poolStructurePiece) {
Projection projection = poolStructurePiece.getPoolElement().getProjection(); Projection projection = poolStructurePiece.getPoolElement().getProjection();
if(projection == Projection.RIGID) { if(projection == Projection.RIGID) {
this.pieces.add(poolStructurePiece); pieces.add(
new class_7301(
poolStructurePiece.getBoundingBox(), structureTerrainAdaptation,
poolStructurePiece.getGroundLevelDelta()
)
);
maxY = Math.max(maxY, poolStructurePiece.getCenter().getY());
minY = Math.min(minY, poolStructurePiece.getCenter().getY());
} }
for(JigsawJunction jigsawJunction : poolStructurePiece.getJunctions()) { for(JigsawJunction jigsawJunction : poolStructurePiece.getJunctions()) {
int k = jigsawJunction.getSourceX(); int k = jigsawJunction.getSourceX();
int l = jigsawJunction.getSourceZ(); int l = jigsawJunction.getSourceZ();
if(k <= i - 12 || l <= j - 12 || k >= i + 15 + 12 || l >= j + 15 + 12) continue; if(k > i - 12 && l > j - 12 && k < i + 15 + 12 && l < j + 15 + 12) {
junctions.add(jigsawJunction);
maxY = Math.max(maxY, jigsawJunction.getSourceGroundY()); maxY = Math.max(maxY, jigsawJunction.getSourceGroundY());
minY = Math.min(minY, jigsawJunction.getSourceGroundY()); minY = Math.min(minY, jigsawJunction.getSourceGroundY());
this.junctions.add(jigsawJunction);
} }
continue;
} }
} else {
pieces.add(new class_7301(structurePiece.getBoundingBox(), structureTerrainAdaptation, 0));
maxY = Math.max(maxY, structurePiece.getCenter().getY()); maxY = Math.max(maxY, structurePiece.getCenter().getY());
minY = Math.min(minY, structurePiece.getCenter().getY()); minY = Math.min(minY, structurePiece.getCenter().getY());
this.pieces.add(structurePiece);
} }
} }
this.pieceIterator = this.pieces.iterator(); }
this.junctionIterator = this.junctions.iterator();
}
this.pieceIterator = pieces.iterator();
this.junctionIterator = junctions.iterator();
this.minY = minY; this.minY = minY;
this.maxY = maxY; this.maxY = maxY;
} }
@@ -93,20 +107,22 @@ public class BeardGenerator {
/** /**
* Gets the structure weight from the array from the given position, or 0 if the position is out of bounds. * Gets the structure weight from the array from the given position, or 0 if the position is out of bounds.
*/ */
private static double getStructureWeight(int x, int y, int z) { private static double getStructureWeight(int x, int y, int z, int i) {
int xOffset = x + 12; int j = x + 12;
int yOffset = y + 12; int k = y + 12;
int zOffset = z + 12; int l = z + 12;
if(xOffset < 0 || xOffset >= 24) { if (isInRange(j) && isInRange(k) && isInRange(l)) {
double d = (double)i + 0.5;
double e = MathHelper.squaredMagnitude((double)x, d, (double)z);
double f = -d * MathHelper.fastInverseSqrt(e / 2.0) / 2.0;
return f * (double)STRUCTURE_WEIGHT_TABLE[l * 24 * 24 + j * 24 + k];
} else {
return 0.0; return 0.0;
} }
if(yOffset < 0 || yOffset >= 24) {
return 0.0;
} }
if(zOffset < 0 || zOffset >= 24) {
return 0.0; private static boolean isInRange(int i) {
} return i >= 0 && i < 24;
return STRUCTURE_WEIGHT_TABLE[zOffset * 24 * 24 + xOffset * 24 + yOffset];
} }
/** /**
@@ -145,34 +161,40 @@ public class BeardGenerator {
} }
public double calculateNoise(int x, int y, int z) { public double calculateNoise(int x, int y, int z) {
double noise = 0.0; double d;
double var10001;
for(d = 0.0; this.pieceIterator.hasNext(); d += var10001) {
StructureWeightSampler.class_7301 lv = this.pieceIterator.next();
BlockBox blockBox = lv.box();
int l = lv.groundLevelDelta();
int m = Math.max(0, Math.max(blockBox.getMinX() - x, x - blockBox.getMaxX()));
int n = Math.max(0, Math.max(blockBox.getMinZ() - z, z - blockBox.getMaxZ()));
int o = blockBox.getMinY() + l;
int p = y - o;
while(this.pieceIterator.hasNext()) { int q = switch(lv.terrainAdjustment()) {
StructurePiece structurePiece = this.pieceIterator.next(); case NONE -> 0;
BlockBox blockBox = structurePiece.getBoundingBox(); case BURY, BEARD_THIN -> p;
int structureX = Math.max(0, Math.max(blockBox.getMinX() - x, x - blockBox.getMaxX())); case BEARD_BOX -> Math.max(0, Math.max(o - y, y - blockBox.getMaxY()));
int structureY = y - (blockBox.getMinY() + (structurePiece instanceof PoolStructurePiece };
? ((PoolStructurePiece) structurePiece).getGroundLevelDelta() var10001 = switch(lv.terrainAdjustment()) {
: 0)); case NONE -> 0.0;
int structureZ = Math.max(0, Math.max(blockBox.getMinZ() - z, z - blockBox.getMaxZ())); case BURY -> getMagnitudeWeight(m, q, n);
StructureWeightType structureWeightType = structurePiece.getWeightType(); case BEARD_THIN, BEARD_BOX -> getStructureWeight(m, q, n, p) * 0.8;
if(structureWeightType == StructureWeightType.BURY) { };
noise += getMagnitudeWeight(structureX, structureY, structureZ);
continue;
} }
if(structureWeightType != StructureWeightType.BEARD) continue;
noise += getStructureWeight(structureX, structureY, structureZ) * 0.8; this.pieceIterator.back(Integer.MAX_VALUE);
}
this.pieceIterator.back(this.pieces.size());
while(this.junctionIterator.hasNext()) { while(this.junctionIterator.hasNext()) {
JigsawJunction structurePiece = this.junctionIterator.next(); JigsawJunction jigsawJunction = this.junctionIterator.next();
int structureX = x - structurePiece.getSourceX(); int r = x - jigsawJunction.getSourceX();
int structureY = y - structurePiece.getSourceGroundY(); int l = y - jigsawJunction.getSourceGroundY();
int structureZ = z - structurePiece.getSourceZ(); int m = z - jigsawJunction.getSourceZ();
noise += getStructureWeight(structureX, structureY, structureZ) * 0.4; d += getStructureWeight(r, l, m, l) * 0.4;
} }
this.junctionIterator.back(this.junctions.size());
return noise; this.junctionIterator.back(Integer.MAX_VALUE);
return d;
} }
} }
@@ -58,11 +58,6 @@ public class TerraBiomeSource extends BiomeSource {
return Codecs.TERRA_BIOME_SOURCE; return Codecs.TERRA_BIOME_SOURCE;
} }
@Override
public BiomeSource withSeed(long seed) {
return new TerraBiomeSource(this.biomeRegistry, seed, pack);
}
@Override @Override
public RegistryEntry<net.minecraft.world.biome.Biome> getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) { public RegistryEntry<net.minecraft.world.biome.Biome> getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) {
return biomeRegistry return biomeRegistry
@@ -1,51 +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.fabric.generation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.structure.StructureSet;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import com.dfsek.terra.api.config.ConfigPack;
@Environment(EnvType.CLIENT)
public class TerraGeneratorType extends GeneratorType {
private final ConfigPack pack;
public TerraGeneratorType(ConfigPack pack) {
super("terra." + pack.getID());
this.pack = pack;
}
@Override
protected ChunkGenerator getChunkGenerator(DynamicRegistryManager manager, long seed) {
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = manager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
RegistryEntry<ChunkGeneratorSettings>
settingsSupplier = chunkGeneratorSettingsRegistry.getEntry(ChunkGeneratorSettings.OVERWORLD).orElseThrow();
Registry<StructureSet> noiseRegistry = manager.get(Registry.STRUCTURE_SET_KEY);
return new FabricChunkGeneratorWrapper(noiseRegistry, new TerraBiomeSource(manager.get(Registry.BIOME_KEY), seed, pack), seed, pack,
settingsSupplier);
}
}
@@ -17,8 +17,11 @@
package com.dfsek.terra.fabric.handle; package com.dfsek.terra.fabric.handle;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.ItemStackArgumentType; import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
@@ -36,7 +39,7 @@ public class FabricItemHandle implements ItemHandle {
@Override @Override
public Item createItem(String data) { public Item createItem(String data) {
try { try {
return (Item) new ItemStackArgumentType().parse(new StringReader(data)).getItem(); return (Item) new ItemStackArgumentType(new CommandRegistryAccess(FabricEntryPoint.getPlatform().getServer().getRegistryManager())).parse(new StringReader(data)).getItem();
} catch(CommandSyntaxException e) { } catch(CommandSyntaxException e) {
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e); throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
} }
@@ -17,6 +17,8 @@
package com.dfsek.terra.fabric.handle; package com.dfsek.terra.fabric.handle;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
@@ -36,9 +38,8 @@ public class FabricWorldHandle implements WorldHandle {
@Override @Override
public @NotNull BlockState createBlockState(@NotNull String data) { public @NotNull BlockState createBlockState(@NotNull String data) {
BlockArgumentParser parser = new BlockArgumentParser(new StringReader(data), true);
try { try {
net.minecraft.block.BlockState state = parser.parse(true).getBlockState(); net.minecraft.block.BlockState state = BlockArgumentParser.block(FabricEntryPoint.getPlatform().getServer().getRegistryManager().get(Registry.BLOCK_KEY), data, true).blockState();
if(state == null) throw new IllegalArgumentException("Invalid data: " + data); if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
return (BlockState) state; return (BlockState) state;
} catch(CommandSyntaxException e) { } catch(CommandSyntaxException e) {
@@ -1,39 +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.fabric.mixin.access;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
@Mixin(GeneratorType.class)
public interface GeneratorTypeAccessor {
@Accessor("VALUES")
static List<GeneratorType> getValues() {
throw new UnsupportedOperationException();
}
@Mutable
@Accessor("displayName")
void setDisplayName(Text translationKey);
}
@@ -18,7 +18,6 @@
package com.dfsek.terra.fabric.mixin.implementations.block.entity; package com.dfsek.terra.fabric.mixin.implementations.block.entity;
import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@@ -42,19 +41,19 @@ public abstract class SignBlockEntityMixin {
public abstract void setTextOnRow(int row, Text text); public abstract void setTextOnRow(int row, Text text);
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException { public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
setTextOnRow(index, new LiteralText(line)); setTextOnRow(index, Text.literal(line));
} }
public @NotNull String[] terra$getLines() { public @NotNull String[] terra$getLines() {
String[] lines = new String[texts.length]; String[] lines = new String[texts.length];
for(int i = 0; i < texts.length; i++) { for(int i = 0; i < texts.length; i++) {
lines[i] = texts[i].asString(); lines[i] = texts[i].getString();
} }
return lines; return lines;
} }
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException { public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
return texts[index].asString(); return texts[index].getString();
} }
public void terra$applyState(String state) { public void terra$applyState(String state) {
@@ -44,9 +44,6 @@ public abstract class EntityMixin {
@Shadow @Shadow
public abstract void teleport(double destX, double destY, double destZ); public abstract void teleport(double destX, double destY, double destZ);
@Shadow
public abstract void sendSystemMessage(Text message, UUID senderUuid);
public Vector3 terra$position() { public Vector3 terra$position() {
return FabricAdapter.adapt(blockPos); return FabricAdapter.adapt(blockPos);
} }
@@ -20,7 +20,6 @@ package com.dfsek.terra.fabric.mixin.implementations.entity;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
@@ -49,7 +48,7 @@ public abstract class ServerCommandSourceMixin {
public abstract net.minecraft.entity.@Nullable Entity getEntity(); public abstract net.minecraft.entity.@Nullable Entity getEntity();
public void terra$sendMessage(String message) { public void terra$sendMessage(String message) {
sendFeedback(new LiteralText(message), true); sendFeedback(Text.literal(message), true);
} }
@Nullable @Nullable
@@ -7,6 +7,7 @@ import net.minecraft.resource.ResourcePackManager;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.SaveLoader; import net.minecraft.server.SaveLoader;
import net.minecraft.server.WorldGenerationProgressListenerFactory; import net.minecraft.server.WorldGenerationProgressListenerFactory;
import net.minecraft.util.ApiServices;
import net.minecraft.util.UserCache; import net.minecraft.util.UserCache;
import net.minecraft.world.level.storage.LevelStorage; import net.minecraft.world.level.storage.LevelStorage;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -23,13 +24,11 @@ import com.dfsek.terra.fabric.FabricEntryPoint;
public class MinecraftServerMixin { public class MinecraftServerMixin {
@Inject(method = "<init>(Ljava/lang/Thread;Lnet/minecraft/world/level/storage/LevelStorage$Session;" + @Inject(method = "<init>(Ljava/lang/Thread;Lnet/minecraft/world/level/storage/LevelStorage$Session;" +
"Lnet/minecraft/resource/ResourcePackManager;Lnet/minecraft/server/SaveLoader;Ljava/net/Proxy;" + "Lnet/minecraft/resource/ResourcePackManager;Lnet/minecraft/server/SaveLoader;Ljava/net/Proxy;" +
"Lcom/mojang/datafixers/DataFixer;Lcom/mojang/authlib/minecraft/MinecraftSessionService;" + "Lcom/mojang/datafixers/DataFixer;Lnet/minecraft/util/ApiServices;" +
"Lcom/mojang/authlib/GameProfileRepository;Lnet/minecraft/util/UserCache;" +
"Lnet/minecraft/server/WorldGenerationProgressListenerFactory;)V", "Lnet/minecraft/server/WorldGenerationProgressListenerFactory;)V",
at = @At("RETURN")) at = @At("RETURN"))
private void injectConstructor(Thread serverThread, LevelStorage.Session session, ResourcePackManager dataPackManager, private void injectConstructor(Thread serverThread, LevelStorage.Session session, ResourcePackManager dataPackManager,
SaveLoader saveLoader, Proxy proxy, DataFixer dataFixer, MinecraftSessionService sessionService, SaveLoader saveLoader, Proxy proxy, DataFixer dataFixer, ApiServices apiServices,
GameProfileRepository gameProfileRepo, UserCache userCache,
WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory, CallbackInfo ci) { WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory, CallbackInfo ci) {
FabricEntryPoint.getPlatform().setServer((MinecraftServer) (Object) this); FabricEntryPoint.getPlatform().setServer((MinecraftServer) (Object) this);
} }
@@ -17,11 +17,8 @@
package com.dfsek.terra.fabric.mixin.lifecycle.client; package com.dfsek.terra.fabric.mixin.lifecycle.client;
import com.dfsek.terra.fabric.util.BiomeUtil;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs; import net.minecraft.client.RunArgs;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.text.LiteralText;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -29,8 +26,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent; import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint; import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.generation.TerraGeneratorType; import com.dfsek.terra.fabric.util.BiomeUtil;
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
@Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
@@ -43,12 +39,6 @@ public class MinecraftClientMixin {
shift = At.Shift.BEFORE)) shift = At.Shift.BEFORE))
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) { public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
FabricEntryPoint.getPlatform().getEventManager().callEvent(new PlatformInitializationEvent()); FabricEntryPoint.getPlatform().getEventManager().callEvent(new PlatformInitializationEvent());
FabricEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> {
final GeneratorType generatorType = new TerraGeneratorType(pack);
//noinspection ConstantConditions
((GeneratorTypeAccessor) generatorType).setDisplayName(new LiteralText("Terra:" + pack.getID()));
GeneratorTypeAccessor.getValues().add(1, generatorType);
});
BiomeUtil.registerBiomes(); BiomeUtil.registerBiomes();
} }
} }
@@ -1,111 +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.fabric.mixin.lifecycle.server;
import net.minecraft.server.dedicated.ServerPropertiesHandler;
import net.minecraft.structure.StructureSet;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
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.CallbackInfoReturnable;
import java.util.Locale;
import java.util.Random;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.PlatformImpl;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
@Mixin(GeneratorOptions.class)
public abstract class GeneratorOptionsMixin {
@Inject(method = "fromProperties(Lnet/minecraft/util/registry/DynamicRegistryManager;" +
"Lnet/minecraft/server/dedicated/ServerPropertiesHandler$WorldGenProperties;)" +
"Lnet/minecraft/world/gen/GeneratorOptions;",
at = @At("HEAD"),
cancellable = true)
private static void fromProperties(DynamicRegistryManager manager,
ServerPropertiesHandler.WorldGenProperties properties,
CallbackInfoReturnable<GeneratorOptions> cir) {
if(properties.levelType() == null) {
return;
}
PlatformImpl main = FabricEntryPoint.getPlatform();
String levelType = properties.levelType();
if(levelType.toLowerCase(Locale.ROOT).startsWith("terra")) {
String seedProperty = properties.levelSeed();
long seed = new Random().nextLong();
if(seedProperty != null) {
try {
long m = Long.parseLong(seedProperty);
if(m != 0L) {
seed = m;
}
} catch(NumberFormatException exception) {
seed = seedProperty.hashCode();
}
}
boolean generateStructures = properties.generateStructures();
Registry<DimensionType> dimensionTypes = manager.get(Registry.DIMENSION_TYPE_KEY);
Registry<Biome> biomeRegistry = manager.get(Registry.BIOME_KEY);
Registry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(manager, seed, false);
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = manager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
RegistryEntry<ChunkGeneratorSettings>
settingsSupplier = chunkGeneratorSettingsRegistry.getEntry(ChunkGeneratorSettings.OVERWORLD).orElseThrow();
Registry<StructureSet> noiseRegistry = manager.get(Registry.STRUCTURE_SET_KEY);
String pack = levelType.substring(levelType.indexOf(":") + 1);
CheckedRegistry<ConfigPack> configRegistry = main.getConfigRegistry();
ConfigPack config = configRegistry
.getByID(pack)
.or(() -> configRegistry.getByID(pack.toUpperCase(Locale.ROOT)))
.orElseThrow(() -> new IllegalArgumentException("No such pack " + pack));
cir.setReturnValue(
new GeneratorOptions(seed,
generateStructures,
false,
GeneratorOptions
.getRegistryWithReplacedOverworldGenerator(
dimensionTypes,
dimensionOptions,
new FabricChunkGeneratorWrapper(noiseRegistry,
new TerraBiomeSource(biomeRegistry, seed, config),
seed,
config,
settingsSupplier))));
}
}
}
@@ -137,12 +137,9 @@ public final class BiomeUtil {
effects.foliageColor(vanillaBiomeProperties.getFoliageColor()); effects.foliageColor(vanillaBiomeProperties.getFoliageColor());
} }
builder.precipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.getPrecipitation()));
builder.precipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.getPrecipitation()))
.category(Objects.requireNonNullElse(vanillaBiomeProperties.getCategory(), vanilla.getCategory()));
} else { } else {
effects.waterColor(vanilla.getWaterColor()) effects.waterColor(vanilla.getWaterColor())
.waterFogColor(vanilla.getWaterFogColor()) .waterFogColor(vanilla.getWaterFogColor())
.fogColor(vanilla.getFogColor()) .fogColor(vanilla.getFogColor())
@@ -150,11 +147,9 @@ public final class BiomeUtil {
vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor); vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor);
vanilla.getEffects().getGrassColor().ifPresent(effects::grassColor); vanilla.getEffects().getGrassColor().ifPresent(effects::grassColor);
builder.precipitation(vanilla.getPrecipitation()) builder.precipitation(vanilla.getPrecipitation());
.category(vanilla.getCategory());
} }
return builder return builder
.temperature(vanilla.getTemperature()) .temperature(vanilla.getTemperature())
.downfall(vanilla.getDownfall()) .downfall(vanilla.getDownfall())
@@ -26,7 +26,7 @@
"depends": { "depends": {
"fabricloader": ">=0.14.2", "fabricloader": ">=0.14.2",
"java": ">=17", "java": ">=17",
"minecraft": "1.18.x" "minecraft": "1.19.x"
}, },
"accessWidener": "terra.accesswidener" "accessWidener": "terra.accesswidener"
} }
@@ -1,5 +1 @@
accessWidener v1 named accessWidener v1 named
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V
accessible method net/minecraft/world/biome/Biome getCategory ()Lnet/minecraft/world/biome/Biome$Category;
@@ -37,11 +37,9 @@
"lifecycle.RegistryMixin" "lifecycle.RegistryMixin"
], ],
"client": [ "client": [
"access.GeneratorTypeAccessor",
"lifecycle.client.MinecraftClientMixin" "lifecycle.client.MinecraftClientMixin"
], ],
"server": [ "server": [
"lifecycle.server.GeneratorOptionsMixin",
"lifecycle.server.ServerMainMixin" "lifecycle.server.ServerMainMixin"
], ],
"injectors": { "injectors": {