This commit is contained in:
Zoë
2022-07-11 14:57:43 -07:00
parent 526e655a8f
commit a286e26656
24 changed files with 774 additions and 198 deletions
@@ -7,30 +7,17 @@ import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent; import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler; import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.world.biome.Biome; import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
public class BukkitAddon implements BaseAddon { public class BukkitAddon implements BaseAddon {
private static final Version VERSION = Versions.getVersion(1, 0, 0); private static final Version VERSION = Versions.getVersion(1, 0, 0);
private final PlatformImpl terraBukkitPlugin; protected final PlatformImpl terraBukkitPlugin;
public BukkitAddon(PlatformImpl terraBukkitPlugin) { public BukkitAddon(PlatformImpl terraBukkitPlugin) {
this.terraBukkitPlugin = terraBukkitPlugin; this.terraBukkitPlugin = terraBukkitPlugin;
} }
@Override
public void initialize() {
terraBukkitPlugin.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationLoadEvent.class)
.then(event -> {
if(event.is(Biome.class)) {
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
}
})
.global();
}
@Override @Override
public Version getVersion() { public Version getVersion() {
@@ -117,7 +117,7 @@ public class PlatformImpl extends AbstractPlatform {
} }
private BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException { protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id, depthTracker); if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
return new BukkitPlatformBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10))); return new BukkitPlatformBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
} }
@@ -47,7 +47,7 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class TerraBukkitPlugin extends JavaPlugin { public class TerraBukkitPlugin extends JavaPlugin {
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class); private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
private final PlatformImpl platform = new PlatformImpl(this); private PlatformImpl platform;
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>(); private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
@Override @Override
@@ -56,6 +56,8 @@ public class TerraBukkitPlugin extends JavaPlugin {
return; return;
} }
platform = Initializer.init(this);
platform.getEventManager().callEvent(new PlatformInitializationEvent()); platform.getEventManager().callEvent(new PlatformInitializationEvent());
@@ -91,8 +93,6 @@ public class TerraBukkitPlugin extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener
PaperUtil.checkPaper(this); PaperUtil.checkPaper(this);
Initializer.init(platform);
} }
public PlatformImpl getPlatform() { public PlatformImpl getPlatform() {
@@ -1,58 +0,0 @@
package com.dfsek.terra.bukkit.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.api.properties.Properties;
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Value("colors.grass")
@Default
private Integer grassColor = null;
@Value("colors.fog")
@Default
private Integer fogColor = null;
@Value("colors.water")
@Default
private Integer waterColor = null;
@Value("colors.water-fog")
@Default
private Integer waterFogColor = null;
@Value("colors.foliage")
@Default
private Integer foliageColor = null;
@Value("colors.sky")
@Default
private Integer skyColor = null;
public Integer getFogColor() {
return fogColor;
}
public Integer getFoliageColor() {
return foliageColor;
}
public Integer getGrassColor() {
return grassColor;
}
public Integer getWaterColor() {
return waterColor;
}
public Integer getWaterFogColor() {
return waterFogColor;
}
public Integer getSkyColor() {
return skyColor;
}
}
@@ -1,5 +1,7 @@
package com.dfsek.terra.bukkit.nms; package com.dfsek.terra.bukkit.nms;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -11,30 +13,35 @@ public interface Initializer {
String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
String TERRA_PACKAGE = Initializer.class.getPackageName(); String TERRA_PACKAGE = Initializer.class.getPackageName();
static void init(PlatformImpl platform) { static PlatformImpl init(TerraBukkitPlugin plugin) {
Logger logger = LoggerFactory.getLogger(Initializer.class); Logger logger = LoggerFactory.getLogger(Initializer.class);
try { try {
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSInitializer"); Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSPlatform");
try { try {
Initializer initializer = (Initializer) initializerClass.getConstructor().newInstance(); return (PlatformImpl) initializerClass.getConstructor().newInstance(plugin);
initializer.initialize(platform);
} catch(ReflectiveOperationException e) { } catch(ReflectiveOperationException e) {
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e); throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
} }
} catch(ClassNotFoundException e) { } catch(ClassNotFoundException e) {
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS); Runnable runnable = () -> { // scary big block of text
logger.error("This is usually due to running Terra on an unsupported Minecraft version."); logger.error("NMS bindings for version {} do not exist.", NMS);
logger.error(""); logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
logger.error(""); logger.error("Terra will now be DISABLED.");
for(int i = 0; i < 20; i++) { logger.error("");
logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!"); logger.error("");
} for(int i = 0; i < 20; i++) {
logger.error(""); logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!");
logger.error(""); }
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS); logger.error("");
logger.error("This is usually due to running Terra on an unsupported Minecraft version."); logger.error("");
logger.error("NMS bindings for version {} do not exist.", NMS);
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
logger.error("Terra will now be DISABLED.");
};
runnable.run();
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, runnable, 200L);
Bukkit.getPluginManager().disablePlugin(plugin);
} }
return null;
} }
void initialize(PlatformImpl plugin);
} }
@@ -11,7 +11,6 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
public class NMSBiomeInjector { public class NMSBiomeInjector {
@@ -1,5 +1,7 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1; package com.dfsek.terra.bukkit.nms.v1_19_R1;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.Lifecycle; import com.mojang.serialization.Lifecycle;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
@@ -10,8 +12,8 @@ import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import org.bukkit.NamespacedKey;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -20,6 +22,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.registry.master.ConfigRegistry;
@@ -28,7 +31,8 @@ import com.dfsek.terra.registry.master.ConfigRegistry;
public class AwfulBukkitHacks { public class AwfulBukkitHacks {
private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class); private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class);
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>(); public static final Map<TagKey<Biome>, List<ResourceLocation>>
TERRA_BIOME_TAG_MAP = new HashMap<>();
public static void registerBiomes(ConfigRegistry configRegistry) { public static void registerBiomes(ConfigRegistry configRegistry) {
try { try {
@@ -40,22 +44,27 @@ public class AwfulBukkitHacks {
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
try { try {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey());
Biome platform = NMSBiomeInjector.createBiome(
biome,
Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)) // get
);
ResourceKey<Biome> delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, ResourceKey<Biome> delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY,
new ResourceLocation("terra", new ResourceLocation("terra",
NMSBiomeInjector.createBiomeID(pack, key))); NMSBiomeInjector.createBiomeID(pack, key)));
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
Biome platform = NMSBiomeInjector.createBiome(vanillaBiomeProperties);
BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform); BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform);
biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); Map villagerMap = Reflection.VILLAGER_TYPE.getByBiome();
villagerMap.put(ResourceKey.create(Registry.BIOME_REGISTRY, delegateKey.location()),
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), VillagerType.PLAINS));
for(ResourceLocation tag : vanillaBiomeProperties.getTags()) {
TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.create(Registry.BIOME_REGISTRY, tag), new ArrayList<>()).add(delegateKey.location());
}
LOGGER.debug("Registered biome: " + delegateKey); LOGGER.debug("Registered biome: " + delegateKey);
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
@@ -65,7 +74,8 @@ public class AwfulBukkitHacks {
Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, true); // freeze registry again :) Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, true); // freeze registry again :)
LOGGER.info("Doing tag garbage...."); LOGGER.info("Doing data-driven biome tag garbage....");
LOGGER.info("who let this data drive?");
Map<TagKey<Biome>, List<Holder<Biome>>> collect = biomeRegistry Map<TagKey<Biome>, List<Holder<Biome>>> collect = biomeRegistry
.getTags() // streamKeysAndEntries .getTags() // streamKeysAndEntries
.collect(HashMap::new, .collect(HashMap::new,
@@ -73,38 +83,15 @@ public class AwfulBukkitHacks {
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
HashMap::putAll); HashMap::putAll);
terraBiomeMap TERRA_BIOME_TAG_MAP.forEach((tag, biomeList) -> {
.forEach((vb, terraBiomes) -> collect.getOrDefault(tag, new ArrayList<>())
NMSBiomeInjector.getEntry(biomeRegistry, vb) .addAll(biomeList.stream()
.ifPresentOrElse( .map(biomeRegistry::getOptional)
vanilla -> terraBiomes .filter(Optional::isPresent)
.forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb) .map(Optional::get)
.ifPresentOrElse( .map(Holder::direct)
terra -> { .toList());
LOGGER.debug( });
vanilla.unwrapKey()
.orElseThrow()
.location() +
" (vanilla for " +
terra.unwrapKey()
.orElseThrow()
.location() +
": " +
vanilla.tags()
.toList());
vanilla.tags()
.forEach(
tag -> collect
.computeIfAbsent(
tag,
t -> new ArrayList<>())
.add(terra));
},
() -> LOGGER.error(
"No such biome: {}",
tb))),
() -> LOGGER.error("No vanilla biome: {}", vb)));
biomeRegistry.resetTags(); biomeRegistry.resetTags();
biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); biomeRegistry.bindTags(ImmutableMap.copyOf(collect));
@@ -0,0 +1,28 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1;
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.bukkit.BukkitAddon;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
public class NMSAddon extends BukkitAddon {
public NMSAddon(PlatformImpl terraBukkitPlugin) {
super(terraBukkitPlugin);
}
@Override
public void initialize() {
terraBukkitPlugin.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationLoadEvent.class)
.then(event -> {
if(event.is(Biome.class)) {
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
}
})
.global();
}
}
@@ -1,9 +1,13 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1; package com.dfsek.terra.bukkit.nms.v1_19_R1;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.BiomeSpecialEffects;
import java.util.Locale; import java.util.Locale;
@@ -11,7 +15,6 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
public class NMSBiomeInjector { public class NMSBiomeInjector {
@@ -22,54 +25,64 @@ public class NMSBiomeInjector {
.map(registry::getOrCreateHolderOrThrow); .map(registry::getOrCreateHolderOrThrow);
} }
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) public static Biome createBiome(VanillaBiomeProperties vanillaBiomeProperties)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Biome.BiomeBuilder builder = new Biome.BiomeBuilder();
builder
.precipitation(vanilla.getPrecipitation())
.downfall(vanilla.getDownfall())
.temperature(vanilla.getBaseTemperature())
.mobSpawnSettings(vanilla.getMobSettings())
.generationSettings(vanilla.getGenerationSettings());
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); net.minecraft.world.level.biome.Biome.BiomeBuilder builder = new BiomeBuilder();
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); effects.waterColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterColor()))
.waterFogColor(Objects.requireNonNull(vanillaBiomeProperties.getWaterFogColor()))
.fogColor(Objects.requireNonNull(vanillaBiomeProperties.getFogColor()))
.skyColor(Objects.requireNonNull(vanillaBiomeProperties.getSkyColor()))
.grassColorModifier(
Objects.requireNonNull(vanillaBiomeProperties.getGrassColorModifier()));
effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) if(vanillaBiomeProperties.getFoliageColor() != null) {
.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))
.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))
.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()));
if(vanillaBiomeProperties.getFoliageColor() == null) {
vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
} else {
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
} }
if(vanillaBiomeProperties.getGrassColor() == null) { if(vanillaBiomeProperties.getGrassColor() != null) {
vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride);
} else {
// grass
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
} }
vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); if(vanillaBiomeProperties.getParticleConfig() != null) {
vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); effects.ambientParticle(vanillaBiomeProperties.getParticleConfig());
vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); }
vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic);
vanilla.getAmbientParticle().ifPresent(effects::ambientParticle);
builder.specialEffects(effects.build()); if(vanillaBiomeProperties.getLoopSound() != null) {
effects.ambientLoopSound(vanillaBiomeProperties.getLoopSound());
}
return builder.build(); if(vanillaBiomeProperties.getMoodSound() != null) {
effects.ambientMoodSound(vanillaBiomeProperties.getMoodSound());
}
if(vanillaBiomeProperties.getAdditionsSound() != null) {
effects.ambientAdditionsSound(vanillaBiomeProperties.getAdditionsSound());
}
if(vanillaBiomeProperties.getMusic() != null) {
effects.backgroundMusic(vanillaBiomeProperties.getMusic());
}
builder.precipitation(Objects.requireNonNull(vanillaBiomeProperties.getPrecipitation()));
builder.temperature(Objects.requireNonNull(vanillaBiomeProperties.getTemperature()));
builder.downfall(Objects.requireNonNull(vanillaBiomeProperties.getDownfall()));
builder.temperatureAdjustment(Objects.requireNonNull(vanillaBiomeProperties.getTemperatureModifier()));
builder.mobSpawnSettings(Objects.requireNonNull(vanillaBiomeProperties.getSpawnSettings()));
return builder
.specialEffects(effects.build())
.generationSettings(generationSettings.build())
.build();
} }
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
@@ -1,15 +0,0 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1;
import org.bukkit.Bukkit;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.Initializer;
public class NMSInitializer implements Initializer {
@Override
public void initialize(PlatformImpl platform) {
AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry());
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
}
}
@@ -0,0 +1,94 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1;
import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.world.biome.PlatformBiome;
import com.dfsek.terra.bukkit.BukkitAddon;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.BiomeAdditionsSoundTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.BiomeMoodSoundTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.BiomeParticleConfigTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.EntityTypeTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.MusicSoundTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SoundEventTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnCostConfig;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnEntryTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnSettingsTemplate;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.SpawnTypeConfig;
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VillagerTypeTemplate;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
import net.minecraft.world.level.biome.AmbientMoodSettings;
import net.minecraft.world.level.biome.AmbientParticleSettings;
import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import org.bukkit.Bukkit;
import com.dfsek.terra.bukkit.PlatformImpl;
import java.util.List;
import java.util.Locale;
public class NMSPlatform extends PlatformImpl {
public NMSPlatform(TerraBukkitPlugin plugin) {
super(plugin);
AwfulBukkitHacks.registerBiomes(getRawConfigRegistry());
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), plugin);
}
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
.registerLoader(ResourceLocation.class, (type, o, loader, depthTracker) -> {
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
if(identifier == null)
throw new LoadException("Invalid identifier: " + o, depthTracker);
return identifier;
})
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(MobCategory.class, (type, o, loader, depthTracker) -> MobCategory.valueOf((String) o))
.registerLoader(AmbientParticleSettings.class, BiomeParticleConfigTemplate::new)
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
.registerLoader(AmbientMoodSettings.class, BiomeMoodSoundTemplate::new)
.registerLoader(AmbientAdditionsSettings.class, BiomeAdditionsSoundTemplate::new)
.registerLoader(Music.class, MusicSoundTemplate::new)
.registerLoader(EntityType.class, EntityTypeTemplate::new)
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
.registerLoader(SpawnerData.class, SpawnEntryTemplate::new)
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
.registerLoader(MobSpawnSettings.class, SpawnSettingsTemplate::new)
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
}
@Override
protected Iterable<BaseAddon> platformAddon() {
return List.of(new NMSAddon(this));
}
}
@@ -1,21 +1,31 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1; package com.dfsek.terra.bukkit.nms.v1_19_R1;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.Biome;
import xyz.jpenilla.reflectionremapper.ReflectionRemapper; import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory;
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter;
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter;
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
import xyz.jpenilla.reflectionremapper.proxy.annotation.Static;
import java.util.Map;
public class Reflection { public class Reflection {
public static final MappedRegistryProxy MAPPED_REGISTRY; public static final MappedRegistryProxy MAPPED_REGISTRY;
public static final VillagerTypeProxy VILLAGER_TYPE;
static { static {
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper,
Reflection.class.getClassLoader()); Reflection.class.getClassLoader());
MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class);
VILLAGER_TYPE = reflectionProxyFactory.reflectionProxy(VillagerTypeProxy.class);
} }
@@ -24,4 +34,11 @@ public class Reflection {
@FieldSetter("frozen") @FieldSetter("frozen")
void setFrozen(MappedRegistry<?> instance, boolean frozen); void setFrozen(MappedRegistry<?> instance, boolean frozen);
} }
@Proxies(VillagerTypeProxy.class)
public interface VillagerTypeProxy {
@Static
@FieldGetter("BY_BIOME")
Map<ResourceKey<Biome>, VillagerType> getByBiome();
}
} }
@@ -0,0 +1,27 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
public class BiomeAdditionsSoundTemplate implements ObjectTemplate<AmbientAdditionsSettings> {
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("sound-chance")
@Default
private Double soundChance = null;
@Override
public AmbientAdditionsSettings get() {
if(sound == null || soundChance == null) {
return null;
} else {
return new AmbientAdditionsSettings(sound, soundChance);
}
}
}
@@ -0,0 +1,35 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.biome.AmbientMoodSettings;
public class BiomeMoodSoundTemplate implements ObjectTemplate<AmbientMoodSettings> {
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("cultivation-ticks")
@Default
private Integer soundCultivationTicks = null;
@Value("spawn-range")
@Default
private Integer soundSpawnRange = null;
@Value("extra-distance")
@Default
private Double soundExtraDistance = null;
@Override
public AmbientMoodSettings get() {
if(sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
return null;
} else {
return new AmbientMoodSettings(sound, soundCultivationTicks, soundSpawnRange, soundExtraDistance);
}
}
}
@@ -0,0 +1,33 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.world.level.biome.AmbientParticleSettings;
public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientParticleSettings> {
@Value("particle")
@Default
private String particle = null;
@Value("probability")
@Default
private Integer probability = null;
@Override
public AmbientParticleSettings get() {
if(particle == null || probability == null) {
return null;
}
try {
return new AmbientParticleSettings(ParticleArgument.readParticle(new StringReader(particle)), probability);
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,20 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
public class EntityTypeTemplate implements ObjectTemplate<EntityType<?>> {
@Value("id")
@Default
private ResourceLocation id = null;
@Override
public EntityType<?> get() {
return Registry.ENTITY_TYPE.get(id);
}
}
@@ -0,0 +1,35 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
public class MusicSoundTemplate implements ObjectTemplate<Music> {
@Value("sound")
@Default
private SoundEvent sound = null;
@Value("min-delay")
@Default
private Integer minDelay = null;
@Value("max-delay")
@Default
private Integer maxDelay = null;
@Value("replace-current-music")
@Default
private Boolean replaceCurrentMusic = null;
@Override
public Music get() {
if(sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
return null;
} else {
return new Music(sound, minDelay, maxDelay, replaceCurrentMusic);
}
}
}
@@ -0,0 +1,29 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
@Value("id")
@Default
private ResourceLocation id = null;
@Value("distance-to-travel")
@Default
private Float distanceToTravel = null;
@Override
public SoundEvent get() {
if(id == null) {
return null;
} else if(distanceToTravel == null) {
return new SoundEvent(id);
} else {
return new SoundEvent(id, distanceToTravel);
}
}
}
@@ -0,0 +1,38 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.world.entity.EntityType;
public class SpawnCostConfig implements ObjectTemplate<SpawnCostConfig> {
@Value("type")
@Default
private EntityType<?> type = null;
@Value("mass")
@Default
private Double mass = null;
@Value("gravity")
@Default
private Double gravity = null;
public EntityType<?> getType() {
return type;
}
public Double getMass() {
return mass;
}
public Double getGravity() {
return gravity;
}
@Override
public SpawnCostConfig get() {
return this;
}
}
@@ -0,0 +1,31 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
public class SpawnEntryTemplate implements ObjectTemplate<SpawnerData> {
@Value("type")
@Default
private EntityType<?> type = null;
@Value("weight")
@Default
private Integer weight = null;
@Value("min-group-size")
@Default
private Integer minGroupSize = null;
@Value("max-group-size")
@Default
private Integer maxGroupSize = null;
@Override
public SpawnerData get() {
return new SpawnerData(type, weight, minGroupSize, maxGroupSize);
}
}
@@ -0,0 +1,43 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import java.util.List;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
@Value("spawns")
@Default
private List<SpawnTypeConfig> spawns = null;
@Value("costs")
@Default
private List<SpawnCostConfig> costs = null;
@Value("probability")
@Default
private Float probability = null;
@Override
public MobSpawnSettings get() {
MobSpawnSettings.Builder builder = new MobSpawnSettings.Builder();
for(SpawnTypeConfig spawn : spawns) {
MobCategory group = spawn.getGroup();
for (SpawnerData entry : spawn.getEntry()) {
builder.addSpawn(group, entry);
}
}
for(SpawnCostConfig cost : costs) {
builder.addMobCharge(cost.getType(), cost.getMass(), cost.getGravity());
}
if(probability != null) {
builder.creatureGenerationProbability(probability);
}
return builder.build();
}
}
@@ -0,0 +1,32 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import java.util.List;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
@Value("group")
@Default
private MobCategory group = null;
@Value("entries")
@Default
private List<SpawnerData> entry = null;
public MobCategory getGroup() {
return group;
}
public List<SpawnerData> getEntry() {
return entry;
}
@Override
public SpawnTypeConfig get() {
return this;
}
}
@@ -0,0 +1,174 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import java.util.List;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
import net.minecraft.world.level.biome.AmbientMoodSettings;
import net.minecraft.world.level.biome.AmbientParticleSettings;
import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
import net.minecraft.world.level.biome.MobSpawnSettings;
import com.dfsek.terra.api.properties.Properties;
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Value("minecraft.tags")
@Default
private List<ResourceLocation> tags = null;
@Value("minecraft.colors.grass")
@Default
private Integer grassColor = null;
@Value("minecraft.colors.fog")
@Default
private Integer fogColor = null;
@Value("minecraft.colors.water")
@Default
private Integer waterColor = null;
@Value("minecraft.colors.water-fog")
@Default
private Integer waterFogColor = null;
@Value("minecraft.colors.foliage")
@Default
private Integer foliageColor = null;
@Value("minecraft.colors.sky")
@Default
private Integer skyColor = null;
@Value("minecraft.colors.modifier")
@Default
private GrassColorModifier grassColorModifier = null;
@Value("minecraft.particles")
@Default
private AmbientParticleSettings particleConfig = null;
@Value("minecraft.climate.precipitation")
@Default
private Precipitation precipitation = null;
@Value("minecraft.climate.temperature")
@Default
private Float temperature = null;
@Value("minecraft.climate.temperature-modifier")
@Default
private TemperatureModifier temperatureModifier = null;
@Value("minecraft.climate.downfall")
@Default
private Float downfall = null;
@Value("minecraft.sound.loop-sound.sound")
@Default
private SoundEvent loopSound = null;
@Value("minecraft.sound.mood-sound")
@Default
private AmbientMoodSettings moodSound = null;
@Value("minecraft.sound.additions-sound")
@Default
private AmbientAdditionsSettings additionsSound = null;
@Value("minecraft.sound.music")
@Default
private Music music = null;
@Value("minecraft.spawning")
@Default
private MobSpawnSettings spawnSettings = null;
@Value("minecraft.villager-type")
@Default
private VillagerType villagerType = null;
public List<ResourceLocation> getTags() {
return tags;
}
public Integer getGrassColor() {
return grassColor;
}
public Integer getFogColor() {
return fogColor;
}
public Integer getWaterColor() {
return waterColor;
}
public Integer getWaterFogColor() {
return waterFogColor;
}
public Integer getFoliageColor() {
return foliageColor;
}
public Integer getSkyColor() {
return skyColor;
}
public GrassColorModifier getGrassColorModifier() {
return grassColorModifier;
}
public AmbientParticleSettings getParticleConfig() {
return particleConfig;
}
public Precipitation getPrecipitation() {
return precipitation;
}
public Float getTemperature() {
return temperature;
}
public TemperatureModifier getTemperatureModifier() {
return temperatureModifier;
}
public Float getDownfall() {
return downfall;
}
public SoundEvent getLoopSound() {
return loopSound;
}
public AmbientMoodSettings getMoodSound() {
return moodSound;
}
public AmbientAdditionsSettings getAdditionsSound() {
return additionsSound;
}
public Music getMusic() {
return music;
}
public MobSpawnSettings getSpawnSettings() {
return spawnSettings;
}
public VillagerType getVillagerType() {
return villagerType;
}
}
@@ -0,0 +1,20 @@
package com.dfsek.terra.bukkit.nms.v1_19_R1.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.npc.VillagerType;
public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
@Value("id")
@Default
private ResourceLocation id = null;
@Override
public VillagerType get() {
return Registry.VILLAGER_TYPE.get(id);
}
}