Merge PR #568 (Wyck) from OakLoaf

This commit is contained in:
Zoe Gidiere committed 2026-11-07 15:57:40 -07:00
commit 12a5c8b1f5
60 files changed
+646 -1798

No files matched your search

@@ -4,17 +4,20 @@ import ca.solostudios.strata.Versions;
import ca.solostudios.strata.version.Version;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
public class BukkitAddon implements BaseAddon {
private static final Version VERSION = Versions.getVersion(1, 0, 0);
protected final PlatformImpl terraBukkitPlugin;
protected final BukkitPlatform terraBukkitPlugin;
public BukkitAddon(PlatformImpl terraBukkitPlugin) {
public BukkitAddon(BukkitPlatform terraBukkitPlugin) {
this.terraBukkitPlugin = terraBukkitPlugin;
}
@@ -25,6 +28,16 @@ public class BukkitAddon implements BaseAddon {
.register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
.global();
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
@@ -20,16 +20,43 @@ package com.dfsek.terra.bukkit;
import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.bukkit.config.BiomeAdditionsSoundTemplate;
import com.dfsek.terra.bukkit.config.BiomeMoodSoundTemplate;
import com.dfsek.terra.bukkit.config.BiomeParticleConfigTemplate;
import com.dfsek.terra.bukkit.config.EntityTypeTemplate;
import com.dfsek.terra.bukkit.config.MusicSoundTemplate;
import com.dfsek.terra.bukkit.config.SoundEventTemplate;
import com.dfsek.terra.bukkit.config.SpawnCostConfig;
import com.dfsek.terra.bukkit.config.SpawnEntryConfig;
import com.dfsek.terra.bukkit.config.SpawnSettingsTemplate;
import com.dfsek.terra.bukkit.config.SpawnTypeConfig;
import com.dfsek.terra.bukkit.config.VillagerTypeTemplate;
import dev.wyck.biome.TemperatureModifier;
import dev.wyck.biome.entity.MobCategory;
import dev.wyck.biome.entity.MobSpawnSettings;
import dev.wyck.environment.GrassColorModifier;
import dev.wyck.environment.particle.ParticleCatalog;
import dev.wyck.environment.sounds.AmbientAdditionsSettings;
import dev.wyck.environment.sounds.AmbientMoodSettings;
import dev.wyck.environment.sounds.Music;
import dev.wyck.environment.sounds.SoundEvent;
import dev.wyck.keys.ResourceKey;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
import java.util.Locale;
import com.dfsek.terra.AbstractPlatform;
import com.dfsek.terra.api.block.state.BlockState;
@@ -42,8 +69,8 @@ import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
public class PlatformImpl extends AbstractPlatform {
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformImpl.class);
public class BukkitPlatform extends AbstractPlatform {
private static final Logger LOGGER = LoggerFactory.getLogger(BukkitPlatform.class);
private final ItemHandle itemHandle = new BukkitItemHandle();
@@ -53,7 +80,7 @@ public class PlatformImpl extends AbstractPlatform {
private int generationThreads;
public PlatformImpl(TerraBukkitPlugin plugin) {
public BukkitPlatform(TerraBukkitPlugin plugin) {
generationThreads = getMoonriseGenerationThreadsWithReflection();
if(generationThreads == 0) {
generationThreads = 1;
@@ -88,6 +115,11 @@ public class PlatformImpl extends AbstractPlatform {
return "Bukkit";
}
@Override
protected Iterable<BaseAddon> platformAddon() {
return List.of(new BukkitAddon(this));
}
@Override
public void runPossiblyUnsafeTask(@NotNull Runnable runnable) {
plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
@@ -118,8 +150,32 @@ public class PlatformImpl extends AbstractPlatform {
super.register(registry);
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> handle.createBlockState((String) o))
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
.registerLoader(EntityType.class, (type, o, loader, depthTracker) -> EntityType.valueOf((String) o));
.registerLoader(EntityType.class, (type, o, loader, depthTracker) -> EntityType.valueOf((String) o))
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
.registerLoader(ResourceKey.class, (type, o, loader, depthTracker) -> {
String[] parts = ((String) o).split(":", 2);
if(parts.length == 0 || parts.length > 2)
throw new LoadException("Invalid identifier: " + o, depthTracker);
return ResourceKey.of(parts[0], parts[1]);
})
.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(ParticleCatalog.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(SpawnEntryConfig.class, SpawnEntryConfig::new)
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
.registerLoader(MobSpawnSettings.class, SpawnSettingsTemplate::new)
.registerLoader(Villager.Type.class, VillagerTypeTemplate::new);
}
protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
@@ -1,66 +0,0 @@
package com.dfsek.terra.bukkit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import com.dfsek.terra.bukkit.util.VersionUtil;
import com.dfsek.terra.bukkit.util.BukkitNMSAccess;
import com.dfsek.terra.bukkit.util.BukkitUtils;
public interface NMSInitializer {
List<String> SUPPORTED_VERSIONS = List.of("v26.1.2", "v26.2", "v26.3");
String MINECRAFT_VERSION = VersionUtil.getMinecraftVersionInfo().toString();
String TERRA_PACKAGE = NMSInitializer.class.getPackageName();
static PlatformImpl init(TerraBukkitPlugin plugin) {
Logger logger = LoggerFactory.getLogger(NMSInitializer.class);
if(!SUPPORTED_VERSIONS.contains(MINECRAFT_VERSION)) {
logger.error("You are running your server on Minecraft version {} which is not supported by this version of Terra.",
MINECRAFT_VERSION);
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + MINECRAFT_VERSION.replace(".", "_") + "ButIWillProceedAnyway";
if(System.getProperty(bypassKey) == null) {
logger.error("Because of this **TERRA HAS BEEN DISABLED**.");
logger.error("Do not come ask us why it is not working.");
logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey);
return null;
} else {
logger.error("");
logger.error("");
for(int i = 0; i < 20; i++) {
logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!");
}
logger.error("");
logger.error("");
logger.error("We will not give you any support for issues that may arise.");
logger.error("Since you enabled the \"{}\" flag, we won't disable Terra. But be warned.", bypassKey);
}
}
return constructPlatform(plugin);
}
private static PlatformImpl constructPlatform(TerraBukkitPlugin plugin) {
try {
String bindingsVersion = switch(MINECRAFT_VERSION) {
case "v26.3" -> "v26_3";
case "v26.1.2", "v26.2" -> "v26_1";
default -> "v26_1";
};
Class<?> platformClass = Class.forName(TERRA_PACKAGE + ".nms." + bindingsVersion + ".NMSPlatform");
PlatformImpl platform = (PlatformImpl) platformClass
.getConstructor(TerraBukkitPlugin.class)
.newInstance(plugin);
if(platform instanceof BukkitNMSAccess nmsAccess) {
BukkitUtils.setNMSAccess(nmsAccess);
}
return platform;
} catch(ReflectiveOperationException e) {
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
}
}
}
@@ -0,0 +1,94 @@
package com.dfsek.terra.bukkit;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.bukkit.world.BiomeHandler;
import com.dfsek.terra.registry.master.ConfigRegistry;
import dev.wyck.biome.Biome;
import dev.wyck.keys.ResourceKey;
import dev.wyck.registry.bootstrap.BootstrapBiomeRegistry;
import dev.wyck.registry.bootstrap.Composer;
import dev.wyck.tags.TagSet;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TerraBootstrapper implements PluginBootstrap {
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBootstrapper.class);
private static final Map<ResourceKey, List<ResourceKey>> terraBiomeMap = new HashMap<>();
@Override
public void bootstrap(BootstrapContext context) {
BootstrapBiomeRegistry registry = BootstrapBiomeRegistry.compose(context, Composer.DATAPACK);
registry.deferring(() -> {
registerBiomes(context, ); // TODO: Get raw config registry instance here
});
}
public static void registerBiomes(BootstrapContext context, ConfigRegistry configRegistry) {
BootstrapBiomeRegistry biomeRegistry = BootstrapBiomeRegistry.compose(context, Composer.DATAPACK);
// Register the terra biomes to the registry
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
try {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
ResourceKey vanillaMinecraftKey = ResourceKey.of(platformBiome.getHandle().getKey());
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
Biome wyckBiome = BiomeHandler.createBiome(vanillaMinecraftKey, vanillaBiomeProperties);
ResourceKey delegateKey = ResourceKey.of("terra", BiomeHandler.createBiomeID(pack, key));
biomeRegistry.queue(wyckBiome);
platformBiome.getContext().put(new BukkitBiomeInfo(delegateKey));
// TODO: Reimplement VillagerTypes - ideally this could be made into an EnvironmentAttribute in Wyck
// Map<ResourceKey<Biome>, ResourceKey<VillagerType>> villagerMap = Reflection.VILLAGER_TYPE.getByBiome();
//
// villagerMap.put(delegateKey,
// Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
// villagerMap.getOrDefault(delegateKey, VillagerType.PLAINS)));
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.identifier());
LOGGER.debug("Registered biome: " + delegateKey);
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}));
// Add each terra biome to the same tag sets as it's associated vanilla biome
terraBiomeMap.forEach((vb, terraBiomes) -> {
Biome vanilla = BiomeHandler.getBiome(vb);
if(vanilla != null) {
terraBiomes.forEach(tb -> {
Biome terra = BiomeHandler.getBiome(tb);
if(terra != null) {
LOGGER.debug("{} (vanilla for {}): {}",
vanilla.resourceKey().identifier(),
terra.resourceKey().identifier(),
vanilla.tags().toList());
vanilla.tags() // TODO: Waiting on implementation from Wyck
.forEach(tag -> TagSet.ofBiomes(tag.key(), terra).append());
} else {
LOGGER.error("No such biome: {}", tb);
}
});
} else {
LOGGER.error("No vanilla biome: {}", vb);
}
});
}
}
@@ -48,7 +48,7 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class TerraBukkitPlugin extends JavaPlugin {
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
private PlatformImpl platform;
private BukkitPlatform platform;
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
private GlobalRegionScheduler globalRegionScheduler = this.getServer().getGlobalRegionScheduler();
@@ -59,12 +59,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
return;
}
platform = NMSInitializer.init(this);
if(platform == null) {
Bukkit.getPluginManager().disablePlugin(this);
return;
}
platform = new BukkitPlatform(this);
platform.getEventManager().callEvent(new PlatformInitializationEvent());
try {
@@ -101,7 +96,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
return commandManager;
}
public PlatformImpl getPlatform() {
public BukkitPlatform getPlatform() {
return platform;
}
@@ -0,0 +1,30 @@
package com.dfsek.terra.bukkit.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 dev.wyck.environment.sounds.AmbientAdditionsSettings;
import dev.wyck.environment.sounds.SoundEvent;
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 AmbientAdditionsSettings.builder()
.soundEvent(sound)
.tickChance(soundChance)
.build();
}
}
}
@@ -0,0 +1,40 @@
package com.dfsek.terra.bukkit.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 dev.wyck.environment.sounds.AmbientMoodSettings;
import dev.wyck.environment.sounds.SoundEvent;
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 AmbientMoodSettings.builder()
.soundEvent(sound)
.tickDelay(soundCultivationTicks)
.blockSearchExtent(soundSpawnRange)
.soundPositionOffset(soundExtraDistance)
.build();
}
}
}
@@ -0,0 +1,32 @@
package com.dfsek.terra.bukkit.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 dev.wyck.environment.particle.ParticleCatalog;
import dev.wyck.environment.particle.ParticleOptions;
public class BiomeParticleConfigTemplate implements ObjectTemplate<ParticleCatalog> {
@Value("particle")
@Default
private String particle = null;
@Value("probability")
@Default
private Float probability = 0.1f;
@Override
public ParticleCatalog get() {
if(particle == null) {
return null;
} else {
ParticleOptions particleOptions = ParticleArgument.readParticle(new StringReader(particle));
return ParticleCatalog.builder()
.particle(particleOptions) // TODO: Check that this supports custom particles
.probability(probability)
.build();
}
}
}
@@ -0,0 +1,22 @@
package com.dfsek.terra.bukkit.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 dev.wyck.keys.ResourceKey;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.entity.EntityType;
public class EntityTypeTemplate implements ObjectTemplate<EntityType> {
@Value("id")
@Default
private ResourceKey id = null;
@Override
public EntityType get() {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.ENTITY_TYPE)
.getOrThrow(id);
}
}
@@ -0,0 +1,40 @@
package com.dfsek.terra.bukkit.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 dev.wyck.environment.sounds.Music;
import dev.wyck.environment.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 Music.builder()
.sound(sound)
.minDelay(minDelay)
.maxDelay(maxDelay)
.replaceCurrentMusic(replaceCurrentMusic)
.build();
}
}
}
@@ -0,0 +1,29 @@
package com.dfsek.terra.bukkit.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 dev.wyck.environment.sounds.SoundEvent;
import dev.wyck.keys.ResourceKey;
public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
@Value("id")
@Default
private ResourceKey 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 SoundEvent.variableRange(id);
} else {
return SoundEvent.fixedRange(id, distanceToTravel);
}
}
}
@@ -0,0 +1,38 @@
package com.dfsek.terra.bukkit.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 org.bukkit.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,39 @@
package com.dfsek.terra.bukkit.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.dfsek.terra.api.util.range.Range;
import dev.wyck.biome.entity.SpawnerData;
import dev.wyck.worldgen.valueproviders.IntProvider;
import org.bukkit.entity.EntityType;
public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
@Value("type")
@Default
private EntityType type = null;
@Value("weight")
@Default
private Integer weight = null;
@Value("group-size")
@Default
private Range groupSize = null;
public Integer getWeight() {
return weight;
}
public SpawnerData getSpawnEntry() {
return SpawnerData.of(type, IntProvider.uniform(groupSize.getMin(), groupSize.getMax()));
}
@Override
public SpawnEntryConfig get() {
return this;
}
}
@@ -0,0 +1,49 @@
package com.dfsek.terra.bukkit.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 dev.wyck.biome.entity.MobCategory;
import dev.wyck.biome.entity.MobSpawnSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
private static final Logger logger = LoggerFactory.getLogger(SpawnTypeConfig.class);
private static boolean used = false;
@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 = MobSpawnSettings.builder();
for(SpawnTypeConfig spawn : spawns) {
MobCategory group = spawn.getGroup();
for(SpawnEntryConfig entry : spawn.getEntries()) {
builder.addSpawn(group, entry.getWeight(), entry.getSpawnEntry());
}
}
for(SpawnCostConfig cost : costs) {
builder.addMobSpawnCost(cost.getType(), cost.getMass(), cost.getGravity());
}
if(probability != null) {
builder.creatureGenerationProbability(probability);
}
return builder.build();
}
}
@@ -0,0 +1,32 @@
package com.dfsek.terra.bukkit.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 dev.wyck.biome.entity.MobCategory;
import java.util.List;
public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
@Value("group")
@Default
private MobCategory group = null;
@Value("entries")
@Default
private List<SpawnEntryConfig> entries = null;
public MobCategory getGroup() {
return group;
}
public List<SpawnEntryConfig> getEntries() {
return entries;
}
@Override
public SpawnTypeConfig get() {
return this;
}
}
@@ -0,0 +1,181 @@
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;
import dev.wyck.biome.TemperatureModifier;
import dev.wyck.biome.entity.MobSpawnSettings;
import dev.wyck.environment.GrassColorModifier;
import dev.wyck.environment.particle.AmbientParticle;
import dev.wyck.environment.particle.ParticleCatalog;
import dev.wyck.environment.sounds.AmbientAdditionsSettings;
import dev.wyck.environment.sounds.AmbientMoodSettings;
import dev.wyck.environment.sounds.Music;
import dev.wyck.environment.sounds.SoundEvent;
import org.bukkit.entity.Villager;
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.dry-foliage")
@Default
private Integer dryFoliageColor = null;
@Value("colors.sky")
@Default
private Integer skyColor = null;
@Value("colors.modifier")
@Default
private GrassColorModifier grassColorModifier = null;
@Value("particles")
@Default
private ParticleCatalog particleConfig = null;
@Value("climate.precipitation")
@Default
private Boolean precipitation = true;
@Value("climate.temperature")
@Default
private Float temperature = null;
@Value("climate.temperature-modifier")
@Default
private TemperatureModifier temperatureModifier = null;
@Value("climate.downfall")
@Default
private Float downfall = null;
@Value("sound.loop-sound.sound")
@Default
private SoundEvent loopSound = null;
@Value("sound.mood-sound")
@Default
private AmbientMoodSettings moodSound = null;
@Value("sound.additions-sound")
@Default
private AmbientAdditionsSettings additionsSound = null;
@Value("sound.music")
@Default
private Music music = null;
@Value("sound.music-volume")
@Default
private Float musicVolume = null;
@Value("spawning")
@Default
private MobSpawnSettings spawnSettings = null;
@Value("villager-type")
@Default
private Villager.Type villagerType = null;
public Integer getFogColor() {
return fogColor;
}
public Integer getFoliageColor() {
return foliageColor;
}
public Integer getDryFoliageColor() {
return dryFoliageColor;
}
public Integer getGrassColor() {
return grassColor;
}
public Integer getWaterColor() {
return waterColor;
}
public Integer getWaterFogColor() {
return waterFogColor;
}
public Integer getSkyColor() {
return skyColor;
}
public GrassColorModifier getGrassColorModifier() {
return grassColorModifier;
}
public ParticleCatalog getParticles() {
return particleConfig;
}
public Boolean 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 Float getMusicVolume() {
return musicVolume;
}
public MobSpawnSettings getSpawnSettings() {
return spawnSettings;
}
public Villager.Type getVillagerType() {
return villagerType;
}
}
@@ -0,0 +1,22 @@
package com.dfsek.terra.bukkit.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 dev.wyck.keys.ResourceKey;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.entity.Villager;
public class VillagerTypeTemplate implements ObjectTemplate<Villager.Type> {
@Value("id")
@Default
private ResourceKey id = null;
@Override
public Villager.Type get() {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.VILLAGER_TYPE)
.getOrThrow(id);
}
}
@@ -17,6 +17,7 @@
package com.dfsek.terra.bukkit.listeners;
import dev.wyck.keys.ResourceKey;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@@ -85,10 +86,10 @@ public class CommonListener implements Listener {
return;
}
NamespacedKey biomeKey = wolf.getWorld().getBiome(wolf.getLocation()).getKey();
ResourceKey biomeKey = ResourceKey.of(wolf.getWorld().getBiome(wolf.getLocation()).getKey());
pack.getBiomeProvider().stream()
.filter(biome -> {
NamespacedKey key = ((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
ResourceKey key = ((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
.get(BukkitBiomeInfo.class)
.biomeKey();
return key.equals(biomeKey);
@@ -0,0 +1,92 @@
package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
import dev.wyck.biome.Biome;
import dev.wyck.biome.Biome.Builder;
import dev.wyck.biome.BiomeGenerationSettings;
import dev.wyck.biome.BiomeSpecialEffects;
import dev.wyck.biome.ClimateSettings;
import dev.wyck.environment.attribute.EnvironmentAttributeSupplier;
import dev.wyck.environment.attribute.EnvironmentAttributes;
import dev.wyck.environment.sounds.AmbientSounds;
import dev.wyck.environment.sounds.BackgroundMusic;
import dev.wyck.keys.KeyChains;
import dev.wyck.keys.ResourceKey;
import java.util.Locale;
import java.util.Objects;
public class BiomeHandler {
public static Biome getBiome(ResourceKey key) {
Biome biome = KeyChains.BIOMES.get(key);
return biome != null ? biome.wrap() : null;
}
public static Biome getBiomeOrThrow(ResourceKey key) {
return KeyChains.BIOMES.getOrThrow(key).wrap();
}
public static Biome createBiome(ResourceKey vanillaBiomeKey, VanillaBiomeProperties vanillaBiomeProperties)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Biome vanilla = getBiomeOrThrow(vanillaBiomeKey);
Builder builder = dev.wyck.biome.Biome.builder();
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.FOG_COLOR, vanillaBiomeProperties.getFogColor());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.WATER_FOG_COLOR, vanillaBiomeProperties.getWaterFogColor());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.SKY_COLOR, vanillaBiomeProperties.getSkyColor());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.AMBIENT_PARTICLES, vanillaBiomeProperties.getParticles());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.AMBIENT_SOUNDS, AmbientSounds.builder()
.loop(vanillaBiomeProperties.getLoopSound())
.mood(vanillaBiomeProperties.getMoodSound())
.addition(vanillaBiomeProperties.getAdditionsSound())
.build());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.BACKGROUND_MUSIC, BackgroundMusic.builder()
.defaultMusic(vanillaBiomeProperties.getMusic())
.build());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.MUSIC_VOLUME, vanillaBiomeProperties.getMusicVolume());
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.NATURAL_MOB_SPAWNS, vanillaBiomeProperties.getSpawnSettings());
builder.climateSettings(ClimateSettings.builder()
.hasPrecipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.climateSettings().hasPrecipitation()))
.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.climateSettings().temperature()))
.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), vanilla.climateSettings().temperatureModifier()))
.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.climateSettings().downfall()))
.build());
BiomeSpecialEffects.Builder effects = BiomeSpecialEffects.builder();
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.specialEffects().waterColor()));
effects.grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.specialEffects().grassColorModifier()));
if(vanillaBiomeProperties.getGrassColor() == null) {
vanilla.specialEffects().grassColorOverride().ifPresent(effects::grassColorOverride);
} else {
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
}
if(vanillaBiomeProperties.getFoliageColor() == null) {
vanilla.specialEffects().foliageColorOverride().ifPresent(effects::foliageColorOverride);
} else {
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
}
return builder
.specialEffects(effects.build())
.generationSettings(BiomeGenerationSettings.builder()
.build())
.build();
}
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
return pack.getID().toLowerCase(Locale.ROOT)
+ "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT)
+ "/" + biomeID.getID().toLowerCase(Locale.ROOT);
}
private static <T> void setAttributeOrDefault(Biome.Builder builder, Biome def, EnvironmentAttributeSupplier<T> attribute, T value) {
builder.attribute(attribute, Objects.requireNonNullElse(value, def.attributes().get(attribute)));
}
}
@@ -1,9 +1,9 @@
package com.dfsek.terra.bukkit.world;
import org.bukkit.NamespacedKey;
import dev.wyck.keys.ResourceKey;
import com.dfsek.terra.api.properties.Properties;
public record BukkitBiomeInfo(NamespacedKey biomeKey) implements Properties {
public record BukkitBiomeInfo(ResourceKey biomeKey) implements Properties {
}
@@ -0,0 +1,40 @@
package com.dfsek.terra.bukkit.world;
import dev.wyck.biome.Biome;
import dev.wyck.worldgen.biome.custom.BiomeSourceContext;
import dev.wyck.worldgen.biome.custom.CustomBiomeSource;
import java.util.Set;
import java.util.stream.Collectors;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
public class BukkitBiomeProvider extends CustomBiomeSource {
private final BiomeProvider delegate;
private final long seed;
public BukkitBiomeProvider(BiomeProvider delegate, long seed) {
super();
this.delegate = delegate;
this.seed = seed;
}
@Override
public Biome biome(BiomeSourceContext context) {
return BiomeHandler.getBiomeOrThrow(((BukkitPlatformBiome) delegate.getBiome(context.blockX() << 2, context.blockY() << 2, context.blockZ() << 2, seed)
.getPlatformBiome()).getContext()
.get(BukkitBiomeInfo.class)
.biomeKey());
}
@Override
public Set<Biome> possibleBiomes() {
return delegate.stream()
.map(biome -> BiomeHandler.getBiomeOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome())
.getContext()
.get(BukkitBiomeInfo.class)
.biomeKey()))
.collect(Collectors.toSet());
}
}
@@ -4,6 +4,18 @@ version: "@VERSION@"
load: "STARTUP"
authors: [ "dfsek", "duplexsystem", "Astrash", "solonovamax", "Sancires", "Aureus", "RogueShade", "OakLoaf" ]
website: "@WIKI@"
api-version: "1.21.1"
api-version: "26.3"
bootstrapper: "com.dfsek.terra.bukkit.TerraBootstrapper"
description: "@DESCRIPTION@"
folia-supported: true
depend:
bootstrap:
Wyck:
load: BEFORE
required: true
join-classpath: true
server:
Wyck:
load: BEFORE
required: true
join-classpath: true