mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-23 16:49:10 +00:00
reformat all code
This commit is contained in:
@@ -91,7 +91,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener
|
||||
PaperUtil.checkPaper(this);
|
||||
|
||||
|
||||
Initializer.init(platform);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,23 +46,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
|
||||
private record SeededVector(int x, int z, WorldProperties worldProperties) {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof SeededVector that) {
|
||||
return this.z == that.z && this.x == that.x && this.worldProperties.equals(that.worldProperties);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = x;
|
||||
code = 31 * code + z;
|
||||
return 31 * code + worldProperties.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BukkitChunkGeneratorWrapper(ChunkGenerator delegate, ConfigPack pack, BlockState air) {
|
||||
this.delegate = delegate;
|
||||
this.pack = pack;
|
||||
@@ -108,13 +92,12 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
public boolean shouldGenerateDecorations() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateMobs() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateStructures() {
|
||||
return true;
|
||||
@@ -133,4 +116,22 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
public ChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
private record SeededVector(int x, int z, WorldProperties worldProperties) {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof SeededVector that) {
|
||||
return this.z == that.z && this.x == that.x && this.worldProperties.equals(that.worldProperties);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = x;
|
||||
code = 31 * code + z;
|
||||
return 31 * code + worldProperties.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ public interface Initializer {
|
||||
String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
||||
|
||||
void initialize(PlatformImpl plugin);
|
||||
|
||||
static void init(PlatformImpl platform) {
|
||||
Logger logger = LoggerFactory.getLogger(Initializer.class);
|
||||
try {
|
||||
@@ -37,4 +35,6 @@ public interface Initializer {
|
||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||
}
|
||||
}
|
||||
|
||||
void initialize(PlatformImpl plugin);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
package com.dfsek.terra.bukkit.world.inventory.meta;
|
||||
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.dfsek.terra.api.inventory.item.Damageable;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitItemMeta;
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -23,6 +20,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class AwfulBukkitHacks {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NMSBiomeInjector.class);
|
||||
@@ -44,9 +44,11 @@ public class AwfulBukkitHacks {
|
||||
Biome platform = NMSBiomeInjector.createBiome(
|
||||
biome,
|
||||
biomeRegistry.get(vanillaMinecraftKey) // get
|
||||
);
|
||||
);
|
||||
|
||||
ResourceKey<Biome> delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key)));
|
||||
ResourceKey<Biome> delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra",
|
||||
NMSBiomeInjector.createBiomeID(
|
||||
pack, key)));
|
||||
|
||||
BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform);
|
||||
biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
|
||||
@@ -73,28 +75,35 @@ public class AwfulBukkitHacks {
|
||||
terraBiomeMap
|
||||
.forEach((vb, terraBiomes) ->
|
||||
NMSBiomeInjector.getEntry(biomeRegistry, vb)
|
||||
.ifPresentOrElse(
|
||||
vanilla -> terraBiomes
|
||||
.forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
LOGGER.debug(vanilla.unwrapKey().orElseThrow().location() +
|
||||
" (vanilla for " +
|
||||
terra.unwrapKey().orElseThrow().location() +
|
||||
": " +
|
||||
vanilla.tags().toList());
|
||||
|
||||
vanilla.tags()
|
||||
.forEach(
|
||||
tag -> collect
|
||||
.computeIfAbsent(tag,
|
||||
t -> new ArrayList<>())
|
||||
.add(terra));
|
||||
},
|
||||
() -> LOGGER.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> LOGGER.error("No vanilla biome: {}", vb)));
|
||||
.ifPresentOrElse(
|
||||
vanilla -> terraBiomes
|
||||
.forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
LOGGER.debug(
|
||||
vanilla.unwrapKey()
|
||||
.orElseThrow()
|
||||
.location() +
|
||||
" (vanilla for " +
|
||||
terra.unwrapKey()
|
||||
.orElseThrow()
|
||||
.location() +
|
||||
": " +
|
||||
vanilla.tags()
|
||||
.toList());
|
||||
|
||||
vanilla.tags()
|
||||
.forEach(
|
||||
tag -> collect
|
||||
.computeIfAbsent(
|
||||
tag,
|
||||
t -> new ArrayList<>())
|
||||
.add(terra));
|
||||
},
|
||||
() -> LOGGER.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> LOGGER.error("No vanilla biome: {}", vb)));
|
||||
|
||||
biomeRegistry.resetTags(); // clearTags
|
||||
biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); // populateTags
|
||||
|
||||
@@ -1,33 +1,17 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class NMSBiomeInjector {
|
||||
@@ -45,33 +29,32 @@ public class NMSBiomeInjector {
|
||||
|
||||
builder.biomeCategory(Reflection.BIOME.getBiomeCategory(vanilla))
|
||||
.precipitation(vanilla.getPrecipitation()) // getPrecipitation
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(vanilla.getGenerationSettings())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.downfall(vanilla.getDownfall());
|
||||
|
||||
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(vanilla.getGenerationSettings())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.downfall(vanilla.getDownfall());
|
||||
|
||||
|
||||
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
|
||||
|
||||
|
||||
effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier());
|
||||
|
||||
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
|
||||
effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor()))
|
||||
|
||||
|
||||
.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))
|
||||
|
||||
|
||||
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
|
||||
|
||||
|
||||
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()));
|
||||
|
||||
|
||||
if(vanillaBiomeProperties.getFoliageColor() == null) {
|
||||
vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
} else {
|
||||
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() == null) {
|
||||
vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
} else {
|
||||
@@ -83,7 +66,7 @@ public class NMSBiomeInjector {
|
||||
vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound);
|
||||
vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic);
|
||||
vanilla.getAmbientParticle().ifPresent(effects::ambientParticle);
|
||||
|
||||
|
||||
builder.specialEffects(effects.build());
|
||||
|
||||
return builder.build(); // build()
|
||||
|
||||
@@ -49,17 +49,14 @@ import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class);
|
||||
private static final Lazy<List<ChunkPos>> EMPTY = Lazy.lazy(List::of);
|
||||
private final NMSBiomeProvider biomeSource;
|
||||
private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate;
|
||||
|
||||
private final ChunkGenerator vanilla;
|
||||
private final ConfigPack pack;
|
||||
|
||||
private final long seed;
|
||||
|
||||
private final Map<ConcentricRingsStructurePlacement, Lazy<List<ChunkPos>>> ringPositions = new Object2ObjectArrayMap<>();
|
||||
private static final Lazy<List<ChunkPos>> EMPTY = Lazy.lazy(List::of);
|
||||
|
||||
private volatile boolean rings = false;
|
||||
|
||||
public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) {
|
||||
super(Registries.structureSet(), Optional.empty(), biomeProvider, biomeProvider, seed);
|
||||
@@ -71,13 +68,15 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull BiomeManager biomeAccess, @NotNull StructureFeatureManager structureAccessor,
|
||||
public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull BiomeManager biomeAccess,
|
||||
@NotNull StructureFeatureManager structureAccessor,
|
||||
@NotNull ChunkAccess chunk, GenerationStep.@NotNull Carving generationStep) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, @NotNull StructureFeatureManager structureAccessor) {
|
||||
public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk,
|
||||
@NotNull StructureFeatureManager structureAccessor) {
|
||||
vanilla.applyBiomeDecoration(world, chunk, structureAccessor);
|
||||
}
|
||||
|
||||
@@ -87,7 +86,8 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, @NotNull StructureFeatureManager structureAccessor,
|
||||
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Executor executor, @NotNull Blender blender,
|
||||
@NotNull StructureFeatureManager structureAccessor,
|
||||
@NotNull ChunkAccess chunk) {
|
||||
return vanilla.fillFromNoise(executor, blender, structureAccessor, chunk);
|
||||
}
|
||||
@@ -161,8 +161,6 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
return ringPositions.getOrDefault(concentricringsstructureplacement, EMPTY).value();
|
||||
}
|
||||
|
||||
private volatile boolean rings = false;
|
||||
|
||||
@Override
|
||||
public synchronized void ensureStructuresGenerated() {
|
||||
if(!this.rings) {
|
||||
|
||||
@@ -25,15 +25,16 @@ public class NMSInjectListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
if (!INJECTED.contains(event.getWorld()) && event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
if(!INJECTED.contains(event.getWorld()) &&
|
||||
event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
INJECT_LOCK.lock();
|
||||
INJECTED.add(event.getWorld());
|
||||
LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName());
|
||||
CraftWorld craftWorld = (CraftWorld) event.getWorld();
|
||||
ServerLevel serverWorld = craftWorld.getHandle();
|
||||
|
||||
|
||||
ConfigPack pack = bukkitChunkGeneratorWrapper.getPack();
|
||||
|
||||
|
||||
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
|
||||
NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), vanilla.getBiomeSource(), craftWorld.getSeed());
|
||||
NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed());
|
||||
|
||||
@@ -15,18 +15,21 @@ public class Reflection {
|
||||
|
||||
static {
|
||||
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
|
||||
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, Reflection.class.getClassLoader());
|
||||
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper,
|
||||
Reflection.class.getClassLoader());
|
||||
|
||||
MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class);
|
||||
BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(MappedRegistry.class)
|
||||
public interface MappedRegistryProxy {
|
||||
@FieldSetter("frozen")
|
||||
void setFrozen(MappedRegistry<?> instance, boolean frozen);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(Biome.class)
|
||||
public interface BiomeProxy {
|
||||
@FieldGetter("biomeCategory")
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -17,7 +15,15 @@ import org.bukkit.NamespacedKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class AwfulBukkitHacks {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class);
|
||||
@@ -39,10 +45,11 @@ public class AwfulBukkitHacks {
|
||||
Biome platform = NMSBiomeInjector.createBiome(
|
||||
biome,
|
||||
Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)) // get
|
||||
);
|
||||
);
|
||||
|
||||
ResourceKey<Biome> delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY,
|
||||
new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key)));
|
||||
new ResourceLocation("terra",
|
||||
NMSBiomeInjector.createBiomeID(pack, key)));
|
||||
|
||||
BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform);
|
||||
biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
|
||||
@@ -62,35 +69,42 @@ public class AwfulBukkitHacks {
|
||||
Map<TagKey<Biome>, List<Holder<Biome>>> collect = biomeRegistry
|
||||
.getTags() // streamKeysAndEntries
|
||||
.collect(HashMap::new,
|
||||
(map, pair) ->
|
||||
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
|
||||
HashMap::putAll);
|
||||
(map, pair) ->
|
||||
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
|
||||
HashMap::putAll);
|
||||
|
||||
terraBiomeMap
|
||||
.forEach((vb, terraBiomes) ->
|
||||
NMSBiomeInjector.getEntry(biomeRegistry, vb)
|
||||
.ifPresentOrElse(
|
||||
vanilla -> terraBiomes
|
||||
.forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
LOGGER.debug(vanilla.unwrapKey().orElseThrow().location() +
|
||||
" (vanilla for " +
|
||||
terra.unwrapKey().orElseThrow().location() +
|
||||
": " +
|
||||
vanilla.tags().toList());
|
||||
|
||||
vanilla.tags()
|
||||
.forEach(
|
||||
tag -> collect
|
||||
.computeIfAbsent(tag,
|
||||
t -> new ArrayList<>())
|
||||
.add(terra));
|
||||
},
|
||||
() -> LOGGER.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> LOGGER.error("No vanilla biome: {}", vb)));
|
||||
NMSBiomeInjector.getEntry(biomeRegistry, vb)
|
||||
.ifPresentOrElse(
|
||||
vanilla -> terraBiomes
|
||||
.forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
LOGGER.debug(
|
||||
vanilla.unwrapKey()
|
||||
.orElseThrow()
|
||||
.location() +
|
||||
" (vanilla for " +
|
||||
terra.unwrapKey()
|
||||
.orElseThrow()
|
||||
.location() +
|
||||
": " +
|
||||
vanilla.tags()
|
||||
.toList());
|
||||
|
||||
vanilla.tags()
|
||||
.forEach(
|
||||
tag -> collect
|
||||
.computeIfAbsent(
|
||||
tag,
|
||||
t -> new ArrayList<>())
|
||||
.add(terra));
|
||||
},
|
||||
() -> LOGGER.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> LOGGER.error("No vanilla biome: {}", vb)));
|
||||
|
||||
biomeRegistry.resetTags();
|
||||
biomeRegistry.bindTags(ImmutableMap.copyOf(collect));
|
||||
|
||||
@@ -1,33 +1,17 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class NMSBiomeInjector {
|
||||
|
||||
@@ -18,7 +18,11 @@ public class NMSBiomeProvider extends BiomeSource {
|
||||
private final Registry<Biome> biomeRegistry = Registries.biomeRegistry();
|
||||
|
||||
public NMSBiomeProvider(BiomeProvider delegate, long seed) {
|
||||
super(delegate.stream().map(biome -> Registries.biomeRegistry().getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey())));
|
||||
super(delegate.stream()
|
||||
.map(biome -> Registries.biomeRegistry()
|
||||
.getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey())));
|
||||
this.delegate = delegate;
|
||||
this.seed = seed;
|
||||
}
|
||||
@@ -30,6 +34,9 @@ public class NMSBiomeProvider extends BiomeSource {
|
||||
|
||||
@Override
|
||||
public @NotNull Holder<Biome> getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) {
|
||||
return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey());
|
||||
return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed)
|
||||
.getPlatformBiome()).getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
private final ConfigPack pack;
|
||||
|
||||
private final long seed;
|
||||
private final Map<ConcentricRingsStructurePlacement, Lazy<List<ChunkPos>>> ringPositions = new Object2ObjectArrayMap<>();
|
||||
private volatile boolean rings = false;
|
||||
|
||||
public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) {
|
||||
super(Registries.structureSet(), Optional.empty(), biomeProvider);
|
||||
@@ -137,19 +139,16 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
.getHandle()).getState();
|
||||
}
|
||||
return new NoiseColumn(getMinY(), array);
|
||||
|
||||
|
||||
*/
|
||||
return vanilla.getBaseColumn(x, z, world, noiseConfig);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(@NotNull List<String> text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private volatile boolean rings = false;
|
||||
private final Map<ConcentricRingsStructurePlacement, Lazy<List<ChunkPos>>> ringPositions = new Object2ObjectArrayMap<>();
|
||||
|
||||
@Override
|
||||
public void ensureStructuresGenerated(@NotNull RandomState noiseConfig) {
|
||||
if(!this.rings) {
|
||||
@@ -161,7 +160,8 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChunkPos> getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement structurePlacement, @NotNull RandomState noiseConfig) {
|
||||
public List<ChunkPos> getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement structurePlacement,
|
||||
@NotNull RandomState noiseConfig) {
|
||||
ensureStructuresGenerated(noiseConfig);
|
||||
return ringPositions.get(structurePlacement).value();
|
||||
}
|
||||
@@ -179,13 +179,15 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
if (match) {
|
||||
if (holder.placement() instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) {
|
||||
this.ringPositions.put(concentricringsstructureplacement, Lazy.lazy(() -> this.generateRingPositions(holder, noiseConfig, concentricringsstructureplacement)));
|
||||
if(match) {
|
||||
if(holder.placement() instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) {
|
||||
this.ringPositions.put(concentricringsstructureplacement, Lazy.lazy(
|
||||
() -> this.generateRingPositions(holder, noiseConfig, concentricringsstructureplacement)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<ChunkPos> generateRingPositions(StructureSet holder, RandomState randomstate,
|
||||
ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot
|
||||
if(concentricringsstructureplacement.count() == 0) {
|
||||
|
||||
@@ -25,15 +25,16 @@ public class NMSInjectListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
if (!INJECTED.contains(event.getWorld()) && event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
if(!INJECTED.contains(event.getWorld()) &&
|
||||
event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
INJECT_LOCK.lock();
|
||||
INJECTED.add(event.getWorld());
|
||||
LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName());
|
||||
CraftWorld craftWorld = (CraftWorld) event.getWorld();
|
||||
ServerLevel serverWorld = craftWorld.getHandle();
|
||||
|
||||
|
||||
ConfigPack pack = bukkitChunkGeneratorWrapper.getPack();
|
||||
|
||||
|
||||
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
|
||||
NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed());
|
||||
NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed());
|
||||
|
||||
@@ -12,11 +12,13 @@ public class Reflection {
|
||||
|
||||
static {
|
||||
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
|
||||
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, Reflection.class.getClassLoader());
|
||||
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper,
|
||||
Reflection.class.getClassLoader());
|
||||
|
||||
MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(MappedRegistry.class)
|
||||
public interface MappedRegistryProxy {
|
||||
@FieldSetter("frozen")
|
||||
|
||||
@@ -16,8 +16,8 @@ public class Registries {
|
||||
return dedicatedserver
|
||||
.registryAccess()
|
||||
.registryOrThrow( // getRegistry
|
||||
key
|
||||
);
|
||||
key
|
||||
);
|
||||
}
|
||||
|
||||
public static Registry<Biome> biomeRegistry() {
|
||||
|
||||
@@ -16,9 +16,9 @@ public class CLIBlockState implements BlockState {
|
||||
public CLIBlockState(String value) {
|
||||
this.value = value;
|
||||
if(value.contains("[")) {
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
this.isAir = value.startsWith("minecraft:air");
|
||||
this.nbt = new CompoundTag();
|
||||
|
||||
@@ -25,7 +25,13 @@ dependencies {
|
||||
|
||||
modImplementation("net.fabricmc:fabric-loader:${Versions.Fabric.fabricLoader}")
|
||||
|
||||
setOf("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base", "fabric-command-api-v2", "fabric-networking-api-v1").forEach { apiModule ->
|
||||
setOf(
|
||||
"fabric-lifecycle-events-v1",
|
||||
"fabric-resource-loader-v0",
|
||||
"fabric-api-base",
|
||||
"fabric-command-api-v2",
|
||||
"fabric-networking-api-v1"
|
||||
).forEach { apiModule ->
|
||||
val module = fabricApi.module(apiModule, Versions.Fabric.fabricAPI)
|
||||
modImplementation(module)
|
||||
include(module)
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.dfsek.terra.fabric;
|
||||
import com.dfsek.terra.mod.MinecraftAddon;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
public class FabricAddon extends MinecraftAddon {
|
||||
|
||||
public class FabricAddon extends MinecraftAddon {
|
||||
|
||||
public FabricAddon(ModPlatform modPlatform) {
|
||||
super(modPlatform);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-fabric";
|
||||
|
||||
@@ -32,7 +32,7 @@ public class FabricEntryPoint implements ModInitializer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FabricEntryPoint.class);
|
||||
|
||||
private static final FabricPlatform TERRA_PLUGIN = new FabricPlatform();
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
logger.info("Initializing Terra Fabric mod...");
|
||||
|
||||
@@ -20,9 +20,6 @@ package com.dfsek.terra.fabric;
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
@@ -35,8 +32,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
|
||||
public class FabricPlatform extends LifecyclePlatform {
|
||||
@@ -59,6 +55,7 @@ public class FabricPlatform extends LifecyclePlatform {
|
||||
return Stream.empty();
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "Fabric";
|
||||
@@ -68,7 +65,7 @@ public class FabricPlatform extends LifecyclePlatform {
|
||||
public @NotNull File getDataFolder() {
|
||||
return new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseAddon getPlatformAddon() {
|
||||
return new FabricAddon(this);
|
||||
|
||||
@@ -70,7 +70,7 @@ tasks {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
remapJar {
|
||||
inputFile.set(shadowJar.get().archiveFile)
|
||||
archiveFileName.set("${rootProject.name.capitalize()}-${project.version}.jar")
|
||||
|
||||
@@ -1,32 +1,22 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
|
||||
import cpw.mods.cl.ModuleClassLoader;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import org.burningwave.core.classes.Classes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
|
||||
|
||||
@@ -73,7 +63,7 @@ public final class AwfulForgeHacks {
|
||||
}
|
||||
|
||||
public static void loadAllTerraClasses() {
|
||||
if (FMLLoader.isProduction()) {
|
||||
if(FMLLoader.isProduction()) {
|
||||
try(JarFile jar = getTerraJar()) {
|
||||
jar.stream()
|
||||
.forEach(jarEntry -> {
|
||||
@@ -96,45 +86,52 @@ public final class AwfulForgeHacks {
|
||||
}
|
||||
} else {
|
||||
// Forgive me for what I'm about to do...
|
||||
LOGGER.warn("I felt a great disturbance in the JVM, as if millions of class not found exceptions suddenly cried out in terror and were suddenly silenced.");
|
||||
LOGGER.warn(
|
||||
"I felt a great disturbance in the JVM, as if millions of class not found exceptions suddenly cried out in terror and" +
|
||||
" were suddenly silenced.");
|
||||
ArrayList<Path> pathsToLoad = new ArrayList<>();
|
||||
|
||||
Path terraRoot = Path.of(System.getProperty("user.dir")).getParent().getParent().getParent();
|
||||
Path commonRoot = terraRoot.resolve("common");
|
||||
Path implementationRoot = commonRoot.resolve("implementation");
|
||||
|
||||
|
||||
pathsToLoad.add(commonRoot.resolve("api"));
|
||||
pathsToLoad.add(implementationRoot.resolve("base"));
|
||||
pathsToLoad.add(implementationRoot.resolve("bootstrap-addon-loader"));
|
||||
for (Path path : pathsToLoad) {
|
||||
for(Path path : pathsToLoad) {
|
||||
try {
|
||||
Path target = path.resolve("build").resolve("classes").resolve("java").resolve("main");
|
||||
|
||||
BootstrapAddonClassLoader cl = new BootstrapAddonClassLoader(new URL[] { path.toUri().toURL()});
|
||||
|
||||
Classes.Loaders omegaCL = Classes.Loaders.create();
|
||||
BootstrapAddonClassLoader cl = new BootstrapAddonClassLoader(new URL[]{ path.toUri().toURL() });
|
||||
|
||||
Classes.Loaders omegaCL = Classes.Loaders.create();
|
||||
Files.walk(target, Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(it -> it.getFileName().toString().endsWith(".class"))
|
||||
.map(Path::toFile)
|
||||
.forEach(it -> {
|
||||
String name = it.getAbsolutePath().replace(target + "/", "").replace('\\', '.').replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
LOGGER.info("Loading class {}", name);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException e) {
|
||||
try {
|
||||
String pathToJar = cl.loadClass(name).getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
|
||||
|
||||
cl.addURL(new URL("jar:file:" + pathToJar + "!/"));
|
||||
Class newClassLoad = Class.forName(name, true, cl);
|
||||
omegaCL.loadOrDefine(newClassLoad, AbstractPlatform.class.getClassLoader());
|
||||
} catch(ClassNotFoundException | URISyntaxException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
.filter(it -> it.getFileName().toString().endsWith(".class"))
|
||||
.map(Path::toFile)
|
||||
.forEach(it -> {
|
||||
String name = it.getAbsolutePath().replace(target + "/", "").replace('\\', '.').replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
LOGGER.info("Loading class {}", name);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException e) {
|
||||
try {
|
||||
String pathToJar = cl.loadClass(name)
|
||||
.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.toURI()
|
||||
.getPath();
|
||||
|
||||
cl.addURL(new URL("jar:file:" + pathToJar + "!/"));
|
||||
Class newClassLoad = Class.forName(name, true, cl);
|
||||
omegaCL.loadOrDefine(newClassLoad, AbstractPlatform.class.getClassLoader());
|
||||
} catch(ClassNotFoundException | URISyntaxException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Could not load all Terra classes", e);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.dfsek.terra.forge;
|
||||
import com.dfsek.terra.mod.MinecraftAddon;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
public class ForgeAddon extends MinecraftAddon {
|
||||
|
||||
public class ForgeAddon extends MinecraftAddon {
|
||||
|
||||
public ForgeAddon(ModPlatform modPlatform) {
|
||||
super(modPlatform);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-forge";
|
||||
|
||||
@@ -43,28 +43,24 @@ import com.dfsek.terra.mod.data.Codecs;
|
||||
@Mod("terra")
|
||||
@EventBusSubscriber(bus = Bus.MOD)
|
||||
public class ForgeEntryPoint {
|
||||
private final RegistrySanityCheck sanityCheck = new RegistrySanityCheck();
|
||||
|
||||
public static final String MODID = "terra";
|
||||
private static final Logger logger = LoggerFactory.getLogger(ForgeEntryPoint.class);
|
||||
private static final ForgePlatform TERRA_PLUGIN;
|
||||
static {
|
||||
AwfulForgeHacks.loadAllTerraClasses();
|
||||
TERRA_PLUGIN = new ForgePlatform();
|
||||
}
|
||||
|
||||
public static final String MODID = "terra";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ForgeEntryPoint.class);
|
||||
|
||||
private static final ForgePlatform TERRA_PLUGIN;
|
||||
|
||||
public static ForgePlatform getPlatform() {
|
||||
return TERRA_PLUGIN;
|
||||
}
|
||||
private final RegistrySanityCheck sanityCheck = new RegistrySanityCheck();
|
||||
|
||||
public ForgeEntryPoint() {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
modEventBus.register(this);
|
||||
}
|
||||
|
||||
public static ForgePlatform getPlatform() {
|
||||
return TERRA_PLUGIN;
|
||||
}
|
||||
|
||||
public static void initialize(RegisterHelper<Biome> helper) {
|
||||
getPlatform().getEventManager().callEvent(
|
||||
new PlatformInitializationEvent());
|
||||
@@ -75,10 +71,12 @@ public class ForgeEntryPoint {
|
||||
public void registerBiomes(RegisterEvent event) {
|
||||
event.register(Keys.BLOCKS, helper -> sanityCheck.progress(RegistryStep.BLOCK, () -> logger.debug("Block registration detected.")));
|
||||
event.register(Keys.BIOMES, helper -> sanityCheck.progress(RegistryStep.BIOME, () -> initialize(helper)));
|
||||
event.register(Registry.WORLD_PRESET_KEY, helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
|
||||
event.register(Registry.WORLD_PRESET_KEY,
|
||||
helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
|
||||
|
||||
|
||||
event.register(Registry.CHUNK_GENERATOR_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
|
||||
event.register(Registry.CHUNK_GENERATOR_KEY,
|
||||
helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
|
||||
event.register(Registry.BIOME_SOURCE_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,33 +43,33 @@ import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
public class ForgePlatform extends ModPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ForgePlatform.class);
|
||||
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File("./config/Terra"));
|
||||
|
||||
|
||||
public ForgePlatform() {
|
||||
CommonPlatform.initialize(this);
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
getRawConfigRegistry().clear();
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
|
||||
MinecraftServer server = getServer();
|
||||
|
||||
if (server != null) {
|
||||
|
||||
if(server != null) {
|
||||
server.reloadResources(server.getDataPackManager().getNames()).exceptionally(throwable -> {
|
||||
LOGGER.warn("Failed to execute reload", throwable);
|
||||
return null;
|
||||
}).join();
|
||||
//BiomeUtil.registerBiomes();
|
||||
server.getWorlds().forEach(world -> {
|
||||
if (world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
if(world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
||||
chunkGeneratorWrapper.setPack(pack);
|
||||
LOGGER.info("Replaced pack in chunk generator for world {}", world);
|
||||
@@ -79,34 +79,35 @@ public class ForgePlatform extends ModPlatform {
|
||||
}
|
||||
return succeed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
List<BaseAddon> addons = new ArrayList<>();
|
||||
|
||||
|
||||
super.platformAddon().forEach(addons::add);
|
||||
|
||||
|
||||
String mcVersion = MinecraftVersion.CURRENT.getReleaseTarget();
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion), "minecraft"));
|
||||
} catch (ParseException e) {
|
||||
} catch(ParseException e) {
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion + ".0"), "minecraft"));
|
||||
} catch (ParseException ex) {
|
||||
} catch(ParseException ex) {
|
||||
LOGGER.warn("Failed to parse Minecraft version", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FMLLoader.getLoadingModList().getMods().forEach(mod -> {
|
||||
String id = mod.getModId();
|
||||
if (id.equals("terra") || id.equals("minecraft") || id.equals("java")) return;
|
||||
Version version = Versions.getVersion(mod.getVersion().getMajorVersion(), mod.getVersion().getMinorVersion(), mod.getVersion().getIncrementalVersion());
|
||||
if(id.equals("terra") || id.equals("minecraft") || id.equals("java")) return;
|
||||
Version version = Versions.getVersion(mod.getVersion().getMajorVersion(), mod.getVersion().getMinorVersion(),
|
||||
mod.getVersion().getIncrementalVersion());
|
||||
addons.add(new EphemeralAddon(version, "forge:" + id));
|
||||
});
|
||||
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "Forge";
|
||||
@@ -116,7 +117,7 @@ public class ForgePlatform extends ModPlatform {
|
||||
public @NotNull File getDataFolder() {
|
||||
return dataFolder.value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseAddon getPlatformAddon() {
|
||||
return new ForgeAddon(this);
|
||||
|
||||
@@ -24,7 +24,15 @@ public class NoiseConfigMixin {
|
||||
@Final
|
||||
private long legacyWorldSeed;
|
||||
|
||||
@Redirect(method = "<init>(Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;Lnet/minecraft/util/registry/Registry;J)V", at = @At(value = "NEW", target = "(Lnet/minecraft/world/gen/densityfunction/DensityFunction;Lnet/minecraft/world/gen/densityfunction/DensityFunction;Lnet/minecraft/world/gen/densityfunction/DensityFunction;Lnet/minecraft/world/gen/densityfunction/DensityFunction;Lnet/minecraft/world/gen/densityfunction/DensityFunction;Lnet/minecraft/world/gen/densityfunction/DensityFunction;Ljava/util/List;)Lnet/minecraft/world/biome/source/util/MultiNoiseUtil$MultiNoiseSampler;"))
|
||||
@Redirect(method = "<init>(Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;Lnet/minecraft/util/registry/Registry;J)V",
|
||||
at = @At(value = "NEW",
|
||||
target = "(Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
|
||||
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
|
||||
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
|
||||
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
|
||||
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
|
||||
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;Ljava/util/List;)" +
|
||||
"Lnet/minecraft/world/biome/source/util/MultiNoiseUtil$MultiNoiseSampler;"))
|
||||
private MultiNoiseSampler t(DensityFunction densityFunction, DensityFunction densityFunction2, DensityFunction densityFunction3,
|
||||
DensityFunction densityFunction4, DensityFunction densityFunction5, DensityFunction densityFunction6,
|
||||
List<NoiseHypercube> list) {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@@ -22,6 +19,8 @@ import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
|
||||
@@ -32,7 +31,7 @@ public final class BiomeUtil {
|
||||
private BiomeUtil() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void registerBiomes(RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
logger.info("Registering biomes...");
|
||||
@@ -51,29 +50,41 @@ public final class BiomeUtil {
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
*/
|
||||
private static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id, RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()) .get(BuiltinRegistries.BIOME);
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id,
|
||||
RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(BuiltinRegistries.BIOME);
|
||||
|
||||
|
||||
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
|
||||
} else {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla).value(), vanillaBiomeProperties);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome,
|
||||
ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla)
|
||||
.value(),
|
||||
vanillaBiomeProperties);
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
if(ForgeRegistries.BIOMES.containsKey(identifier)) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier).orElseThrow().getKey().orElseThrow());
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
|
||||
.orElseThrow()
|
||||
.getKey()
|
||||
.orElseThrow());
|
||||
} else {
|
||||
helper.register(MinecraftUtil.registerKey(identifier).getValue(), minecraftBiome);
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier).orElseThrow().getKey().orElseThrow());
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
|
||||
.orElseThrow()
|
||||
.getKey()
|
||||
.orElseThrow());
|
||||
}
|
||||
|
||||
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
|
||||
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier), Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
|
||||
villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[41,)"
|
||||
license = "GNU General Public License, v3.0"
|
||||
issueTrackerURL="https://github.com/PolyhedralDev/Terra/issues"
|
||||
issueTrackerURL = "https://github.com/PolyhedralDev/Terra/issues"
|
||||
|
||||
[[mods]]
|
||||
modId = "terra"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "Terra Resources",
|
||||
"pack_format": 9
|
||||
}
|
||||
"pack": {
|
||||
"description": "Terra Resources",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"package": "com.dfsek.terra.forge.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"lifecycle.NoiseConfigMixin"
|
||||
"lifecycle.NoiseConfigMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
||||
@@ -61,10 +61,10 @@ public abstract class MinecraftAddon implements BaseAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,6 @@ package com.dfsek.terra.mod;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.mod.config.SpawnSettingsTemplate;
|
||||
|
||||
import com.dfsek.terra.mod.handle.MinecraftItemHandle;
|
||||
|
||||
import com.dfsek.terra.mod.handle.MinecraftWorldHandle;
|
||||
|
||||
import com.dfsek.terra.mod.config.VillagerTypeTemplate;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -31,6 +20,7 @@ import net.minecraft.world.biome.BiomeParticleConfig;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
|
||||
import net.minecraft.world.gen.WorldPreset;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -38,6 +28,8 @@ import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.mod.config.BiomeAdditionsSoundTemplate;
|
||||
import com.dfsek.terra.mod.config.BiomeMoodSoundTemplate;
|
||||
@@ -49,17 +41,19 @@ import com.dfsek.terra.mod.config.SoundEventTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnCostConfig;
|
||||
import com.dfsek.terra.mod.config.SpawnEntryTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnGroupTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnSettingsTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnTypeConfig;
|
||||
import com.dfsek.terra.mod.config.VillagerTypeTemplate;
|
||||
import com.dfsek.terra.mod.handle.MinecraftItemHandle;
|
||||
import com.dfsek.terra.mod.handle.MinecraftWorldHandle;
|
||||
import com.dfsek.terra.mod.util.PresetUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public abstract class ModPlatform extends AbstractPlatform {
|
||||
public abstract MinecraftServer getServer();
|
||||
|
||||
private final ItemHandle itemHandle = new MinecraftItemHandle();
|
||||
private final WorldHandle worldHandle = new MinecraftWorldHandle();
|
||||
|
||||
public abstract MinecraftServer getServer();
|
||||
|
||||
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) {
|
||||
getRawConfigRegistry()
|
||||
@@ -78,10 +72,12 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
})
|
||||
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class, (type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class, (type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new)
|
||||
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
|
||||
.registerLoader(BiomeMoodSound.class, BiomeMoodSoundTemplate::new)
|
||||
@@ -101,12 +97,12 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
|
||||
return new ProtoPlatformBiome(identifier);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return List.of(getPlatformAddon());
|
||||
}
|
||||
|
||||
|
||||
protected abstract BaseAddon getPlatformAddon();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ public class BiomeAdditionsSoundTemplate implements ObjectTemplate<BiomeAddition
|
||||
|
||||
@Override
|
||||
public BiomeAdditionsSound get() {
|
||||
if (sound == null || soundChance == null) {
|
||||
if(sound == null || soundChance == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new BiomeAdditionsSound(sound, soundChance);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class BiomeMoodSoundTemplate implements ObjectTemplate<BiomeMoodSound> {
|
||||
|
||||
@Override
|
||||
public BiomeMoodSound get() {
|
||||
if (sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
|
||||
if(sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new BiomeMoodSound(sound, soundCultivationTicks, soundSpawnRange, soundExtraDistance);
|
||||
|
||||
@@ -17,10 +17,10 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticle
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Integer probability = null;
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeParticleConfig get() {
|
||||
if (particle == null || probability == null) {
|
||||
if(particle == null || probability == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MusicSoundTemplate implements ObjectTemplate<MusicSound> {
|
||||
|
||||
@Override
|
||||
public MusicSound get() {
|
||||
if (sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
|
||||
if(sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new MusicSound(sound, minDelay, maxDelay, replaceCurrentMusic);
|
||||
|
||||
@@ -18,9 +18,9 @@ public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
|
||||
|
||||
@Override
|
||||
public SoundEvent get() {
|
||||
if (id == null) {
|
||||
if(id == null) {
|
||||
return null;
|
||||
} else if (distanceToTravel == null) {
|
||||
} else if(distanceToTravel == null) {
|
||||
return new SoundEvent(id);
|
||||
} else {
|
||||
return new SoundEvent(id, distanceToTravel);
|
||||
|
||||
@@ -24,13 +24,13 @@ public class SpawnSettingsTemplate implements ObjectTemplate<SpawnSettings> {
|
||||
@Override
|
||||
public SpawnSettings get() {
|
||||
SpawnSettings.Builder builder = new SpawnSettings.Builder();
|
||||
for (SpawnTypeConfig spawn : spawns) {
|
||||
for(SpawnTypeConfig spawn : spawns) {
|
||||
builder.spawn(spawn.getGroup(), spawn.getEntry());
|
||||
}
|
||||
for (SpawnCostConfig cost: costs) {
|
||||
for(SpawnCostConfig cost : costs) {
|
||||
builder.spawnCost(cost.getType(), cost.getMass(), cost.getGravity());
|
||||
}
|
||||
if (probability != null) {
|
||||
if(probability != null) {
|
||||
builder.creatureSpawnProbability(probability);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ 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.entity.EntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.village.VillagerType;
|
||||
|
||||
@@ -31,8 +31,8 @@ public final class Codecs {
|
||||
.getConfigRegistry()
|
||||
.get(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException(
|
||||
"No such config pack " +
|
||||
id)))));
|
||||
"No such config pack " +
|
||||
id)))));
|
||||
|
||||
public static final Codec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
|
||||
.create(instance -> instance.group(RegistryOps.createRegistryCodec(Registry.BIOME_KEY)
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Mixin(VillagerType.class)
|
||||
public interface VillagerTypeAccessor {
|
||||
@Accessor("BIOME_TO_TYPE")
|
||||
|
||||
@@ -20,7 +20,8 @@ import com.dfsek.terra.mod.CommonPlatform;
|
||||
MoveToFlowerGoal.class
|
||||
})
|
||||
public class BeeMoveGoalsUnsynchronizedRandomAccessFix {
|
||||
@Redirect(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;random:Lnet/minecraft/util/math/random/Random;"))
|
||||
@Redirect(method = "<init>",
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;random:Lnet/minecraft/util/math/random/Random;"))
|
||||
public Random redirectRandomAccess(World instance) {
|
||||
return new CheckedRandom(CommonPlatform.get().getServer().getTicks()); // replace with new random seeded by tick time.
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
|
||||
/**
|
||||
* Disable fossil generation in Terra worlds, as they are very expensive due to consistently triggering cache misses.
|
||||
*
|
||||
* Currently, on Fabric, Terra cannot be specified as a Nether generator. TODO: logic to turn fossils back on if chunk generator is in nether.
|
||||
* <p>
|
||||
* Currently, on Fabric, Terra cannot be specified as a Nether generator. TODO: logic to turn fossils back on if chunk generator is in
|
||||
* nether.
|
||||
*/
|
||||
@Mixin(NetherFossilStructure.class)
|
||||
public class NetherFossilOptimization {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
@@ -10,7 +8,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.Builder;
|
||||
@@ -69,18 +66,23 @@ public final class MinecraftUtil {
|
||||
TERRA_BIOME_MAP
|
||||
.forEach((vb, terraBiomes) ->
|
||||
biomes.getOrEmpty(vb)
|
||||
.ifPresentOrElse(vanilla -> terraBiomes
|
||||
.forEach(tb -> biomes.getOrEmpty(tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(vanilla.getGenerationSettings().getFlowerFeatures());
|
||||
logger.debug("Injecting flora into biome {} : {}", tb, flowerFeatures);
|
||||
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures(flowerFeatures);
|
||||
},
|
||||
() -> logger.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> logger.error("No vanilla biome: {}", vb)));
|
||||
.ifPresentOrElse(vanilla -> terraBiomes
|
||||
.forEach(tb -> biomes.getOrEmpty(tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
|
||||
vanilla.getGenerationSettings()
|
||||
.getFlowerFeatures());
|
||||
logger.debug("Injecting flora into biome" +
|
||||
" {} : {}", tb,
|
||||
flowerFeatures);
|
||||
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures(
|
||||
flowerFeatures);
|
||||
},
|
||||
() -> logger.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> logger.error("No vanilla biome: {}", vb)));
|
||||
|
||||
}
|
||||
|
||||
@@ -92,70 +94,73 @@ public final class MinecraftUtil {
|
||||
return RegistryKey.of(Registry.BIOME_KEY, identifier);
|
||||
}
|
||||
|
||||
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla, VanillaBiomeProperties vanillaBiomeProperties) {
|
||||
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla,
|
||||
VanillaBiomeProperties vanillaBiomeProperties) {
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
|
||||
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder();
|
||||
|
||||
|
||||
net.minecraft.world.biome.Biome.Builder builder = new Builder();
|
||||
|
||||
|
||||
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.getEffects().getGrassColorModifier()));
|
||||
|
||||
if (vanillaBiomeProperties.getFoliageColor() == null) {
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(),
|
||||
vanilla.getEffects().getGrassColorModifier()));
|
||||
|
||||
if(vanillaBiomeProperties.getFoliageColor() == null) {
|
||||
vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor);
|
||||
} else {
|
||||
effects.foliageColor(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
if (vanillaBiomeProperties.getGrassColor() == null) {
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() == null) {
|
||||
vanilla.getEffects().getGrassColor().ifPresent(effects::grassColor);
|
||||
} else {
|
||||
effects.grassColor(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
if (vanillaBiomeProperties.getParticleConfig() == null) {
|
||||
|
||||
if(vanillaBiomeProperties.getParticleConfig() == null) {
|
||||
vanilla.getEffects().getParticleConfig().ifPresent(effects::particleConfig);
|
||||
} else {
|
||||
effects.particleConfig(vanillaBiomeProperties.getParticleConfig());
|
||||
}
|
||||
|
||||
if (vanillaBiomeProperties.getLoopSound() == null) {
|
||||
|
||||
if(vanillaBiomeProperties.getLoopSound() == null) {
|
||||
vanilla.getEffects().getLoopSound().ifPresent(effects::loopSound);
|
||||
} else {
|
||||
effects.loopSound(vanillaBiomeProperties.getLoopSound());
|
||||
}
|
||||
|
||||
if (vanillaBiomeProperties.getMoodSound() == null) {
|
||||
|
||||
if(vanillaBiomeProperties.getMoodSound() == null) {
|
||||
vanilla.getEffects().getMoodSound().ifPresent(effects::moodSound);
|
||||
} else {
|
||||
effects.moodSound(vanillaBiomeProperties.getMoodSound());
|
||||
}
|
||||
|
||||
if (vanillaBiomeProperties.getAdditionsSound() == null) {
|
||||
|
||||
if(vanillaBiomeProperties.getAdditionsSound() == null) {
|
||||
vanilla.getEffects().getAdditionsSound().ifPresent(effects::additionsSound);
|
||||
} else {
|
||||
effects.additionsSound(vanillaBiomeProperties.getAdditionsSound());
|
||||
}
|
||||
|
||||
if (vanillaBiomeProperties.getMusic() == null) {
|
||||
|
||||
if(vanillaBiomeProperties.getMusic() == null) {
|
||||
vanilla.getEffects().getMusic().ifPresent(effects::music);
|
||||
} else {
|
||||
effects.music(vanillaBiomeProperties.getMusic());
|
||||
}
|
||||
|
||||
|
||||
builder.precipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.getPrecipitation()));
|
||||
|
||||
|
||||
builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getTemperature()));
|
||||
|
||||
|
||||
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.getDownfall()));
|
||||
|
||||
builder.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), ((BiomeAccessor)((Object)vanilla)).getWeather().temperatureModifier()));
|
||||
|
||||
builder.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(),
|
||||
((BiomeAccessor) ((Object) vanilla)).getWeather().temperatureModifier()));
|
||||
|
||||
builder.spawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getSpawnSettings()));
|
||||
|
||||
return builder
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PresetUtil {
|
||||
Registry<StructureSet> structureSetRegistry = BuiltinRegistries.STRUCTURE_SET;
|
||||
Registry<NoiseParameters> noiseParametersRegistry = BuiltinRegistries.NOISE_PARAMETERS;
|
||||
Registry<Biome> biomeRegistry = BuiltinRegistries.BIOME;
|
||||
|
||||
|
||||
RegistryEntry<DimensionType> theNetherDimensionType = dimensionTypeRegistry.getOrCreateEntry(DimensionTypes.THE_NETHER);
|
||||
RegistryEntry<ChunkGeneratorSettings>
|
||||
netherChunkGeneratorSettings = chunkGeneratorSettingsRegistry.getOrCreateEntry(ChunkGeneratorSettings.NETHER);
|
||||
@@ -57,19 +57,19 @@ public class PresetUtil {
|
||||
new NoiseChunkGenerator(structureSetRegistry, noiseParametersRegistry,
|
||||
new TheEndBiomeSource(biomeRegistry),
|
||||
endChunkGeneratorSettings));
|
||||
|
||||
|
||||
RegistryEntry<DimensionType> overworldDimensionType = dimensionTypeRegistry.getOrCreateEntry(DimensionTypes.OVERWORLD);
|
||||
|
||||
|
||||
RegistryEntry<ChunkGeneratorSettings> overworld = chunkGeneratorSettingsRegistry.getOrCreateEntry(ChunkGeneratorSettings.OVERWORLD);
|
||||
|
||||
|
||||
Identifier generatorID = Identifier.of("terra", pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.getNamespace().toLowerCase(
|
||||
Locale.ROOT));
|
||||
|
||||
|
||||
PRESETS.add(generatorID);
|
||||
|
||||
|
||||
TerraBiomeSource biomeSource = new TerraBiomeSource(biomeRegistry, pack);
|
||||
ChunkGenerator generator = new MinecraftChunkGeneratorWrapper(structureSetRegistry, biomeSource, pack, overworld);
|
||||
|
||||
|
||||
DimensionOptions dimensionOptions = new DimensionOptions(overworldDimensionType, generator);
|
||||
WorldPreset preset = new WorldPreset(
|
||||
Map.of(
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.dfsek.terra.mod.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"access.BiomeAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
"access.StructureAccessorAccessor",
|
||||
"access.VillagerTypeAccessor",
|
||||
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFix",
|
||||
"fix.NetherFossilOptimization",
|
||||
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
|
||||
"implementations.terra.BiomeMixin",
|
||||
"implementations.terra.HandleImplementationMixin",
|
||||
"implementations.terra.block.BlockMixin",
|
||||
"implementations.terra.block.entity.BlockEntityMixin",
|
||||
"implementations.terra.block.entity.LootableContainerBlockEntityMixin",
|
||||
"implementations.terra.block.entity.MobSpawnerBlockEntityMixin",
|
||||
"implementations.terra.block.entity.SignBlockEntityMixin",
|
||||
"implementations.terra.block.state.BlockStateMixin",
|
||||
"implementations.terra.block.state.PropertyMixin",
|
||||
"implementations.terra.chunk.ChunkRegionMixin",
|
||||
"implementations.terra.chunk.WorldChunkMixin",
|
||||
"implementations.terra.chunk.data.ProtoChunkMixin",
|
||||
"implementations.terra.entity.EntityMixin",
|
||||
"implementations.terra.entity.EntityTypeMixin",
|
||||
"implementations.terra.entity.PlayerEntityMixin",
|
||||
"implementations.terra.entity.ServerCommandSourceMixin",
|
||||
"implementations.terra.inventory.LockableContainerBlockEntityMixin",
|
||||
"implementations.terra.inventory.item.ItemMixin",
|
||||
"implementations.terra.inventory.item.ItemStackMixin",
|
||||
"implementations.terra.inventory.meta.EnchantmentMixin",
|
||||
"implementations.terra.inventory.meta.ItemStackDamageableMixin",
|
||||
"implementations.terra.inventory.meta.ItemStackMetaMixin",
|
||||
"implementations.terra.world.ChunkRegionMixin",
|
||||
"implementations.terra.world.ServerWorldMixin",
|
||||
"lifecycle.DataPackContentsMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.dfsek.terra.mod.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"access.BiomeAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
"access.StructureAccessorAccessor",
|
||||
"access.VillagerTypeAccessor",
|
||||
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFix",
|
||||
"fix.NetherFossilOptimization",
|
||||
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
|
||||
"implementations.terra.BiomeMixin",
|
||||
"implementations.terra.HandleImplementationMixin",
|
||||
"implementations.terra.block.BlockMixin",
|
||||
"implementations.terra.block.entity.BlockEntityMixin",
|
||||
"implementations.terra.block.entity.LootableContainerBlockEntityMixin",
|
||||
"implementations.terra.block.entity.MobSpawnerBlockEntityMixin",
|
||||
"implementations.terra.block.entity.SignBlockEntityMixin",
|
||||
"implementations.terra.block.state.BlockStateMixin",
|
||||
"implementations.terra.block.state.PropertyMixin",
|
||||
"implementations.terra.chunk.ChunkRegionMixin",
|
||||
"implementations.terra.chunk.WorldChunkMixin",
|
||||
"implementations.terra.chunk.data.ProtoChunkMixin",
|
||||
"implementations.terra.entity.EntityMixin",
|
||||
"implementations.terra.entity.EntityTypeMixin",
|
||||
"implementations.terra.entity.PlayerEntityMixin",
|
||||
"implementations.terra.entity.ServerCommandSourceMixin",
|
||||
"implementations.terra.inventory.LockableContainerBlockEntityMixin",
|
||||
"implementations.terra.inventory.item.ItemMixin",
|
||||
"implementations.terra.inventory.item.ItemStackMixin",
|
||||
"implementations.terra.inventory.meta.EnchantmentMixin",
|
||||
"implementations.terra.inventory.meta.ItemStackDamageableMixin",
|
||||
"implementations.terra.inventory.meta.ItemStackMetaMixin",
|
||||
"implementations.terra.world.ChunkRegionMixin",
|
||||
"implementations.terra.world.ServerWorldMixin",
|
||||
"lifecycle.DataPackContentsMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"refmap": "terra.common.refmap.json"
|
||||
}
|
||||
@@ -28,15 +28,15 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
load();
|
||||
}
|
||||
|
||||
public static void setServer(MinecraftServer server) {
|
||||
LifecyclePlatform.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void setServer(MinecraftServer server) {
|
||||
LifecyclePlatform.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
|
||||
@@ -24,8 +24,10 @@ public class NoiseConfigMixin {
|
||||
@Final
|
||||
private MultiNoiseSampler multiNoiseSampler;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;Lnet/minecraft/util/registry/Registry;J)V", at = @At("TAIL"))
|
||||
private void mapMultiNoise(ChunkGeneratorSettings chunkGeneratorSettings, Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry, long seed, CallbackInfo ci) {
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;Lnet/minecraft/util/registry/Registry;J)V",
|
||||
at = @At("TAIL"))
|
||||
private void mapMultiNoise(ChunkGeneratorSettings chunkGeneratorSettings,
|
||||
Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry, long seed, CallbackInfo ci) {
|
||||
SeedHack.register(multiNoiseSampler, seed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.dfsek.terra.lifecycle.mixin;
|
||||
|
||||
import com.dfsek.terra.lifecycle.util.RegistryUtil;
|
||||
|
||||
import net.minecraft.util.registry.Registry;
|
||||
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 com.dfsek.terra.lifecycle.util.RegistryUtil;
|
||||
|
||||
|
||||
@Mixin(Registry.class)
|
||||
public class RegistryMixin {
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@@ -21,6 +17,8 @@ import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
|
||||
@@ -48,7 +46,7 @@ public final class BiomeUtil {
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
*/
|
||||
private static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
Registry<net.minecraft.world.biome.Biome> registry = BuiltinRegistries.BIOME;
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(registry);
|
||||
|
||||
@@ -58,7 +56,8 @@ public final class BiomeUtil {
|
||||
} else {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, registry.get(vanilla), vanillaBiomeProperties);
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, registry.get(vanilla),
|
||||
vanillaBiomeProperties);
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
@@ -69,14 +68,17 @@ public final class BiomeUtil {
|
||||
.orElseThrow());
|
||||
} else {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry,
|
||||
MinecraftUtil.registerKey(identifier).getValue(),
|
||||
MinecraftUtil.registerKey(identifier)
|
||||
.getValue(),
|
||||
minecraftBiome).getKey().orElseThrow());
|
||||
}
|
||||
|
||||
|
||||
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
|
||||
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier), Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
|
||||
|
||||
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
|
||||
villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
|
||||
|
||||
public final class LifecycleUtil {
|
||||
private LifecycleUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
import com.dfsek.terra.mod.data.Codecs;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import com.dfsek.terra.mod.data.Codecs;
|
||||
|
||||
|
||||
public final class RegistryUtil {
|
||||
private RegistryUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
},
|
||||
"refmap": "terra.lifecycle.refmap.json"
|
||||
}
|
||||
@@ -30,7 +30,7 @@ dependencies {
|
||||
modImplementation("org.quiltmc:quilt-loader:${Versions.Quilt.quiltLoader}")
|
||||
|
||||
modImplementation("org.quiltmc.quilted-fabric-api:quilted-fabric-api:${Versions.Quilt.fabricApi}")
|
||||
|
||||
|
||||
modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) {
|
||||
exclude("net.fabricmc")
|
||||
exclude("net.fabricmc.fabric-api")
|
||||
|
||||
@@ -4,40 +4,41 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
/**
|
||||
* So you want to Mixin into Authlib/Brigadier/DataFixerUpper, on Fabric you'll need this guy.
|
||||
*
|
||||
* <p>YOU SHOULD ONLY USE THIS CLASS DURING "preLaunch" and ONLY TARGET A CLASS WHICH IS NOT ANY CLASS YOU MIXIN TO.
|
||||
*
|
||||
* <p>
|
||||
* This will likely not work on Gson because FabricLoader has some special logic related to Gson.
|
||||
*/
|
||||
public final class AwfulQuiltHacks {
|
||||
private AwfulQuiltHacks() {}
|
||||
private static final ClassLoader KNOT_CLASSLOADER = Thread.currentThread().getContextClassLoader();
|
||||
private static final Method ADD_URL_METHOD;
|
||||
static {
|
||||
Method tempAddUrlMethod = null;
|
||||
try {
|
||||
tempAddUrlMethod = KNOT_CLASSLOADER.getClass().getMethod("addURL", URL.class);
|
||||
tempAddUrlMethod.setAccessible(true);
|
||||
} catch(ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to load Classloader fields", e);
|
||||
}
|
||||
|
||||
private static final ClassLoader KNOT_CLASSLOADER = Thread.currentThread().getContextClassLoader();
|
||||
private static final Method ADD_URL_METHOD;
|
||||
ADD_URL_METHOD = tempAddUrlMethod;
|
||||
}
|
||||
|
||||
static {
|
||||
Method tempAddUrlMethod = null;
|
||||
try {
|
||||
tempAddUrlMethod = KNOT_CLASSLOADER.getClass().getMethod("addURL", URL.class);
|
||||
tempAddUrlMethod.setAccessible(true);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to load Classloader fields", e);
|
||||
}
|
||||
private AwfulQuiltHacks() { }
|
||||
|
||||
ADD_URL_METHOD = tempAddUrlMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hackily load the package which a mixin may exist within.
|
||||
*
|
||||
* YOU SHOULD NOT TARGET A CLASS WHICH YOU MIXIN TO.
|
||||
*
|
||||
* @param pathOfAClass The path of any class within the package.
|
||||
*/
|
||||
public static void hackilyLoadForMixin(String pathOfAClass) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {
|
||||
URL url = Class.forName(pathOfAClass).getProtectionDomain().getCodeSource().getLocation();
|
||||
ADD_URL_METHOD.invoke(KNOT_CLASSLOADER, url);
|
||||
}
|
||||
/**
|
||||
* Hackily load the package which a mixin may exist within.
|
||||
* <p>
|
||||
* YOU SHOULD NOT TARGET A CLASS WHICH YOU MIXIN TO.
|
||||
*
|
||||
* @param pathOfAClass The path of any class within the package.
|
||||
*/
|
||||
public static void hackilyLoadForMixin(String pathOfAClass)
|
||||
throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {
|
||||
URL url = Class.forName(pathOfAClass).getProtectionDomain().getCodeSource().getLocation();
|
||||
ADD_URL_METHOD.invoke(KNOT_CLASSLOADER, url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.quilt;
|
||||
import com.dfsek.terra.mod.MinecraftAddon;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
|
||||
public class QuiltAddon extends MinecraftAddon {
|
||||
|
||||
public QuiltAddon(ModPlatform modPlatform) {
|
||||
|
||||
@@ -33,6 +33,7 @@ public class QuiltEntryPoint implements ModInitializer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(QuiltEntryPoint.class);
|
||||
|
||||
private static final QuiltPlatform TERRA_PLUGIN = new QuiltPlatform();
|
||||
|
||||
@Override
|
||||
public void onInitialize(ModContainer container) {
|
||||
logger.info("Initializing Terra Quilt mod...");
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
|
||||
@@ -41,7 +40,7 @@ public class QuiltPlatform extends LifecyclePlatform {
|
||||
|
||||
@Override
|
||||
protected Collection<BaseAddon> getPlatformMods() {
|
||||
return QuiltLoader.getAllMods().stream().flatMap(mod -> {
|
||||
return QuiltLoader.getAllMods().stream().flatMap(mod -> {
|
||||
String id = mod.metadata().id();
|
||||
if(id.equals("terra") || id.equals("minecraft") || id.equals("java")) return Stream.empty();
|
||||
try {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
public class QuiltPreLaunchEntryPoint implements PreLaunchEntrypoint {
|
||||
@Override
|
||||
public void onPreLaunch(ModContainer mod) {
|
||||
if (QuiltLoader.isDevelopmentEnvironment()) {
|
||||
if(QuiltLoader.isDevelopmentEnvironment()) {
|
||||
try {
|
||||
AwfulQuiltHacks.hackilyLoadForMixin(BrigadierMappingBuilder.class.getName());
|
||||
} catch(ClassNotFoundException | InvocationTargetException | IllegalAccessException e) {
|
||||
|
||||
Reference in New Issue
Block a user