mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 14:56:28 +00:00
Merge pull request #341 from duplexsystem/dev/enviroment
Remove vanilla key, Comminfy Some code, Minor Biome Enviroment Tweaks, Port all Enviroment Settings to Bukkit, and Implment Fertilization
This commit is contained in:
@@ -8,7 +8,6 @@ import java.nio.file.StandardCopyOption
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.BasePluginExtension
|
||||
import org.gradle.kotlin.dsl.TaskContainerScope
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
@@ -88,7 +87,8 @@ fun Project.configureDistribution() {
|
||||
val jar = getJarTask().archiveFileName.get()
|
||||
resources.computeIfAbsent(
|
||||
if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "addons/bootstrap"
|
||||
else "addons") { ArrayList() }.add(jar)
|
||||
else "addons"
|
||||
) { ArrayList() }.add(jar)
|
||||
}
|
||||
|
||||
val options = DumperOptions()
|
||||
@@ -109,7 +109,7 @@ fun Project.configureDistribution() {
|
||||
FileWriter(manifest).use {
|
||||
yaml.dump(resources, it)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,6 @@ public class BiomeFactory implements ConfigFactory<BiomeTemplate, Biome> {
|
||||
|
||||
@Override
|
||||
public Biome build(BiomeTemplate template, Platform platform) {
|
||||
return new UserDefinedBiome(template.getVanilla(), template);
|
||||
return new UserDefinedBiome(template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
@@ -37,13 +36,11 @@ public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTempl
|
||||
@Default
|
||||
private List<String> extended = Collections.emptyList();
|
||||
|
||||
@Value("vanilla")
|
||||
private @Meta PlatformBiome vanilla;
|
||||
|
||||
@Value("color")
|
||||
@Final
|
||||
@Default
|
||||
private @Meta int color = 0;
|
||||
|
||||
@Value("tags")
|
||||
@Default
|
||||
private @Meta Set<@Meta String> tags = new HashSet<>();
|
||||
@@ -77,8 +74,4 @@ public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTempl
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public PlatformBiome getVanilla() {
|
||||
return vanilla;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
@@ -18,16 +19,14 @@ import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
* Class representing a config-defined biome
|
||||
*/
|
||||
public class UserDefinedBiome implements Biome {
|
||||
private final PlatformBiome vanilla;
|
||||
private final String id;
|
||||
private final BiomeTemplate config;
|
||||
private final int color;
|
||||
private final Set<String> tags;
|
||||
|
||||
private final Context context = new Context();
|
||||
private PlatformBiome platformBiome;
|
||||
|
||||
public UserDefinedBiome(PlatformBiome vanilla, BiomeTemplate config) {
|
||||
this.vanilla = vanilla;
|
||||
public UserDefinedBiome(BiomeTemplate config) {
|
||||
this.id = config.getID();
|
||||
this.config = config;
|
||||
this.color = config.getColor();
|
||||
@@ -41,14 +40,18 @@ public class UserDefinedBiome implements Biome {
|
||||
return "{BIOME:" + getID() + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Vanilla biomes to represent the custom biome.
|
||||
*
|
||||
* @return Collection of biomes to represent the custom biome.
|
||||
*/
|
||||
@Override
|
||||
public PlatformBiome getPlatformBiome() {
|
||||
return vanilla;
|
||||
public Optional<PlatformBiome> getPlatformBiome() {
|
||||
return Optional.ofNullable(platformBiome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlatformBiome(PlatformBiome biome) {
|
||||
if(platformBiome != null) {
|
||||
throw new IllegalStateException("Platform biome already set");
|
||||
}
|
||||
|
||||
this.platformBiome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,6 @@ public class StructureGenerationStage implements GenerationStage {
|
||||
|
||||
@Override
|
||||
public void populate(ProtoWorld world) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.dfsek.terra.api.world.biome;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
@@ -24,7 +25,12 @@ public interface Biome extends PropertyHolder, StringIdentifiable {
|
||||
*
|
||||
* @return The platform biome.
|
||||
*/
|
||||
PlatformBiome getPlatformBiome();
|
||||
Optional<PlatformBiome> getPlatformBiome();
|
||||
|
||||
/**
|
||||
* Sets the platform biome this custom biome delegates to.
|
||||
*/
|
||||
void setPlatformBiome(PlatformBiome biome);
|
||||
|
||||
/**
|
||||
* Get the color of this biome.
|
||||
|
||||
@@ -27,7 +27,7 @@ public class InternalAddon implements BaseAddon {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
public InternalAddon() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,9 +23,7 @@ import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
@@ -37,46 +35,10 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("variables")
|
||||
@Default
|
||||
private @Meta Map<String, @Meta Double> variables = new HashMap<>();
|
||||
|
||||
@Value("beta.carving")
|
||||
@Default
|
||||
private @Meta boolean betaCarvers = false;
|
||||
|
||||
@Value("structures.locatable")
|
||||
@Default
|
||||
private @Meta Map<@Meta String, @Meta String> locatable = new HashMap<>();
|
||||
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
private @Meta int elevationBlend = 4;
|
||||
|
||||
@Value("vanilla.mobs")
|
||||
@Default
|
||||
private @Meta boolean vanillaMobs = true;
|
||||
|
||||
@Value("vanilla.caves")
|
||||
@Default
|
||||
private @Meta boolean vanillaCaves = false;
|
||||
|
||||
@Value("vanilla.decorations")
|
||||
@Default
|
||||
private @Meta boolean vanillaDecorations = false;
|
||||
|
||||
@Value("vanilla.structures")
|
||||
@Default
|
||||
private @Meta boolean vanillaStructures = false;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
|
||||
@Value("disable.sapling")
|
||||
@Default
|
||||
private @Meta boolean disableSaplings = false;
|
||||
|
||||
@Value("stages")
|
||||
@Default
|
||||
private @Meta List<@Meta GenerationStage> stages = Collections.emptyList();
|
||||
@@ -84,26 +46,6 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@Value("version")
|
||||
private Version version;
|
||||
|
||||
@Value("disable.carvers")
|
||||
@Default
|
||||
private @Meta boolean disableCarvers = false;
|
||||
|
||||
@Value("disable.structures")
|
||||
@Default
|
||||
private @Meta boolean disableStructures = false;
|
||||
|
||||
@Value("disable.ores")
|
||||
@Default
|
||||
private @Meta boolean disableOres = false;
|
||||
|
||||
@Value("disable.trees")
|
||||
@Default
|
||||
private @Meta boolean disableTrees = false;
|
||||
|
||||
@Value("disable.flora")
|
||||
@Default
|
||||
private @Meta boolean disableFlora = false;
|
||||
|
||||
@Value("generator")
|
||||
private @Meta ChunkGeneratorProvider generatorProvider;
|
||||
|
||||
@@ -111,46 +53,6 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@Default
|
||||
private boolean biomeCache = false;
|
||||
|
||||
public boolean disableCarvers() {
|
||||
return disableCarvers;
|
||||
}
|
||||
|
||||
public boolean disableFlora() {
|
||||
return disableFlora;
|
||||
}
|
||||
|
||||
public boolean disableOres() {
|
||||
return disableOres;
|
||||
}
|
||||
|
||||
public boolean disableStructures() {
|
||||
return disableStructures;
|
||||
}
|
||||
|
||||
public boolean disableTrees() {
|
||||
return disableTrees;
|
||||
}
|
||||
|
||||
public boolean vanillaMobs() {
|
||||
return vanillaMobs;
|
||||
}
|
||||
|
||||
public boolean vanillaCaves() {
|
||||
return vanillaCaves;
|
||||
}
|
||||
|
||||
public boolean vanillaDecorations() {
|
||||
return vanillaDecorations;
|
||||
}
|
||||
|
||||
public boolean vanillaStructures() {
|
||||
return vanillaStructures;
|
||||
}
|
||||
|
||||
public boolean doBetaCarvers() {
|
||||
return betaCarvers;
|
||||
}
|
||||
|
||||
public ChunkGeneratorProvider getGeneratorProvider() {
|
||||
return generatorProvider;
|
||||
}
|
||||
@@ -163,10 +65,6 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
return version;
|
||||
}
|
||||
|
||||
public boolean isDisableSaplings() {
|
||||
return disableSaplings;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
@@ -175,18 +73,6 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
return author;
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
public int getElevationBlend() {
|
||||
return elevationBlend;
|
||||
}
|
||||
|
||||
public Map<String, String> getLocatable() {
|
||||
return locatable;
|
||||
}
|
||||
|
||||
public boolean getBiomeCache() {
|
||||
return biomeCache;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
Path bootstrapFolder = addonsFolder.resolve("bootstrap");
|
||||
Files.createDirectories(bootstrapFolder);
|
||||
logger.debug("Loading bootstrap addons from {}", bootstrapFolder);
|
||||
|
||||
|
||||
try(Stream<Path> bootstrapAddons = Files.walk(bootstrapFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
|
||||
return bootstrapAddons.filter(path -> path.toFile().isFile())
|
||||
.filter(path -> path.toFile().canRead())
|
||||
@@ -96,7 +96,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "BOOTSTRAP";
|
||||
|
||||
@@ -4,9 +4,7 @@ terra.source=https://github.com/PolyhedralDev/Terra
|
||||
terra.issues=https://github.com/PolyhedralDev/Terra/issues
|
||||
terra.wiki=https://github.com/PolyhedralDev/Terra/wiki
|
||||
terra.license=MIT
|
||||
|
||||
# Gradle options
|
||||
org.gradle.jvmargs=-Xmx4096M -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
|
||||
org.gradle.warning.mode=all
|
||||
#org.gradle.parallel=true
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
shaded(project(":platforms:bukkit:common"))
|
||||
shaded(project(":platforms:bukkit:nms:v1_18_R2", configuration = "reobf"))
|
||||
shaded(project(":platforms:bukkit:nms:v1_19_R1", configuration = "reobf"))
|
||||
shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper)
|
||||
}
|
||||
|
||||
@@ -4,33 +4,17 @@ import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class BukkitAddon implements BaseAddon {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
private final PlatformImpl terraBukkitPlugin;
|
||||
protected final PlatformImpl terraBukkitPlugin;
|
||||
|
||||
public BukkitAddon(PlatformImpl terraBukkitPlugin) {
|
||||
this.terraBukkitPlugin = terraBukkitPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
terraBukkitPlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -28,18 +26,15 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
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.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class PlatformImpl extends AbstractPlatform {
|
||||
@@ -112,13 +107,7 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> handle.createBlockState((String) o))
|
||||
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(EntityType.class, (type, o, loader, depthTracker) -> EntityType.valueOf((String) o));
|
||||
|
||||
}
|
||||
|
||||
private BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
|
||||
return new BukkitPlatformBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.listeners.CommonListener;
|
||||
import com.dfsek.terra.bukkit.nms.Initializer;
|
||||
import com.dfsek.terra.bukkit.util.PaperUtil;
|
||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||
@@ -46,9 +45,8 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
public class TerraBukkitPlugin extends JavaPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||
|
||||
private final PlatformImpl platform = new PlatformImpl(this);
|
||||
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
|
||||
private PlatformImpl platform;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -56,6 +54,8 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
platform = Initializer.init(this);
|
||||
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
|
||||
@@ -89,10 +89,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener
|
||||
PaperUtil.checkPaper(this);
|
||||
|
||||
Initializer.init(platform);
|
||||
}
|
||||
|
||||
public PlatformImpl getPlatform() {
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.config;
|
||||
|
||||
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.Value;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
@Value("colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = null;
|
||||
|
||||
@Value("colors.fog")
|
||||
@Default
|
||||
private Integer fogColor = null;
|
||||
|
||||
@Value("colors.water")
|
||||
@Default
|
||||
private Integer waterColor = null;
|
||||
|
||||
@Value("colors.water-fog")
|
||||
@Default
|
||||
private Integer waterFogColor = null;
|
||||
|
||||
@Value("colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = null;
|
||||
|
||||
@Value("colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = null;
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
public Integer getFoliageColor() {
|
||||
return foliageColor;
|
||||
}
|
||||
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
public Integer getWaterColor() {
|
||||
return waterColor;
|
||||
}
|
||||
|
||||
public Integer getWaterFogColor() {
|
||||
return waterFogColor;
|
||||
}
|
||||
|
||||
public Integer getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.stream.StreamSupport;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class BukkitBiomeProvider extends BiomeProvider implements Handle {
|
||||
@@ -20,13 +21,13 @@ public class BukkitBiomeProvider extends BiomeProvider implements Handle {
|
||||
@Override
|
||||
public @NotNull org.bukkit.block.Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
|
||||
Biome biome = delegate.getBiome(x, y, z, worldInfo.getSeed());
|
||||
return (org.bukkit.block.Biome) biome.getPlatformBiome().getHandle();
|
||||
return ((BukkitPlatformBiome) biome.getPlatformBiome().get()).getBukkitBiome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<org.bukkit.block.Biome> getBiomes(@NotNull WorldInfo worldInfo) {
|
||||
return StreamSupport.stream(delegate.getBiomes().spliterator(), false)
|
||||
.map(terraBiome -> (org.bukkit.block.Biome) terraBiome.getPlatformBiome().getHandle())
|
||||
.map(terraBiome -> ((BukkitPlatformBiome) terraBiome.getPlatformBiome().get()).getBukkitBiome())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
|
||||
|
||||
|
||||
public BukkitChunkGeneratorWrapper(ChunkGenerator delegate, ConfigPack pack, BlockState air) {
|
||||
this.delegate = delegate;
|
||||
this.pack = pack;
|
||||
@@ -97,7 +97,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
public boolean shouldGenerateMobs() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateStructures() {
|
||||
return true;
|
||||
@@ -117,7 +117,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private record SeededVector(int x, int z, WorldProperties worldProperties) {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -126,7 +126,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = x;
|
||||
|
||||
@@ -1,29 +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.bukkit.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
|
||||
/**
|
||||
* Listener for events on all implementations.
|
||||
*/
|
||||
public class CommonListener implements Listener {
|
||||
public CommonListener() {
|
||||
}
|
||||
}
|
||||
@@ -1,104 +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.bukkit.listeners;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
|
||||
* <p>
|
||||
* (This is currently loaded on all servers; once Paper accepts the StructureLocateEvent PR this will only be loaded on servers without
|
||||
* StructureLocateEvent).
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
||||
private final Platform platform;
|
||||
|
||||
public SpigotListener(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEnderEye(EntitySpawnEvent e) {
|
||||
/*
|
||||
Entity entity = e.getEntity();
|
||||
if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
|
||||
logger.info("Detected Ender Signal...");
|
||||
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
||||
EnderSignal signal = (EnderSignal) entity;
|
||||
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
||||
("STRONGHOLD"));
|
||||
if(config != null) {
|
||||
logger.info("Overriding Ender Signal...");
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()
|
||||
.toVector()), tw.getWorld(), 0, 500, location -> {
|
||||
if(location != null)
|
||||
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
||||
logger.info("Location: {}", location);
|
||||
}, main);
|
||||
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
||||
} else
|
||||
logger.warn("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
||||
if(!(e.getEntity() instanceof Villager))
|
||||
return;
|
||||
if(((Villager) e.getEntity()).getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| Prevented server crash by stopping Cartographer villager from |
|
||||
| spawning. Please upgrade to Paper, which has a StructureLocateEvent |
|
||||
| that fixes this issue at the source, and doesn't require us to do |
|
||||
| stupid band-aids. |
|
||||
|------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server.
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
||||
if(e.getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| Prevented server crash by stopping Cartographer villager from leveling |
|
||||
| up. Please upgrade to Paper, which has a StructureLocateEvent that |
|
||||
| fixes this issue at the source, and doesn't require us to do stupid |
|
||||
| band-aids. |
|
||||
|------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,36 +5,42 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
|
||||
|
||||
public interface Initializer {
|
||||
String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
||||
|
||||
static void init(PlatformImpl platform) {
|
||||
static PlatformImpl init(TerraBukkitPlugin plugin) {
|
||||
Logger logger = LoggerFactory.getLogger(Initializer.class);
|
||||
try {
|
||||
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSInitializer");
|
||||
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSPlatform");
|
||||
try {
|
||||
Initializer initializer = (Initializer) initializerClass.getConstructor().newInstance();
|
||||
initializer.initialize(platform);
|
||||
return (PlatformImpl) initializerClass.getConstructor().newInstance(plugin);
|
||||
} catch(ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
|
||||
}
|
||||
} catch(ClassNotFoundException e) {
|
||||
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
|
||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
for(int i = 0; i < 20; i++) {
|
||||
logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!");
|
||||
}
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
|
||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||
Runnable runnable = () -> { // scary big block of text
|
||||
logger.error("NMS bindings for version {} do not exist.", NMS);
|
||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||
logger.error("Terra will now be DISABLED.");
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
for(int i = 0; i < 20; i++) {
|
||||
logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!");
|
||||
}
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
logger.error("NMS bindings for version {} do not exist.", NMS);
|
||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||
logger.error("Terra will now be DISABLED.");
|
||||
};
|
||||
runnable.run();
|
||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, runnable, 200L);
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void initialize(PlatformImpl plugin);
|
||||
}
|
||||
|
||||
@@ -1,42 +1,10 @@
|
||||
/*
|
||||
* 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.bukkit.world;
|
||||
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
|
||||
public class BukkitPlatformBiome implements PlatformBiome, PropertyHolder {
|
||||
private final org.bukkit.block.Biome biome;
|
||||
private final Context context = new Context();
|
||||
|
||||
public BukkitPlatformBiome(org.bukkit.block.Biome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.Biome getHandle() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
public interface BukkitPlatformBiome extends PlatformBiome {
|
||||
Biome getBukkitBiome();
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
|
||||
repositories {
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":platforms:bukkit:common"))
|
||||
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
implementation("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
assemble {
|
||||
dependsOn("reobfJar")
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
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 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.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);
|
||||
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();
|
||||
|
||||
|
||||
public static void registerBiomes(ConfigRegistry configRegistry) {
|
||||
try {
|
||||
LOGGER.info("Hacking biome registry...");
|
||||
WritableRegistry<Biome> biomeRegistry = (WritableRegistry<Biome>) Registries.biomeRegistry();
|
||||
|
||||
Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, false);
|
||||
|
||||
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
||||
try {
|
||||
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
||||
ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey());
|
||||
Biome platform = NMSBiomeInjector.createBiome(
|
||||
biome,
|
||||
biomeRegistry.get(vanillaMinecraftKey) // get
|
||||
);
|
||||
|
||||
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());
|
||||
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
||||
|
||||
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location());
|
||||
|
||||
LOGGER.debug("Registered biome: " + delegateKey);
|
||||
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
|
||||
Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, true); // freeze registry again :)
|
||||
|
||||
LOGGER.info("Doing tag garbage....");
|
||||
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);
|
||||
|
||||
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)));
|
||||
|
||||
biomeRegistry.resetTags(); // clearTags
|
||||
biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); // populateTags
|
||||
|
||||
} catch(SecurityException | IllegalArgumentException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public record NMSBiomeInfo(ResourceKey<Biome> biomeKey) implements Properties {
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class NMSBiomeInjector {
|
||||
|
||||
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) {
|
||||
return registry.getOptional(identifier)
|
||||
.flatMap(registry::getResourceKey)
|
||||
.map(registry::getOrCreateHolder);
|
||||
}
|
||||
|
||||
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla)
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); // Builder
|
||||
|
||||
|
||||
builder.biomeCategory(Reflection.BIOME.getBiomeCategory(vanilla))
|
||||
.precipitation(vanilla.getPrecipitation()) // getPrecipitation
|
||||
.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 {
|
||||
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound);
|
||||
vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound);
|
||||
vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound);
|
||||
vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic);
|
||||
vanilla.getAmbientParticle().ifPresent(effects::ambientParticle);
|
||||
|
||||
builder.specialEffects(effects.build());
|
||||
|
||||
return builder.build(); // build()
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
|
||||
return pack.getID()
|
||||
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class NMSBiomeProvider extends BiomeSource {
|
||||
private final BiomeProvider delegate;
|
||||
private final BiomeSource vanilla;
|
||||
private final long seed;
|
||||
private final Registry<Biome> biomeRegistry = Registries.biomeRegistry();
|
||||
|
||||
public NMSBiomeProvider(BiomeProvider delegate, BiomeSource vanilla, long seed) {
|
||||
super(delegate.stream()
|
||||
.map(biome -> Registries.biomeRegistry()
|
||||
.getOrCreateHolder(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey())));
|
||||
this.delegate = delegate;
|
||||
this.vanilla = vanilla;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> codec() {
|
||||
return BiomeSource.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BiomeSource withSeed(long seed) {
|
||||
return new NMSBiomeProvider(delegate, vanilla, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Holder<Biome> getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) {
|
||||
return biomeRegistry.getOrCreateHolder(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome())
|
||||
.getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey());
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.NoiseColumn;
|
||||
import net.minecraft.world.level.StructureFeatureManager;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement;
|
||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
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 volatile boolean rings = false;
|
||||
|
||||
public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) {
|
||||
super(Registries.structureSet(), Optional.empty(), biomeProvider, biomeProvider, seed);
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
this.vanilla = vanilla;
|
||||
this.biomeSource = biomeProvider;
|
||||
this.pack = pack;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
vanilla.applyBiomeDecoration(world, chunk, structureAccessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return vanilla.getSeaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Executor executor, @NotNull Blender blender,
|
||||
@NotNull StructureFeatureManager structureAccessor,
|
||||
@NotNull ChunkAccess chunk) {
|
||||
return vanilla.fillFromNoise(executor, blender, structureAccessor, chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureFeatureManager structures, @NotNull ChunkAccess chunk) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Codec<? extends ChunkGenerator> codec() {
|
||||
return ChunkGenerator.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height) {
|
||||
/*
|
||||
BlockState[] array = new BlockState[height.getHeight()];
|
||||
WorldProperties properties = new NMSWorldProperties(seed, height);
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties);
|
||||
for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) {
|
||||
array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider)
|
||||
.getHandle()).getState();
|
||||
}
|
||||
return new NoiseColumn(getMinY(), array);
|
||||
*/
|
||||
return vanilla.getBaseColumn(x, z, height);
|
||||
}
|
||||
|
||||
@Override // withSeed
|
||||
public @NotNull ChunkGenerator withSeed(long seed) {
|
||||
return new NMSChunkGeneratorDelegate(vanilla, pack, biomeSource, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(@NotNull WorldGenRegion regionlimitedworldaccess) {
|
||||
vanilla.spawnOriginalMobs(regionlimitedworldaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenDepth() {
|
||||
return vanilla.getGenDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Sampler climateSampler() {
|
||||
return Climate.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return vanilla.getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int x, int z, Heightmap.@NotNull Types heightmap, @NotNull LevelHeightAccessor world) {
|
||||
WorldProperties properties = new NMSWorldProperties(seed, world);
|
||||
int y = properties.getMaxHeight();
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
while(y >= getMinY() && !heightmap.isOpaque().test(
|
||||
((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) {
|
||||
y--;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<ChunkPos> getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement concentricringsstructureplacement) {
|
||||
ensureStructuresGenerated();
|
||||
return ringPositions.getOrDefault(concentricringsstructureplacement, EMPTY).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void ensureStructuresGenerated() {
|
||||
if(!this.rings) {
|
||||
super.ensureStructuresGenerated();
|
||||
this.populateStrongholdData();
|
||||
this.rings = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void populateStrongholdData() {
|
||||
LOGGER.info("Generating safe stronghold data. This may take up to a minute.");
|
||||
Set<Holder<Biome>> set = this.runtimeBiomeSource.possibleBiomes();
|
||||
possibleStructureSets().map(Holder::value).forEach((holder) -> { // we dont need the spigot crap because it doesnt touch concentric.
|
||||
StructurePlacement structureplacement = holder.placement();
|
||||
if(structureplacement instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) {
|
||||
if(holder.structures().stream().anyMatch((structureset_a1) -> structureset_a1.generatesInMatchingBiome(set::contains))) {
|
||||
this.ringPositions.put(concentricringsstructureplacement,
|
||||
Lazy.lazy(() -> this.generateRingPositions(holder, concentricringsstructureplacement)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<ChunkPos> generateRingPositions(StructureSet holder,
|
||||
ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot
|
||||
if(concentricringsstructureplacement.count() == 0) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<ChunkPos> list = new ArrayList<>();
|
||||
Set<Holder<Biome>> set = holder
|
||||
.structures()
|
||||
.stream()
|
||||
.flatMap((structureset_a) -> structureset_a.structure().value().biomes().stream())
|
||||
.collect(Collectors.toSet());
|
||||
int i = concentricringsstructureplacement.distance();
|
||||
int j = concentricringsstructureplacement.count();
|
||||
int k = concentricringsstructureplacement.spread();
|
||||
Random random = new Random();
|
||||
|
||||
// Paper start
|
||||
if(this.conf.strongholdSeed != null && this.structureSets.getResourceKey(holder).orElse(null) ==
|
||||
net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS) {
|
||||
random.setSeed(this.conf.strongholdSeed);
|
||||
} else {
|
||||
// Paper end
|
||||
random.setSeed(this.ringPlacementSeed);
|
||||
} // Paper
|
||||
double d0 = random.nextDouble() * 3.141592653589793D * 2.0D;
|
||||
int l = 0;
|
||||
int i1 = 0;
|
||||
|
||||
for(int j1 = 0; j1 < j; ++j1) {
|
||||
double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5D) * (double) i * 2.5D;
|
||||
int k1 = (int) Math.round(Math.cos(d0) * d1);
|
||||
int l1 = (int) Math.round(Math.sin(d0) * d1);
|
||||
int i2 = SectionPos.sectionToBlockCoord(k1, 8);
|
||||
int j2 = SectionPos.sectionToBlockCoord(l1, 8);
|
||||
|
||||
Objects.requireNonNull(set);
|
||||
Pair<BlockPos, Holder<Biome>> pair = this.biomeSource.findBiomeHorizontal(i2, 0, j2, 112, set::contains, random,
|
||||
this.climateSampler());
|
||||
|
||||
if(pair != null) {
|
||||
BlockPos blockposition = pair.getFirst();
|
||||
|
||||
k1 = SectionPos.blockToSectionCoord(blockposition.getX());
|
||||
l1 = SectionPos.blockToSectionCoord(blockposition.getZ());
|
||||
}
|
||||
|
||||
list.add(new ChunkPos(k1, l1));
|
||||
d0 += 6.283185307179586D / (double) k;
|
||||
++l;
|
||||
if(l == k) {
|
||||
++i1;
|
||||
l = 0;
|
||||
k += 2 * k / (i1 + 1);
|
||||
k = Math.min(k, j - j1);
|
||||
d0 += random.nextDouble() * 3.141592653589793D * 2.0D;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(@NotNull List<String> arg0, @NotNull BlockPos arg1) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
import com.dfsek.terra.bukkit.nms.Initializer;
|
||||
|
||||
|
||||
public class NMSInitializer implements Initializer {
|
||||
@Override
|
||||
public void initialize(PlatformImpl platform) {
|
||||
AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry());
|
||||
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
|
||||
|
||||
public class NMSInjectListener implements Listener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class);
|
||||
private static final Set<World> INJECTED = new HashSet<>();
|
||||
private static final ReentrantLock INJECT_LOCK = new ReentrantLock();
|
||||
|
||||
@EventHandler
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
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());
|
||||
|
||||
custom.conf = vanilla.conf; // world config from Spigot
|
||||
|
||||
serverWorld.getChunkSource().chunkMap.generator = custom;
|
||||
|
||||
LOGGER.info("Successfully injected into world.");
|
||||
|
||||
serverWorld.getChunkSource().chunkMap.generator.ensureStructuresGenerated(); // generate stronghold data now
|
||||
|
||||
INJECT_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
|
||||
public class NMSWorldProperties implements WorldProperties {
|
||||
private final long seed;
|
||||
private final LevelHeightAccessor height;
|
||||
|
||||
public NMSWorldProperties(long seed, LevelHeightAccessor height) {
|
||||
this.seed = seed;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return height.getMaxBuildHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return height.getMinBuildHeight();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
|
||||
|
||||
|
||||
public class Reflection {
|
||||
public static final MappedRegistryProxy MAPPED_REGISTRY;
|
||||
public static final BiomeProxy BIOME;
|
||||
|
||||
static {
|
||||
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
|
||||
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")
|
||||
Biome.BiomeCategory getBiomeCategory(Biome instance);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
|
||||
|
||||
|
||||
public class Registries {
|
||||
private static <T> Registry<T> getRegistry(ResourceKey<Registry<T>> key) {
|
||||
CraftServer craftserver = (CraftServer) Bukkit.getServer();
|
||||
DedicatedServer dedicatedserver = craftserver.getServer();
|
||||
return dedicatedserver
|
||||
.registryAccess()
|
||||
.registryOrThrow( // getRegistry
|
||||
key
|
||||
);
|
||||
}
|
||||
|
||||
public static Registry<Biome> biomeRegistry() {
|
||||
return getRegistry(Registry.BIOME_REGISTRY);
|
||||
}
|
||||
|
||||
public static Registry<StructureSet> structureSet() {
|
||||
return getRegistry(Registry.STRUCTURE_SET_REGISTRY);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,33 @@
|
||||
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 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.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.util.BiomeUtil;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.util.TagUtil;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class AwfulBukkitHacks {
|
||||
public static final Map<Holder<net.minecraft.world.level.biome.Biome>, Map<ResourceLocation,
|
||||
ProbabilityCollection<ConfiguredStructure>>>
|
||||
TERRA_BIOME_FERTILIZABLE_MAP = new HashMap<>();
|
||||
public static final Map<TagKey<Biome>, List<ResourceLocation>>
|
||||
TERRA_BIOME_TAG_MAP = new HashMap<>();
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class);
|
||||
|
||||
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();
|
||||
|
||||
public static void registerBiomes(ConfigRegistry configRegistry) {
|
||||
try {
|
||||
LOGGER.info("Hacking biome registry...");
|
||||
@@ -38,76 +36,12 @@ public class AwfulBukkitHacks {
|
||||
Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, false);
|
||||
|
||||
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
||||
try {
|
||||
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
||||
ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey());
|
||||
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)));
|
||||
|
||||
BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform);
|
||||
biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
|
||||
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
||||
|
||||
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location());
|
||||
|
||||
LOGGER.debug("Registered biome: " + delegateKey);
|
||||
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
BiomeUtil.registerBiome(biome, pack, key);
|
||||
}));
|
||||
|
||||
Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, true); // freeze registry again :)
|
||||
|
||||
LOGGER.info("Doing tag garbage....");
|
||||
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);
|
||||
|
||||
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)));
|
||||
|
||||
biomeRegistry.resetTags();
|
||||
biomeRegistry.bindTags(ImmutableMap.copyOf(collect));
|
||||
TagUtil.registerBiomeTags(biomeRegistry);
|
||||
|
||||
} catch(SecurityException | IllegalArgumentException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.bukkit.BukkitAddon;
|
||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class NMSAddon extends BukkitAddon {
|
||||
public NMSAddon(PlatformImpl terraBukkitPlugin) {
|
||||
super(terraBukkitPlugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
terraBukkitPlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -11,65 +13,75 @@ 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.nms.v1_19_R1.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class NMSBiomeInjector {
|
||||
|
||||
|
||||
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) {
|
||||
return registry.getOptional(identifier)
|
||||
.flatMap(registry::getResourceKey)
|
||||
.map(registry::getOrCreateHolderOrThrow);
|
||||
}
|
||||
|
||||
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla)
|
||||
public static Biome createBiome(VanillaBiomeProperties vanillaBiomeProperties)
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
Biome.BiomeBuilder builder = new Biome.BiomeBuilder();
|
||||
|
||||
builder
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(vanilla.getGenerationSettings());
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
|
||||
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
|
||||
|
||||
effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier());
|
||||
net.minecraft.world.level.biome.Biome.BiomeBuilder builder = new BiomeBuilder();
|
||||
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
effects.waterColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterColor()))
|
||||
.waterFogColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterFogColor()))
|
||||
.fogColor(Objects.requireNonNull(vanillaBiomeProperties.getFogColor()))
|
||||
.skyColor(Objects.requireNonNull(vanillaBiomeProperties.getSkyColor()))
|
||||
.grassColorModifier(
|
||||
Objects.requireNonNull(vanillaBiomeProperties.getGrassColorModifier()));
|
||||
|
||||
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 {
|
||||
if(vanillaBiomeProperties.getFoliageColor() != null) {
|
||||
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() == null) {
|
||||
vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
} else {
|
||||
// grass
|
||||
if(vanillaBiomeProperties.getGrassColor() != null) {
|
||||
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound);
|
||||
vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound);
|
||||
vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound);
|
||||
vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic);
|
||||
vanilla.getAmbientParticle().ifPresent(effects::ambientParticle);
|
||||
if(vanillaBiomeProperties.getParticleConfig() != null) {
|
||||
effects.ambientParticle(vanillaBiomeProperties.getParticleConfig());
|
||||
}
|
||||
|
||||
builder.specialEffects(effects.build());
|
||||
if(vanillaBiomeProperties.getLoopSound() != null) {
|
||||
effects.ambientLoopSound(vanillaBiomeProperties.getLoopSound());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
if(vanillaBiomeProperties.getMoodSound() != null) {
|
||||
effects.ambientMoodSound(vanillaBiomeProperties.getMoodSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getAdditionsSound() != null) {
|
||||
effects.ambientAdditionsSound(vanillaBiomeProperties.getAdditionsSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getMusic() != null) {
|
||||
effects.backgroundMusic(vanillaBiomeProperties.getMusic());
|
||||
}
|
||||
|
||||
builder.precipitation(Objects.requireNonNull(vanillaBiomeProperties.getPrecipitation()));
|
||||
|
||||
builder.temperature(Objects.requireNonNull(vanillaBiomeProperties.getTemperature()));
|
||||
|
||||
builder.downfall(Objects.requireNonNull(vanillaBiomeProperties.getDownfall()));
|
||||
|
||||
builder.temperatureAdjustment(Objects.requireNonNull(vanillaBiomeProperties.getTemperatureModifier()));
|
||||
|
||||
builder.mobSpawnSettings(Objects.requireNonNull(vanillaBiomeProperties.getSpawnSettings()));
|
||||
|
||||
return builder
|
||||
.specialEffects(effects.build())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.ProtoPlatformBiome;
|
||||
|
||||
|
||||
public class NMSBiomeProvider extends BiomeSource {
|
||||
@@ -20,9 +20,7 @@ public class NMSBiomeProvider extends BiomeSource {
|
||||
public NMSBiomeProvider(BiomeProvider delegate, long seed) {
|
||||
super(delegate.stream()
|
||||
.map(biome -> Registries.biomeRegistry()
|
||||
.getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey())));
|
||||
.getHolderOrThrow(((ProtoPlatformBiome) biome.getPlatformBiome()).getBiome())));
|
||||
this.delegate = delegate;
|
||||
this.seed = seed;
|
||||
}
|
||||
@@ -34,9 +32,7 @@ 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(((ProtoPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed)
|
||||
.getPlatformBiome()).getBiome());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,10 +143,10 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
*/
|
||||
return vanilla.getBaseColumn(x, z, world, noiseConfig);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(@NotNull List<String> text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,7 +187,7 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private List<ChunkPos> generateRingPositions(StructureSet holder, RandomState randomstate,
|
||||
ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot
|
||||
if(concentricringsstructureplacement.count() == 0) {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
import com.dfsek.terra.bukkit.nms.Initializer;
|
||||
|
||||
|
||||
public class NMSInitializer implements Initializer {
|
||||
@Override
|
||||
public void initialize(PlatformImpl platform) {
|
||||
AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry());
|
||||
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
|
||||
import net.minecraft.world.level.biome.AmbientMoodSettings;
|
||||
import net.minecraft.world.level.biome.AmbientParticleSettings;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.BiomeAdditionsSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.BiomeMoodSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.BiomeParticleConfigTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.EntityTypeTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.FertilizableConfig;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.MusicSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SoundEventTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnCostConfig;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnEntryTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnSettingsTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnTypeConfig;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VillagerTypeTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.util.BiomeUtil;
|
||||
|
||||
|
||||
public class NMSPlatform extends PlatformImpl {
|
||||
|
||||
public NMSPlatform(TerraBukkitPlugin plugin) {
|
||||
super(plugin);
|
||||
AwfulBukkitHacks.registerBiomes(getRawConfigRegistry());
|
||||
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), plugin);
|
||||
}
|
||||
|
||||
public ResourceKey<Biome> getBiomeKey(ResourceLocation identifier) {
|
||||
return BiomeUtil.getBiomeKey(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(ResourceLocation.class, (type, o, loader, depthTracker) -> {
|
||||
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
|
||||
if(identifier == null)
|
||||
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||
return identifier;
|
||||
})
|
||||
.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(MobCategory.class, (type, o, loader, depthTracker) -> MobCategory.valueOf((String) o))
|
||||
.registerLoader(AmbientParticleSettings.class, BiomeParticleConfigTemplate::new)
|
||||
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
|
||||
.registerLoader(AmbientMoodSettings.class, BiomeMoodSoundTemplate::new)
|
||||
.registerLoader(AmbientAdditionsSettings.class, BiomeAdditionsSoundTemplate::new)
|
||||
.registerLoader(Music.class, MusicSoundTemplate::new)
|
||||
.registerLoader(EntityType.class, EntityTypeTemplate::new)
|
||||
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
|
||||
.registerLoader(SpawnerData.class, SpawnEntryTemplate::new)
|
||||
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
|
||||
.registerLoader(MobSpawnSettings.class, SpawnSettingsTemplate::new)
|
||||
.registerLoader(VillagerType.class, VillagerTypeTemplate::new)
|
||||
.registerLoader(FertilizableConfig.class, FertilizableConfig::new);
|
||||
}
|
||||
|
||||
|
||||
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
|
||||
ResourceLocation identifier = ResourceLocation.tryParse(id);
|
||||
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
|
||||
return new ProtoPlatformBiome(identifier, getBiomeKey(identifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return List.of(new NMSAddon(this));
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,31 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.Static;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Reflection {
|
||||
public static final MappedRegistryProxy MAPPED_REGISTRY;
|
||||
|
||||
public static final VillagerTypeProxy VILLAGER_TYPE;
|
||||
|
||||
static {
|
||||
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
|
||||
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper,
|
||||
Reflection.class.getClassLoader());
|
||||
|
||||
MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class);
|
||||
VILLAGER_TYPE = reflectionProxyFactory.reflectionProxy(VillagerTypeProxy.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,4 +34,12 @@ public class Reflection {
|
||||
@FieldSetter("frozen")
|
||||
void setFrozen(MappedRegistry<?> instance, boolean frozen);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(VillagerTypeProxy.class)
|
||||
public interface VillagerTypeProxy {
|
||||
@Static
|
||||
@FieldGetter("BY_BIOME")
|
||||
Map<ResourceKey<Biome>, VillagerType> getByBiome();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.sounds.SoundEvent;
|
||||
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
|
||||
|
||||
|
||||
public class BiomeAdditionsSoundTemplate implements ObjectTemplate<AmbientAdditionsSettings> {
|
||||
@Value("sound")
|
||||
@Default
|
||||
private SoundEvent sound = null;
|
||||
|
||||
@Value("sound-chance")
|
||||
@Default
|
||||
private Double soundChance = null;
|
||||
|
||||
@Override
|
||||
public AmbientAdditionsSettings get() {
|
||||
if(sound == null || soundChance == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new AmbientAdditionsSettings(sound, soundChance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.sounds.SoundEvent;
|
||||
import net.minecraft.world.level.biome.AmbientMoodSettings;
|
||||
|
||||
|
||||
public class BiomeMoodSoundTemplate implements ObjectTemplate<AmbientMoodSettings> {
|
||||
@Value("sound")
|
||||
@Default
|
||||
private SoundEvent sound = null;
|
||||
|
||||
@Value("cultivation-ticks")
|
||||
@Default
|
||||
private Integer soundCultivationTicks = null;
|
||||
|
||||
@Value("spawn-range")
|
||||
@Default
|
||||
private Integer soundSpawnRange = null;
|
||||
|
||||
@Value("extra-distance")
|
||||
@Default
|
||||
private Double soundExtraDistance = null;
|
||||
|
||||
@Override
|
||||
public AmbientMoodSettings get() {
|
||||
if(sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new AmbientMoodSettings(sound, soundCultivationTicks, soundSpawnRange, soundExtraDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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 com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.arguments.ParticleArgument;
|
||||
import net.minecraft.world.level.biome.AmbientParticleSettings;
|
||||
|
||||
|
||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientParticleSettings> {
|
||||
@Value("particle")
|
||||
@Default
|
||||
private String particle = null;
|
||||
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Integer probability = null;
|
||||
|
||||
@Override
|
||||
public AmbientParticleSettings get() {
|
||||
if(particle == null || probability == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new AmbientParticleSettings(ParticleArgument.readParticle(new StringReader(particle)), probability);
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
||||
|
||||
public class EntityTypeTemplate implements ObjectTemplate<EntityType<?>> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private ResourceLocation id = null;
|
||||
|
||||
@Override
|
||||
public EntityType<?> get() {
|
||||
return Registry.ENTITY_TYPE.get(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.resources.ResourceLocation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class FertilizableConfig implements ObjectTemplate<FertilizableConfig> {
|
||||
@Value("strucutres")
|
||||
@Default
|
||||
private ProbabilityCollection<ConfiguredStructure> structures = null;
|
||||
|
||||
@Value("cooldowns")
|
||||
@Default
|
||||
private Map<ResourceLocation, Double> cooldowns = null;
|
||||
|
||||
@Value("can-grow")
|
||||
@Default
|
||||
private ConfiguredStructure canGrow = null;
|
||||
|
||||
@Value("villager-fertilizable")
|
||||
@Default
|
||||
private Boolean villagerFertilizable = null;
|
||||
|
||||
public ProbabilityCollection<ConfiguredStructure> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
||||
public Map<ResourceLocation, Double> getCooldowns() {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
public ConfiguredStructure getCanGrow() {
|
||||
return canGrow;
|
||||
}
|
||||
|
||||
public Boolean isVillagerFertilizable() {
|
||||
return villagerFertilizable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FertilizableConfig get() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
public class MusicSoundTemplate implements ObjectTemplate<Music> {
|
||||
@Value("sound")
|
||||
@Default
|
||||
private SoundEvent sound = null;
|
||||
|
||||
@Value("delay")
|
||||
@Default
|
||||
private Range delay = null;
|
||||
|
||||
|
||||
@Value("replace-current-music")
|
||||
@Default
|
||||
private Boolean replaceCurrentMusic = null;
|
||||
|
||||
@Override
|
||||
public Music get() {
|
||||
if(sound == null || delay == null || replaceCurrentMusic == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new Music(sound, delay.getMin(), delay.getMax(), replaceCurrentMusic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.bukkit.nms.v1_19_R1.config;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.util.MinecraftUtil;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class ProtoPlatformBiome implements PlatformBiome, BukkitPlatformBiome {
|
||||
private final ResourceLocation identifier;
|
||||
|
||||
private final ResourceKey<Biome> biome;
|
||||
|
||||
public ProtoPlatformBiome(ResourceLocation identifier, ResourceKey<Biome> biome) {
|
||||
this.identifier = identifier;
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
public ResourceKey<Biome> get(Registry<Biome> registry) {
|
||||
return MinecraftUtil.getEntry(registry, identifier).orElseThrow().unwrapKey().orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public ResourceKey<Biome> getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.Biome getBukkitBiome() {
|
||||
return org.bukkit.block.Biome.CUSTOM;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
|
||||
|
||||
public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private ResourceLocation id = null;
|
||||
|
||||
@Value("distance-to-travel")
|
||||
@Default
|
||||
private Float distanceToTravel = null;
|
||||
|
||||
@Override
|
||||
public SoundEvent get() {
|
||||
if(id == null) {
|
||||
return null;
|
||||
} else if(distanceToTravel == null) {
|
||||
return new SoundEvent(id);
|
||||
} else {
|
||||
return new SoundEvent(id, distanceToTravel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.world.entity.EntityType;
|
||||
|
||||
|
||||
public class SpawnCostConfig implements ObjectTemplate<SpawnCostConfig> {
|
||||
@Value("type")
|
||||
@Default
|
||||
private EntityType<?> type = null;
|
||||
|
||||
@Value("mass")
|
||||
@Default
|
||||
private Double mass = null;
|
||||
|
||||
@Value("gravity")
|
||||
@Default
|
||||
private Double gravity = null;
|
||||
|
||||
public EntityType<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Double getMass() {
|
||||
return mass;
|
||||
}
|
||||
|
||||
public Double getGravity() {
|
||||
return gravity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnCostConfig get() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
public class SpawnEntryTemplate implements ObjectTemplate<SpawnerData> {
|
||||
@Value("type")
|
||||
@Default
|
||||
private EntityType<?> type = null;
|
||||
|
||||
@Value("weight")
|
||||
@Default
|
||||
private Integer weight = null;
|
||||
|
||||
@Value("group-size")
|
||||
@Default
|
||||
private Range groupSize = null;
|
||||
|
||||
@Override
|
||||
public SpawnerData get() {
|
||||
return new SpawnerData(type, weight, groupSize.getMin(), groupSize.getMax());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
|
||||
@Value("spawns")
|
||||
@Default
|
||||
private List<SpawnTypeConfig> spawns = null;
|
||||
|
||||
@Value("costs")
|
||||
@Default
|
||||
private List<SpawnCostConfig> costs = null;
|
||||
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Float probability = null;
|
||||
|
||||
@Override
|
||||
public MobSpawnSettings get() {
|
||||
MobSpawnSettings.Builder builder = new MobSpawnSettings.Builder();
|
||||
for(SpawnTypeConfig spawn : spawns) {
|
||||
MobCategory group = spawn.getGroup();
|
||||
for(SpawnerData entry : spawn.getEntry()) {
|
||||
builder.addSpawn(group, entry);
|
||||
}
|
||||
}
|
||||
for(SpawnCostConfig cost : costs) {
|
||||
builder.addMobCharge(cost.getType(), cost.getMass(), cost.getGravity());
|
||||
}
|
||||
if(probability != null) {
|
||||
builder.creatureGenerationProbability(probability);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
|
||||
@Value("group")
|
||||
@Default
|
||||
private MobCategory group = null;
|
||||
|
||||
@Value("entries")
|
||||
@Default
|
||||
private List<SpawnerData> entry = null;
|
||||
|
||||
public MobCategory getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public List<SpawnerData> getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnTypeConfig get() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
|
||||
|
||||
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.Value;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
|
||||
import net.minecraft.world.level.biome.AmbientMoodSettings;
|
||||
import net.minecraft.world.level.biome.AmbientParticleSettings;
|
||||
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("minecraft.fertilizables")
|
||||
@Default
|
||||
private Map<ResourceLocation, FertilizableConfig> fertilizables = Collections.emptyMap();
|
||||
|
||||
@Value("minecraft.tags")
|
||||
@Default
|
||||
private List<ResourceLocation> tags = Collections.emptyList();
|
||||
|
||||
@Value("minecraft.colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = 0;
|
||||
|
||||
@Value("minecraft.colors.fog")
|
||||
@Default
|
||||
private Integer fogColor = 0;
|
||||
|
||||
@Value("minecraft.colors.water")
|
||||
@Default
|
||||
private Integer waterColor = 0;
|
||||
|
||||
@Value("minecraft.colors.water-fog")
|
||||
@Default
|
||||
private Integer waterFogColor = 0;
|
||||
|
||||
@Value("minecraft.colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = 0;
|
||||
|
||||
@Value("minecraft.colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = 0;
|
||||
|
||||
@Value("minecraft.colors.modifier")
|
||||
@Default
|
||||
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
|
||||
|
||||
@Value("minecraft.particles")
|
||||
@Default
|
||||
private AmbientParticleSettings particleConfig = null;
|
||||
|
||||
@Value("minecraft.climate.precipitation")
|
||||
@Default
|
||||
private Precipitation precipitation = Precipitation.NONE;
|
||||
|
||||
@Value("minecraft.climate.temperature")
|
||||
@Default
|
||||
private Float temperature = 0.0f;
|
||||
|
||||
@Value("minecraft.climate.temperature-modifier")
|
||||
@Default
|
||||
private TemperatureModifier temperatureModifier = TemperatureModifier.NONE;
|
||||
|
||||
@Value("minecraft.climate.downfall")
|
||||
@Default
|
||||
private Float downfall = 0.0f;
|
||||
|
||||
@Value("minecraft.sound.loop-sound.sound")
|
||||
@Default
|
||||
private SoundEvent loopSound = null;
|
||||
|
||||
@Value("minecraft.sound.mood-sound")
|
||||
@Default
|
||||
private AmbientMoodSettings moodSound = null;
|
||||
|
||||
@Value("minecraft.sound.additions-sound")
|
||||
@Default
|
||||
private AmbientAdditionsSettings additionsSound = null;
|
||||
|
||||
@Value("minecraft.sound.music")
|
||||
@Default
|
||||
private Music music = null;
|
||||
|
||||
@Value("minecraft.spawning")
|
||||
@Default
|
||||
private MobSpawnSettings spawnSettings = MobSpawnSettings.EMPTY;
|
||||
|
||||
@Value("minecraft.villager-type")
|
||||
@Default
|
||||
private VillagerType villagerType = null;
|
||||
|
||||
public Map<ResourceLocation, FertilizableConfig> getFertilizables() {
|
||||
return fertilizables;
|
||||
}
|
||||
|
||||
public List<ResourceLocation> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
public Integer getWaterColor() {
|
||||
return waterColor;
|
||||
}
|
||||
|
||||
public Integer getWaterFogColor() {
|
||||
return waterFogColor;
|
||||
}
|
||||
|
||||
public Integer getFoliageColor() {
|
||||
return foliageColor;
|
||||
}
|
||||
|
||||
public Integer getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
|
||||
public GrassColorModifier getGrassColorModifier() {
|
||||
return grassColorModifier;
|
||||
}
|
||||
|
||||
public AmbientParticleSettings getParticleConfig() {
|
||||
return particleConfig;
|
||||
}
|
||||
|
||||
public Precipitation getPrecipitation() {
|
||||
return precipitation;
|
||||
}
|
||||
|
||||
public Float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public TemperatureModifier getTemperatureModifier() {
|
||||
return temperatureModifier;
|
||||
}
|
||||
|
||||
public Float getDownfall() {
|
||||
return downfall;
|
||||
}
|
||||
|
||||
public SoundEvent getLoopSound() {
|
||||
return loopSound;
|
||||
}
|
||||
|
||||
public AmbientMoodSettings getMoodSound() {
|
||||
return moodSound;
|
||||
}
|
||||
|
||||
public AmbientAdditionsSettings getAdditionsSound() {
|
||||
return additionsSound;
|
||||
}
|
||||
|
||||
public Music getMusic() {
|
||||
return music;
|
||||
}
|
||||
|
||||
public MobSpawnSettings getSpawnSettings() {
|
||||
return spawnSettings;
|
||||
}
|
||||
|
||||
public VillagerType getVillagerType() {
|
||||
return villagerType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.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.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
|
||||
|
||||
public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private ResourceLocation id = null;
|
||||
|
||||
@Override
|
||||
public VillagerType get() {
|
||||
return Registry.VILLAGER_TYPE.get(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.util;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.Reflection;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.FertilizableConfig;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class BiomeUtil {
|
||||
public static final Map<Holder<net.minecraft.world.level.biome.Biome>, Map<ResourceLocation, FertilizableConfig>>
|
||||
TERRA_BIOME_FERTILIZABLE_MAP = new HashMap<>();
|
||||
public static final Map<TagKey<net.minecraft.world.level.biome.Biome>, List<ResourceLocation>>
|
||||
TERRA_BIOME_TAG_MAP = new HashMap<>();
|
||||
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
|
||||
|
||||
protected static ResourceKey<net.minecraft.world.level.biome.Biome> registerBiome(ResourceLocation identifier,
|
||||
net.minecraft.world.level.biome.Biome biome) {
|
||||
BuiltinRegistries.register(BuiltinRegistries.BIOME,
|
||||
MinecraftUtil.registerKey(identifier)
|
||||
.location(),
|
||||
biome);
|
||||
return getBiomeKey(identifier);
|
||||
}
|
||||
|
||||
public static ResourceKey<net.minecraft.world.level.biome.Biome> getBiomeKey(ResourceLocation identifier) {
|
||||
return BuiltinRegistries.BIOME.getResourceKey(BuiltinRegistries.BIOME.get(identifier)).orElseThrow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
*/
|
||||
public static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
net.minecraft.world.level.biome.Biome minecraftBiome = MinecraftUtil.createBiome(vanillaBiomeProperties);
|
||||
|
||||
ResourceLocation identifier = new ResourceLocation("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
biome.setPlatformBiome(new ProtoPlatformBiome(identifier, registerBiome(identifier, minecraftBiome)));
|
||||
|
||||
Map villagerMap = Reflection.VILLAGER_TYPE.getByBiome();
|
||||
|
||||
villagerMap.put(ResourceKey.create(Registry.BIOME_REGISTRY, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), VillagerType.PLAINS));
|
||||
|
||||
TERRA_BIOME_FERTILIZABLE_MAP.put(Holder.direct(minecraftBiome), vanillaBiomeProperties.getFertilizables());
|
||||
|
||||
for(ResourceLocation tag : vanillaBiomeProperties.getTags()) {
|
||||
TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.create(Registry.BIOME_REGISTRY, tag), new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.bukkit.nms.v1_19_R1.util;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
|
||||
public final class MinecraftAdapter {
|
||||
|
||||
public static Vector3 adapt(BlockPos pos) {
|
||||
return Vector3.of(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static WorldProperties adapt(LevelHeightAccessor height, long seed) {
|
||||
return new WorldProperties() {
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return height.getMaxBuildHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return height.getMinBuildHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return height;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.util;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||
import com.dfsek.terra.api.block.entity.Sign;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public final class MinecraftUtil {
|
||||
public static final Logger logger = LoggerFactory.getLogger(MinecraftUtil.class);
|
||||
|
||||
|
||||
private MinecraftUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) {
|
||||
return registry.getOptional(identifier)
|
||||
.flatMap(registry::getResourceKey)
|
||||
.map(registry::getOrCreateHolderOrThrow);
|
||||
}
|
||||
|
||||
public static BlockEntity createState(LevelAccessor worldAccess, BlockPos pos) {
|
||||
net.minecraft.world.level.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof SpawnerBlockEntity) {
|
||||
return (MobSpawner) entity;
|
||||
} else if(entity instanceof RandomizableContainerBlockEntity) {
|
||||
return (Container) entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ResourceKey<Biome> registerKey(ResourceLocation identifier) {
|
||||
return ResourceKey.create(Registry.BIOME_REGISTRY, identifier);
|
||||
}
|
||||
|
||||
public static Biome createBiome(VanillaBiomeProperties vanillaBiomeProperties) {
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
|
||||
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
|
||||
|
||||
BiomeBuilder builder = new BiomeBuilder();
|
||||
|
||||
effects.waterColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterColor()))
|
||||
.waterFogColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterFogColor()))
|
||||
.fogColor(Objects.requireNonNull(vanillaBiomeProperties.getFogColor()))
|
||||
.skyColor(Objects.requireNonNull(vanillaBiomeProperties.getSkyColor()))
|
||||
.grassColorModifier(
|
||||
Objects.requireNonNull(vanillaBiomeProperties.getGrassColorModifier()));
|
||||
|
||||
if(vanillaBiomeProperties.getFoliageColor() != null) {
|
||||
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() != null) {
|
||||
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getParticleConfig() != null) {
|
||||
effects.ambientParticle(vanillaBiomeProperties.getParticleConfig());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getLoopSound() != null) {
|
||||
effects.ambientLoopSound(vanillaBiomeProperties.getLoopSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getMoodSound() != null) {
|
||||
effects.ambientMoodSound(vanillaBiomeProperties.getMoodSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getAdditionsSound() != null) {
|
||||
effects.ambientAdditionsSound(vanillaBiomeProperties.getAdditionsSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getMusic() != null) {
|
||||
effects.backgroundMusic(vanillaBiomeProperties.getMusic());
|
||||
}
|
||||
|
||||
builder.precipitation(Objects.requireNonNull(vanillaBiomeProperties.getPrecipitation()));
|
||||
|
||||
builder.temperature(Objects.requireNonNull(vanillaBiomeProperties.getTemperature()));
|
||||
|
||||
builder.downfall(Objects.requireNonNull(vanillaBiomeProperties.getDownfall()));
|
||||
|
||||
builder.temperatureAdjustment(Objects.requireNonNull(vanillaBiomeProperties.getTemperatureModifier()));
|
||||
|
||||
builder.mobSpawnSettings(Objects.requireNonNull(vanillaBiomeProperties.getSpawnSettings()));
|
||||
|
||||
return builder
|
||||
.specialEffects(effects.build())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
|
||||
return pack.getID()
|
||||
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.util;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public final class TagUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TagUtil.class);
|
||||
|
||||
private TagUtil() {
|
||||
|
||||
}
|
||||
|
||||
private static <T> Map<TagKey<T>, List<Holder<T>>> tagsToMutableMap(Registry<T> registry) {
|
||||
return registry
|
||||
.getTags()
|
||||
.collect(HashMap::new,
|
||||
(map, pair) ->
|
||||
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
public static void registerBiomeTags(Registry<Biome> registry) {
|
||||
logger.info("Doing data-driven biome tag garbage....");
|
||||
logger.info("who let this data drive?");
|
||||
Map<TagKey<Biome>, List<Holder<Biome>>> collect = tagsToMutableMap(registry);
|
||||
|
||||
BiomeUtil.TERRA_BIOME_TAG_MAP.forEach((tag, biomeList) -> {
|
||||
collect.getOrDefault(tag, new ArrayList<>())
|
||||
.addAll(biomeList.stream()
|
||||
.map(registry::getOptional)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(Holder::direct)
|
||||
.toList());
|
||||
});
|
||||
|
||||
registry.resetTags();
|
||||
registry.bindTags(ImmutableMap.copyOf(collect));
|
||||
|
||||
if(logger.isDebugEnabled()) {
|
||||
registry.holders()
|
||||
.map(e -> e.key().location() + ": " +
|
||||
e.tags().reduce("", (s, t) -> t.location() + ", " + s, String::concat))
|
||||
.forEach(logger::debug);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ architectury {
|
||||
dependencies {
|
||||
shadedApi(project(":common:implementation:base"))
|
||||
|
||||
annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}")
|
||||
annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}")
|
||||
|
||||
implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
"developmentFabric"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionFabric")) { isTransitive = false }
|
||||
|
||||
@@ -17,35 +17,16 @@
|
||||
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
import com.dfsek.terra.lifecycle.LifecycleEntryPoint;
|
||||
|
||||
|
||||
public class FabricEntryPoint implements ModInitializer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FabricEntryPoint.class);
|
||||
|
||||
public class FabricEntryPoint extends LifecycleEntryPoint implements ModInitializer {
|
||||
private static final FabricPlatform TERRA_PLUGIN = new FabricPlatform();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
logger.info("Initializing Terra Fabric mod...");
|
||||
|
||||
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
serverCommandSource -> (CommandSender) serverCommandSource,
|
||||
commandSender -> (ServerCommandSource) commandSender
|
||||
);
|
||||
|
||||
|
||||
manager.brigadierManager().setNativeNumberSuggestions(false);
|
||||
|
||||
TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(manager));
|
||||
initialize("Fabric", TERRA_PLUGIN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,43 +17,24 @@
|
||||
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
|
||||
public class FabricPlatform extends LifecyclePlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FabricPlatform.class);
|
||||
|
||||
@Override
|
||||
protected Collection<BaseAddon> getPlatformMods() {
|
||||
return FabricLoader.getInstance().getAllMods().stream().flatMap(mod -> {
|
||||
String id = mod.getMetadata().getId();
|
||||
if(id.equals("terra") || id.equals("minecraft") || id.equals("java")) return Stream.empty();
|
||||
try {
|
||||
Version version = Versions.parseVersion(mod.getMetadata().getVersion().getFriendlyString());
|
||||
return Stream.<BaseAddon>of(new EphemeralAddon(version, "fabric:" + id));
|
||||
} catch(ParseException e) {
|
||||
LOGGER.warn(
|
||||
"Mod {}, version {} does not follow semantic versioning specification, Terra addons will be unable to depend on " +
|
||||
"it.",
|
||||
id, mod.getMetadata().getVersion().getFriendlyString());
|
||||
}
|
||||
return Stream.empty();
|
||||
}).collect(Collectors.toList());
|
||||
return FabricLoader.getInstance().getAllMods().stream().flatMap(
|
||||
mod -> parseModData(mod.getMetadata().getId(), mod.getMetadata().getVersion().getFriendlyString())).collect(
|
||||
Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.forge.AwfulForgeHacks.RegistrySanityCheck;
|
||||
import com.dfsek.terra.forge.AwfulForgeHacks.RegistryStep;
|
||||
import com.dfsek.terra.forge.util.BiomeUtil;
|
||||
import com.dfsek.terra.forge.util.ForgeBiomeUtil;
|
||||
import com.dfsek.terra.mod.data.Codecs;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ForgeEntryPoint {
|
||||
public static void initialize(RegisterHelper<Biome> helper) {
|
||||
getPlatform().getEventManager().callEvent(
|
||||
new PlatformInitializationEvent());
|
||||
BiomeUtil.registerBiomes(helper);
|
||||
ForgeBiomeUtil.registerBiomes(helper);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
|
||||
@@ -22,6 +22,9 @@ import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,6 +38,7 @@ import java.util.List;
|
||||
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.forge.util.ForgeBiomeUtil;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
@@ -49,6 +53,11 @@ public class ForgePlatform extends ModPlatform {
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryKey<Biome> getBiomeKey(Identifier identifier) {
|
||||
return ForgeBiomeUtil.getBiomeKey(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
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;
|
||||
|
||||
|
||||
public final class BiomeUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
|
||||
|
||||
|
||||
private BiomeUtil() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void registerBiomes(RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
logger.info("Registering biomes...");
|
||||
ForgeEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
pack.getCheckedRegistry(Biome.class)
|
||||
.forEach((id, biome) -> registerBiome(biome, pack, id, helper));
|
||||
});
|
||||
MinecraftUtil.registerFlora(BuiltinRegistries.BIOME);
|
||||
logger.info("Terra biomes registered.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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());
|
||||
} else {
|
||||
helper.register(MinecraftUtil.registerKey(identifier).getValue(), minecraftBiome);
|
||||
((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)));
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
|
||||
|
||||
import com.dfsek.terra.mod.util.BiomeUtil;
|
||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
|
||||
public final class ForgeBiomeUtil extends BiomeUtil {
|
||||
static RegisterHelper<Biome> helper;
|
||||
|
||||
public static void registerBiomes(RegisterHelper<Biome> helper) {
|
||||
ForgeBiomeUtil.helper = helper;
|
||||
registerBiomes();
|
||||
}
|
||||
|
||||
protected static RegistryKey<net.minecraft.world.biome.Biome> registerBiome(Identifier identifier,
|
||||
net.minecraft.world.biome.Biome biome) {
|
||||
helper.register(MinecraftUtil.registerKey(identifier).getValue(), biome);
|
||||
return ForgeRegistries.BIOMES.getHolder(identifier)
|
||||
.orElseThrow()
|
||||
.getKey()
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,9 @@ import net.minecraft.sound.MusicSound;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.biome.Biome.TemperatureModifier;
|
||||
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
|
||||
@@ -35,24 +37,25 @@ import com.dfsek.terra.mod.config.BiomeAdditionsSoundTemplate;
|
||||
import com.dfsek.terra.mod.config.BiomeMoodSoundTemplate;
|
||||
import com.dfsek.terra.mod.config.BiomeParticleConfigTemplate;
|
||||
import com.dfsek.terra.mod.config.EntityTypeTemplate;
|
||||
import com.dfsek.terra.mod.config.FertilizableConfig;
|
||||
import com.dfsek.terra.mod.config.MusicSoundTemplate;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
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.BiomeUtil;
|
||||
import com.dfsek.terra.mod.util.PresetUtil;
|
||||
|
||||
|
||||
public abstract class ModPlatform extends AbstractPlatform {
|
||||
private final ItemHandle itemHandle = new MinecraftItemHandle();
|
||||
private final WorldHandle worldHandle = new MinecraftWorldHandle();
|
||||
|
||||
|
||||
public abstract MinecraftServer getServer();
|
||||
|
||||
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) {
|
||||
@@ -60,6 +63,10 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
.forEach(pack -> PresetUtil.createDefault(pack).apply(registerFunction));
|
||||
}
|
||||
|
||||
public RegistryKey<Biome> getBiomeKey(Identifier identifier) {
|
||||
return BiomeUtil.getBiomeKey(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
@@ -78,6 +85,7 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(SpawnGroup.class, (type, o, loader, depthTracker) -> SpawnGroup.valueOf((String) o))
|
||||
.registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new)
|
||||
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
|
||||
.registerLoader(BiomeMoodSound.class, BiomeMoodSoundTemplate::new)
|
||||
@@ -86,16 +94,16 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
.registerLoader(EntityType.class, EntityTypeTemplate::new)
|
||||
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
|
||||
.registerLoader(SpawnEntry.class, SpawnEntryTemplate::new)
|
||||
.registerLoader(SpawnGroup.class, SpawnGroupTemplate::new)
|
||||
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
|
||||
.registerLoader(SpawnSettings.class, SpawnSettingsTemplate::new)
|
||||
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
|
||||
.registerLoader(VillagerType.class, VillagerTypeTemplate::new)
|
||||
.registerLoader(FertilizableConfig.class, FertilizableConfig::new);
|
||||
}
|
||||
|
||||
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
|
||||
Identifier identifier = Identifier.tryParse(id);
|
||||
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
|
||||
return new ProtoPlatformBiome(identifier);
|
||||
return new ProtoPlatformBiome(identifier, getBiomeKey(identifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.dfsek.terra.mod.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class FertilizableConfig implements ObjectTemplate<FertilizableConfig> {
|
||||
@Value("strucutres")
|
||||
@Default
|
||||
private ProbabilityCollection<ConfiguredStructure> structures = null;
|
||||
|
||||
@Value("cooldowns")
|
||||
@Default
|
||||
private Map<Identifier, Double> cooldowns = null;
|
||||
|
||||
@Value("can-grow")
|
||||
@Default
|
||||
private ConfiguredStructure canGrow = null;
|
||||
|
||||
@Value("villager-fertilizable")
|
||||
@Default
|
||||
private Boolean villagerFertilizable = null;
|
||||
|
||||
public ProbabilityCollection<ConfiguredStructure> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
||||
public Map<Identifier, Double> getCooldowns() {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
public ConfiguredStructure getCanGrow() {
|
||||
return canGrow;
|
||||
}
|
||||
|
||||
public Boolean isVillagerFertilizable() {
|
||||
return villagerFertilizable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FertilizableConfig get() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,17 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.sound.MusicSound;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
public class MusicSoundTemplate implements ObjectTemplate<MusicSound> {
|
||||
@Value("sound")
|
||||
@Default
|
||||
private SoundEvent sound = null;
|
||||
|
||||
@Value("min-delay")
|
||||
@Value("delay")
|
||||
@Default
|
||||
private Integer minDelay = null;
|
||||
|
||||
@Value("max-delay")
|
||||
@Default
|
||||
private Integer maxDelay = null;
|
||||
private Range delay = null;
|
||||
|
||||
@Value("replace-current-music")
|
||||
@Default
|
||||
@@ -26,10 +24,10 @@ public class MusicSoundTemplate implements ObjectTemplate<MusicSound> {
|
||||
|
||||
@Override
|
||||
public MusicSound get() {
|
||||
if(sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
|
||||
if(sound == null || delay == null || replaceCurrentMusic == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new MusicSound(sound, minDelay, maxDelay, replaceCurrentMusic);
|
||||
return new MusicSound(sound, delay.getMin(), delay.getMax(), replaceCurrentMusic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,6 @@ import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||
@Value("minecraft.use-vanilla-biomes")
|
||||
@Default
|
||||
private boolean vanillaBiomes = false;
|
||||
|
||||
@Value("minecraft.beard.enable")
|
||||
@Default
|
||||
private boolean beard = true;
|
||||
@@ -42,10 +38,6 @@ public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||
@Default
|
||||
private double airThreshold = -0.5;
|
||||
|
||||
public boolean useVanillaBiomes() {
|
||||
return vanillaBiomes;
|
||||
}
|
||||
|
||||
public boolean isBeard() {
|
||||
return beard;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
@@ -31,10 +29,11 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
public class ProtoPlatformBiome implements PlatformBiome {
|
||||
private final Identifier identifier;
|
||||
|
||||
private RegistryKey<Biome> delegate;
|
||||
private final RegistryKey<Biome> biome;
|
||||
|
||||
public ProtoPlatformBiome(Identifier identifier) {
|
||||
public ProtoPlatformBiome(Identifier identifier, RegistryKey<Biome> biome) {
|
||||
this.identifier = identifier;
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
public RegistryKey<Biome> get(Registry<net.minecraft.world.biome.Biome> registry) {
|
||||
@@ -46,11 +45,7 @@ public class ProtoPlatformBiome implements PlatformBiome {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public RegistryKey<Biome> getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDelegate(RegistryKey<Biome> delegate) {
|
||||
this.delegate = Objects.requireNonNull(delegate);
|
||||
public RegistryKey<Biome> getBiome() {
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
public class SpawnEntryTemplate implements ObjectTemplate<SpawnEntry> {
|
||||
@Value("type")
|
||||
@@ -16,16 +18,12 @@ public class SpawnEntryTemplate implements ObjectTemplate<SpawnEntry> {
|
||||
@Default
|
||||
private Integer weight = null;
|
||||
|
||||
@Value("min-group-size")
|
||||
@Value("group-size")
|
||||
@Default
|
||||
private Integer minGroupSize = null;
|
||||
|
||||
@Value("max-group-size")
|
||||
@Default
|
||||
private Integer maxGroupSize = null;
|
||||
private Range groupSize = null;
|
||||
|
||||
@Override
|
||||
public SpawnEntry get() {
|
||||
return new SpawnEntry(type, weight, minGroupSize, maxGroupSize);
|
||||
return new SpawnEntry(type, weight, groupSize.getMin(), groupSize.getMax());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
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.SpawnGroup;
|
||||
|
||||
|
||||
public class SpawnGroupTemplate implements ObjectTemplate<SpawnGroup> {
|
||||
@Value("group")
|
||||
@Default
|
||||
private String group = null;
|
||||
|
||||
@Override
|
||||
public SpawnGroup get() {
|
||||
return SpawnGroup.valueOf(group);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ 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.SpawnGroup;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,7 +27,10 @@ public class SpawnSettingsTemplate implements ObjectTemplate<SpawnSettings> {
|
||||
public SpawnSettings get() {
|
||||
SpawnSettings.Builder builder = new SpawnSettings.Builder();
|
||||
for(SpawnTypeConfig spawn : spawns) {
|
||||
builder.spawn(spawn.getGroup(), spawn.getEntry());
|
||||
SpawnGroup group = spawn.getGroup();
|
||||
for(SpawnEntry entry : spawn.getEntry()) {
|
||||
builder.spawn(group, entry);
|
||||
}
|
||||
}
|
||||
for(SpawnCostConfig cost : costs) {
|
||||
builder.spawnCost(cost.getType(), cost.getMass(), cost.getGravity());
|
||||
|
||||
@@ -6,21 +6,23 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
|
||||
@Value("group")
|
||||
@Default
|
||||
private SpawnGroup group = null;
|
||||
|
||||
@Value("entry")
|
||||
@Value("entries")
|
||||
@Default
|
||||
private SpawnEntry entry = null;
|
||||
private List<SpawnEntry> entry = null;
|
||||
|
||||
public SpawnGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public SpawnEntry getEntry() {
|
||||
public List<SpawnEntry> getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.sound.BiomeAdditionsSound;
|
||||
import net.minecraft.sound.BiomeMoodSound;
|
||||
import net.minecraft.sound.MusicSound;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraft.world.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.biome.Biome.TemperatureModifier;
|
||||
@@ -14,82 +15,103 @@ import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
|
||||
import net.minecraft.world.biome.BiomeParticleConfig;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
@Value("colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = null;
|
||||
|
||||
@Value("colors.fog")
|
||||
@Value("minecraft.fertilizables")
|
||||
@Default
|
||||
private Integer fogColor = null;
|
||||
private Map<Identifier, FertilizableConfig> fertilizables = Collections.emptyMap();
|
||||
|
||||
@Value("colors.water")
|
||||
@Value("minecraft.tags")
|
||||
@Default
|
||||
private Integer waterColor = null;
|
||||
private List<Identifier> tags = Collections.emptyList();
|
||||
|
||||
@Value("colors.water-fog")
|
||||
@Value("minecraft.colors.grass")
|
||||
@Default
|
||||
private Integer waterFogColor = null;
|
||||
private Integer grassColor = 0;
|
||||
|
||||
@Value("colors.foliage")
|
||||
@Value("minecraft.colors.fog")
|
||||
@Default
|
||||
private Integer foliageColor = null;
|
||||
private Integer fogColor = 0;
|
||||
|
||||
@Value("colors.sky")
|
||||
@Value("minecraft.colors.water")
|
||||
@Default
|
||||
private Integer skyColor = null;
|
||||
private Integer waterColor = 0;
|
||||
|
||||
@Value("colors.modifier")
|
||||
@Value("minecraft.colors.water-fog")
|
||||
@Default
|
||||
private GrassColorModifier grassColorModifier = null;
|
||||
private Integer waterFogColor = 0;
|
||||
|
||||
@Value("particles")
|
||||
@Value("minecraft.colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = 0;
|
||||
|
||||
@Value("minecraft.colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = 0;
|
||||
|
||||
@Value("minecraft.colors.modifier")
|
||||
@Default
|
||||
private GrassColorModifier grassColorModifier = GrassColorModifier.NONE;
|
||||
|
||||
@Value("minecraft.particles")
|
||||
@Default
|
||||
private BiomeParticleConfig particleConfig = null;
|
||||
|
||||
@Value("climate.precipitation")
|
||||
@Value("minecraft.climate.precipitation")
|
||||
@Default
|
||||
private Precipitation precipitation = null;
|
||||
private Precipitation precipitation = Precipitation.NONE;
|
||||
|
||||
@Value("climate.temperature")
|
||||
@Value("minecraft.climate.temperature")
|
||||
@Default
|
||||
private Float temperature = null;
|
||||
private Float temperature = 0.0f;
|
||||
|
||||
@Value("climate.temperature-modifier")
|
||||
@Value("minecraft.climate.temperature-modifier")
|
||||
@Default
|
||||
private TemperatureModifier temperatureModifier = null;
|
||||
private TemperatureModifier temperatureModifier = TemperatureModifier.NONE;
|
||||
|
||||
@Value("climate.downfall")
|
||||
@Value("minecraft.climate.downfall")
|
||||
@Default
|
||||
private Float downfall = null;
|
||||
private Float downfall = 0.0f;
|
||||
|
||||
@Value("sound.loop-sound.sound")
|
||||
@Value("minecraft.sound.loop-sound.sound")
|
||||
@Default
|
||||
private SoundEvent loopSound = null;
|
||||
|
||||
@Value("sound.mood-sound")
|
||||
@Value("minecraft.sound.mood-sound")
|
||||
@Default
|
||||
private BiomeMoodSound moodSound = null;
|
||||
|
||||
@Value("sound.additions-sound")
|
||||
@Value("minecraft.sound.additions-sound")
|
||||
@Default
|
||||
private BiomeAdditionsSound additionsSound = null;
|
||||
|
||||
@Value("sound.music")
|
||||
@Value("minecraft.sound.music")
|
||||
@Default
|
||||
private MusicSound music = null;
|
||||
|
||||
@Value("spawning")
|
||||
@Value("minecraft.spawning")
|
||||
@Default
|
||||
private SpawnSettings spawnSettings = null;
|
||||
private SpawnSettings spawnSettings = SpawnSettings.INSTANCE;
|
||||
|
||||
@Value("villager-type")
|
||||
@Value("minecraft.villager-type")
|
||||
@Default
|
||||
private VillagerType villagerType = null;
|
||||
|
||||
public Map<Identifier, FertilizableConfig> getFertilizables() {
|
||||
return fertilizables;
|
||||
}
|
||||
|
||||
public List<Identifier> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
.stream(pack.getBiomeProvider()
|
||||
.getBiomes()
|
||||
.spliterator(), false)
|
||||
.map(b -> biomes.getOrCreateEntry(((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate())));
|
||||
.map(b -> biomes.getOrCreateEntry(((ProtoPlatformBiome) b.getPlatformBiome().get()).getBiome())));
|
||||
this.biomeRegistry = biomes;
|
||||
this.pack = pack;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
.entryOf(((ProtoPlatformBiome) pack
|
||||
.getBiomeProvider()
|
||||
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(noiseSampler))
|
||||
.getPlatformBiome()).getDelegate()
|
||||
.getPlatformBiome().get()).getBiome()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.dfsek.terra.mod.CommonPlatform;
|
||||
MoveToHiveGoal.class,
|
||||
MoveToFlowerGoal.class
|
||||
})
|
||||
public class BeeMoveGoalsUnsynchronizedRandomAccessFix {
|
||||
public class BeeMoveGoalsUnsynchronizedRandomAccessFixMixin {
|
||||
@Redirect(method = "<init>",
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;random:Lnet/minecraft/util/math/random/Random;"))
|
||||
public Random redirectRandomAccess(World instance) {
|
||||
@@ -20,7 +20,7 @@ import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
* nether.
|
||||
*/
|
||||
@Mixin(NetherFossilStructure.class)
|
||||
public class NetherFossilOptimization {
|
||||
public class NetherFossilOptimizationMixin {
|
||||
@Inject(method = "getStructurePosition", at = @At("HEAD"), cancellable = true)
|
||||
public void injectFossilPositions(Context context, CallbackInfoReturnable<Optional<StructurePosition>> cir) {
|
||||
if(context.chunkGenerator() instanceof MinecraftChunkGeneratorWrapper) {
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.dfsek.terra.mod.mixin.gameplay;
|
||||
|
||||
|
||||
import net.minecraft.item.BoneMealItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
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 com.dfsek.terra.mod.util.FertilizableUtil;
|
||||
|
||||
|
||||
@Mixin(BoneMealItem.class)
|
||||
public class BoneMealItemMixin {
|
||||
private static final Identifier cooldownId = new Identifier("terra", "bone_meal_cooldown");
|
||||
|
||||
@Inject(method = "useOnFertilizable", at = @At("HEAD"), cancellable = true)
|
||||
private static void injectUseOnFertilizable(ItemStack stack, World world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
|
||||
if(world instanceof ServerWorld) {
|
||||
Boolean value = FertilizableUtil.grow((ServerWorld) world, pos, world.getBlockState(pos), cooldownId);
|
||||
stack.decrement(1);
|
||||
if(value != null) {
|
||||
cir.setReturnValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.dfsek.terra.mod.mixin.gameplay;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.ai.brain.task.BoneMealTask;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
import com.dfsek.terra.mod.config.FertilizableConfig;
|
||||
import com.dfsek.terra.mod.util.BiomeUtil;
|
||||
|
||||
|
||||
@Mixin(BoneMealTask.class)
|
||||
public class BoneMealTaskMixin {
|
||||
|
||||
@Inject(method = "canBoneMeal", at = @At("HEAD"), cancellable = true)
|
||||
public void injectCanBoneMeal(BlockPos pos, ServerWorld world, CallbackInfoReturnable<Boolean> cir) {
|
||||
Map<Identifier, FertilizableConfig> map = BiomeUtil.TERRA_BIOME_FERTILIZABLE_MAP.get(world.getBiome(pos));
|
||||
if(map != null) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
FertilizableConfig config = map.get(Registry.BLOCK.getId(block));
|
||||
if(config != null) {
|
||||
Boolean villagerFertilizable = config.isVillagerFertilizable();
|
||||
if(villagerFertilizable != null) {
|
||||
if(villagerFertilizable) {
|
||||
ConfiguredStructure canGrow = config.getCanGrow();
|
||||
if(canGrow != null) {
|
||||
Random random = (Random) world.getRandom();
|
||||
cir.setReturnValue(canGrow.getStructure().get(random).generate(
|
||||
Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE));
|
||||
return;
|
||||
}
|
||||
cir.setReturnValue(true);
|
||||
return;
|
||||
}
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.dfsek.terra.mod.mixin.gameplay;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import com.dfsek.terra.mod.util.FertilizableUtil;
|
||||
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public class ServerWorldMixin {
|
||||
private static final Identifier cooldownId = new Identifier("terra", "random_cooldown");
|
||||
|
||||
@Redirect(method = "tickChunk",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/BlockState;randomTick(Lnet/minecraft/server/world/ServerWorld;" +
|
||||
"Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/random/Random;)V"))
|
||||
public void injectTickChunk(BlockState instance, ServerWorld serverWorld, BlockPos blockPos, Random random) {
|
||||
Boolean value = FertilizableUtil.grow(serverWorld, blockPos, instance, cooldownId);
|
||||
if(value != null) {
|
||||
if(!value) {
|
||||
instance.randomTick(serverWorld, blockPos, random);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setDelay(int delay) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMinSpawnDelay() {
|
||||
@@ -70,7 +70,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setMinSpawnDelay(int delay) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMaxSpawnDelay() {
|
||||
@@ -78,7 +78,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setMaxSpawnDelay(int delay) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int terra$getSpawnCount() {
|
||||
@@ -86,7 +86,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setSpawnCount(int spawnCount) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMaxNearbyEntities() {
|
||||
@@ -94,7 +94,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setMaxNearbyEntities(int maxNearbyEntities) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int terra$getRequiredPlayerRange() {
|
||||
@@ -102,7 +102,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setRequiredPlayerRange(int requiredPlayerRange) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int terra$getSpawnRange() {
|
||||
@@ -110,7 +110,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
}
|
||||
|
||||
public void terra$setSpawnRange(int spawnRange) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void terra$applyState(String state) {
|
||||
|
||||
@@ -9,7 +9,6 @@ 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.mod.util.MinecraftUtil;
|
||||
import com.dfsek.terra.mod.util.TagUtil;
|
||||
|
||||
|
||||
@@ -24,6 +23,5 @@ public class DataPackContentsMixin {
|
||||
|
||||
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(Registry.BIOME_KEY);
|
||||
TagUtil.registerBiomeTags(biomeRegistry);
|
||||
MinecraftUtil.registerFlora(biomeRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import net.minecraft.tag.TagKey;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.config.FertilizableConfig;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
|
||||
|
||||
public class BiomeUtil {
|
||||
public static final Map<RegistryEntry<net.minecraft.world.biome.Biome>, Map<Identifier, FertilizableConfig>>
|
||||
TERRA_BIOME_FERTILIZABLE_MAP = new HashMap<>();
|
||||
public static final Map<TagKey<net.minecraft.world.biome.Biome>, List<Identifier>>
|
||||
TERRA_BIOME_TAG_MAP = new HashMap<>();
|
||||
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
|
||||
|
||||
public static void registerBiomes() {
|
||||
logger.info("Registering biomes...");
|
||||
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
pack.getCheckedRegistry(Biome.class)
|
||||
.forEach((id, biome) -> registerBiome(biome, pack, id));
|
||||
});
|
||||
logger.info("Terra biomes registered.");
|
||||
}
|
||||
|
||||
protected static RegistryKey<net.minecraft.world.biome.Biome> registerBiome(Identifier identifier,
|
||||
net.minecraft.world.biome.Biome biome) {
|
||||
BuiltinRegistries.add(BuiltinRegistries.BIOME,
|
||||
MinecraftUtil.registerKey(identifier)
|
||||
.getValue(),
|
||||
biome);
|
||||
return getBiomeKey(identifier);
|
||||
}
|
||||
|
||||
public static RegistryKey<net.minecraft.world.biome.Biome> getBiomeKey(Identifier identifier) {
|
||||
return BuiltinRegistries.BIOME.getKey(BuiltinRegistries.BIOME.get(identifier)).orElseThrow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
*/
|
||||
protected static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(vanillaBiomeProperties);
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
biome.setPlatformBiome(new ProtoPlatformBiome(identifier, registerBiome(identifier, minecraftBiome)));
|
||||
|
||||
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
|
||||
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), VillagerType.PLAINS));
|
||||
|
||||
TERRA_BIOME_FERTILIZABLE_MAP.put(RegistryEntry.of(minecraftBiome), vanillaBiomeProperties.getFertilizables());
|
||||
|
||||
for(Identifier tag : vanillaBiomeProperties.getTags()) {
|
||||
TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.of(Registry.BIOME_KEY, tag), new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
import com.dfsek.terra.mod.config.FertilizableConfig;
|
||||
|
||||
|
||||
public class FertilizableUtil {
|
||||
|
||||
private static final Random mojankRandom = new Random();
|
||||
|
||||
public static Boolean grow(ServerWorld world, BlockPos pos, BlockState state, Identifier cooldownId) {
|
||||
return grow(world, mojankRandom, pos, state, cooldownId);
|
||||
}
|
||||
|
||||
public static Boolean grow(ServerWorld world, Random random, BlockPos pos, BlockState state, Identifier cooldownId) {
|
||||
Map<Identifier, FertilizableConfig> map = BiomeUtil.TERRA_BIOME_FERTILIZABLE_MAP.get(world.getBiome(pos));
|
||||
if(map != null) {
|
||||
Block block = state.getBlock();
|
||||
FertilizableConfig config = map.get(Registry.BLOCK.getId(block));
|
||||
if(config != null) {
|
||||
ConfiguredStructure canGrow = config.getCanGrow();
|
||||
if(canGrow != null) {
|
||||
if(!canGrow.getStructure().get(random).generate(
|
||||
Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Double cooldown = config.getCooldowns().get(cooldownId);
|
||||
if(cooldown != null) {
|
||||
if(random.nextFloat() > cooldown) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
config.getStructures().get(random).getStructure().get(random).generate(
|
||||
Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,10 @@ import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.Builder;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -30,14 +26,11 @@ import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||
import com.dfsek.terra.api.block.entity.Sign;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.BiomeAccessor;
|
||||
import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
|
||||
|
||||
|
||||
public final class MinecraftUtil {
|
||||
public static final Logger logger = LoggerFactory.getLogger(MinecraftUtil.class);
|
||||
public static final Map<Identifier, List<Identifier>>
|
||||
TERRA_BIOME_MAP = new HashMap<>();
|
||||
|
||||
|
||||
private MinecraftUtil() {
|
||||
|
||||
@@ -61,107 +54,62 @@ public final class MinecraftUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerFlora(Registry<net.minecraft.world.biome.Biome> biomes) {
|
||||
logger.info("Injecting flora into Terra biomes...");
|
||||
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)));
|
||||
|
||||
}
|
||||
|
||||
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {
|
||||
return Map.copyOf(TERRA_BIOME_MAP);
|
||||
}
|
||||
|
||||
public static RegistryKey<Biome> registerKey(Identifier identifier) {
|
||||
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(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()))
|
||||
effects.waterColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterColor()))
|
||||
.waterFogColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterFogColor()))
|
||||
.fogColor(Objects.requireNonNull(vanillaBiomeProperties.getFogColor()))
|
||||
.skyColor(Objects.requireNonNull(vanillaBiomeProperties.getSkyColor()))
|
||||
.grassColorModifier(
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(),
|
||||
vanilla.getEffects().getGrassColorModifier()));
|
||||
Objects.requireNonNull(vanillaBiomeProperties.getGrassColorModifier()));
|
||||
|
||||
if(vanillaBiomeProperties.getFoliageColor() == null) {
|
||||
vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getFoliageColor() != null) {
|
||||
effects.foliageColor(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() == null) {
|
||||
vanilla.getEffects().getGrassColor().ifPresent(effects::grassColor);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getGrassColor() != null) {
|
||||
effects.grassColor(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getParticleConfig() == null) {
|
||||
vanilla.getEffects().getParticleConfig().ifPresent(effects::particleConfig);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getParticleConfig() != null) {
|
||||
effects.particleConfig(vanillaBiomeProperties.getParticleConfig());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getLoopSound() == null) {
|
||||
vanilla.getEffects().getLoopSound().ifPresent(effects::loopSound);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getLoopSound() != null) {
|
||||
effects.loopSound(vanillaBiomeProperties.getLoopSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getMoodSound() == null) {
|
||||
vanilla.getEffects().getMoodSound().ifPresent(effects::moodSound);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getMoodSound() != null) {
|
||||
effects.moodSound(vanillaBiomeProperties.getMoodSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getAdditionsSound() == null) {
|
||||
vanilla.getEffects().getAdditionsSound().ifPresent(effects::additionsSound);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getAdditionsSound() != null) {
|
||||
effects.additionsSound(vanillaBiomeProperties.getAdditionsSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getMusic() == null) {
|
||||
vanilla.getEffects().getMusic().ifPresent(effects::music);
|
||||
} else {
|
||||
if(vanillaBiomeProperties.getMusic() != null) {
|
||||
effects.music(vanillaBiomeProperties.getMusic());
|
||||
}
|
||||
|
||||
builder.precipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.getPrecipitation()));
|
||||
builder.precipitation(Objects.requireNonNull(vanillaBiomeProperties.getPrecipitation()));
|
||||
|
||||
builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getTemperature()));
|
||||
builder.temperature(Objects.requireNonNull(vanillaBiomeProperties.getTemperature()));
|
||||
|
||||
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.getDownfall()));
|
||||
builder.downfall(Objects.requireNonNull(vanillaBiomeProperties.getDownfall()));
|
||||
|
||||
builder.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(),
|
||||
((BiomeAccessor) ((Object) vanilla)).getWeather().temperatureModifier()));
|
||||
builder.temperatureModifier(Objects.requireNonNull(vanillaBiomeProperties.getTemperatureModifier()));
|
||||
|
||||
builder.spawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getSpawnSettings()));
|
||||
builder.spawnSettings(Objects.requireNonNull(vanillaBiomeProperties.getSpawnSettings()));
|
||||
|
||||
return builder
|
||||
.effects(effects.build())
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public final class TagUtil {
|
||||
@@ -51,44 +52,19 @@ public final class TagUtil {
|
||||
}
|
||||
|
||||
public static void registerBiomeTags(Registry<Biome> registry) {
|
||||
logger.info("Doing biome tag garbage....");
|
||||
logger.info("Doing data-driven biome tag garbage....");
|
||||
logger.info("who let this data drive?");
|
||||
Map<TagKey<Biome>, List<RegistryEntry<Biome>>> collect = tagsToMutableMap(registry);
|
||||
|
||||
MinecraftUtil
|
||||
.getTerraBiomeMap()
|
||||
.forEach((vb, terraBiomes) ->
|
||||
MinecraftUtil
|
||||
.getEntry(registry, vb)
|
||||
.ifPresentOrElse(
|
||||
vanilla -> terraBiomes
|
||||
.forEach(tb -> MinecraftUtil
|
||||
.getEntry(registry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
logger.debug(
|
||||
vanilla.getKey()
|
||||
.orElseThrow()
|
||||
.getValue() +
|
||||
" (vanilla for " +
|
||||
terra.getKey()
|
||||
.orElseThrow()
|
||||
.getValue() +
|
||||
": " +
|
||||
vanilla.streamTags()
|
||||
.toList());
|
||||
|
||||
vanilla.streamTags()
|
||||
.forEach(
|
||||
tag -> collect
|
||||
.computeIfAbsent(
|
||||
tag,
|
||||
t -> new ArrayList<>())
|
||||
.add(terra));
|
||||
},
|
||||
() -> logger.error(
|
||||
"No such biome: {}",
|
||||
tb))),
|
||||
() -> logger.error("No vanilla biome: {}", vb)));
|
||||
BiomeUtil.TERRA_BIOME_TAG_MAP.forEach((tag, biomeList) -> {
|
||||
collect.getOrDefault(tag, new ArrayList<>())
|
||||
.addAll(biomeList.stream()
|
||||
.map(registry::getOrEmpty)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(RegistryEntry::of)
|
||||
.toList());
|
||||
});
|
||||
|
||||
registry.clearTags();
|
||||
registry.populateTags(ImmutableMap.copyOf(collect));
|
||||
|
||||
@@ -9,8 +9,11 @@
|
||||
"access.StateAccessor",
|
||||
"access.StructureAccessorAccessor",
|
||||
"access.VillagerTypeAccessor",
|
||||
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFix",
|
||||
"fix.NetherFossilOptimization",
|
||||
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFixMixin",
|
||||
"fix.NetherFossilOptimizationMixin",
|
||||
"gameplay.BoneMealItemMixin",
|
||||
"gameplay.BoneMealTaskMixin",
|
||||
"gameplay.ServerWorldMixin",
|
||||
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
|
||||
"implementations.terra.BiomeMixin",
|
||||
"implementations.terra.HandleImplementationMixin",
|
||||
|
||||
@@ -15,6 +15,11 @@ dependencies {
|
||||
|
||||
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
|
||||
mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2")
|
||||
|
||||
modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) {
|
||||
exclude("net.fabricmc")
|
||||
exclude("net.fabricmc.fabric-api")
|
||||
}
|
||||
}
|
||||
|
||||
loom {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.lifecycle;
|
||||
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
|
||||
|
||||
public class LifecycleEntryPoint {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LifecycleEntryPoint.class);
|
||||
|
||||
protected static void initialize(String modName, LifecyclePlatform platform) {
|
||||
logger.info("Initializing Terra {} mod...", modName);
|
||||
|
||||
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
serverCommandSource -> (CommandSender) serverCommandSource,
|
||||
commandSender -> (ServerCommandSource) commandSender
|
||||
);
|
||||
|
||||
|
||||
manager.brigadierManager().setNativeNumberSuggestions(false);
|
||||
|
||||
platform.getEventManager().callEvent(new CommandRegistrationEvent(manager));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.lifecycle;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.slf4j.Logger;
|
||||
@@ -10,13 +11,14 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.lifecycle.util.BiomeUtil;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.mod.util.BiomeUtil;
|
||||
|
||||
|
||||
public abstract class LifecyclePlatform extends ModPlatform {
|
||||
@@ -84,5 +86,19 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
return addons;
|
||||
}
|
||||
|
||||
protected Stream<EphemeralAddon> parseModData(String id, String modVersion) {
|
||||
if(id.equals("terra") || id.equals("minecraft") || id.equals("java")) return Stream.empty();
|
||||
try {
|
||||
Version version = Versions.parseVersion(modVersion);
|
||||
return Stream.of(new EphemeralAddon(version, "quilt:" + id));
|
||||
} catch(ParseException e) {
|
||||
LOGGER.warn(
|
||||
"Mod {}, version {} does not follow semantic versioning specification, Terra addons will be unable to depend on " +
|
||||
"it.",
|
||||
id, modVersion);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
protected abstract Collection<BaseAddon> getPlatformMods();
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
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;
|
||||
|
||||
|
||||
public final class BiomeUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
|
||||
|
||||
private BiomeUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static void registerBiomes() {
|
||||
logger.info("Registering biomes...");
|
||||
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
pack.getCheckedRegistry(Biome.class)
|
||||
.forEach((id, biome) -> registerBiome(biome, pack, id));
|
||||
});
|
||||
MinecraftUtil.registerFlora(BuiltinRegistries.BIOME);
|
||||
logger.info("Terra biomes registered.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
*/
|
||||
private static void registerBiome(Biome biome, ConfigPack pack,
|
||||
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);
|
||||
|
||||
|
||||
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, registry.get(vanilla),
|
||||
vanillaBiomeProperties);
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
if(registry.containsId(identifier)) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(MinecraftUtil.getEntry(registry, identifier)
|
||||
.orElseThrow()
|
||||
.getKey()
|
||||
.orElseThrow());
|
||||
} else {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry,
|
||||
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)));
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,11 +4,12 @@ import net.minecraft.util.registry.BuiltinRegistries;
|
||||
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.util.BiomeUtil;
|
||||
|
||||
|
||||
public final class LifecycleUtil {
|
||||
private LifecycleUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
public abstract class LoaderUtil {
|
||||
public static LoaderUtil INSTANCE;
|
||||
|
||||
public abstract String mapClassName(String namespace, String className);
|
||||
|
||||
public abstract String mapMethodName(String namespace, String owner, String name, String descriptor);
|
||||
}
|
||||
@@ -15,7 +15,6 @@ dependencies {
|
||||
annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}")
|
||||
annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}")
|
||||
|
||||
|
||||
implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
"developmentQuilt"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionQuilt")) { isTransitive = false }
|
||||
|
||||
@@ -23,12 +23,12 @@ public final class AwfulQuiltHacks {
|
||||
} catch(ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to load Classloader fields", e);
|
||||
}
|
||||
|
||||
|
||||
ADD_URL_METHOD = tempAddUrlMethod;
|
||||
}
|
||||
|
||||
|
||||
private AwfulQuiltHacks() { }
|
||||
|
||||
|
||||
/**
|
||||
* Hackily load the package which a mixin may exist within.
|
||||
* <p>
|
||||
|
||||
@@ -5,11 +5,11 @@ import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
|
||||
public class QuiltAddon extends MinecraftAddon {
|
||||
|
||||
|
||||
public QuiltAddon(ModPlatform modPlatform) {
|
||||
super(modPlatform);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-quilt";
|
||||
|
||||
@@ -17,36 +17,17 @@
|
||||
|
||||
package com.dfsek.terra.quilt;
|
||||
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import org.quiltmc.loader.api.ModContainer;
|
||||
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
import com.dfsek.terra.lifecycle.LifecycleEntryPoint;
|
||||
|
||||
|
||||
public class QuiltEntryPoint implements ModInitializer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(QuiltEntryPoint.class);
|
||||
|
||||
public class QuiltEntryPoint extends LifecycleEntryPoint implements ModInitializer {
|
||||
private static final QuiltPlatform TERRA_PLUGIN = new QuiltPlatform();
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize(ModContainer container) {
|
||||
logger.info("Initializing Terra Quilt mod...");
|
||||
|
||||
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
serverCommandSource -> (CommandSender) serverCommandSource,
|
||||
commandSender -> (ServerCommandSource) commandSender
|
||||
);
|
||||
|
||||
|
||||
manager.brigadierManager().setNativeNumberSuggestions(false);
|
||||
|
||||
TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(manager));
|
||||
initialize("Quilt", TERRA_PLUGIN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,43 +17,23 @@
|
||||
|
||||
package com.dfsek.terra.quilt;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.quiltmc.loader.api.QuiltLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
|
||||
public class QuiltPlatform extends LifecyclePlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(QuiltPlatform.class);
|
||||
|
||||
@Override
|
||||
protected Collection<BaseAddon> getPlatformMods() {
|
||||
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 {
|
||||
Version version = Versions.parseVersion(mod.metadata().version().raw());
|
||||
return Stream.of(new EphemeralAddon(version, "quilt:" + id));
|
||||
} catch(ParseException e) {
|
||||
LOGGER.warn(
|
||||
"Mod {}, version {} does not follow semantic versioning specification, Terra addons will be unable to depend on " +
|
||||
"it.",
|
||||
id, mod.metadata().version().raw());
|
||||
}
|
||||
return Stream.empty();
|
||||
}).collect(Collectors.toList());
|
||||
return QuiltLoader.getAllMods().stream().flatMap(mod -> parseModData(mod.metadata().id(), mod.metadata().version().raw())).collect(
|
||||
Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user