mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 08:40:26 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5354cdebf6 | |||
| 66758859bb |
@@ -7,7 +7,7 @@ to your specifications, with no knowledge of Java required.
|
||||
|
||||
* Paper+ servers (Paper, Tuinity, Purpur, etc): [SpigotMC](https://www.spigotmc.org/resources/85151/)
|
||||
* Fabric: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
|
||||
* Forge **(ALPHA - NOT PRODUCTION-READY)**: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
|
||||
* Forge: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
|
||||
|
||||
## Building and Running Terra
|
||||
|
||||
@@ -32,15 +32,15 @@ To run Minecraft with Terra in the IDE (for testing) use the following tasks:
|
||||
* `runPaper` - Run the Paper test server with Terra (`installPaper` must have been run previously).
|
||||
* `runPurpur` - Run the Purpur test server with Terra (`installPurpur` must have been run previously).
|
||||
* Fabric
|
||||
* `runClient` - Run a Minecraft Fabric client with Terra installed.
|
||||
* `runServer` - Run a Minecraft Fabric server with Terra installed.
|
||||
* `runClient` - Run a Minecraft client with Terra installed.
|
||||
* `runServer` - Run a Minecraft server with Terra installed.
|
||||
* Forge
|
||||
* `runClient` - Run a Minecraft Forge client with Terra installed.
|
||||
* `runServer` - Run a Minecraft Forge server with Terra installed.
|
||||
* `runClient` - Run a Minecraft client with Terra installed.
|
||||
* `runServer` - Run a Minecraft server with Terra installed.
|
||||
## Contributing
|
||||
Contributions are welcome! If you want to see a feature in Terra, please, open an issue, or implement it yourself and
|
||||
submit a PR!
|
||||
Join the discord [here](https://discord.gg/PXUEbbF) if you would like to talk more about the project!
|
||||
|
||||
## Beta
|
||||
Terra is still in beta! While it is stable, it is not feature-complete. There is a lot to be added!
|
||||
Terra is still in beta! While it is stable, it is not feature-complete. There is a lot to be added!
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.getGitHash
|
||||
|
||||
val versionObj = Version("5", "3", "3", true)
|
||||
val versionObj = Version("5", "3", "1", true)
|
||||
|
||||
allprojects {
|
||||
version = versionObj
|
||||
|
||||
@@ -29,12 +29,7 @@ fun Project.configureCompilation() {
|
||||
include("**/*.*")
|
||||
filter<org.apache.tools.ant.filters.ReplaceTokens>(
|
||||
"tokens" to mapOf(
|
||||
"VERSION" to project.version.toString(),
|
||||
"DESCRIPTION" to project.properties["terra.description"],
|
||||
"WIKI" to project.properties["terra.wiki"],
|
||||
"SOURCE" to project.properties["terra.source"],
|
||||
"ISSUES" to project.properties["terra.issues"],
|
||||
"LICENSE" to project.properties["terra.license"]
|
||||
"VERSION" to project.version.toString()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+1
-18
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
@@ -10,28 +8,13 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
||||
*/
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent {
|
||||
private final ConfigPack pack;
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
|
||||
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||
public ConfigPackLoadEvent(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
}
|
||||
|
||||
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||
void accept(T value) throws ConfigException;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,13 +1,12 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called when a config pack has finished loading.
|
||||
*/
|
||||
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> loader) {
|
||||
super(pack, loader);
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,14 +1,12 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
|
||||
*/
|
||||
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||
super(pack, configLoader);
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.transform;
|
||||
|
||||
public class NotNullValidator<T> implements Validator<T> {
|
||||
@Override
|
||||
public boolean validate(T value) {
|
||||
return !(value == null);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.dfsek.terra.api.transform;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public interface Validator<T> {
|
||||
boolean validate(T value) throws TransformException;
|
||||
|
||||
static <T> Validator<T> notNull() {
|
||||
return Objects::nonNull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ public class MutableInteger extends MutableNumber<Integer> {
|
||||
add(1);
|
||||
}
|
||||
|
||||
public void addMod(int add, int mod) {
|
||||
add(add);
|
||||
value %= mod;
|
||||
}
|
||||
|
||||
public void decrement() {
|
||||
subtract(1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.dfsek.terra.config.builder;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.world.generation.WorldGenerator;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneratorBuilder {
|
||||
private final Map<Long, WorldGenerator> gens = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private String noiseEquation;
|
||||
|
||||
private String elevationEquation;
|
||||
|
||||
private String carvingEquation;
|
||||
|
||||
private Scope varScope;
|
||||
|
||||
private Map<String, NoiseSeeded> noiseBuilderMap;
|
||||
|
||||
private Map<String, FunctionTemplate> functionTemplateMap;
|
||||
|
||||
private PaletteHolder palettes;
|
||||
|
||||
private PaletteHolder slantPalettes;
|
||||
|
||||
private boolean preventInterpolation;
|
||||
|
||||
private boolean interpolateElevation;
|
||||
|
||||
private NoiseSeeded biomeNoise;
|
||||
|
||||
private double elevationWeight;
|
||||
|
||||
private int blendDistance;
|
||||
|
||||
private int blendStep;
|
||||
|
||||
private double blendWeight;
|
||||
|
||||
public WorldGenerator build(long seed) {
|
||||
synchronized(gens) {
|
||||
return gens.computeIfAbsent(seed, k -> {
|
||||
NoiseSampler noise;
|
||||
NoiseSampler elevation;
|
||||
NoiseSampler carving;
|
||||
try {
|
||||
noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
elevation = elevationEquation == null ? new ConstantSampler(0) : new ExpressionSampler(elevationEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
carving = new ExpressionSampler(carvingEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
} catch(ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new WorldGenerator(palettes, slantPalettes, noise, elevation, carving, biomeNoise.apply(seed), elevationWeight, blendDistance, blendStep, blendWeight);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlendWeight(double blendWeight) {
|
||||
this.blendWeight = blendWeight;
|
||||
}
|
||||
|
||||
public void setFunctionTemplateMap(Map<String, FunctionTemplate> functionTemplateMap) {
|
||||
this.functionTemplateMap = functionTemplateMap;
|
||||
}
|
||||
|
||||
public void setBlendStep(int blendStep) {
|
||||
this.blendStep = blendStep;
|
||||
}
|
||||
|
||||
public void setBlendDistance(int blendDistance) {
|
||||
this.blendDistance = blendDistance;
|
||||
}
|
||||
|
||||
public void setBiomeNoise(NoiseSeeded biomeNoise) {
|
||||
this.biomeNoise = biomeNoise;
|
||||
}
|
||||
|
||||
public void setElevationWeight(double elevationWeight) {
|
||||
this.elevationWeight = elevationWeight;
|
||||
}
|
||||
|
||||
public void setNoiseEquation(String noiseEquation) {
|
||||
this.noiseEquation = noiseEquation;
|
||||
}
|
||||
|
||||
public void setElevationEquation(String elevationEquation) {
|
||||
this.elevationEquation = elevationEquation;
|
||||
}
|
||||
|
||||
public void setCarvingEquation(String carvingEquation) {
|
||||
this.carvingEquation = carvingEquation;
|
||||
}
|
||||
|
||||
public Scope getVarScope() {
|
||||
return varScope;
|
||||
}
|
||||
|
||||
public void setVarScope(Scope varScope) {
|
||||
this.varScope = varScope;
|
||||
}
|
||||
|
||||
public void setNoiseBuilderMap(Map<String, NoiseSeeded> noiseBuilderMap) {
|
||||
this.noiseBuilderMap = noiseBuilderMap;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalettes() {
|
||||
return palettes;
|
||||
}
|
||||
|
||||
public void setPalettes(PaletteHolder palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
public PaletteHolder getSlantPalettes() {
|
||||
return slantPalettes;
|
||||
}
|
||||
|
||||
public void setSlantPalettes(PaletteHolder slantPalettes) {
|
||||
this.slantPalettes = slantPalettes;
|
||||
}
|
||||
|
||||
public boolean isPreventInterpolation() {
|
||||
return preventInterpolation;
|
||||
}
|
||||
|
||||
public void setPreventInterpolation(boolean preventInterpolation) {
|
||||
this.preventInterpolation = preventInterpolation;
|
||||
}
|
||||
|
||||
public void setInterpolateElevation(boolean interpolateElevation) {
|
||||
this.interpolateElevation = interpolateElevation;
|
||||
}
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
@@ -111,8 +110,6 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
private final TerraPlugin main;
|
||||
private final Loader loader;
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||
|
||||
|
||||
@@ -133,15 +130,11 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
try {
|
||||
configuration = new Configuration(new FileInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
selfLoader.load(template, new FileInputStream(pack));
|
||||
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, new FileInputStream(pack));
|
||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||
@@ -181,12 +174,9 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
|
||||
|
||||
configuration = new Configuration(file.getInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
selfLoader.load(template, file.getInputStream(pack));
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
@@ -221,6 +211,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
|
||||
private void load(long start, TerraPlugin main) throws ConfigException {
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this));
|
||||
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey(), var.getValue());
|
||||
}
|
||||
@@ -253,7 +245,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this));
|
||||
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TerraWorld {
|
||||
double noise = sampler.sample(fdX, y, fdZ);
|
||||
if(noise > 0) {
|
||||
int level = 0;
|
||||
for(int yi = world.getMaxHeight()-1; yi > y; yi--) {
|
||||
for(int yi = world.getMaxHeight(); yi > y; yi--) {
|
||||
if(sampler.sample(fdX, yi, fdZ) > 0) level++;
|
||||
else level = 0;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ cache:
|
||||
carver: 512
|
||||
structure: 32
|
||||
sampler: 128
|
||||
biome-provider: 32
|
||||
master-disable:
|
||||
caves: false
|
||||
script:
|
||||
max-recursion: 1000
|
||||
@@ -1,122 +0,0 @@
|
||||
enable:
|
||||
- "Pokud se vám líbí Terra, můžete nás podpořit na Patreon!"
|
||||
- "Získáte přístup k experimentálním funkcím, než budou vydány!"
|
||||
- "Podpořit projekt můžete zde: https://www.patreon.com/dfsek"
|
||||
disable:
|
||||
- "Děkujeme, že používáte Terra!"
|
||||
command:
|
||||
debug-only: "Tento příkaz musí být použit se zapnutým debug modem!"
|
||||
player-only: "Tento příkaz je pouze pro hráče!"
|
||||
invalid: "Neznámý příkaz. (Očekáváno %1$s argumentů, nalezeno %2$s)."
|
||||
players-only: "Příkaz je pouze pro použití hráčem."
|
||||
world: "Tento příkaz musí být použit v Terra světě!"
|
||||
reload: "Obnoven Terra konfig."
|
||||
reload-error: "Nastaly chyby při obnově Terra konfigurace. Podívejte se do logů pro více informací."
|
||||
version: "Na tomto serveru běží Terra verze \"%1$s\", na platformě \"%2$s\""
|
||||
main-menu:
|
||||
- "--------------------Terra--------------------"
|
||||
- "reload - Obnoví konfigurační data"
|
||||
- "biome - Ukáže aktuální biom"
|
||||
- "ore - Generuje žílu rud v lokaci, ve směru kam se koukáte (Pro debugging)"
|
||||
- "save-data - Uložit populační data"
|
||||
- "structure - Nahrát a exportovat struktury"
|
||||
- "profile - Profiler možnosti"
|
||||
- "image - Obrázek/GUI možnosti"
|
||||
biome:
|
||||
biome-found: "Lokalizován biom na (%1$s, %2$s)"
|
||||
unable-to-locate: "Nelze lokalizovat biom."
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid: "Nesprávné ID bomu: \"%s\""
|
||||
in: "Jste v \"%s\""
|
||||
packs:
|
||||
main: "Aktuální instalované konfigurační balíčky:"
|
||||
pack: " - %1$s v%3$s od %2$s"
|
||||
none: "Žádné konfigurační balíčky nejsou nainstalovány."
|
||||
ore:
|
||||
main-menu:
|
||||
- "---------------Terra/ore---------------"
|
||||
- "Generuje žílu rud na bloku, na který koukáte."
|
||||
out-of-range: "Blok mimo dosah"
|
||||
invalid-ore: "Nelze nalézt Rudu \"%s\""
|
||||
geometry:
|
||||
main-menu:
|
||||
- "---------------Terra/geometry----------------"
|
||||
- "Různé voxel geometrické debugging příkazy"
|
||||
- "sphere - Generuje kouli"
|
||||
- "deformsphere - Generuje deformovanou kouli"
|
||||
- "tube - Generuje válec"
|
||||
deform:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid-deform: "Nesprávná deformace: \"%s\""
|
||||
invalid-frequency: "Nesprávná frekvence: \"%s\""
|
||||
sphere:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
tube:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
image:
|
||||
main-menu:
|
||||
- "---------------Terra/image---------------"
|
||||
- "render - Vykreslí obrázek s danou šířkou a výškou, který může být později importován jako svět."
|
||||
- "gui - Otevřít debug GUI (Musí být zapnuto v konfigu)"
|
||||
gui:
|
||||
main-menu:
|
||||
- "-------------Terra/image/gui-------------"
|
||||
- "raw - Otevře GUI s raw Biom daty"
|
||||
- "step - Znovu vykreslí data k lepšímu zobrazení borderu"
|
||||
debug: "Debug mod musí být zapnutý pro použití této možnosti! Debug GUI NENÍ PRODUKČNĚ BEZPEČNÉ!"
|
||||
render:
|
||||
save: "Uložen obrázek jako \"%s\""
|
||||
error: "Nastala chyba při generování obrázku!"
|
||||
profile:
|
||||
main-menu:
|
||||
- "---------------Terra/profile---------------"
|
||||
- "start - Zapne profiler"
|
||||
- "stop - Vypne profiler"
|
||||
- "query - Ukáže profiler data"
|
||||
- "reset - Resetuje profiler data"
|
||||
reset: "Profiler byl resetován."
|
||||
start: "Profiler byl zapnut."
|
||||
stop: "Profiler byl vypnut."
|
||||
structure:
|
||||
main-menu:
|
||||
- "---------------Terra/structure---------------"
|
||||
- "export - Export vašeho výběru WorldEdit jako Terra struktura."
|
||||
- "load - Načíst Terra strukturu"
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid-rotation: "Nesprávná rotace: \"%s\""
|
||||
invalid: "Nesprávné ID struktury: \"%s\""
|
||||
export: "Uložena struktura do \"%s\""
|
||||
world-config:
|
||||
load: "Načteny konfigurační hodnoty světa pro svět \"%s\"..."
|
||||
not-found: "Konfigurace pro svět \"%s\" nenalezena. Kopíruji defaultní konfig."
|
||||
using-image: "Načítám svět z obrázku."
|
||||
error: "Nelze načíst konfigurace pro svět %s"
|
||||
done: "Načítání světa \"%1$s\" dokončeno. Uplynulý čas: %2$sms"
|
||||
config-pack:
|
||||
loaded: "Konfigurační balíček %1$s v%4$s od %3$s byl načten za %2$sms."
|
||||
config:
|
||||
loaded: "Načten %1$s ze souboru %2$s"
|
||||
loaded-all: "Načteno %1$s %2$s(s) za %3$sms."
|
||||
error:
|
||||
invalid-failover: "Nesprávný typ failover: \"%s\""
|
||||
duplicate: "Duplikační ID nalezeno v souboru: %s"
|
||||
file:
|
||||
- "Konfigurační chyba pro Terra objekt. Soubor: %1$s"
|
||||
- "%2$s"
|
||||
- "Opravte jej před pokračováním!"
|
||||
generic:
|
||||
- "Nastala chyba při načítání konfigurace."
|
||||
- "Prosíme nahlašte to na Terra."
|
||||
warning:
|
||||
no-population: "Žádné populační chunky nebyly načteny. Pokud je to poprvé, co zapínáte server s Terra, či vytváříte nový svět, je tohle normální."
|
||||
error:
|
||||
severe-config: "Vážná konfigurační chyba zabránila Terra ze správné generace terénu na koordinátech: %1$s, %2$s. Prosíme zkontrolujte konfiguraci pro chyby. Jakékoli konfigurační chyby jsou vypsány výše."
|
||||
debug:
|
||||
data-save : "Uložena populační data."
|
||||
use-paper:
|
||||
- "Vypadá to, že používáte Spigot/CraftBukkit."
|
||||
- "Ačkoli Terra &ofunguje&r na Spigot, některé funkce budou ztraceny. (Terra je netestována na CraftBukkit; žádná podpora nebude dána pro CraftBukkit)."
|
||||
- "Pro nejvíce funkcí s Terra, použijte Paper."
|
||||
- "Navíc, Paper přináší obrovské výkonnostní zlepešení než Spigot, a všechny Spigot pluginy by měli fungovat s Paper!"
|
||||
- "Pro nejlepší zážitek s Terra a všemi pluginy, použijte prosím Paper."
|
||||
- "Více info najdete na stránce Paperu: https://papermc.io/"
|
||||
+1
-6
@@ -7,9 +7,4 @@ org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.warning.mode=all
|
||||
#org.gradle.logging.level=info
|
||||
# Project information
|
||||
terra.description=A fast, modern, extensible, platform-agnostic data-driven world generator
|
||||
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=GNU General Public License, version 3.0
|
||||
org.gradle.configureondemand=true
|
||||
|
||||
@@ -19,6 +19,7 @@ public class PaperListener implements Listener {
|
||||
@EventHandler
|
||||
public void onStructureLocate(StructureLocateEvent e) {
|
||||
if(!BukkitAdapter.adapt(e.getWorld()).isTerraWorld()) return;
|
||||
e.setResult(null); // Assume no result.
|
||||
String name = "minecraft:" + e.getType().getName();
|
||||
main.getDebugLogger().info("Overriding structure location for \"" + name + "\"");
|
||||
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld()));
|
||||
@@ -31,8 +32,10 @@ public class PaperListener implements Listener {
|
||||
}, main);
|
||||
finder.run(); // Do this synchronously.
|
||||
} else {
|
||||
e.setResult(e.getOrigin());
|
||||
main.logger().warning("No overrides are defined for \"" + name + "\". Locating this structure will NOT work properly!");
|
||||
main.logger().warning("No overrides are defined for \"" + name + "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,16 @@ main: "com.dfsek.terra.bukkit.TerraBukkitPlugin"
|
||||
version: "@VERSION@"
|
||||
load: "STARTUP"
|
||||
author: dfsek
|
||||
website: "@WIKI@"
|
||||
api-version: "1.13"
|
||||
description: "@DESCRIPTION@"
|
||||
description: "An insanely powerful free & open-source data-driven world generator."
|
||||
softdepend: [ "WorldEdit" ]
|
||||
commands:
|
||||
terra:
|
||||
description: "Terra base command"
|
||||
usage: "/terra "
|
||||
aliases: [ "te" ]
|
||||
permission: "terra.command"
|
||||
permission: "terra.command"
|
||||
locate:
|
||||
description: "Locate a Terra Structure"
|
||||
usage: "/locate <STRUCTURE_ID> <radius>"
|
||||
permission: "terra.locate"
|
||||
@@ -27,13 +27,7 @@ dependencies {
|
||||
"mappings"("net.fabricmc:yarn:1.16.5+build.5:v2")
|
||||
"modImplementation"("net.fabricmc:fabric-loader:0.11.2")
|
||||
|
||||
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
|
||||
exclude(group = "com.google.guava", module = "guava")
|
||||
exclude(group = "com.google.code.gson", module = "gson")
|
||||
exclude(group = "it.unimi.dsi", module = "fastutil")
|
||||
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
|
||||
exclude(group = "org.apache.logging.log4j", module = "log4j-core")
|
||||
}
|
||||
"modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16")
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.Axis;
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
@@ -11,136 +8,149 @@ import com.dfsek.terra.api.addons.annotations.Author;
|
||||
import com.dfsek.terra.api.addons.annotations.Version;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.TerraCommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.transform.NotNullValidator;
|
||||
import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.api.transform.Validator;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.config.DimensionConfig;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.handle.FabricItemHandle;
|
||||
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.GeneratorOptions;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.NopeDecoratorConfig;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeatures;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.FeatureConfig;
|
||||
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
|
||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
|
||||
|
||||
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
|
||||
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
|
||||
private static TerraFabricPlugin instance;
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
|
||||
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
}
|
||||
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final Logger logger = new Logger() {
|
||||
private final org.apache.logging.log4j.Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
log4jLogger.info(message);
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(String message) {
|
||||
log4jLogger.warn(message);
|
||||
logger.warn(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String message) {
|
||||
log4jLogger.error(message);
|
||||
logger.error(message);
|
||||
}
|
||||
};
|
||||
|
||||
private final DebugLogger debugLogger = new DebugLogger(logger);
|
||||
private final ItemHandle itemHandle = new FabricItemHandle();
|
||||
private final WorldHandle worldHandle = new FabricWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final FabricAddon fabricAddon = new FabricAddon(this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(fabricAddon, this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new FabricAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
|
||||
private final DimensionConfig dimensionConfig = new DimensionConfig();
|
||||
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), Validator.notNull())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), Validator.notNull()).build();
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
private File dataFolder;
|
||||
private final CommandManager manager = new TerraCommandManager(this);
|
||||
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static TerraFabricPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
@@ -148,12 +158,15 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((WorldAccess) world).getDimension());
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, ((FabricChunkGeneratorWrapper) world.getGenerator()).getPack(), this);
|
||||
});
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
public TerraWorld getWorld(long seed) {
|
||||
TerraWorld world = worldMap.get(seed);
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with seed " + seed);
|
||||
return world;
|
||||
}
|
||||
|
||||
@@ -174,7 +187,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,11 +210,14 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
worldMap.forEach((seed, pair) -> {
|
||||
pair.getRight().getConfig().getSamplerCache().clear();
|
||||
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||
Map<Long, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((seed, tw) -> {
|
||||
tw.getConfig().getSamplerCache().clear();
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@@ -235,30 +251,87 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
genericLoaders.register(registry);
|
||||
registry
|
||||
.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o))
|
||||
.registerLoader(Identifier.class, (t, o, l) -> {
|
||||
Identifier identifier = Identifier.tryParse((String) o);
|
||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
||||
return identifier;
|
||||
});
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o));
|
||||
}
|
||||
|
||||
private Biome createBiome(BiomeBuilder biome) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState()))); // It needs a surfacebuilder, even though we dont use it.
|
||||
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
} else {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.category(vanilla.getCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.effects(effects.build())
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public void packInit() {
|
||||
logger.info("Loading config packs...");
|
||||
registry.loadAll(this);
|
||||
|
||||
registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", FabricUtil.createBiomeID(pack, id)), FabricUtil.createBiome(fabricAddon, biome, pack)))); // Register all Terra biomes.
|
||||
registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", createBiomeID(pack, id)), createBiome(biome)))); // Register all Terra biomes.
|
||||
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.registerLoader(ConfigPack.class, registry);
|
||||
register(loader);
|
||||
try {
|
||||
logger.info("Loading dimension config...");
|
||||
loader.load(dimensionConfig, new FileInputStream(configFile));
|
||||
logger.info("Loaded " + dimensionConfig.getDimensionPacks().size() + " dimension overrides.");
|
||||
} catch(ConfigException | FileNotFoundException e) {
|
||||
throw new RuntimeException("Failed to load dimension config", e);
|
||||
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
registry.forEach(pack -> {
|
||||
|
||||
});
|
||||
|
||||
ConfigPack pack = registry.get("DEFAULT");
|
||||
final GeneratorType generatorType = new GeneratorType("terra") {
|
||||
@Override
|
||||
public TerraGeneratorOptions createDefaultOptions(DynamicRegistryManager.Impl registryManager, long seed, boolean generateStructures, boolean bonusChest) {
|
||||
Registry<Biome> registry = registryManager.get(Registry.BIOME_KEY);
|
||||
Registry<DimensionType> registry2 = registryManager.get(Registry.DIMENSION_TYPE_KEY);
|
||||
Registry<ChunkGeneratorSettings> registry3 = registryManager.get(Registry.NOISE_SETTINGS_WORLDGEN);
|
||||
|
||||
|
||||
return new TerraGeneratorOptions(seed, generateStructures, bonusChest, GeneratorOptions.method_28608(registry2, DimensionType.createDefaultDimensionOptions(registry2, registry, registry3, seed), this.getChunkGenerator(registry, registry3, seed)), registry, registry3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
};
|
||||
Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> screenProviderMap = new HashMap<>(GeneratorTypeAccessor.getScreenProviders());
|
||||
|
||||
screenProviderMap.put(Optional.of(generatorType), (screen, generatorOptions) -> new TerraOptionsScreen(screen, (TerraGeneratorOptions) generatorOptions));
|
||||
|
||||
GeneratorTypeAccessor.setScreenProviders(ImmutableMap.copyOf(screenProviderMap)); // jumping through hoops because ImmutableMap
|
||||
|
||||
GeneratorTypeAccessor.getValues().add(generatorType);
|
||||
}
|
||||
|
||||
logger.info("Loaded packs.");
|
||||
@@ -271,7 +344,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
this.dataFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
debugLogger.setDebug(config.isDebug());
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
@@ -281,22 +353,76 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "populator"));
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "flora_populator"));
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||
|
||||
CommandManager manager = new TerraCommandManager(this);
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, manager));
|
||||
}
|
||||
|
||||
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
|
||||
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
|
||||
//dispatcher.register(literal("te").redirect(root));
|
||||
}
|
||||
);
|
||||
logger.info("Finished initialization.");
|
||||
}
|
||||
|
||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EventManager getEventManager() {
|
||||
@@ -311,12 +437,10 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
@Addon("Terra-Fabric")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
private static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
|
||||
private FabricAddon(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
@@ -349,40 +473,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", ConfiguredFeatures.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
||||
try {
|
||||
event.getPack().getTreeRegistry().add(entry.getKey().getValue().toString(), (Tree) entry.getValue());
|
||||
main.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
@@ -392,9 +482,5 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
import com.dfsek.terra.fabric.mixin.access.SimpleRegistryAccessor;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.dimension.DimensionOptions;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.GeneratorOptions;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.Random;
|
||||
|
||||
public class TerraGeneratorOptions extends GeneratorOptions {
|
||||
private final Map<DimensionType, ImmutablePair<GeneratorType, ChunkGenerator>> override = new HashMap<>();
|
||||
private final Registry<Biome> biomeRegistry;
|
||||
private final Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry;
|
||||
|
||||
public TerraGeneratorOptions(long seed, boolean generateStructures, boolean bonusChest, SimpleRegistry<DimensionOptions> simpleRegistry,
|
||||
Registry<Biome> registry2, Registry<ChunkGeneratorSettings> registry3) {
|
||||
super(seed, generateStructures, bonusChest, simpleRegistry);
|
||||
System.out.println("Creating Terra options");
|
||||
Thread.dumpStack();
|
||||
this.biomeRegistry = registry2;
|
||||
this.chunkGeneratorSettingsRegistry = registry3;
|
||||
}
|
||||
|
||||
public Registry<ChunkGeneratorSettings> getChunkGeneratorSettingsRegistry() {
|
||||
return chunkGeneratorSettingsRegistry;
|
||||
}
|
||||
|
||||
public Registry<Biome> getBiomeRegistry() {
|
||||
return biomeRegistry;
|
||||
}
|
||||
|
||||
public void overrideChunkGenerator(DimensionType dimensionType, GeneratorType identifier, ChunkGenerator newGenerator) {
|
||||
override.put(dimensionType, ImmutablePair.of(identifier, newGenerator));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraGeneratorOptions toggleGenerateStructures() {
|
||||
return new TerraGeneratorOptions(getSeed(), !shouldGenerateStructures(), hasBonusChest(), getDimensions(), biomeRegistry, chunkGeneratorSettingsRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraGeneratorOptions toggleBonusChest() {
|
||||
return new TerraGeneratorOptions(getSeed(), shouldGenerateStructures(), !hasBonusChest(), getDimensions(), biomeRegistry, chunkGeneratorSettingsRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorOptions withHardcore(boolean hardcore, OptionalLong seed) {
|
||||
long l = seed.orElse(this.getSeed());
|
||||
SimpleRegistry<DimensionOptions> simpleRegistry2;
|
||||
if(seed.isPresent()) {
|
||||
simpleRegistry2 = new SimpleRegistry<>(Registry.DIMENSION_OPTIONS, Lifecycle.experimental());
|
||||
long longSeed = seed.getAsLong();
|
||||
|
||||
for(Map.Entry<RegistryKey<DimensionOptions>, DimensionOptions> registryKeyDimensionOptionsEntry : getDimensions().getEntries()) {
|
||||
RegistryKey<DimensionOptions> registryKey = registryKeyDimensionOptionsEntry.getKey();
|
||||
simpleRegistry2.add(registryKey, new DimensionOptions(registryKeyDimensionOptionsEntry.getValue().getDimensionTypeSupplier(), registryKeyDimensionOptionsEntry.getValue().getChunkGenerator().withSeed(longSeed)), getDimensions().getEntryLifecycle(registryKeyDimensionOptionsEntry.getValue()));
|
||||
}
|
||||
} else {
|
||||
simpleRegistry2 = getDimensions();
|
||||
}
|
||||
|
||||
GeneratorOptions generatorOptions2;
|
||||
|
||||
if(this.isDebugWorld()) {
|
||||
generatorOptions2 = new TerraGeneratorOptions(l, false, false, simpleRegistry2, biomeRegistry, chunkGeneratorSettingsRegistry);
|
||||
} else {
|
||||
generatorOptions2 = new TerraGeneratorOptions(l, this.shouldGenerateStructures(), hasBonusChest() && !hardcore, simpleRegistry2, biomeRegistry, chunkGeneratorSettingsRegistry);
|
||||
}
|
||||
|
||||
return generatorOptions2;
|
||||
}
|
||||
|
||||
public Map<DimensionType, ImmutablePair<GeneratorType, ChunkGenerator>> getOverrides() {
|
||||
return override;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getChunkGenerator() {
|
||||
System.out.println("Getting chunk generator");
|
||||
Thread.dumpStack();
|
||||
return super.getChunkGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleRegistry<DimensionOptions> getDimensions() {
|
||||
new SimpleRegistry<DimensionOptions>(Registry.DIMENSION_OPTIONS, Lifecycle.stable()) {
|
||||
@Nullable
|
||||
@Override
|
||||
public DimensionOptions get(int index) {
|
||||
DimensionOptions options = super.get(index);
|
||||
if(options == null) return null;
|
||||
return new DimensionOptionsOverride(options);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DimensionOptions get(@Nullable RegistryKey<DimensionOptions> key) {
|
||||
DimensionOptions options = super.get(key);
|
||||
if(options == null) return null;
|
||||
return new DimensionOptionsOverride(options);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DimensionOptions get(@Nullable Identifier id) {
|
||||
DimensionOptions options = super.get(id);
|
||||
if(options == null) return null;
|
||||
return new DimensionOptionsOverride(options);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DimensionOptions getRandom(Random random) {
|
||||
DimensionOptions options = super.getRandom(random);
|
||||
if(options == null) return null;
|
||||
return new DimensionOptionsOverride(options);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "ConstantConditions"})
|
||||
@Override
|
||||
public Iterator<DimensionOptions> iterator() {
|
||||
return Iterators.filter(((SimpleRegistryAccessor<DimensionOptions>) (Object) this).getRawIdToEntry().stream().map(DimensionOptionsOverride::new).map(dimensionOptionsOverride -> (DimensionOptions) dimensionOptionsOverride).iterator(), Objects::nonNull);
|
||||
}
|
||||
};
|
||||
return super.getDimensions();
|
||||
}
|
||||
|
||||
public final class DimensionOptionsOverride extends DimensionOptions {
|
||||
|
||||
public DimensionOptionsOverride(DimensionOptions options) {
|
||||
super(options.getDimensionTypeSupplier(), options.getChunkGenerator());
|
||||
System.out.println("Overriding " + getDimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getChunkGenerator() {
|
||||
ChunkGenerator overridden = override.get(getDimensionType()).getRight();
|
||||
if(overridden != null) return overridden;
|
||||
return super.getChunkGenerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonListWidget;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.options.CyclingOption;
|
||||
import net.minecraft.client.options.GameOptions;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TerraOptionsScreen extends Screen {
|
||||
private final Screen parent;
|
||||
private final List<GeneratorType> generatorList = new ArrayList<>();
|
||||
private final TerraGeneratorOptions terraGeneratorOptions;
|
||||
private ButtonListWidget buttonListWidget;
|
||||
|
||||
public TerraOptionsScreen(Screen parent, TerraGeneratorOptions terraGeneratorOptions) {
|
||||
super(new LiteralText("Terra Options"));
|
||||
this.parent = parent;
|
||||
this.terraGeneratorOptions = terraGeneratorOptions;
|
||||
generatorList.add(GeneratorType.DEFAULT);
|
||||
|
||||
TerraFabricPlugin.getInstance().getConfigRegistry().forEach(pack -> generatorList.add(new TempGeneratorType(pack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
addButton(new ButtonWidget(width / 2 - 60, height - 30, 120, 20, new TranslatableText("terra.screen.close"), btn -> client.openScreen(parent)));
|
||||
this.buttonListWidget = new ButtonListWidget(client, width - 20, height - 20, 32, height - 50, 25);
|
||||
|
||||
buttonListWidget.setLeftPos(10);
|
||||
|
||||
terraGeneratorOptions.getDimensions().getEntries().forEach((entry) -> buttonListWidget.addSingleOptionEntry(new GeneratorCycler(entry.getKey().getValue(), entry.getValue().getDimensionType())));
|
||||
|
||||
addChild(buttonListWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
this.buttonListWidget.render(matrices, mouseX, mouseY, delta);
|
||||
DrawableHelper.drawCenteredText(matrices, textRenderer, new TranslatableText("terra.config-screen"), width / 2, 20, 0xffffff);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
private static final class TempGeneratorType extends GeneratorType {
|
||||
private final ConfigPack pack;
|
||||
|
||||
protected TempGeneratorType(ConfigPack pack) {
|
||||
super("terra:" + pack.getTemplate().getID());
|
||||
this.pack = pack;
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) (Object) this).setTranslationKey(new LiteralText("Terra:" + this.pack.getTemplate().getID()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return pack.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof TempGeneratorType)) return false;
|
||||
return ((TempGeneratorType) obj).pack.equals(this.pack);
|
||||
}
|
||||
}
|
||||
|
||||
private final class GeneratorCycler extends CyclingOption {
|
||||
private final MutableInteger amount = new MutableInteger(0);
|
||||
private final DimensionType value;
|
||||
|
||||
public GeneratorCycler(Identifier key, DimensionType value) {
|
||||
super(key.toString(), null, null);
|
||||
this.value = value;
|
||||
ImmutablePair<GeneratorType, ChunkGenerator> generatorTypeChunkGeneratorImmutablePair = terraGeneratorOptions.getOverrides().get(value);
|
||||
|
||||
if(generatorTypeChunkGeneratorImmutablePair != null) {
|
||||
this.amount.set(generatorList.indexOf(generatorTypeChunkGeneratorImmutablePair.getLeft()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getMessage(GameOptions options) {
|
||||
return ((BaseText) getDisplayPrefix()).copy().append(new LiteralText(": ")).append(generatorList.get(amount.get()).getTranslationKey().copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cycle(GameOptions options, int amount) {
|
||||
this.amount.addMod(amount, generatorList.size());
|
||||
terraGeneratorOptions.overrideChunkGenerator(value, generatorList.get(this.amount.get()),
|
||||
((GeneratorTypeAccessor) generatorList.get(this.amount.get()))
|
||||
.callGetChunkGenerator(terraGeneratorOptions.getBiomeRegistry(),
|
||||
terraGeneratorOptions.getChunkGeneratorSettingsRegistry(),
|
||||
terraGeneratorOptions.getSeed()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
+1
-1
@@ -2,8 +2,8 @@ package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.data.Directional;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
|
||||
|
||||
+1
-1
@@ -2,8 +2,8 @@ package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.Axis;
|
||||
import com.dfsek.terra.api.platform.block.data.Orientable;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.data.Slab;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.data.Stairs;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class DimensionConfig implements ConfigTemplate {
|
||||
@Value("dimensions")
|
||||
@Default
|
||||
private Map<Identifier, ConfigPack> dimensionPacks = new HashMap<>();
|
||||
|
||||
public Map<Identifier, ConfigPack> getDimensionPacks() {
|
||||
return dimensionPacks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FabricWorldConfig implements ConfigTemplate {
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@Value(".")
|
||||
@Default
|
||||
private Map<String, ConfigPack> worlds;
|
||||
|
||||
public FabricWorldConfig(Map<String, ConfigPack> worlds) {
|
||||
this.worlds = worlds;
|
||||
}
|
||||
|
||||
public FabricWorldConfig() {
|
||||
this(new HashMap<>());
|
||||
}
|
||||
|
||||
public Map<String, ConfigPack> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-biome.enable")
|
||||
@Default
|
||||
private boolean doBiomeInjection = false;
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
@Value("features.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedBiomeFeatures = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedBiomeStructures = new HashSet<>();
|
||||
|
||||
public boolean doBiomeInjection() {
|
||||
return doBiomeInjection;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedBiomeFeatures() {
|
||||
return excludedBiomeFeatures;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedBiomeStructures() {
|
||||
return excludedBiomeStructures;
|
||||
}
|
||||
}
|
||||
+36
-74
@@ -4,13 +4,11 @@ import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
@@ -20,7 +18,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -30,14 +27,9 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
@@ -46,7 +38,6 @@ import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -64,14 +55,13 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
private DimensionType dimensionType;
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new StructuresConfig(configPack.getTemplate().vanillaStructures()));
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new DefaultChunkGenerator3D(pack, TerraFabricPlugin.getInstance());
|
||||
@@ -97,31 +87,31 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
}
|
||||
|
||||
public void setDimensionType(DimensionType dimensionType) {
|
||||
this.dimensionType = dimensionType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) {
|
||||
if(!pack.getTemplate().disableStructures()) {
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
|
||||
TerraWorld terraWorld = TerraFabricPlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(FabricAdapter.adapt(location));
|
||||
}, TerraFabricPlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
|
||||
TerraWorld terraWorld = TerraFabricPlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(FabricAdapter.adapt(location));
|
||||
}, TerraFabricPlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return super.locateStructure(world, feature, center, radius, skipExistingChunks);
|
||||
TerraFabricPlugin.getInstance().logger().warning("No overrides are defined for \"" + name + "\"");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
|
||||
super.generateFeatures(region, accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,39 +121,44 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
@Override
|
||||
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
|
||||
if(pack.getTemplate().vanillaCaves()) super.carve(seed, access, chunk, carver);
|
||||
// No caves
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStructureStarts(DynamicRegistryManager dynamicRegistryManager, StructureAccessor structureAccessor, Chunk chunk, StructureManager structureManager, long worldSeed) {
|
||||
if(pack.getTemplate().vanillaStructures())
|
||||
super.setStructureStarts(dynamicRegistryManager, structureAccessor, chunk, structureManager, worldSeed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(seed);
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
|
||||
int cx = FastMath.floorMod(x, 16);
|
||||
int cz = FastMath.floorMod(z, 16);
|
||||
|
||||
int height = world.getWorld().getMaxHeight();
|
||||
while(height >= 0 && !heightmapType.getBlockPredicate().test(((FabricBlockData) world.getUngeneratedBlock(x, height-1, z)).getHandle())) {
|
||||
|
||||
while (height >= 0 && sampler.sample(cx, height - 1, cz) < 0) {
|
||||
height--;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockView getColumnSample(int x, int z) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
int height = 64; // TODO: implementation
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
if(y > getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.getDefaultState();
|
||||
} else {
|
||||
array[y] = Blocks.WATER.getDefaultState();
|
||||
@@ -176,39 +171,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
return new VerticalBlockSample(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpawnSettings.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
|
||||
if(pack.getTemplate().vanillaStructures()) {
|
||||
if(accessor.getStructureAt(pos, true, StructureFeature.SWAMP_HUT).hasChildren()) {
|
||||
if(group == SpawnGroup.MONSTER) return StructureFeature.SWAMP_HUT.getMonsterSpawns();
|
||||
if(group == SpawnGroup.CREATURE) return StructureFeature.SWAMP_HUT.getCreatureSpawns();
|
||||
}
|
||||
|
||||
if(group == SpawnGroup.MONSTER) {
|
||||
if(accessor.getStructureAt(pos, false, StructureFeature.PILLAGER_OUTPOST).hasChildren()) {
|
||||
return StructureFeature.PILLAGER_OUTPOST.getMonsterSpawns();
|
||||
} else if(accessor.getStructureAt(pos, false, StructureFeature.MONUMENT).hasChildren()) {
|
||||
return StructureFeature.MONUMENT.getMonsterSpawns();
|
||||
} else if(accessor.getStructureAt(pos, true, StructureFeature.FORTRESS).hasChildren()) {
|
||||
return StructureFeature.FORTRESS.getMonsterSpawns();
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getEntitySpawnList(biome, accessor, group, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterChunkX();
|
||||
int cy = region.getCenterChunkZ();
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
|
||||
ChunkRandom chunkRandom = new ChunkRandom();
|
||||
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
SpawnHelper.populateEntities(region, biome, cx, cy, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
|
||||
+1
-1
@@ -2,6 +2,7 @@ package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
@@ -21,7 +22,6 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
if(!(chunkGenerator instanceof FabricChunkGeneratorWrapper)) return true;
|
||||
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate((World) world, (Chunk) world));
|
||||
return true;
|
||||
|
||||
+11
-6
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -12,8 +11,8 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryLookupCodec;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TerraBiomeSource extends BiomeSource {
|
||||
@@ -32,9 +31,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraBiomeSource(Registry<Biome> biomes, long seed, ConfigPack pack) {
|
||||
super(biomes.stream()
|
||||
.filter(biome -> Objects.requireNonNull(biomes.getId(biome)).getNamespace().equals("terra")) // Filter out non-Terra biomes.
|
||||
.collect(Collectors.toList()));
|
||||
super(biomes.stream().collect(Collectors.toList()));
|
||||
this.biomeRegistry = biomes;
|
||||
this.seed = seed;
|
||||
this.grid = pack.getBiomeProviderBuilder().build(seed);
|
||||
@@ -54,6 +51,14 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
@Override
|
||||
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(biomeX << 2, biomeZ << 2);
|
||||
return biomeRegistry.get(new Identifier("terra", FabricUtil.createBiomeID(pack, biome.getID())));
|
||||
return biomeRegistry.get(new Identifier("terra", TerraFabricPlugin.createBiomeID(pack, biome.getID())));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasStructureFeature(StructureFeature<?> feature) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
public class TerraGeneratorType extends GeneratorType {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraGeneratorType(ConfigPack pack) {
|
||||
super("terra." + pack.getTemplate().getID());
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
+1
-15
@@ -1,13 +1,9 @@
|
||||
package com.dfsek.terra.fabric.handle;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.util.WorldEditUtil;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -37,14 +33,4 @@ public class FabricWorldHandle implements WorldHandle {
|
||||
if(identifier == null) identifier = Identifier.tryParse("minecraft:" + id.toLowerCase(Locale.ROOT));
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Location, Location> getSelectedLocation(Player player) {
|
||||
try {
|
||||
Class.forName("com.sk89q.worldedit.WorldEdit");
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new IllegalStateException("WorldEdit is not installed.");
|
||||
}
|
||||
return WorldEditUtil.getSelection(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
@Mixin(CommandManager.class)
|
||||
public abstract class CommandManagerMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private CommandDispatcher<ServerCommandSource> dispatcher;
|
||||
|
||||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V", remap = false))
|
||||
private void injectTerraCommands(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
|
||||
com.dfsek.terra.api.command.CommandManager manager = TerraFabricPlugin.getInstance().getManager();
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, manager));
|
||||
}
|
||||
|
||||
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
|
||||
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
|
||||
}
|
||||
|
||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, com.dfsek.terra.api.command.CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
}
|
||||
+19
-2
@@ -2,8 +2,9 @@ package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.TerraGeneratorOptions;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@@ -13,7 +14,9 @@ import net.minecraft.world.dimension.DimensionOptions;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.GeneratorOptions;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@@ -21,8 +24,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
|
||||
import static net.minecraft.world.gen.GeneratorOptions.method_28608;
|
||||
|
||||
@Mixin(GeneratorOptions.class)
|
||||
public abstract class GeneratorOptionsMixin {
|
||||
@Shadow
|
||||
public static NoiseChunkGenerator createOverworldGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Inject(method = "fromProperties(Lnet/minecraft/util/registry/DynamicRegistryManager;Ljava/util/Properties;)Lnet/minecraft/world/gen/GeneratorOptions;", at = @At("HEAD"), cancellable = true)
|
||||
private static void fromProperties(DynamicRegistryManager dynamicRegistryManager, Properties properties, CallbackInfoReturnable<GeneratorOptions> cir) {
|
||||
if(properties.get("level-type") == null) {
|
||||
@@ -51,13 +61,20 @@ public abstract class GeneratorOptionsMixin {
|
||||
Registry<ChunkGeneratorSettings> chunkGeneratorSettings = dynamicRegistryManager.get(Registry.NOISE_SETTINGS_WORLDGEN);
|
||||
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomes, chunkGeneratorSettings, l);
|
||||
|
||||
|
||||
prop = prop.substring(prop.indexOf(":") + 1);
|
||||
|
||||
ConfigPack pack = TerraFabricPlugin.getInstance().getConfigRegistry().get(prop);
|
||||
|
||||
if(pack == null) throw new IllegalArgumentException("No such pack " + prop);
|
||||
|
||||
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.method_28608(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
|
||||
cir.setReturnValue(new TerraGeneratorOptions(l, generateStructures, false, method_28608(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack)), biomes, chunkGeneratorSettings));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getDefaultOptions(Lnet/minecraft/util/registry/Registry;Lnet/minecraft/util/registry/Registry;Lnet/minecraft/util/registry/Registry;)Lnet/minecraft/world/gen/GeneratorOptions;", at = @At("HEAD"), cancellable = true)
|
||||
private static void injectDefaultOptions(Registry<DimensionType> registry, Registry<Biome> registry2, Registry<ChunkGeneratorSettings> registry3, CallbackInfoReturnable<GeneratorOptions> cir) {
|
||||
long l = (new Random()).nextLong();
|
||||
cir.setReturnValue(new TerraGeneratorOptions(l, true, false, method_28608(registry, DimensionType.createDefaultDimensionOptions(registry, registry2, registry3, l), createOverworldGenerator(registry2, registry3, l)), registry2, registry3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldGenerationProgressListener;
|
||||
import net.minecraft.world.SaveProperties;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public abstract class MinecraftServerMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
protected SaveProperties saveProperties;
|
||||
|
||||
|
||||
@Inject(method = "createWorlds(Lnet/minecraft/server/WorldGenerationProgressListener;)V", at = @At("HEAD"))
|
||||
public void injectCreateWorlds(WorldGenerationProgressListener worldGenerationProgressListener, CallbackInfo ci) {
|
||||
System.out.println("Generator: " + this.saveProperties.getGeneratorOptions());
|
||||
Thread.dumpStack();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldGenerationProgressListener;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.Spawner;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.ServerWorldProperties;
|
||||
import net.minecraft.world.level.storage.LevelStorage;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@Inject(method = "<init>", at = @At(value = "RETURN"))
|
||||
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
|
||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
|
||||
((FabricChunkGeneratorWrapper) chunkGenerator).setDimensionType(dimensionType);
|
||||
TerraFabricPlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -2,11 +2,18 @@ package com.dfsek.terra.fabric.mixin.access;
|
||||
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(GeneratorType.class)
|
||||
public interface GeneratorTypeAccessor {
|
||||
@@ -15,7 +22,21 @@ public interface GeneratorTypeAccessor {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Accessor("SCREEN_PROVIDERS")
|
||||
static Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> getScreenProviders() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Mutable
|
||||
@Accessor("SCREEN_PROVIDERS")
|
||||
static void setScreenProviders(Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> SCREEN_PROVIDERS) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Mutable
|
||||
@Accessor("translationKey")
|
||||
void setTranslationKey(Text translationKey);
|
||||
|
||||
@Invoker("getChunkGenerator")
|
||||
ChunkGenerator callGetChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed);
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.dfsek.terra.fabric.mixin.access;
|
||||
|
||||
import net.minecraft.world.gen.GeneratorOptions;
|
||||
import net.minecraft.world.level.LevelProperties;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(LevelProperties.class)
|
||||
public interface LevelPropertiesAccessor {
|
||||
@Accessor("generatorOptions")
|
||||
void setGeneratorOptions(GeneratorOptions generatorOptions);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.dfsek.terra.fabric.mixin.access;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(SimpleRegistry.class)
|
||||
public interface SimpleRegistryAccessor<T> {
|
||||
@Accessor("rawIdToEntry")
|
||||
ObjectList<T> getRawIdToEntry();
|
||||
}
|
||||
+1
-11
@@ -1,12 +1,8 @@
|
||||
package com.dfsek.terra.fabric.mixin.init;
|
||||
package com.dfsek.terra.fabric.mixin.client;
|
||||
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.TerraGeneratorType;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.RunArgs;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -19,11 +15,5 @@ public class MinecraftClientMixin {
|
||||
shift = At.Shift.BEFORE))
|
||||
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
|
||||
TerraFabricPlugin.getInstance().packInit(); // Load during MinecraftClient construction, after other mods have registered blocks and stuff
|
||||
TerraFabricPlugin.getInstance().getConfigRegistry().forEach(pack -> {
|
||||
final GeneratorType generatorType = new TerraGeneratorType(pack);
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||
GeneratorTypeAccessor.getValues().add(1, generatorType);
|
||||
});
|
||||
}
|
||||
}
|
||||
-2
@@ -3,13 +3,11 @@ package com.dfsek.terra.fabric.mixin.implementations;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Biome.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.Biome.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BiomeMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -3,13 +3,11 @@ package com.dfsek.terra.fabric.mixin.implementations;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ChunkGenerator.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.generator.ChunkGenerator.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ChunkGeneratorMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-3
@@ -3,15 +3,14 @@ package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -30,7 +29,6 @@ public abstract class BlockEntityMixin {
|
||||
@Shadow
|
||||
public abstract boolean hasWorld();
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-3
@@ -2,13 +2,12 @@ package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -18,7 +17,6 @@ public abstract class BlockMixin {
|
||||
@Shadow
|
||||
private BlockState defaultState;
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import com.dfsek.terra.fabric.mixin.implementations.block.BlockEntityMixin;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(LootableContainerBlockEntity.class)
|
||||
@@ -16,7 +15,6 @@ public abstract class LootableContainerBlockEntityMixin extends BlockEntityMixin
|
||||
return (Inventory) this;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+3
-1
@@ -51,5 +51,7 @@ public abstract class ChunkRegionMixin {
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4)), ((FabricBlockData) blockData).getHandle(), 0);
|
||||
}
|
||||
|
||||
// getHandle already added in world/ChunkRegionMixin.
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -12,7 +12,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -48,7 +47,6 @@ public abstract class WorldChunkMixin {
|
||||
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -9,7 +9,6 @@ import net.minecraft.world.chunk.ProtoChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -27,7 +26,6 @@ public abstract class ProtoChunkMixin {
|
||||
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-3
@@ -2,14 +2,13 @@ package com.dfsek.terra.fabric.mixin.implementations.entity;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -30,7 +29,6 @@ public abstract class EntityMixin {
|
||||
@Shadow
|
||||
public abstract void sendSystemMessage(Text message, UUID senderUuid);
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -3,13 +3,11 @@ package com.dfsek.terra.fabric.mixin.implementations.entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(EntityType.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.entity.EntityType.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class EntityTypeMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -20,7 +19,6 @@ public abstract class ServerCommandSourceMixin {
|
||||
sendFeedback(new LiteralText(message), true);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -6,13 +6,11 @@ import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.item.Items;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(LockableContainerBlockEntity.class)
|
||||
@Implements(@Interface(iface = Inventory.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public class LockableContainerBlockEntityMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import net.minecraft.item.Item;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -14,7 +13,6 @@ public abstract class ItemMixin {
|
||||
@Shadow
|
||||
public abstract int getMaxDamage();
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -50,7 +50,6 @@ public abstract class ItemStackMixin {
|
||||
setTag(((ItemStack) (Object) meta).getTag());
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -5,7 +5,6 @@ import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -20,7 +19,6 @@ public abstract class EnchantmentMixin {
|
||||
@Shadow
|
||||
public abstract boolean canCombine(Enchantment other);
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -28,7 +28,6 @@ public abstract class ItemStackMetaMixin {
|
||||
@Shadow
|
||||
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -67,7 +67,6 @@ public abstract class ChunkRegionMixin {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -58,7 +58,6 @@ public abstract class ServerWorldMixin {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin.init;
|
||||
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import net.minecraft.server.Main;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Main.class)
|
||||
public class ServerMainMixin {
|
||||
@Inject(method = "main([Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistryManager;create()Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
|
||||
private static void injectConstructor(String[] args, CallbackInfo ci) {
|
||||
TerraFabricPlugin.getInstance().packInit(); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.fabric.mixin.server;
|
||||
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.mojang.authlib.GameProfileRepository;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import net.minecraft.resource.ResourcePackManager;
|
||||
import net.minecraft.resource.ServerResourceManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldGenerationProgressListenerFactory;
|
||||
import net.minecraft.util.UserCache;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.SaveProperties;
|
||||
import net.minecraft.world.level.storage.LevelStorage;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.net.Proxy;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void injectConstructor(Thread thread, DynamicRegistryManager.Impl impl, LevelStorage.Session session,
|
||||
SaveProperties saveProperties, ResourcePackManager resourcePackManager, Proxy proxy,
|
||||
DataFixer dataFixer, ServerResourceManager serverResourceManager,
|
||||
MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository,
|
||||
UserCache userCache, WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory,
|
||||
CallbackInfo callbackInfo) {
|
||||
TerraFabricPlugin.getInstance().packInit(); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.carver.ConfiguredCarver;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class FabricUtil {
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param fabricAddon The Fabric addon instance.
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
* @return The Minecraft delegate biome.
|
||||
*/
|
||||
public static Biome createBiome(TerraFabricPlugin.FabricAddon fabricAddon, BiomeBuilder biome, ConfigPack pack) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
|
||||
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
|
||||
|
||||
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, TerraFabricPlugin.POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
if(pack.getTemplate().vanillaCaves()) {
|
||||
for(GenerationStep.Carver carver : GenerationStep.Carver.values()) {
|
||||
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarversForStep(carver)) {
|
||||
generationSettings.carver(carver, configuredCarverSupplier.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = fabricAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
|
||||
Identifier key = BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getId(structureFeature.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.structureFeature(structureFeature.get());
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
if(compatibilityOptions.doBiomeInjection()) {
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
||||
Identifier key = BuiltinRegistries.CONFIGURED_FEATURE.getId(featureSupplier.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.feature(step, featureSupplier);
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
} else {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.category(vanilla.getCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.effects(effects.build())
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public final class WorldEditUtil {
|
||||
public static Pair<Location, Location> getSelection(Player player) {
|
||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||
try {
|
||||
Region selection = worldEdit.getSessionManager()
|
||||
.get(com.sk89q.worldedit.fabric.FabricAdapter.adaptPlayer((ServerPlayerEntity) player))
|
||||
.getSelection(com.sk89q.worldedit.fabric.FabricAdapter.adapt((World) player.getWorld()));
|
||||
BlockVector3 min = selection.getMinimumPoint();
|
||||
BlockVector3 max = selection.getMaximumPoint();
|
||||
Location l1 = new Location(player.getWorld(), min.getBlockX(), min.getBlockY(), min.getBlockZ());
|
||||
Location l2 = new Location(player.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
|
||||
return Pair.of(l1, l2);
|
||||
} catch(IncompleteRegionException e) {
|
||||
throw new IllegalStateException("No selection has been made", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"generator.terra": "Terra"
|
||||
"generator.terra": "Terra",
|
||||
"terra.config-screen": "Terra Configuration",
|
||||
"terra.screen.close": "Close"
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
"id": "terra",
|
||||
"version": "@VERSION@",
|
||||
"name": "Terra",
|
||||
"description": "@DESCRIPTION@",
|
||||
"description": "An insanely powerful free & open-source data-driven world generator.",
|
||||
"authors": [
|
||||
"dfsek"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "@WIKI@",
|
||||
"sources": "@SOURCE@",
|
||||
"issues": "@ISSUES@"
|
||||
"homepage": "https://github.com/PolyhedralDev/Terra/wiki",
|
||||
"sources": "https://github.com/PolyhedralDev/Terra"
|
||||
},
|
||||
"license": "@LICENSE@",
|
||||
"license": "GPL-3.0",
|
||||
"icon": "assets/terra/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
@@ -25,6 +24,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"accessWidener": "terra.accesswidener"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
accessWidener v1 named
|
||||
|
||||
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V
|
||||
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V
|
||||
|
||||
extendable class net/minecraft/world/dimension/DimensionOptions
|
||||
@@ -4,11 +4,12 @@
|
||||
"package": "com.dfsek.terra.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"CommandManagerMixin",
|
||||
"GeneratorOptionsMixin",
|
||||
"ServerWorldMixin",
|
||||
"MinecraftServerMixin",
|
||||
"access.BiomeEffectsAccessor",
|
||||
"access.LevelPropertiesAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.SimpleRegistryAccessor",
|
||||
"access.StateAccessor",
|
||||
"implementations.BiomeMixin",
|
||||
"implementations.ChunkGeneratorMixin",
|
||||
@@ -36,10 +37,10 @@
|
||||
],
|
||||
"client": [
|
||||
"access.GeneratorTypeAccessor",
|
||||
"init.MinecraftClientMixin"
|
||||
"client.MinecraftClientMixin"
|
||||
],
|
||||
"server": [
|
||||
"init.ServerMainMixin"
|
||||
"server.MinecraftServerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.configureCommon
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import net.minecraftforge.gradle.common.util.RunConfig
|
||||
import net.minecraftforge.gradle.mcp.task.GenerateSRG
|
||||
import net.minecraftforge.gradle.userdev.UserDevExtension
|
||||
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace
|
||||
|
||||
@@ -55,17 +55,11 @@ if ("true" == System.getProperty("idea.sync.active")) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
archiveBaseName.set(tasks.getByName<Jar>("jar").archiveBaseName.orNull) // Pain. Agony, even.
|
||||
archiveClassifier.set("") // Suffering, if you will.
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks.named<RenameJarInPlace>("reobfJar") {
|
||||
val shadow = tasks.getByName<ShadowJar>("shadowJar");
|
||||
dependsOn(shadow)
|
||||
input = shadow.archiveFile.orNull?.asFile
|
||||
val reobf = extensions.getByName<NamedDomainObjectContainer<RenameJarInPlace>>("reobf")
|
||||
reobf.maybeCreate("shadowJar").run {
|
||||
group = "forge"
|
||||
mappings = tasks.getByName<GenerateSRG>("createMcpToSrg").output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +71,7 @@ configure<UserDevExtension> {
|
||||
runs {
|
||||
val runConfig = Action<RunConfig> {
|
||||
properties(mapOf(
|
||||
//"forge.logging.markers" to "SCAN,REGISTRIES,REGISTRYDUMP",
|
||||
"forge.logging.markers" to "SCAN,REGISTRIES,REGISTRYDUMP",
|
||||
"forge.logging.console.level" to "debug"
|
||||
))
|
||||
arg("-mixin.config=terra.mixins.json")
|
||||
@@ -130,12 +124,12 @@ tasks.jar {
|
||||
}
|
||||
|
||||
tasks.register<com.modrinth.minotaur.TaskModrinthUpload>("publishModrinthForge") {
|
||||
dependsOn("reobfJar")
|
||||
dependsOn("reobfShadowJar")
|
||||
group = "forge"
|
||||
token = System.getenv("MODRINTH_SECRET")
|
||||
projectId = "FIlZB9L0"
|
||||
versionNumber = "${project.version}-forge"
|
||||
uploadFile = tasks.named<RenameJarInPlace>("reobfJar").get().input.absoluteFile
|
||||
uploadFile = tasks.named<RenameJarInPlace>("reobfShadowJar").get().input.absoluteFile
|
||||
releaseType = "alpha"
|
||||
addGameVersion("1.16.5")
|
||||
addLoader("forge")
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.state.Container;
|
||||
import com.dfsek.terra.api.platform.block.state.MobSpawner;
|
||||
import com.dfsek.terra.api.platform.block.state.Sign;
|
||||
import com.dfsek.terra.forge.block.ForgeBlockData;
|
||||
import com.dfsek.terra.forge.block.data.ForgeDirectional;
|
||||
import com.dfsek.terra.forge.block.data.ForgeMultipleFacing;
|
||||
import com.dfsek.terra.forge.block.data.ForgeOrientable;
|
||||
import com.dfsek.terra.forge.block.data.ForgeRotatable;
|
||||
import com.dfsek.terra.forge.block.data.ForgeSlab;
|
||||
import com.dfsek.terra.forge.block.data.ForgeStairs;
|
||||
import com.dfsek.terra.forge.block.data.ForgeWaterlogged;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.LockableLootTileEntity;
|
||||
import net.minecraft.tileentity.MobSpawnerTileEntity;
|
||||
import net.minecraft.tileentity.SignTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class ForgeAdapter {
|
||||
public static BlockPos adapt(Vector3 v) {
|
||||
return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
}
|
||||
|
||||
public static Vector3 adapt(BlockPos pos) {
|
||||
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static ForgeBlockData adapt(BlockState state) {
|
||||
if(state.hasProperty(BlockStateProperties.STAIRS_SHAPE)) return new ForgeStairs(state);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.SLAB_TYPE)) return new ForgeSlab(state);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.AXIS)) return new ForgeOrientable(state, BlockStateProperties.AXIS);
|
||||
if(state.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) return new ForgeOrientable(state, BlockStateProperties.HORIZONTAL_AXIS);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.ROTATION_16)) return new ForgeRotatable(state);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.FACING)) return new ForgeDirectional(state, BlockStateProperties.FACING);
|
||||
if(state.hasProperty(BlockStateProperties.FACING_HOPPER)) return new ForgeDirectional(state, BlockStateProperties.FACING_HOPPER);
|
||||
if(state.hasProperty(BlockStateProperties.HORIZONTAL_FACING))
|
||||
return new ForgeDirectional(state, BlockStateProperties.HORIZONTAL_FACING);
|
||||
|
||||
if(state.getProperties().containsAll(Arrays.asList(BlockStateProperties.NORTH, BlockStateProperties.SOUTH, BlockStateProperties.EAST, BlockStateProperties.WEST)))
|
||||
return new ForgeMultipleFacing(state);
|
||||
if(state.hasProperty(BlockStateProperties.WATERLOGGED)) return new ForgeWaterlogged(state);
|
||||
return new ForgeBlockData(state);
|
||||
}
|
||||
|
||||
public static com.dfsek.terra.api.platform.block.state.BlockState adapt(com.dfsek.terra.api.platform.block.Block block) {
|
||||
IWorld worldAccess = (IWorld) block.getLocation().getWorld();
|
||||
|
||||
TileEntity entity = worldAccess.getBlockEntity(adapt(block.getLocation().toVector()));
|
||||
if(entity instanceof SignTileEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof MobSpawnerTileEntity) {
|
||||
return (MobSpawner) entity;
|
||||
} else if(entity instanceof LockableLootTileEntity) {
|
||||
return (Container) entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Direction adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.WorldGenRegistries;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.carver.ConfiguredCarver;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class ForgeUtil {
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static Biome createBiome(BiomeBuilder biome, ConfigPack pack, TerraForgePlugin.ForgeAddon forgeAddon) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
|
||||
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
|
||||
|
||||
generationSettings.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, TerraForgePlugin.POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
if(pack.getTemplate().vanillaCaves()) {
|
||||
for(GenerationStage.Carving carver : GenerationStage.Carving.values()) {
|
||||
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarvers(carver)) {
|
||||
generationSettings.addCarver(carver, configuredCarverSupplier.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = forgeAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<StructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().structures()) {
|
||||
ResourceLocation key = WorldGenRegistries.CONFIGURED_STRUCTURE_FEATURE.getKey(structureFeature.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.addStructureStart(structureFeature.get());
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
if(compatibilityOptions.doBiomeInjection()) {
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().features().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().features().get(step)) {
|
||||
ResourceLocation key = WorldGenRegistries.CONFIGURED_FEATURE.getKey(featureSupplier.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.addFeature(step, featureSupplier);
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BiomeAmbience vanillaEffects = vanilla.getSpecialEffects();
|
||||
BiomeAmbience.Builder effects = new BiomeAmbience.Builder()
|
||||
.waterColor(colors.getOrDefault("water", vanillaEffects.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", vanillaEffects.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", vanillaEffects.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", vanillaEffects.getSkyColor()))
|
||||
.grassColorModifier(vanillaEffects.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColorOverride(colors.get("grass"));
|
||||
} else {
|
||||
vanillaEffects.getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
}
|
||||
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColorOverride(colors.get("foliage"));
|
||||
} else {
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.biomeCategory(vanilla.getBiomeCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.specialEffects(effects.build())
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build()
|
||||
.setRegistryName("terra", createBiomeID(template.getPack(), template.getID()));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
@@ -10,14 +8,15 @@ import com.dfsek.terra.api.addons.annotations.Author;
|
||||
import com.dfsek.terra.api.addons.annotations.Version;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.TerraCommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
@@ -25,48 +24,67 @@ import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.transform.NotNullValidator;
|
||||
import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.api.transform.Validator;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.forge.handle.ForgeItemHandle;
|
||||
import com.dfsek.terra.forge.handle.ForgeWorldHandle;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.forge.inventory.ForgeItemHandle;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import com.dfsek.terra.forge.world.ForgeBiome;
|
||||
import com.dfsek.terra.forge.world.ForgeTree;
|
||||
import com.dfsek.terra.forge.world.ForgeWorldHandle;
|
||||
import com.dfsek.terra.forge.world.features.PopulatorFeature;
|
||||
import com.dfsek.terra.forge.world.generator.ForgeChunkGenerator;
|
||||
import com.dfsek.terra.forge.world.generator.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.world.generator.config.TerraLevelType;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.WorldGenRegistries;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.Features;
|
||||
import net.minecraft.world.gen.feature.IFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.gen.placement.DecoratedPlacement;
|
||||
import net.minecraft.world.gen.placement.NoPlacementConfig;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeWorldTypeScreens;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.world.ForgeWorldType;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -76,12 +94,20 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
||||
import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument;
|
||||
|
||||
@Mod("terra")
|
||||
@Mod.EventBusSubscriber(modid = "terra", bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class TerraForgePlugin implements TerraPlugin {
|
||||
@@ -89,7 +115,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configured(IFeatureConfig.NONE).decorated(DecoratedPlacement.NOPE.configured(NoPlacementConfig.INSTANCE));
|
||||
|
||||
private static TerraForgePlugin INSTANCE;
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
@@ -114,51 +140,129 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
logger.error(message);
|
||||
}
|
||||
};
|
||||
|
||||
private final DebugLogger debugLogger = new DebugLogger(logger);
|
||||
private final ItemHandle itemHandle = new ForgeItemHandle();
|
||||
private final WorldHandle worldHandle = new ForgeWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final ForgeAddon addon = new ForgeAddon(this);
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(addon, this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new ForgeAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse(id)), Validator.notNull())
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse("minecraft:" + id.toLowerCase())), Validator.notNull()).build();
|
||||
private final File dataFolder;
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
private File dataFolder;
|
||||
|
||||
public TerraForgePlugin() {
|
||||
if(INSTANCE != null) throw new IllegalStateException("Only one TerraPlugin instance may exist.");
|
||||
INSTANCE = this;
|
||||
this.dataFolder = Paths.get("config", "Terra").toFile();
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
debugLogger.setDebug(config.isDebug());
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(ClientEvents.class);
|
||||
MinecraftForge.EVENT_BUS.register(getClass());
|
||||
MinecraftForge.EVENT_BUS.register(ForgeEvents.class);
|
||||
}
|
||||
|
||||
public static TerraForgePlugin getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void setupListener(FMLCommonSetupEvent event) {
|
||||
event.enqueueWork(() -> {
|
||||
Registry.register(Registry.BIOME_SOURCE, "terra:biome", TerraBiomeSource.CODEC);
|
||||
Registry.register(Registry.CHUNK_GENERATOR, "terra:generator", ForgeChunkGeneratorWrapper.CODEC);
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<CommandSource, String> assemble(RequiredArgumentBuilder<CommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = ForgeAdapter.adapt(context.getSource());
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
try {
|
||||
manager.execute(args.remove(0), ForgeAdapter.adapt(context.getSource()), args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendFailure(new StringTextComponent(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
public void init() {
|
||||
private static List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<Biome> event) {
|
||||
INSTANCE.setup(); // Setup now because we need the biomes, and this event happens after blocks n stuff
|
||||
INSTANCE.getConfigRegistry().forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> event.getRegistry().register(INSTANCE.createBiome(biome)))); // Register all Terra biomes.
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerLevels(RegistryEvent.Register<ForgeWorldType> event) {
|
||||
INSTANCE.logger().info("Registering level types...");
|
||||
event.getRegistry().register(TerraLevelType.FORGE_WORLD_TYPE);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPop(RegistryEvent.Register<Feature<?>> event) {
|
||||
event.getRegistry().register(POPULATOR_FEATURE);
|
||||
}
|
||||
|
||||
public Biome createBiome(BiomeBuilder biome) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = ((ForgeBiome) new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderConfig(Blocks.GRASS_BLOCK.defaultBlockState(), Blocks.DIRT.defaultBlockState(), Blocks.GRAVEL.defaultBlockState()))); // It needs a surfacebuilder, even though we dont use it.
|
||||
generationSettings.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
BiomeAmbience vanillaEffects = vanilla.getSpecialEffects();
|
||||
BiomeAmbience.Builder effects = new BiomeAmbience.Builder()
|
||||
.waterColor(colors.getOrDefault("water", vanillaEffects.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", vanillaEffects.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", vanillaEffects.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", vanillaEffects.getSkyColor()))
|
||||
.grassColorModifier(vanillaEffects.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColorOverride(colors.get("grass"));
|
||||
} else {
|
||||
vanillaEffects.getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
}
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColorOverride(colors.get("foliage"));
|
||||
} else {
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.biomeCategory(vanilla.getBiomeCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.specialEffects(effects.build())
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build().setRegistryName("terra", createBiomeID(template.getPack(), template.getID()));
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
this.dataFolder = Paths.get("config", "Terra").toFile();
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
if(!addonRegistry.loadAll()) {
|
||||
@@ -167,11 +271,15 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
registry.loadAll(this);
|
||||
|
||||
logger.info("Loaded packs.");
|
||||
|
||||
((ForgeRegistry<Biome>) ForgeRegistries.BIOMES).unfreeze(); // Evil
|
||||
getConfigRegistry().forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> ForgeRegistries.BIOMES.register(ForgeUtil.createBiome(biome, pack, addon)))); // Register all Terra biomes.
|
||||
((ForgeRegistry<Biome>) ForgeRegistries.BIOMES).freeze();
|
||||
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,22 +289,12 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((IWorld) world).dimensionType());
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, ((ForgeChunkGeneratorWrapper) ((ForgeChunkGenerator) world.getGenerator()).getHandle()).getPack(), this);
|
||||
});
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* evil code brought to you by Forge Mod Loader
|
||||
* <p>
|
||||
* Forge changes the JAR URI to something that cannot
|
||||
* be resolved back to the original JAR, so we have to
|
||||
* do this to get our JAR.
|
||||
*/
|
||||
@Override
|
||||
public JarFile getModJar() throws URISyntaxException, IOException {
|
||||
File modsDir = new File("./mods");
|
||||
@@ -213,6 +311,12 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(long seed) {
|
||||
TerraWorld world = worldMap.get(seed);
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with seed " + seed);
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.util.logging.Logger logger() {
|
||||
return logger;
|
||||
@@ -230,7 +334,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,11 +357,14 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
worldMap.forEach((seed, pair) -> {
|
||||
pair.getRight().getConfig().getSamplerCache().clear();
|
||||
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||
Map<Long, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((seed, tw) -> {
|
||||
tw.getConfig().getSamplerCache().clear();
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@@ -291,12 +398,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
genericLoaders.register(registry);
|
||||
registry
|
||||
.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o))
|
||||
.registerLoader(ResourceLocation.class, (t, o, l) -> {
|
||||
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
|
||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
||||
return identifier;
|
||||
});
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> new ForgeBiome(biomeFixer.translate((String) o)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,20 +411,28 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
@Mod.EventBusSubscriber(modid = "terra", bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public static final class ForgeEvents {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
int max = INSTANCE.manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<CommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<CommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
arg = next.then(assemble(arg, INSTANCE.manager));
|
||||
}
|
||||
|
||||
event.getDispatcher().register(literal("terra").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.manager)));
|
||||
event.getDispatcher().register(literal("te").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.manager)));
|
||||
}
|
||||
}
|
||||
|
||||
@Addon("Terra-Forge")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public static final class ForgeAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
private static final class ForgeAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
@@ -358,51 +468,43 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", Features.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", Features.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", Features.WARPED_FUNGI);
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
WorldGenRegistries.CONFIGURED_FEATURE.entrySet().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getRegistryName())) {
|
||||
try {
|
||||
event.getPack().getTreeRegistry().add(entry.getKey().getRegistryName().toString(), (Tree) entry.getValue());
|
||||
main.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getRegistryName() + " as Tree: " + entry.getValue());
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) {
|
||||
try {
|
||||
registry.add(id, (Tree) tree);
|
||||
registry.add(id, new ForgeTree(tree, id, TerraForgePlugin.getInstance()));
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static final class ClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void register(FMLClientSetupEvent event) {
|
||||
INSTANCE.logger.info("Client setup...");
|
||||
|
||||
ForgeWorldType world = TerraLevelType.FORGE_WORLD_TYPE;
|
||||
ForgeWorldTypeScreens.registerFactory(world, (returnTo, dimensionGeneratorSettings) -> new Screen(world.getDisplayName()) {
|
||||
private final MutableInteger num = new MutableInteger(0);
|
||||
private final List<ConfigPack> packs = new ArrayList<>();
|
||||
private final Button toggle = new Button(0, 25, 120, 20, new StringTextComponent(""), button -> {
|
||||
num.increment();
|
||||
if(num.get() >= packs.size()) num.set(0);
|
||||
button.setMessage(new StringTextComponent("Pack: " + packs.get(num.get()).getTemplate().getID()));
|
||||
});
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
packs.clear();
|
||||
INSTANCE.registry.forEach((Consumer<ConfigPack>) packs::add);
|
||||
addButton(new Button(0, 0, 120, 20, new StringTextComponent("Close"), btn -> Minecraft.getInstance().setScreen(returnTo)));
|
||||
toggle.setMessage(new StringTextComponent("Pack: " + packs.get(num.get()).getTemplate().getID()));
|
||||
addButton(toggle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<ResourceLocation>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<ResourceLocation>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<ResourceLocation>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<ResourceLocation>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-biome.enable")
|
||||
@Default
|
||||
private boolean doBiomeInjection = false;
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
@Value("features.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedBiomeFeatures = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedBiomeStructures = new HashSet<>();
|
||||
|
||||
public boolean doBiomeInjection() {
|
||||
return doBiomeInjection;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedBiomeFeatures() {
|
||||
return excludedBiomeFeatures;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedBiomeStructures() {
|
||||
return excludedBiomeStructures;
|
||||
}
|
||||
}
|
||||
-202
@@ -1,202 +0,0 @@
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.ForgeAdapter;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.block.ForgeBlockData;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.util.SharedSeedRandom;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.DynamicRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.Blockreader;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeManager;
|
||||
import net.minecraft.world.biome.MobSpawnInfo;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.gen.WorldGenRegion;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraft.world.gen.feature.structure.StructureManager;
|
||||
import net.minecraft.world.gen.feature.template.TemplateManager;
|
||||
import net.minecraft.world.gen.settings.DimensionStructuresSettings;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.spawner.WorldEntitySpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
|
||||
private final long seed;
|
||||
private final DefaultChunkGenerator3D delegate;
|
||||
private final TerraBiomeSource biomeSource;
|
||||
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
|
||||
Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID())
|
||||
).apply(config, config.stable(TerraForgePlugin.getInstance().getConfigRegistry()::get))));
|
||||
public static final Codec<ForgeChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed),
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(ForgeChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
private DimensionType dimensionType;
|
||||
|
||||
public ForgeChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new DimensionStructuresSettings(configPack.getTemplate().vanillaStructures()));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new DefaultChunkGenerator3D(pack, TerraForgePlugin.getInstance());
|
||||
delegate.getMain().logger().info("Loading world with config pack " + pack.getTemplate().getID());
|
||||
this.biomeSource = biomeSource;
|
||||
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Codec<? extends ChunkGenerator> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkGenerator withSeed(long seed) {
|
||||
return new ForgeChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurfaceAndBedrock(@NotNull WorldGenRegion p_225551_1_, @NotNull IChunk p_225551_2_) {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockPos findNearestMapFeature(@NotNull ServerWorld world, @NotNull Structure<?> feature, @NotNull BlockPos center, int radius, boolean skipExistingChunks) {
|
||||
if(!pack.getTemplate().disableStructures()) {
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getKey(feature)).toString();
|
||||
TerraWorld terraWorld = TerraForgePlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, ForgeAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(ForgeAdapter.adapt(location));
|
||||
}, TerraForgePlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.findNearestMapFeature(world, feature, center, radius, skipExistingChunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStronghold(@NotNull ChunkPos p_235952_1_) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.hasStronghold(p_235952_1_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStructures(@NotNull DynamicRegistries dynamicRegistries, @NotNull StructureManager manager, @NotNull IChunk chunk, @NotNull TemplateManager templateManager, long p_242707_5_) {
|
||||
if(pack.getTemplate().vanillaStructures()) super.createStructures(dynamicRegistries, manager, chunk, templateManager, p_242707_5_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(long p_230350_1_, @NotNull BiomeManager biomeManager, @NotNull IChunk chunk, GenerationStage.@NotNull Carving carving) {
|
||||
if(pack.getTemplate().vanillaCaves()) super.applyCarvers(p_230350_1_, biomeManager, chunk, carving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillFromNoise(@NotNull IWorld world, @NotNull StructureManager p_230352_2_, @NotNull IChunk chunk) {
|
||||
delegate.generateChunkData((World) world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int x, int z, Heightmap.@NotNull Type type) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(dimensionType);
|
||||
int height = world.getWorld().getMaxHeight();
|
||||
while(height >= 0 && !type.isOpaque().test(((ForgeBlockData) world.getUngeneratedBlock(x, height-1, z)).getHandle())) {
|
||||
height--;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull IBlockReader getBaseColumn(int x, int z) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getBaseHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.defaultBlockState();
|
||||
} else {
|
||||
array[y] = Blocks.WATER.defaultBlockState();
|
||||
}
|
||||
} else {
|
||||
array[y] = Blocks.STONE.defaultBlockState();
|
||||
}
|
||||
}
|
||||
|
||||
return new Blockreader(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(WorldGenRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterX();
|
||||
int cy = region.getCenterZ();
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getWorldPosition());
|
||||
SharedSeedRandom chunkRandom = new SharedSeedRandom();
|
||||
chunkRandom.setDecorationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
WorldEntitySpawner.spawnMobsForChunkGeneration(region, biome, cx, cy, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobSpawnInfo.Spawners> getMobsAt(Biome p_230353_1_, StructureManager p_230353_2_, EntityClassification p_230353_3_, BlockPos p_230353_4_) {
|
||||
List<MobSpawnInfo.Spawners> spawns = net.minecraftforge.common.world.StructureSpawnManager.getStructureSpawns(p_230353_2_, p_230353_3_, p_230353_4_);
|
||||
if(spawns != null) return spawns;
|
||||
return super.getMobsAt(p_230353_1_, p_230353_2_, p_230353_3_, p_230353_4_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDimensionType(DimensionType dimensionType) {
|
||||
this.dimensionType = dimensionType;
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.DimensionSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TerraGeneratorType extends BiomeGeneratorTypeScreens {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraGeneratorType(ConfigPack pack) {
|
||||
super(new StringTextComponent("Terra:" + pack.getTemplate().getID()));
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull ChunkGenerator generator(@NotNull Registry<Biome> biomeRegistry, @NotNull Registry<DimensionSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new ForgeChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ForgeEnchantment implements Enchantment {
|
||||
private final net.minecraft.enchantment.Enchantment enchantment;
|
||||
|
||||
public ForgeEnchantment(net.minecraft.enchantment.Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.enchantment.Enchantment getHandle() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack itemStack) {
|
||||
return enchantment.canEnchant(ForgeAdapter.adapt(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return Objects.requireNonNull(ForgeRegistries.ENCHANTMENTS.getKey(enchantment)).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
return !enchantment.isCompatibleWith(ForgeAdapter.adapt(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return enchantment.getMaxLevel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.Inventory;
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
public class ForgeInventory implements Inventory {
|
||||
private final net.minecraft.inventory.IInventory delegate;
|
||||
|
||||
public ForgeInventory(IInventory delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.inventory.IInventory getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return delegate.getContainerSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot) {
|
||||
net.minecraft.item.ItemStack itemStack = delegate.getItem(slot);
|
||||
return itemStack.getItem() == Items.AIR ? null : ForgeAdapter.adapt(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack newStack) {
|
||||
delegate.setItem(slot, ForgeAdapter.adapt(newStack));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
|
||||
public class ForgeItem implements Item {
|
||||
private final net.minecraft.item.Item delegate;
|
||||
|
||||
public ForgeItem(net.minecraft.item.Item delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.item.Item getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack newItemStack(int amount) {
|
||||
return new ForgeItemStack(new net.minecraft.item.ItemStack(delegate, amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxDurability() {
|
||||
return delegate.getMaxDamage();
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -1,12 +1,14 @@
|
||||
package com.dfsek.terra.forge.handle;
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.arguments.ItemArgument;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -17,7 +19,7 @@ public class ForgeItemHandle implements ItemHandle {
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
try {
|
||||
return (Item) new ItemArgument().parse(new StringReader(data)).getItem();
|
||||
return ForgeAdapter.adapt(new ItemArgument().parse(new StringReader(data)).getItem());
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
|
||||
}
|
||||
@@ -25,11 +27,11 @@ public class ForgeItemHandle implements ItemHandle {
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return (Enchantment) ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryParse(id));
|
||||
return ForgeAdapter.adapt(ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryParse(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return ForgeRegistries.ENCHANTMENTS.getEntries().stream().map(entry -> (Enchantment) entry.getValue()).collect(Collectors.toSet());
|
||||
return ForgeRegistries.ENCHANTMENTS.getEntries().stream().map(entry -> ForgeAdapter.adapt(entry.getValue())).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||
import com.dfsek.terra.forge.inventory.meta.ForgeDamageable;
|
||||
import com.dfsek.terra.forge.inventory.meta.ForgeItemMeta;
|
||||
|
||||
public class ForgeItemStack implements ItemStack {
|
||||
private net.minecraft.item.ItemStack delegate;
|
||||
|
||||
public ForgeItemStack(net.minecraft.item.ItemStack delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return delegate.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmount(int i) {
|
||||
delegate.setCount(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getType() {
|
||||
return new ForgeItem(delegate.getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMeta getItemMeta() {
|
||||
if(delegate.isDamageableItem()) return new ForgeDamageable(delegate.copy());
|
||||
return new ForgeItemMeta(delegate.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemMeta(ItemMeta meta) {
|
||||
this.delegate = ((ForgeItemMeta) meta).getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.item.ItemStack getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.forge.inventory.meta;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.item.Damageable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ForgeDamageable extends ForgeItemMeta implements Damageable {
|
||||
public ForgeDamageable(ItemStack delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return delegate.getDamageValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(int damage) {
|
||||
delegate.setDamageValue(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDamage() {
|
||||
return delegate.isDamaged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.dfsek.terra.forge.inventory.meta;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import net.minecraft.command.arguments.NBTCompoundTagArgument;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ForgeItemMeta implements ItemMeta {
|
||||
protected final ItemStack delegate;
|
||||
|
||||
public ForgeItemMeta(ItemStack delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
if(!delegate.isEnchanted()) return Collections.emptyMap();
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
|
||||
delegate.getEnchantmentTags().forEach(enchantment -> {
|
||||
CompoundNBT eTag = (CompoundNBT) enchantment;
|
||||
map.put(ForgeAdapter.adapt(Registry.ENCHANTMENT.byId(eTag.getInt("id"))), eTag.getInt("lvl"));
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnchantment(Enchantment enchantment, int level) {
|
||||
delegate.enchant(ForgeAdapter.adapt(enchantment), level);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.dfsek.terra.forge.listener;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
||||
import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = "terra", bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class ForgeListener {
|
||||
private static final TerraForgePlugin INSTANCE = TerraForgePlugin.getInstance();
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
int max = INSTANCE.getManager().getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<CommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<CommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, INSTANCE.getManager()));
|
||||
}
|
||||
|
||||
event.getDispatcher().register(literal("terra").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.getManager())));
|
||||
event.getDispatcher().register(literal("te").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.getManager())));
|
||||
}
|
||||
|
||||
public static RequiredArgumentBuilder<CommandSource, String> assemble(RequiredArgumentBuilder<CommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrException();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
try {
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrException();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendFailure(new StringTextComponent(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private static List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.dfsek.terra.forge.listener;
|
||||
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class RegistryListener {
|
||||
@SubscribeEvent
|
||||
public static void registerPop(RegistryEvent.Register<Feature<?>> event) {
|
||||
event.getRegistry().register(TerraForgePlugin.POPULATOR_FEATURE);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import net.minecraft.util.registry.DynamicRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import net.minecraft.world.Dimension;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.DimensionSettings;
|
||||
import net.minecraft.world.gen.settings.DimensionGeneratorSettings;
|
||||
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.Properties;
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(DimensionGeneratorSettings.class)
|
||||
public abstract class DimensionGeneratorSettingsMixin {
|
||||
@Inject(method = "create(Lnet/minecraft/util/registry/DynamicRegistries;Ljava/util/Properties;)Lnet/minecraft/world/gen/settings/DimensionGeneratorSettings;", at = @At("HEAD"), cancellable = true)
|
||||
private static void fromProperties(DynamicRegistries dynamicRegistries, Properties properties, CallbackInfoReturnable<DimensionGeneratorSettings> cir) {
|
||||
if(properties.get("level-type") == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String prop = properties.get("level-type").toString().trim();
|
||||
if(prop.startsWith("Terra")) {
|
||||
String seed = (String) MoreObjects.firstNonNull(properties.get("level-seed"), "");
|
||||
long l = new Random().nextLong();
|
||||
if(!seed.isEmpty()) {
|
||||
try {
|
||||
long m = Long.parseLong(seed);
|
||||
if(m != 0L) {
|
||||
l = m;
|
||||
}
|
||||
} catch(NumberFormatException exception) {
|
||||
l = seed.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
String generate_structures = (String) properties.get("generate-structures");
|
||||
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
|
||||
Registry<DimensionType> dimensionTypes = dynamicRegistries.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
Registry<Biome> biomes = dynamicRegistries.registryOrThrow(Registry.BIOME_REGISTRY);
|
||||
Registry<DimensionSettings> chunkGeneratorSettings = dynamicRegistries.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY);
|
||||
SimpleRegistry<Dimension> dimensionOptions = DimensionType.defaultDimensions(dimensionTypes, biomes, chunkGeneratorSettings, l);
|
||||
|
||||
prop = prop.substring(prop.indexOf(":") + 1);
|
||||
|
||||
ConfigPack pack = TerraForgePlugin.getInstance().getConfigRegistry().get(prop);
|
||||
|
||||
if(pack == null) throw new IllegalArgumentException("No such pack " + prop);
|
||||
|
||||
TerraForgePlugin.getInstance().logger().info("Using config pack " + pack.getTemplate().getID());
|
||||
cir.setReturnValue(new DimensionGeneratorSettings(l, generateStructures, false, DimensionGeneratorSettings.withOverworld(dimensionTypes, dimensionOptions, new ForgeChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerChunkProvider;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ServerChunkProvider chunkSource;
|
||||
|
||||
@Shadow
|
||||
protected abstract void initCapabilities();
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;initCapabilities()V"))
|
||||
public void injectConstructor(ServerWorld serverWorld) {
|
||||
if(chunkSource.getGenerator() instanceof ForgeChunkGeneratorWrapper) {
|
||||
ForgeChunkGeneratorWrapper chunkGeneratorWrapper = (ForgeChunkGeneratorWrapper) chunkSource.getGenerator();
|
||||
DimensionType dimensionType = ((World) (Object) this).dimensionType();
|
||||
TerraForgePlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, chunkGeneratorWrapper.getPack(), TerraForgePlugin.getInstance())));
|
||||
chunkGeneratorWrapper.setDimensionType(dimensionType);
|
||||
TerraForgePlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||
}
|
||||
initCapabilities();
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.spawner.AbstractSpawner;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(AbstractSpawner.class)
|
||||
public interface AbstractSpawnerAccessor {
|
||||
@Invoker("getEntityId")
|
||||
ResourceLocation callGetEntityId();
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(BiomeGeneratorTypeScreens.class)
|
||||
public interface BiomeGeneratorTypeScreensAccessor {
|
||||
@Accessor("PRESETS")
|
||||
static List<BiomeGeneratorTypeScreens> getPresets() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Mutable
|
||||
@Accessor
|
||||
void setDescription(ITextComponent description);
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Biome.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.Biome.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BiomeMixin {
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations;
|
||||
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ChunkGenerator.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.generator.ChunkGenerator.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ChunkGeneratorMixin {
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.profiler.ProfileFrame;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ISeedReader;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(ConfiguredFeature.class)
|
||||
@Implements(@Interface(iface = Tree.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ConfiguredFeatureMixin {
|
||||
|
||||
@Shadow
|
||||
public abstract boolean place(ISeedReader p_242765_1_, ChunkGenerator p_242765_2_, Random p_242765_3_, BlockPos p_242765_4_);
|
||||
|
||||
@SuppressWarnings({"try"})
|
||||
public boolean terra$plant(Location l, Random r) {
|
||||
try(ProfileFrame ignore = TerraForgePlugin.getInstance().getProfiler().profile("forge_tree")) {
|
||||
ISeedReader world = ((ISeedReader) l.getWorld());
|
||||
ChunkGenerator generatorWrapper = (ChunkGenerator) l.getWorld().getGenerator();
|
||||
return place(world, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialSet terra$getSpawnable() {
|
||||
return MaterialSet.get(TerraForgePlugin.getInstance().getWorldHandle().createBlockData("minecraft:grass_block"),
|
||||
TerraForgePlugin.getInstance().getWorldHandle().createBlockData("minecraft:podzol"),
|
||||
TerraForgePlugin.getInstance().getWorldHandle().createBlockData("minecraft:mycelium"));
|
||||
}
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.block;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.forge.ForgeAdapter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(Block.class)
|
||||
@Implements(@Interface(iface = BlockType.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BlockMixin {
|
||||
@Shadow
|
||||
private BlockState defaultBlockState;
|
||||
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockData terra$getDefaultData() {
|
||||
return ForgeAdapter.adapt(defaultBlockState);
|
||||
}
|
||||
|
||||
public boolean terra$isSolid() {
|
||||
return defaultBlockState.canOcclude();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public boolean terra$isWater() {
|
||||
return ((Object) this) == Blocks.WATER;
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.block;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.forge.ForgeAdapter;
|
||||
import com.dfsek.terra.forge.block.ForgeBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mixin(TileEntity.class)
|
||||
@Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class TileEntityMixin {
|
||||
@Shadow
|
||||
protected BlockPos worldPosition;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
protected World level;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
private net.minecraft.block.BlockState blockState;
|
||||
|
||||
@Shadow
|
||||
public abstract boolean hasLevel();
|
||||
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Block terra$getBlock() {
|
||||
return new ForgeBlock(worldPosition, level);
|
||||
}
|
||||
|
||||
public int terra$getX() {
|
||||
return worldPosition.getX();
|
||||
}
|
||||
|
||||
public int terra$getY() {
|
||||
return worldPosition.getY();
|
||||
}
|
||||
|
||||
public int terra$getZ() {
|
||||
return worldPosition.getZ();
|
||||
}
|
||||
|
||||
public BlockData terra$getBlockData() {
|
||||
return ForgeAdapter.adapt(blockState);
|
||||
}
|
||||
|
||||
public boolean terra$update(boolean applyPhysics) {
|
||||
if(hasLevel()) level.getChunk(worldPosition).setBlockEntity(worldPosition, (TileEntity) (Object) this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.block.state;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.state.Container;
|
||||
import com.dfsek.terra.api.platform.inventory.Inventory;
|
||||
import com.dfsek.terra.forge.mixin.implementations.block.TileEntityMixin;
|
||||
import net.minecraft.tileentity.LockableLootTileEntity;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(LockableLootTileEntity.class)
|
||||
@Implements(@Interface(iface = Container.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class LockableLootTileEntityMixin extends TileEntityMixin {
|
||||
public Inventory terra$getInventory() {
|
||||
return (Inventory) this;
|
||||
}
|
||||
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.block.state;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.state.MobSpawner;
|
||||
import com.dfsek.terra.api.platform.block.state.SerialState;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.mixin.access.AbstractSpawnerAccessor;
|
||||
import com.dfsek.terra.forge.mixin.implementations.block.TileEntityMixin;
|
||||
import net.minecraft.tileentity.MobSpawnerTileEntity;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.spawner.AbstractSpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(MobSpawnerTileEntity.class)
|
||||
@Implements(@Interface(iface = MobSpawner.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class MobSpawnerTileEntityMixin extends TileEntityMixin {
|
||||
@Shadow
|
||||
public abstract AbstractSpawner getSpawner();
|
||||
|
||||
public EntityType terra$getSpawnedType() {
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(((AbstractSpawnerAccessor) getSpawner()).callGetEntityId());
|
||||
}
|
||||
|
||||
public void terra$setSpawnedType(@NotNull EntityType creatureType) {
|
||||
getSpawner().setEntityId((net.minecraft.entity.EntityType<?>) creatureType);
|
||||
}
|
||||
|
||||
public int terra$getDelay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setDelay(int delay) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMinSpawnDelay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setMinSpawnDelay(int delay) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMaxSpawnDelay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setMaxSpawnDelay(int delay) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getSpawnCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setSpawnCount(int spawnCount) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMaxNearbyEntities() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setMaxNearbyEntities(int maxNearbyEntities) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getRequiredPlayerRange() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setRequiredPlayerRange(int requiredPlayerRange) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getSpawnRange() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setSpawnRange(int spawnRange) {
|
||||
|
||||
}
|
||||
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type":
|
||||
terra$setSpawnedType(TerraForgePlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
return;
|
||||
case "delay":
|
||||
terra$setDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "min_delay":
|
||||
terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_delay":
|
||||
terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_count":
|
||||
terra$setSpawnCount(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_range":
|
||||
terra$setSpawnRange(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_nearby":
|
||||
terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
return;
|
||||
case "required_player_range":
|
||||
terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.block.state;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.state.SerialState;
|
||||
import com.dfsek.terra.api.platform.block.state.Sign;
|
||||
import net.minecraft.tileentity.SignTileEntity;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(SignTileEntity.class)
|
||||
@Implements(@Interface(iface = Sign.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class SignTileEntityMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ITextComponent[] messages;
|
||||
|
||||
@Shadow
|
||||
public abstract void setMessage(int p_212365_1_, ITextComponent p_212365_2_);
|
||||
|
||||
public @NotNull String[] terra$getLines() {
|
||||
String[] lines = new String[messages.length];
|
||||
for(int i = 0; i < messages.length; i++) {
|
||||
lines[i] = messages[i].getString();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
|
||||
|
||||
return messages[index].getString();
|
||||
}
|
||||
|
||||
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
setMessage(index, new StringTextComponent(line));
|
||||
}
|
||||
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
|
||||
terra$setLine(Integer.parseInt(k.substring(4)), v);
|
||||
});
|
||||
}
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.chunk;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.forge.block.ForgeBlock;
|
||||
import com.dfsek.terra.forge.block.ForgeBlockData;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(net.minecraft.world.chunk.Chunk.class)
|
||||
@Implements(@Interface(iface = Chunk.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ChunkMixin {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private net.minecraft.world.World level;
|
||||
|
||||
public int terra$getX() {
|
||||
return ((IChunk) this).getPos().x;
|
||||
}
|
||||
|
||||
public int terra$getZ() {
|
||||
return ((IChunk) this).getPos().z;
|
||||
}
|
||||
|
||||
public World terra$getWorld() {
|
||||
return (World) level;
|
||||
}
|
||||
|
||||
public Block terra$getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + (terra$getX() << 4), y, z + (terra$getZ() << 4));
|
||||
return new ForgeBlock(pos, level);
|
||||
}
|
||||
|
||||
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
|
||||
return terra$getBlock(x, y, z).getBlockData();
|
||||
}
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
((IChunk) this).setBlockState(new BlockPos(x, y, z), ((ForgeBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user