mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-12-03 11:52:14 +00:00
feat: finish Wyck port for Paper 26.3
This commit is contained in:
1 parent
12a5c8b1f5
commit
ad1d487032
32 files changed
+504
-722
No files matched your search
@@ -62,7 +62,6 @@ object Versions {
|
|||||||
const val minecraft = "26.3"
|
const val minecraft = "26.3"
|
||||||
const val paperBuild = "$minecraft.build.244-stable"
|
const val paperBuild = "$minecraft.build.244-stable"
|
||||||
const val paper = paperBuild
|
const val paper = paperBuild
|
||||||
const val paperLib = "1.0.8"
|
|
||||||
const val runPaper = "3.0.2"
|
const val runPaper = "3.0.2"
|
||||||
const val wyck = "4.0.0-837d6ec"
|
const val wyck = "4.0.0-837d6ec"
|
||||||
const val cloud = "2.0.1"
|
const val cloud = "2.0.1"
|
||||||
|
|||||||
@@ -89,6 +89,11 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
|
|
||||||
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
||||||
private static final String moonrise = "Moonrise";
|
private static final String moonrise = "Moonrise";
|
||||||
|
private static final String PACK_LOAD_FAILURE_QUOTE = """
|
||||||
|
> I felt a great disturbance in the JVM, as if millions of plugins suddenly cried out in stack traces and were suddenly silenced.
|
||||||
|
> I fear something terrible has happened.
|
||||||
|
> - Astrash
|
||||||
|
""".strip();
|
||||||
private final EventManager eventManager = new EventManagerImpl();
|
private final EventManager eventManager = new EventManagerImpl();
|
||||||
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||||
private final MetaConfigRegistry metaConfigRegistry = new MetaConfigRegistry();
|
private final MetaConfigRegistry metaConfigRegistry = new MetaConfigRegistry();
|
||||||
@@ -215,6 +220,7 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
return false;
|
return false;
|
||||||
} catch(PackLoadFailuresException e) {
|
} catch(PackLoadFailuresException e) {
|
||||||
e.getExceptions().forEach(ex -> logger.error("Failed to load config pack", ex));
|
e.getExceptions().forEach(ex -> logger.error("Failed to load config pack", ex));
|
||||||
|
logger.error(PACK_LOAD_FAILURE_QUOTE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -231,6 +237,7 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
return false;
|
return false;
|
||||||
} catch(PackLoadFailuresException e) {
|
} catch(PackLoadFailuresException e) {
|
||||||
e.getExceptions().forEach(ex -> logger.error("Failed to meta load config pack", ex));
|
e.getExceptions().forEach(ex -> logger.error("Failed to meta load config pack", ex));
|
||||||
|
logger.error(PACK_LOAD_FAILURE_QUOTE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> implements Exte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validatePathIsMember(Path path) {
|
public boolean validatePathIsMember(Path path) {
|
||||||
return Files.isDirectory(path)|| path.getFileName().endsWith(".zip");
|
return Files.isDirectory(path)|| path.getFileName().toString().endsWith(".zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PackLoadFailuresException extends Exception {
|
public static class PackLoadFailuresException extends Exception {
|
||||||
|
|||||||
+1
-1
@@ -68,6 +68,6 @@ public class MetaConfigRegistry extends OpenRegistryImpl<MetaPack> implements Ex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validatePathIsMember(Path path) {
|
public boolean validatePathIsMember(Path path) {
|
||||||
return Files.isDirectory(path) || path.getFileName().endsWith(".zip");
|
return Files.isDirectory(path) || path.getFileName().toString().endsWith(".zip");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,6 @@ tasks.withType<JavaCompile>().configureEach {
|
|||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
shadowJar {
|
shadowJar {
|
||||||
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
|
|
||||||
relocate("com.google.common", "com.dfsek.terra.lib.google.common")
|
relocate("com.google.common", "com.dfsek.terra.lib.google.common")
|
||||||
relocate("org.apache.logging.slf4j", "com.dfsek.terra.lib.slf4j-over-log4j")
|
relocate("org.apache.logging.slf4j", "com.dfsek.terra.lib.slf4j-over-log4j")
|
||||||
exclude("org/slf4j/**")
|
exclude("org/slf4j/**")
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ dependencies {
|
|||||||
|
|
||||||
compileOnly("org.mvplugins.multiverse.core", "multiverse-core", Versions.Bukkit.multiverse)
|
compileOnly("org.mvplugins.multiverse.core", "multiverse-core", Versions.Bukkit.multiverse)
|
||||||
|
|
||||||
shadedApi("io.papermc", "paperlib", Versions.Bukkit.paperLib)
|
|
||||||
|
|
||||||
shadedApi("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
shadedApi("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
||||||
|
|
||||||
shadedApi("org.incendo", "cloud-paper", Versions.Bukkit.cloud)
|
shadedApi("org.incendo", "cloud-paper", Versions.Bukkit.cloud)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package com.dfsek.terra.bukkit;
|
package com.dfsek.terra.bukkit;
|
||||||
|
|
||||||
import com.dfsek.seismic.type.vector.Vector3;
|
import com.dfsek.seismic.type.vector.Vector3;
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import com.dfsek.terra.api.entity.Entity;
|
import com.dfsek.terra.api.entity.Entity;
|
||||||
@@ -45,14 +44,14 @@ public class BukkitEntity implements Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void position(Vector3 location) {
|
public void position(Vector3 location) {
|
||||||
PaperLib.teleportAsync(entity, BukkitAdapter.adapt(location).toLocation(entity.getWorld()));
|
entity.teleportAsync(BukkitAdapter.adapt(location).toLocation(entity.getWorld()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void world(ServerWorld world) {
|
public void world(ServerWorld world) {
|
||||||
Location newLoc = entity.getLocation().clone();
|
Location newLoc = entity.getLocation().clone();
|
||||||
newLoc.setWorld(BukkitAdapter.adapt(world));
|
newLoc.setWorld(BukkitAdapter.adapt(world));
|
||||||
PaperLib.teleportAsync(entity, newLoc);
|
entity.teleportAsync(newLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import com.dfsek.terra.api.world.biome.PlatformBiome;
|
|||||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||||
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
||||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||||
|
import com.dfsek.terra.bukkit.world.BiomeHandler;
|
||||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||||
|
|
||||||
|
|
||||||
@@ -97,6 +98,8 @@ public class BukkitPlatform extends AbstractPlatform {
|
|||||||
public boolean reload() {
|
public boolean reload() {
|
||||||
getTerraConfig().load(this);
|
getTerraConfig().load(this);
|
||||||
boolean succeed = loadConfigPacks();
|
boolean succeed = loadConfigPacks();
|
||||||
|
BiomeHandler.registerBiomes(getRawConfigRegistry());
|
||||||
|
BiomeHandler.addToVanillaTags(getRawConfigRegistry());
|
||||||
|
|
||||||
Bukkit.getWorlds().forEach(world -> {
|
Bukkit.getWorlds().forEach(world -> {
|
||||||
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) {
|
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) {
|
||||||
@@ -149,19 +152,16 @@ public class BukkitPlatform extends AbstractPlatform {
|
|||||||
public void register(TypeRegistry registry) {
|
public void register(TypeRegistry registry) {
|
||||||
super.register(registry);
|
super.register(registry);
|
||||||
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> handle.createBlockState((String) o))
|
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(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||||
.registerLoader(ResourceKey.class, (type, o, loader, depthTracker) -> {
|
.registerLoader(ResourceKey.class, (type, o, loader, depthTracker) -> {
|
||||||
String[] parts = ((String) o).split(":", 2);
|
NamespacedKey key = NamespacedKey.fromString(((String) o).toLowerCase(Locale.ROOT));
|
||||||
if(parts.length == 0 || parts.length > 2)
|
if(key == null) throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||||
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
return ResourceKey.of(key);
|
||||||
return ResourceKey.of(parts[0], parts[1]);
|
|
||||||
})
|
})
|
||||||
.registerLoader(GrassColorModifier.class,
|
.registerLoader(GrassColorModifier.class,
|
||||||
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||||
Locale.ROOT)))
|
Locale.ROOT)))
|
||||||
.registerLoader(GrassColorModifier.class,
|
.registerLoader(TemperatureModifier.class,
|
||||||
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||||
Locale.ROOT)))
|
Locale.ROOT)))
|
||||||
.registerLoader(MobCategory.class, (type, o, loader, depthTracker) -> MobCategory.valueOf((String) o))
|
.registerLoader(MobCategory.class, (type, o, loader, depthTracker) -> MobCategory.valueOf((String) o))
|
||||||
@@ -181,6 +181,8 @@ public class BukkitPlatform extends AbstractPlatform {
|
|||||||
protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||||
NamespacedKey key = NamespacedKey.fromString(id);
|
NamespacedKey key = NamespacedKey.fromString(id);
|
||||||
if(key == null || !key.namespace().equals("minecraft")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
|
if(key == null || !key.namespace().equals("minecraft")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
|
||||||
return new BukkitPlatformBiome(RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).getOrThrow(key));
|
org.bukkit.block.Biome biome = RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).get(key);
|
||||||
|
if(biome == null) throw new LoadException("No such biome " + id, depthTracker);
|
||||||
|
return new BukkitPlatformBiome(biome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
package com.dfsek.terra.bukkit;
|
package com.dfsek.terra.bukkit;
|
||||||
|
|
||||||
import com.dfsek.seismic.type.vector.Vector3;
|
import com.dfsek.seismic.type.vector.Vector3;
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import com.dfsek.terra.api.entity.Player;
|
import com.dfsek.terra.api.entity.Player;
|
||||||
@@ -46,14 +45,14 @@ public class BukkitPlayer implements Player {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void position(Vector3 location) {
|
public void position(Vector3 location) {
|
||||||
PaperLib.teleportAsync(delegate, BukkitAdapter.adapt(location).toLocation(delegate.getWorld()));
|
delegate.teleportAsync(BukkitAdapter.adapt(location).toLocation(delegate.getWorld()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void world(ServerWorld world) {
|
public void world(ServerWorld world) {
|
||||||
Location newLoc = delegate.getLocation().clone();
|
Location newLoc = delegate.getLocation().clone();
|
||||||
newLoc.setWorld(BukkitAdapter.adapt(world));
|
newLoc.setWorld(BukkitAdapter.adapt(world));
|
||||||
PaperLib.teleportAsync(delegate, newLoc);
|
delegate.teleportAsync(newLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+8
-2
@@ -1,7 +1,7 @@
|
|||||||
package com.dfsek.terra.bukkit;
|
package com.dfsek.terra.bukkit;
|
||||||
|
|
||||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
import org.bukkit.ChatColor;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -12,6 +12,12 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
|||||||
|
|
||||||
|
|
||||||
public class CloudCommandSender implements CommandSender {
|
public class CloudCommandSender implements CommandSender {
|
||||||
|
private static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.builder()
|
||||||
|
.character(LegacyComponentSerializer.AMPERSAND_CHAR)
|
||||||
|
.hexColors()
|
||||||
|
.useUnusualXRepeatedCharacterHexFormat()
|
||||||
|
.build();
|
||||||
|
|
||||||
private final CommandSourceStack delegate;
|
private final CommandSourceStack delegate;
|
||||||
|
|
||||||
public CloudCommandSender(CommandSourceStack delegate) {
|
public CloudCommandSender(CommandSourceStack delegate) {
|
||||||
@@ -20,7 +26,7 @@ public class CloudCommandSender implements CommandSender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
delegate.getSender().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
delegate.getSender().sendMessage(LEGACY_AMPERSAND.deserialize(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+14
-87
@@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.bukkit;
|
package com.dfsek.terra.bukkit;
|
||||||
|
|
||||||
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
|
import io.papermc.paper.ServerBuildInfo;
|
||||||
|
import io.papermc.paper.ServerBuildInfo.StringRepresentation;
|
||||||
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
|
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
@@ -32,16 +33,15 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.command.CommandSender;
|
import com.dfsek.terra.api.command.CommandSender;
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||||
|
import com.dfsek.terra.bukkit.listeners.BiomeListener;
|
||||||
import com.dfsek.terra.bukkit.listeners.CommonListener;
|
import com.dfsek.terra.bukkit.listeners.CommonListener;
|
||||||
import com.dfsek.terra.bukkit.util.PaperUtil;
|
import com.dfsek.terra.bukkit.world.BiomeHandler;
|
||||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
|
||||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||||
|
|
||||||
|
|
||||||
@@ -49,18 +49,15 @@ 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 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<>();
|
||||||
private BukkitPlatform platform;
|
private BukkitPlatform platform;
|
||||||
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
|
|
||||||
|
|
||||||
private GlobalRegionScheduler globalRegionScheduler = this.getServer().getGlobalRegionScheduler();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
if(!doVersionCheck()) {
|
logServerVersion();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
platform = new BukkitPlatform(this);
|
platform = new BukkitPlatform(this);
|
||||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
platform.getEventManager().callEvent(new PlatformInitializationEvent()); // Loads config packs
|
||||||
|
BiomeHandler.registerBiomes(platform.getRawConfigRegistry());
|
||||||
|
BiomeHandler.addToVanillaTags(platform.getRawConfigRegistry());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
|
PaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
|
||||||
@@ -79,7 +76,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new CommonListener(platform), this); // Register master event listener
|
Bukkit.getPluginManager().registerEvents(new CommonListener(platform), this); // Register master event listener
|
||||||
PaperUtil.checkPaper(this);
|
Bukkit.getPluginManager().registerEvents(new BiomeListener(platform), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -100,76 +97,10 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "deprecation", "AccessOfSystemProperties" })
|
private void logServerVersion() {
|
||||||
private boolean doVersionCheck() {
|
ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo();
|
||||||
logger.info("Running on Minecraft version {} with server implementation {}.", VersionUtil.getMinecraftVersionInfo(),
|
logger.info("Running on Minecraft version {} with server implementation {} {}.", buildInfo.minecraftVersionName(),
|
||||||
Bukkit.getServer().getName());
|
buildInfo.brandName(), buildInfo.asString(StringRepresentation.VERSION_SIMPLE));
|
||||||
|
|
||||||
if(!VersionUtil.getSpigotVersionInfo().isSpigot())
|
|
||||||
logger.error("YOU ARE RUNNING A CRAFTBUKKIT OR BUKKIT SERVER. PLEASE UPGRADE TO PAPER.");
|
|
||||||
|
|
||||||
if(!VersionUtil.getSpigotVersionInfo().isPaper())
|
|
||||||
logger.error("YOU ARE RUNNING A SPIGOT SERVER. PLEASE UPGRADE TO PAPER.");
|
|
||||||
|
|
||||||
if(VersionUtil.getSpigotVersionInfo().isMohist()) {
|
|
||||||
if(System.getProperty("IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways") == null) {
|
|
||||||
Runnable runnable = () -> { // scary big block of text
|
|
||||||
logger.error("""
|
|
||||||
.----------------------------------------------------------------------------------.
|
|
||||||
| |
|
|
||||||
| ⚠ !! Warning !! ⚠ |
|
|
||||||
| |
|
|
||||||
| You are currently using Mohist. |
|
|
||||||
| |
|
|
||||||
| Do not use Mohist. |
|
|
||||||
| |
|
|
||||||
| The concept of combining the rigid Bukkit platform, which assumes a 100% |
|
|
||||||
| Vanilla server, with the flexible Forge platform, which allows changing |
|
|
||||||
| core components of the game, simply does not work. These platforms are |
|
|
||||||
| incompatible at a conceptual level, the only way to combine them would |
|
|
||||||
| be to make incompatible changes to both. As a result, Mohist's Bukkit |
|
|
||||||
| API implementation is not compliant. This will cause many plugins to |
|
|
||||||
| break. Rather than fix their platform, Mohist has chosen to distribute |
|
|
||||||
| unofficial builds of plugins they deem to be "fixed". These builds are not |
|
|
||||||
| "fixed", they are simply hacked together to work with Mohist's half-baked |
|
|
||||||
| Bukkit implementation. To distribute these as "fixed" versions implies that: |
|
|
||||||
| - These builds are endorsed by the original developers. (They are not) |
|
|
||||||
| - The issue is on the plugin's end, not Mohist's. (It is not. The issue |
|
|
||||||
| is that Mohist chooses to not create a compliant Bukkit implementation) |
|
|
||||||
| Please, do not use Mohist. It causes issues with most plugins, and rather |
|
|
||||||
| than fixing their platform, Mohist has chosen to distribute unofficial |
|
|
||||||
| hacked-together builds of plugins, calling them "fixed". If you want |
|
|
||||||
| to use a server API with Forge mods, look at the Sponge project, an |
|
|
||||||
| API that is designed to be implementation-agnostic, with first-party |
|
|
||||||
| support for the Forge mod loader. You are bound to encounter issues if |
|
|
||||||
| you use Terra with Mohist. We will provide NO SUPPORT for servers running |
|
|
||||||
| Mohist. If you wish to proceed anyways, you can add the JVM System Property |
|
|
||||||
| "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" to enable the plugin. No |
|
|
||||||
| support will be provided for servers running Mohist. |
|
|
||||||
| |
|
|
||||||
| Because of this **TERRA HAS BEEN DISABLED**. |
|
|
||||||
| Do not come ask us why it is not working. |
|
|
||||||
| |
|
|
||||||
|----------------------------------------------------------------------------------|
|
|
||||||
""".strip());
|
|
||||||
};
|
|
||||||
runnable.run();
|
|
||||||
asyncScheduler.runDelayed(this, task -> runnable.run(), 200L, TimeUnit.SECONDS);
|
|
||||||
// Bukkit.shutdown(); // we're not *that* evil
|
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
logger.warn("""
|
|
||||||
You are using Mohist, so we will not give you any support for issues that may arise.
|
|
||||||
Since you enabled the "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" flag, we won't disable Terra. But be warned.
|
|
||||||
|
|
||||||
> I felt a great disturbance in the JVM, as if millions of plugins suddenly cried out in stack traces and were suddenly silenced.
|
|
||||||
> I fear something terrible has happened.
|
|
||||||
> - Astrash
|
|
||||||
""".strip());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -183,11 +114,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
}), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air());
|
}), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncScheduler getAsyncScheduler() {
|
|
||||||
return asyncScheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalRegionScheduler getGlobalRegionScheduler() {
|
public GlobalRegionScheduler getGlobalRegionScheduler() {
|
||||||
return globalRegionScheduler;
|
return getServer().getGlobalRegionScheduler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+18
-8
@@ -3,12 +3,20 @@ package com.dfsek.terra.bukkit.config;
|
|||||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
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.annotations.Value;
|
||||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import dev.wyck.environment.particle.AmbientParticle;
|
||||||
import dev.wyck.environment.particle.ParticleCatalog;
|
import dev.wyck.environment.particle.ParticleCatalog;
|
||||||
import dev.wyck.environment.particle.ParticleOptions;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.util.VanillaParticles;
|
||||||
|
|
||||||
|
|
||||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<ParticleCatalog> {
|
public class BiomeParticleConfigTemplate implements ObjectTemplate<ParticleCatalog> {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(BiomeParticleConfigTemplate.class);
|
||||||
|
|
||||||
@Value("particle")
|
@Value("particle")
|
||||||
@Default
|
@Default
|
||||||
private String particle = null;
|
private String particle = null;
|
||||||
@@ -21,12 +29,14 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<ParticleCatal
|
|||||||
public ParticleCatalog get() {
|
public ParticleCatalog get() {
|
||||||
if(particle == null) {
|
if(particle == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
ParticleOptions particleOptions = ParticleArgument.readParticle(new StringReader(particle));
|
|
||||||
return ParticleCatalog.builder()
|
try {
|
||||||
.particle(particleOptions) // TODO: Check that this supports custom particles
|
AmbientParticle parsed = VanillaParticles.parse(particle, probability);
|
||||||
.probability(probability)
|
return parsed == null ? null : new ParticleCatalog(List.of(parsed));
|
||||||
.build();
|
} catch(CommandSyntaxException | RuntimeException e) {
|
||||||
|
LOGGER.warn("Skipping particle \"{}\": {}", particle, e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-3
@@ -6,7 +6,6 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.util.range.Range;
|
import com.dfsek.terra.api.util.range.Range;
|
||||||
|
|
||||||
import dev.wyck.biome.entity.SpawnerData;
|
|
||||||
import dev.wyck.worldgen.valueproviders.IntProvider;
|
import dev.wyck.worldgen.valueproviders.IntProvider;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
@@ -28,8 +27,12 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
|
|||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpawnerData getSpawnEntry() {
|
public EntityType getType() {
|
||||||
return SpawnerData.of(type, IntProvider.uniform(groupSize.getMin(), groupSize.getMax()));
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntProvider getCount() {
|
||||||
|
return IntProvider.uniform(groupSize.getMin(), groupSize.getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+15
-10
@@ -9,12 +9,13 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
|
||||||
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
|
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SpawnTypeConfig.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(SpawnSettingsTemplate.class);
|
||||||
private static boolean used = false;
|
private static final AtomicBoolean PROBABILITY_WARNING_LOGGED = new AtomicBoolean(false);
|
||||||
|
|
||||||
@Value("spawns")
|
@Value("spawns")
|
||||||
@Default
|
@Default
|
||||||
@@ -31,17 +32,21 @@ public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
|
|||||||
@Override
|
@Override
|
||||||
public MobSpawnSettings get() {
|
public MobSpawnSettings get() {
|
||||||
MobSpawnSettings.Builder builder = MobSpawnSettings.builder();
|
MobSpawnSettings.Builder builder = MobSpawnSettings.builder();
|
||||||
for(SpawnTypeConfig spawn : spawns) {
|
if(spawns != null) {
|
||||||
MobCategory group = spawn.getGroup();
|
for(SpawnTypeConfig spawn : spawns) {
|
||||||
for(SpawnEntryConfig entry : spawn.getEntries()) {
|
MobCategory group = spawn.getGroup();
|
||||||
builder.addSpawn(group, entry.getWeight(), entry.getSpawnEntry());
|
for(SpawnEntryConfig entry : spawn.getEntries()) {
|
||||||
|
builder.addSpawn(entry.getType(), group, entry.getWeight(), entry.getCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(SpawnCostConfig cost : costs) {
|
if(costs != null) {
|
||||||
builder.addMobSpawnCost(cost.getType(), cost.getMass(), cost.getGravity());
|
for(SpawnCostConfig cost : costs) {
|
||||||
|
builder.addMobSpawnCost(cost.getType(), cost.getMass(), cost.getGravity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(probability != null) {
|
if(probability != null && PROBABILITY_WARNING_LOGGED.compareAndSet(false, true)) {
|
||||||
builder.creatureGenerationProbability(probability);
|
LOGGER.warn("Biome spawning.probability is ignored on this server version.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|||||||
+11
-3
@@ -10,6 +10,8 @@ import java.util.stream.StreamSupport;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.Handle;
|
import com.dfsek.terra.api.Handle;
|
||||||
import com.dfsek.terra.api.world.biome.Biome;
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
|
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
|
||||||
|
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||||
|
|
||||||
|
|
||||||
public class BukkitBiomeProvider extends BiomeProvider implements Handle {
|
public class BukkitBiomeProvider extends BiomeProvider implements Handle {
|
||||||
@@ -19,17 +21,23 @@ public class BukkitBiomeProvider extends BiomeProvider implements Handle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull org.bukkit.block.Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
|
public @NotNull org.bukkit.block.Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
|
||||||
Biome biome = delegate.getBiome(x, y, z, worldInfo.getSeed());
|
return toBukkit(delegate.getBiome(x, y, z, worldInfo.getSeed()));
|
||||||
return (org.bukkit.block.Biome) biome.getPlatformBiome().getHandle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<org.bukkit.block.Biome> getBiomes(@NotNull WorldInfo worldInfo) {
|
public @NotNull List<org.bukkit.block.Biome> getBiomes(@NotNull WorldInfo worldInfo) {
|
||||||
return StreamSupport.stream(delegate.getBiomes().spliterator(), false)
|
return StreamSupport.stream(delegate.getBiomes().spliterator(), false)
|
||||||
.map(terraBiome -> (org.bukkit.block.Biome) terraBiome.getPlatformBiome().getHandle())
|
.map(BukkitBiomeProvider::toBukkit)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static org.bukkit.block.Biome toBukkit(Biome biome) {
|
||||||
|
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||||
|
return platformBiome.getContext().has(BukkitBiomeInfo.class)
|
||||||
|
? platformBiome.getContext().get(BukkitBiomeInfo.class).bukkitBiome()
|
||||||
|
: platformBiome.getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getHandle() {
|
public Object getHandle() {
|
||||||
return delegate;
|
return delegate;
|
||||||
|
|||||||
+33
-19
@@ -17,7 +17,12 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.bukkit.generator;
|
package com.dfsek.terra.bukkit.generator;
|
||||||
|
|
||||||
|
import org.bukkit.HeightMap;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Waterlogged;
|
||||||
import org.bukkit.generator.BiomeProvider;
|
import org.bukkit.generator.BiomeProvider;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.WorldInfo;
|
import org.bukkit.generator.WorldInfo;
|
||||||
@@ -33,8 +38,9 @@ import com.dfsek.terra.api.block.state.BlockState;
|
|||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
||||||
import com.dfsek.terra.bukkit.world.BukkitWorldProperties;
|
import com.dfsek.terra.bukkit.world.BukkitWorldProperties;
|
||||||
|
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||||
|
|
||||||
|
|
||||||
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
|
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
|
||||||
@@ -67,6 +73,32 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
|||||||
delegate.generateChunkData(new BukkitProtoChunk(chunkData), properties, pack.getBiomeProvider(), x, z);
|
delegate.generateChunkData(new BukkitProtoChunk(chunkData), properties, pack.getBiomeProvider(), x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBaseHeight(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull HeightMap heightMap) {
|
||||||
|
BukkitWorldProperties properties = new BukkitWorldProperties(worldInfo);
|
||||||
|
com.dfsek.terra.api.world.biome.generation.BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||||
|
int y = properties.getMaxHeight();
|
||||||
|
while(y > properties.getMinHeight() &&
|
||||||
|
!isHeightmapBlock(heightMap, ((BukkitBlockState) delegate.getBlock(properties, x, y - 1, z, biomeProvider)).getHandle())) {
|
||||||
|
y--;
|
||||||
|
}
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isHeightmapBlock(HeightMap heightMap, BlockData data) {
|
||||||
|
Material material = data.getMaterial();
|
||||||
|
return switch(heightMap) {
|
||||||
|
case WORLD_SURFACE, WORLD_SURFACE_WG -> !material.isAir();
|
||||||
|
case OCEAN_FLOOR, OCEAN_FLOOR_WG -> material.isSolid();
|
||||||
|
case MOTION_BLOCKING -> material.isSolid() || hasFluid(data);
|
||||||
|
case MOTION_BLOCKING_NO_LEAVES -> (material.isSolid() || hasFluid(data)) && !Tag.LEAVES.isTagged(material);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasFluid(BlockData data) {
|
||||||
|
return BukkitUtils.isLiquid(data) || (data instanceof Waterlogged waterlogged && waterlogged.isWaterlogged());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||||
return List.of(blockPopulator);
|
return List.of(blockPopulator);
|
||||||
@@ -106,22 +138,4 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
|||||||
public ChunkGenerator getHandle() {
|
public ChunkGenerator getHandle() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private record SeededVector(int x, int z, WorldProperties worldProperties) {
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if(obj instanceof SeededVector that) {
|
|
||||||
return this.z == that.z && this.x == that.x && this.worldProperties.equals(that.worldProperties);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int code = x;
|
|
||||||
code = 31 * code + z;
|
|
||||||
return 31 * code + worldProperties.hashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+10
-5
@@ -17,17 +17,18 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.bukkit.handles;
|
package com.dfsek.terra.bukkit.handles;
|
||||||
|
|
||||||
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.dfsek.terra.api.handle.ItemHandle;
|
import com.dfsek.terra.api.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.inventory.Item;
|
import com.dfsek.terra.api.inventory.Item;
|
||||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||||
import com.dfsek.terra.bukkit.util.MinecraftUtils;
|
|
||||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||||
|
|
||||||
|
|
||||||
@@ -40,12 +41,16 @@ public class BukkitItemHandle implements ItemHandle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Enchantment getEnchantment(String id) {
|
public Enchantment getEnchantment(String id) {
|
||||||
return BukkitAdapter.adapt(
|
NamespacedKey key = NamespacedKey.fromString(id);
|
||||||
org.bukkit.enchantments.Enchantment.getByKey(NamespacedKey.minecraft(MinecraftUtils.stripMinecraftNamespace(id))));
|
return BukkitAdapter.adapt(key == null ? null : enchantments().get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Enchantment> getEnchantments() {
|
public Set<Enchantment> getEnchantments() {
|
||||||
return Arrays.stream(org.bukkit.enchantments.Enchantment.values()).map(BukkitAdapter::adapt).collect(Collectors.toSet());
|
return enchantments().stream().map(BukkitAdapter::adapt).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Registry<org.bukkit.enchantments.Enchantment> enchantments() {
|
||||||
|
return RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-14
@@ -19,7 +19,6 @@ package com.dfsek.terra.bukkit.handles;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -30,8 +29,6 @@ import com.dfsek.terra.api.handle.WorldHandle;
|
|||||||
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
||||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
|
|
||||||
public class BukkitWorldHandle implements WorldHandle {
|
public class BukkitWorldHandle implements WorldHandle {
|
||||||
@@ -44,18 +41,13 @@ public class BukkitWorldHandle implements WorldHandle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized @NotNull BlockState createBlockState(@NotNull String data) {
|
public synchronized @NotNull BlockState createBlockState(@NotNull String data) {
|
||||||
|
// BlockData can't hold block entity NBT.
|
||||||
|
int nbtStart = data.indexOf('{');
|
||||||
|
String state = nbtStart >= 0 ? data.substring(0, nbtStart) : data;
|
||||||
try {
|
try {
|
||||||
org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(data); // somehow bukkit managed to make this not thread safe! :)
|
return BukkitBlockState.newInstance(Bukkit.createBlockData(state)); // somehow bukkit managed to make this not thread safe! :)
|
||||||
return BukkitBlockState.newInstance(bukkitData);
|
} catch(IllegalArgumentException e) {
|
||||||
} catch (Exception ignored) {
|
throw new IllegalArgumentException("Invalid block state data: " + data, e);
|
||||||
try {
|
|
||||||
Class<?> hacks = Class.forName("com.dfsek.terra.bukkit.nms.AwfulBukkitHacks");
|
|
||||||
Method method = hacks.getMethod("createBlockState", String.class);
|
|
||||||
Object result = method.invoke(null, data);
|
|
||||||
return BukkitBlockState.newInstance((BlockData) result);
|
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
|
||||||
throw new IllegalArgumentException("Invalid block state data: " + data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
package com.dfsek.terra.bukkit.listeners;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.entity.ZombieVillager;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
|
import org.bukkit.event.entity.EntityBreedEvent;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.BukkitPlatform;
|
||||||
|
import com.dfsek.terra.bukkit.world.BiomeHandler;
|
||||||
|
|
||||||
|
|
||||||
|
public class BiomeListener implements Listener {
|
||||||
|
private static final Set<SpawnReason> BIOME_TYPED_VILLAGER_REASONS = Set.of(
|
||||||
|
SpawnReason.SPAWNER_EGG, SpawnReason.DISPENSE_EGG, SpawnReason.SPAWNER, SpawnReason.COMMAND);
|
||||||
|
|
||||||
|
private final BukkitPlatform platform;
|
||||||
|
|
||||||
|
public BiomeListener(BukkitPlatform platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
|
||||||
|
BiomeHandler.addToVanillaTags(platform.getRawConfigRegistry());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||||
|
SpawnReason reason = event.getSpawnReason();
|
||||||
|
if(event.getEntity() instanceof Villager villager && BIOME_TYPED_VILLAGER_REASONS.contains(reason)) {
|
||||||
|
applyBiomeType(villager);
|
||||||
|
} else if(event.getEntity() instanceof ZombieVillager zombieVillager && reason != SpawnReason.INFECTION) {
|
||||||
|
Villager.Type type = biomeType(zombieVillager);
|
||||||
|
if(type != null && zombieVillager.getVillagerType() == Villager.Type.PLAINS) {
|
||||||
|
zombieVillager.setVillagerType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onBreed(EntityBreedEvent event) {
|
||||||
|
if(event.getEntity() instanceof Villager child && isNotPlains(event.getMother()) && isNotPlains(event.getFather())) {
|
||||||
|
applyBiomeType(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyBiomeType(Villager villager) {
|
||||||
|
Villager.Type type = biomeType(villager);
|
||||||
|
if(type != null && villager.getVillagerType() == Villager.Type.PLAINS) {
|
||||||
|
villager.setVillagerType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Villager.Type biomeType(Entity entity) {
|
||||||
|
Location location = entity.getLocation();
|
||||||
|
if(!entity.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) return null;
|
||||||
|
return BiomeHandler.getVillagerType(entity.getWorld().getBiome(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isNotPlains(LivingEntity parent) {
|
||||||
|
return parent instanceof Villager villager && villager.getVillagerType() != Villager.Type.PLAINS;
|
||||||
|
}
|
||||||
|
}
|
||||||
-104
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Terra.
|
|
||||||
*
|
|
||||||
* Terra is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Terra is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.bukkit.listeners;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Villager;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
|
||||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
|
||||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
|
|
||||||
* <p>
|
|
||||||
* (This is currently loaded on all servers; once Paper accepts the StructureLocateEvent PR this will only be loaded on servers without
|
|
||||||
* StructureLocateEvent).
|
|
||||||
*/
|
|
||||||
public class SpigotListener implements Listener {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
|
||||||
private final Platform platform;
|
|
||||||
|
|
||||||
public SpigotListener(Platform platform) {
|
|
||||||
this.platform = platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
|
||||||
public void onEnderEye(EntitySpawnEvent e) {
|
|
||||||
/*
|
|
||||||
Entity entity = e.getEntity();
|
|
||||||
if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
|
|
||||||
logger.info("Detected Ender Signal...");
|
|
||||||
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
|
||||||
EnderSignal signal = (EnderSignal) entity;
|
|
||||||
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
|
||||||
("STRONGHOLD"));
|
|
||||||
if(config != null) {
|
|
||||||
logger.info("Overriding Ender Signal...");
|
|
||||||
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()
|
|
||||||
.toVector()), tw.getWorld(), 0, 500, location -> {
|
|
||||||
if(location != null)
|
|
||||||
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
|
||||||
logger.info("Location: {}", location);
|
|
||||||
}, main);
|
|
||||||
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
|
||||||
} else
|
|
||||||
logger.warn("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
|
||||||
if(!(e.getEntity() instanceof Villager))
|
|
||||||
return;
|
|
||||||
if(((Villager) e.getEntity()).getProfession() == Villager.Profession.CARTOGRAPHER) {
|
|
||||||
logger.error("""
|
|
||||||
.------------------------------------------------------------------------.
|
|
||||||
| Prevented server crash by stopping Cartographer villager from |
|
|
||||||
| spawning. Please upgrade to Paper, which has a StructureLocateEvent |
|
|
||||||
| that fixes this issue at the source, and doesn't require us to do |
|
|
||||||
| stupid band-aids. |
|
|
||||||
|------------------------------------------------------------------------|
|
|
||||||
""".strip());
|
|
||||||
e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
|
||||||
if(e.getProfession() == Villager.Profession.CARTOGRAPHER) {
|
|
||||||
logger.error("""
|
|
||||||
.------------------------------------------------------------------------.
|
|
||||||
| Prevented server crash by stopping Cartographer villager from leveling |
|
|
||||||
| up. Please upgrade to Paper, which has a StructureLocateEvent that |
|
|
||||||
| fixes this issue at the source, and doesn't require us to do stupid |
|
|
||||||
| band-aids. |
|
|
||||||
|------------------------------------------------------------------------|
|
|
||||||
""".strip());
|
|
||||||
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
package com.dfsek.terra.bukkit.util;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.block.CreatureSpawner;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.entity.EntityType;
|
|
||||||
import com.dfsek.terra.api.entity.EntityTypeExtended;
|
|
||||||
|
|
||||||
|
|
||||||
public interface BukkitNMSAccess {
|
|
||||||
EntityType getEntityType(String data);
|
|
||||||
|
|
||||||
org.bukkit.entity.Entity spawnEntity(Object target, Location location, EntityType type);
|
|
||||||
|
|
||||||
void setSpawnerEntity(CreatureSpawner spawner, EntityTypeExtended type);
|
|
||||||
}
|
|
||||||
+53
-33
@@ -1,62 +1,82 @@
|
|||||||
package com.dfsek.terra.bukkit.util;
|
package com.dfsek.terra.bukkit.util;
|
||||||
|
|
||||||
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.Registry;
|
import org.bukkit.RegionAccessor;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntitySnapshot;
|
||||||
|
import org.bukkit.generator.LimitedRegion;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import com.dfsek.terra.api.entity.EntityType;
|
import com.dfsek.terra.api.entity.EntityType;
|
||||||
import com.dfsek.terra.api.entity.EntityTypeExtended;
|
import com.dfsek.terra.api.entity.EntityTypeExtended;
|
||||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||||
|
import com.dfsek.terra.bukkit.world.entity.BukkitEntityTypeExtended;
|
||||||
|
|
||||||
|
|
||||||
public class BukkitUtils {
|
public class BukkitUtils {
|
||||||
private static volatile BukkitNMSAccess nmsAccess;
|
|
||||||
|
|
||||||
public static boolean isLiquid(BlockData blockState) {
|
public static boolean isLiquid(BlockData blockState) {
|
||||||
Material material = blockState.getMaterial();
|
Material material = blockState.getMaterial();
|
||||||
return material == Material.WATER || material == Material.LAVA;
|
return material == Material.WATER || material == Material.LAVA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setNMSAccess(BukkitNMSAccess access) {
|
public static EntityType getEntityType(String data) {
|
||||||
nmsAccess = access;
|
int nbtStart = data.indexOf('{');
|
||||||
|
String id = nbtStart >= 0 ? data.substring(0, nbtStart) : data;
|
||||||
|
|
||||||
|
NamespacedKey key = NamespacedKey.fromString(id.toLowerCase(Locale.ROOT));
|
||||||
|
org.bukkit.entity.EntityType type = key == null ? null : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENTITY_TYPE).get(key);
|
||||||
|
if(type == null) throw new IllegalArgumentException("Invalid entity identifier " + data);
|
||||||
|
if(nbtStart < 0) return new BukkitEntityType(type);
|
||||||
|
|
||||||
|
String snbt = data.substring(nbtStart);
|
||||||
|
createSnapshot(type, snbt, null); // fail on invalid SNBT while the pack loads
|
||||||
|
return new BukkitEntityTypeExtended(type, snbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityType getEntityType(String id) {
|
public static Entity spawnEntity(RegionAccessor region, Location location, EntityType entityType) {
|
||||||
BukkitNMSAccess access = nmsAccess;
|
if(entityType instanceof BukkitEntityTypeExtended extended) {
|
||||||
return access == null ? getBukkitEntityType(id) : access.getEntityType(id);
|
World world = region instanceof LimitedRegion limitedRegion ? limitedRegion.getWorld() : (World) region;
|
||||||
}
|
// LimitedRegion only accepts entities already inside it.
|
||||||
|
Entity entity = createSnapshot(extended.getHandle(), (String) extended.getData().getHandle(), location).createEntity(world);
|
||||||
public static org.bukkit.entity.Entity spawnEntity(Object region, org.bukkit.Location location, EntityType entityType) {
|
return region.addEntity(entity);
|
||||||
if(entityType instanceof EntityTypeExtended) {
|
|
||||||
BukkitNMSAccess access = nmsAccess;
|
|
||||||
if(access == null) throw new IllegalStateException("Entity NBT loading requires Terra's NMS bindings");
|
|
||||||
return access.spawnEntity(region, location, entityType);
|
|
||||||
}
|
}
|
||||||
|
return region.spawnEntity(location, ((BukkitEntityType) entityType).getHandle());
|
||||||
org.bukkit.entity.EntityType bukkitType = ((BukkitEntityType) entityType).getHandle();
|
|
||||||
if(region instanceof org.bukkit.generator.LimitedRegion limitedRegion) {
|
|
||||||
return limitedRegion.spawnEntity(location, bukkitType);
|
|
||||||
}
|
|
||||||
return ((org.bukkit.World) region).spawnEntity(location, bukkitType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSpawnerEntity(CreatureSpawner spawner, EntityTypeExtended type) {
|
public static void setSpawnerEntity(CreatureSpawner spawner, EntityTypeExtended type) {
|
||||||
BukkitNMSAccess access = nmsAccess;
|
if(!(type instanceof BukkitEntityTypeExtended extended)) {
|
||||||
if(access == null) throw new IllegalStateException("Entity NBT loading requires Terra's NMS bindings");
|
throw new IllegalArgumentException("Expected a Bukkit entity type with NBT data");
|
||||||
access.setSpawnerEntity(spawner, type);
|
}
|
||||||
|
spawner.setSpawnedEntity(createSnapshot(extended.getHandle(), (String) extended.getData().getHandle(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EntityType getBukkitEntityType(String data) {
|
private static EntitySnapshot createSnapshot(org.bukkit.entity.EntityType type, String snbt, Location position) {
|
||||||
int nbtStart = data.indexOf('{');
|
String body = snbt.strip();
|
||||||
if(nbtStart >= 0) {
|
if(!body.startsWith("{") || !body.endsWith("}")) throw new IllegalArgumentException("Invalid entity NBT: " + snbt);
|
||||||
throw new IllegalArgumentException("Entity NBT loading requires Terra's NMS bindings: " + data);
|
body = body.substring(1, body.length() - 1).strip();
|
||||||
}
|
|
||||||
|
|
||||||
NamespacedKey key = NamespacedKey.fromString(data);
|
StringBuilder compound = new StringBuilder("{id:\"").append(type.getKey()).append('"');
|
||||||
org.bukkit.entity.EntityType type = key == null ? null : Registry.ENTITY_TYPE.get(key);
|
if(position != null) {
|
||||||
if(type == null) throw new IllegalArgumentException("Invalid entity identifier " + data);
|
compound.append(",Pos:[").append(snbtDouble(position.getX())).append(',').append(snbtDouble(position.getY()))
|
||||||
return new BukkitEntityType(type);
|
.append(',').append(snbtDouble(position.getZ())).append(']');
|
||||||
|
}
|
||||||
|
if(!body.isEmpty()) compound.append(',').append(body);
|
||||||
|
compound.append('}');
|
||||||
|
|
||||||
|
return Bukkit.getEntityFactory().createEntitySnapshot(compound.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String snbtDouble(double value) {
|
||||||
|
return BigDecimal.valueOf(value).toPlainString() + "d";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Terra.
|
|
||||||
*
|
|
||||||
* Terra is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Terra is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.bukkit.util;
|
|
||||||
|
|
||||||
public final class MinecraftUtils {
|
|
||||||
public static String stripMinecraftNamespace(String in) {
|
|
||||||
if(in.startsWith("minecraft:")) return in.substring("minecraft:".length());
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Terra.
|
|
||||||
*
|
|
||||||
* Terra is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Terra is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.bukkit.util;
|
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
|
||||||
|
|
||||||
import static io.papermc.lib.PaperLib.suggestPaper;
|
|
||||||
|
|
||||||
|
|
||||||
public final class PaperUtil {
|
|
||||||
public static void checkPaper(TerraBukkitPlugin plugin) {
|
|
||||||
plugin.getAsyncScheduler().runDelayed(plugin, task -> {
|
|
||||||
if(!PaperLib.isPaper()) {
|
|
||||||
suggestPaper(plugin);
|
|
||||||
}
|
|
||||||
}, 100L, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
package com.dfsek.terra.bukkit.util;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.LiteralMessage;
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||||
|
import dev.wyck.environment.particle.AmbientParticle;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
|
|
||||||
|
|
||||||
|
public final class VanillaParticles {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(VanillaParticles.class);
|
||||||
|
private static final SimpleCommandExceptionType TRAILING_DATA = new SimpleCommandExceptionType(
|
||||||
|
new LiteralMessage("Unexpected text after the particle"));
|
||||||
|
|
||||||
|
private VanillaParticles() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable AmbientParticle parse(String particle, float probability) throws CommandSyntaxException {
|
||||||
|
Handles handles = Holder.HANDLES;
|
||||||
|
if(handles == null) return null;
|
||||||
|
|
||||||
|
StringReader reader = new StringReader(particle.strip());
|
||||||
|
Object options;
|
||||||
|
Object ambient;
|
||||||
|
try {
|
||||||
|
options = handles.readParticle.invokeExact(reader, handles.registries);
|
||||||
|
ambient = handles.ambientParticle.invokeExact(options, probability);
|
||||||
|
} catch(CommandSyntaxException | RuntimeException | Error e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Throwable e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
if(reader.canRead()) throw TRAILING_DATA.createWithContext(reader);
|
||||||
|
return AmbientParticle.decode(ambient);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @Nullable Handles resolve() {
|
||||||
|
String step = "net.minecraft.server.MinecraftServer";
|
||||||
|
try {
|
||||||
|
ClassLoader loader = Bukkit.getServer().getClass().getClassLoader();
|
||||||
|
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
|
||||||
|
|
||||||
|
Class<?> server = Class.forName(step, false, loader);
|
||||||
|
step = "MinecraftServer.getServer()";
|
||||||
|
Object instance = lookup.findStatic(server, "getServer", MethodType.methodType(server)).invoke();
|
||||||
|
if(instance == null) throw new IllegalStateException("the server has not started");
|
||||||
|
step = "MinecraftServer.registryAccess()";
|
||||||
|
Object registries = lookup.findVirtual(server, "registryAccess",
|
||||||
|
MethodType.methodType(Class.forName("net.minecraft.core.RegistryAccess$Frozen", false, loader))).invoke(instance);
|
||||||
|
|
||||||
|
step = "ParticleArgument.readParticle(StringReader, HolderLookup.Provider)";
|
||||||
|
Class<?> provider = Class.forName("net.minecraft.core.HolderLookup$Provider", false, loader);
|
||||||
|
Class<?> options = Class.forName("net.minecraft.core.particles.ParticleOptions", false, loader);
|
||||||
|
MethodHandle readParticle = lookup.findStatic(Class.forName("net.minecraft.commands.arguments.ParticleArgument", false, loader),
|
||||||
|
"readParticle", MethodType.methodType(options, StringReader.class, provider))
|
||||||
|
.asType(MethodType.methodType(Object.class, StringReader.class, Object.class));
|
||||||
|
|
||||||
|
step = "AmbientParticle(ParticleOptions, float)";
|
||||||
|
MethodHandle ambientParticle = lookup.findConstructor(Class.forName("net.minecraft.world.attribute.AmbientParticle", false, loader),
|
||||||
|
MethodType.methodType(void.class, options, float.class))
|
||||||
|
.asType(MethodType.methodType(Object.class, Object.class, float.class));
|
||||||
|
|
||||||
|
return new Handles(readParticle, registries, ambientParticle);
|
||||||
|
} catch(Throwable e) {
|
||||||
|
LOGGER.warn("Biome particles are disabled: could not find vanilla's {} ({}). " +
|
||||||
|
"This Minecraft version is probably not supported yet.", step, e.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Handles(MethodHandle readParticle, Object registries, MethodHandle ambientParticle) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final class Holder {
|
||||||
|
private static final @Nullable Handles HANDLES = resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
package com.dfsek.terra.bukkit.util;
|
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
|
|
||||||
public final class VersionUtil {
|
|
||||||
public static final SpigotVersionInfo SPIGOT_VERSION_INFO;
|
|
||||||
public static final MinecraftVersionInfo MINECRAFT_VERSION_INFO;
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(VersionUtil.class);
|
|
||||||
|
|
||||||
static {
|
|
||||||
SPIGOT_VERSION_INFO = new SpigotVersionInfo();
|
|
||||||
|
|
||||||
MinecraftVersionInfo mcVersionInfo;
|
|
||||||
try {
|
|
||||||
mcVersionInfo = new MinecraftVersionInfo();
|
|
||||||
} catch(Throwable t) {
|
|
||||||
logger.error("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
|
|
||||||
mcVersionInfo = new MinecraftVersionInfo(-1, -1, -1);
|
|
||||||
}
|
|
||||||
MINECRAFT_VERSION_INFO = mcVersionInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinecraftVersionInfo getMinecraftVersionInfo() {
|
|
||||||
return MINECRAFT_VERSION_INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SpigotVersionInfo getSpigotVersionInfo() {
|
|
||||||
return SPIGOT_VERSION_INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class SpigotVersionInfo {
|
|
||||||
private final boolean spigot;
|
|
||||||
private final boolean paper;
|
|
||||||
private final boolean mohist;
|
|
||||||
|
|
||||||
|
|
||||||
public SpigotVersionInfo() {
|
|
||||||
logger.debug("Parsing spigot version info...");
|
|
||||||
|
|
||||||
paper = PaperLib.isPaper();
|
|
||||||
spigot = PaperLib.isSpigot();
|
|
||||||
|
|
||||||
|
|
||||||
boolean isMohist = false;
|
|
||||||
try {
|
|
||||||
Class.forName("com.mohistmc.MohistMC");
|
|
||||||
// it's mohist
|
|
||||||
isMohist = true;
|
|
||||||
} catch(ClassNotFoundException ignore) { }
|
|
||||||
this.mohist = isMohist;
|
|
||||||
|
|
||||||
logger.debug("Spigot version info parsed successfully.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPaper() {
|
|
||||||
return paper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMohist() {
|
|
||||||
return mohist;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSpigot() {
|
|
||||||
return spigot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static final class MinecraftVersionInfo {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MinecraftVersionInfo.class);
|
|
||||||
|
|
||||||
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)(?:\\.(\\d+))?");
|
|
||||||
private final int major;
|
|
||||||
private final int minor;
|
|
||||||
private final int patch;
|
|
||||||
|
|
||||||
private MinecraftVersionInfo() {
|
|
||||||
this(Bukkit.getServer().getBukkitVersion().split("-")[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinecraftVersionInfo(int major, int minor, int patch) {
|
|
||||||
this.major = major;
|
|
||||||
this.minor = minor;
|
|
||||||
this.patch = patch;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinecraftVersionInfo(String versionString) {
|
|
||||||
Matcher versionMatcher = VERSION_PATTERN.matcher(versionString);
|
|
||||||
if(versionMatcher.find()) {
|
|
||||||
major = Integer.parseInt(versionMatcher.group(1));
|
|
||||||
minor = Integer.parseInt(versionMatcher.group(2));
|
|
||||||
patch = versionMatcher.group(3) != null ? Integer.parseInt(versionMatcher.group(3)) : -1;
|
|
||||||
} else {
|
|
||||||
logger.warn("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
|
|
||||||
|
|
||||||
major = -1;
|
|
||||||
minor = -1;
|
|
||||||
patch = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
if(major == -1 && minor == -1 && patch == -1)
|
|
||||||
return "Unknown";
|
|
||||||
|
|
||||||
if(patch >= 0) {
|
|
||||||
return String.format("v%d.%d.%d", major, minor, patch);
|
|
||||||
} else {
|
|
||||||
return String.format("v%d.%d", major, minor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMajor() {
|
|
||||||
return major;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMinor() {
|
|
||||||
return minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPatch() {
|
|
||||||
return patch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+134
-56
@@ -1,81 +1,154 @@
|
|||||||
package com.dfsek.terra.bukkit.world;
|
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;
|
||||||
import dev.wyck.biome.Biome.Builder;
|
|
||||||
import dev.wyck.biome.BiomeGenerationSettings;
|
|
||||||
import dev.wyck.biome.BiomeSpecialEffects;
|
import dev.wyck.biome.BiomeSpecialEffects;
|
||||||
import dev.wyck.biome.ClimateSettings;
|
import dev.wyck.biome.ClimateSettings;
|
||||||
|
import dev.wyck.environment.attribute.EnvironmentAttributeMap;
|
||||||
import dev.wyck.environment.attribute.EnvironmentAttributeSupplier;
|
import dev.wyck.environment.attribute.EnvironmentAttributeSupplier;
|
||||||
import dev.wyck.environment.attribute.EnvironmentAttributes;
|
import dev.wyck.environment.attribute.EnvironmentAttributes;
|
||||||
import dev.wyck.environment.sounds.AmbientSounds;
|
import dev.wyck.environment.sounds.AmbientSounds;
|
||||||
import dev.wyck.environment.sounds.BackgroundMusic;
|
import dev.wyck.environment.sounds.BackgroundMusic;
|
||||||
import dev.wyck.keys.KeyChains;
|
|
||||||
import dev.wyck.keys.ResourceKey;
|
import dev.wyck.keys.ResourceKey;
|
||||||
|
import dev.wyck.registry.BiomeRegistry;
|
||||||
|
import dev.wyck.tags.TagSet;
|
||||||
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
|
import io.papermc.paper.registry.TypedKey;
|
||||||
|
import io.papermc.paper.registry.tag.Tag;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
|
import com.dfsek.terra.api.properties.Context;
|
||||||
|
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||||
|
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||||
|
|
||||||
|
|
||||||
public class BiomeHandler {
|
public final class BiomeHandler {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(BiomeHandler.class);
|
||||||
|
private static final Map<NamespacedKey, Villager.Type> VILLAGER_TYPES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static Biome getBiome(ResourceKey key) {
|
private BiomeHandler() { }
|
||||||
Biome biome = KeyChains.BIOMES.get(key);
|
|
||||||
return biome != null ? biome.wrap() : null;
|
public static void registerBiomes(ConfigRegistry configRegistry) {
|
||||||
|
org.bukkit.Registry<org.bukkit.block.Biome> bukkitRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME);
|
||||||
|
List<Biome> toRegister = new ArrayList<>();
|
||||||
|
List<Runnable> afterRegistration = new ArrayList<>();
|
||||||
|
|
||||||
|
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
||||||
|
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||||
|
ResourceKey vanillaKey = ResourceKey.of(platformBiome.getHandle().getKey());
|
||||||
|
ResourceKey terraKey = ResourceKey.of("terra", createBiomeID(pack, key));
|
||||||
|
|
||||||
|
NamespacedKey bukkitKey = new NamespacedKey(terraKey.namespace(), terraKey.path());
|
||||||
|
VanillaBiomeProperties properties = biome.getContext().has(VanillaBiomeProperties.class)
|
||||||
|
? biome.getContext().get(VanillaBiomeProperties.class)
|
||||||
|
: new VanillaBiomeProperties();
|
||||||
|
|
||||||
|
if(bukkitRegistry.get(bukkitKey) == null) {
|
||||||
|
toRegister.add(createBiome(terraKey, getBiomeOrThrow(vanillaKey), properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
afterRegistration.add(() -> {
|
||||||
|
org.bukkit.block.Biome bukkitBiome = bukkitRegistry.getOrThrow(bukkitKey);
|
||||||
|
platformBiome.getContext().put(new BukkitBiomeInfo(terraKey, vanillaKey, bukkitBiome));
|
||||||
|
if(properties.getVillagerType() != null) {
|
||||||
|
VILLAGER_TYPES.put(bukkitKey, properties.getVillagerType());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
LOGGER.info("Registering {} custom biomes through Wyck...", toRegister.size());
|
||||||
|
BiomeRegistry.registry().register(toRegister);
|
||||||
|
afterRegistration.forEach(Runnable::run);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addToVanillaTags(ConfigRegistry configRegistry) {
|
||||||
|
Map<TypedKey<org.bukkit.block.Biome>, Set<Biome>> terraBiomesByVanilla = new HashMap<>();
|
||||||
|
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach(biome -> {
|
||||||
|
Context context = ((BukkitPlatformBiome) biome.getPlatformBiome()).getContext();
|
||||||
|
if(context.has(BukkitBiomeInfo.class)) {
|
||||||
|
BukkitBiomeInfo info = context.get(BukkitBiomeInfo.class);
|
||||||
|
TypedKey<org.bukkit.block.Biome> vanillaKey = TypedKey.create(RegistryKey.BIOME, info.vanillaKey().key());
|
||||||
|
terraBiomesByVanilla.computeIfAbsent(vanillaKey, k -> new HashSet<>()).add(Biome.reference(info.biomeKey()));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
org.bukkit.Registry<org.bukkit.block.Biome> bukkitRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME);
|
||||||
|
int count = 0;
|
||||||
|
for(Tag<org.bukkit.block.Biome> tag : bukkitRegistry.getTags()) {
|
||||||
|
Set<Biome> members = new HashSet<>();
|
||||||
|
terraBiomesByVanilla.forEach((vanillaKey, terraBiomes) -> {
|
||||||
|
if(tag.contains(vanillaKey)) {
|
||||||
|
members.addAll(terraBiomes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!members.isEmpty()) {
|
||||||
|
TagSet.ofBiomes(ResourceKey.of(tag.tagKey().key()), members).append();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOGGER.info("Added Terra biomes to {} vanilla biome tags.", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable Villager.Type getVillagerType(org.bukkit.block.Biome biome) {
|
||||||
|
return VILLAGER_TYPES.get(biome.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Biome getBiomeOrThrow(ResourceKey key) {
|
public static Biome getBiomeOrThrow(ResourceKey key) {
|
||||||
return KeyChains.BIOMES.getOrThrow(key).wrap();
|
return Biome.reference(key).wrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Biome createBiome(ResourceKey vanillaBiomeKey, VanillaBiomeProperties vanillaBiomeProperties)
|
public static Biome createBiome(ResourceKey key, Biome vanilla, VanillaBiomeProperties properties) {
|
||||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
EnvironmentAttributeMap attributes = vanilla.attributes();
|
||||||
Biome vanilla = getBiomeOrThrow(vanillaBiomeKey);
|
attributes = override(attributes, EnvironmentAttributes.FOG_COLOR, properties.getFogColor());
|
||||||
Builder builder = dev.wyck.biome.Biome.builder();
|
attributes = override(attributes, EnvironmentAttributes.WATER_FOG_COLOR, properties.getWaterFogColor());
|
||||||
|
attributes = override(attributes, EnvironmentAttributes.SKY_COLOR, properties.getSkyColor());
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.FOG_COLOR, vanillaBiomeProperties.getFogColor());
|
attributes = override(attributes, EnvironmentAttributes.AMBIENT_PARTICLES, properties.getParticles());
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.WATER_FOG_COLOR, vanillaBiomeProperties.getWaterFogColor());
|
attributes = override(attributes, EnvironmentAttributes.MUSIC_VOLUME, properties.getMusicVolume());
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.SKY_COLOR, vanillaBiomeProperties.getSkyColor());
|
attributes = override(attributes, EnvironmentAttributes.NATURAL_MOB_SPAWNS, properties.getSpawnSettings());
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.AMBIENT_PARTICLES, vanillaBiomeProperties.getParticles());
|
if(properties.getMusic() != null) {
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.AMBIENT_SOUNDS, AmbientSounds.builder()
|
attributes = attributes.with(EnvironmentAttributes.BACKGROUND_MUSIC,
|
||||||
.loop(vanillaBiomeProperties.getLoopSound())
|
BackgroundMusic.builder().defaultMusic(properties.getMusic()).build());
|
||||||
.mood(vanillaBiomeProperties.getMoodSound())
|
}
|
||||||
.addition(vanillaBiomeProperties.getAdditionsSound())
|
if(properties.getLoopSound() != null || properties.getMoodSound() != null || properties.getAdditionsSound() != null) {
|
||||||
.build());
|
AmbientSounds sounds = Objects.requireNonNullElse(attributes.get(EnvironmentAttributes.AMBIENT_SOUNDS), AmbientSounds.EMPTY);
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.BACKGROUND_MUSIC, BackgroundMusic.builder()
|
attributes = attributes.with(EnvironmentAttributes.AMBIENT_SOUNDS, AmbientSounds.of(
|
||||||
.defaultMusic(vanillaBiomeProperties.getMusic())
|
properties.getLoopSound() != null ? properties.getLoopSound() : sounds.loop().orElse(null),
|
||||||
.build());
|
properties.getMoodSound() != null ? properties.getMoodSound() : sounds.mood().orElse(null),
|
||||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.MUSIC_VOLUME, vanillaBiomeProperties.getMusicVolume());
|
properties.getAdditionsSound() != null ? List.of(properties.getAdditionsSound()) : sounds.additions()));
|
||||||
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) {
|
ClimateSettings climate = vanilla.climateSettings();
|
||||||
vanilla.specialEffects().foliageColorOverride().ifPresent(effects::foliageColorOverride);
|
BiomeSpecialEffects effects = vanilla.specialEffects();
|
||||||
} else {
|
|
||||||
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder
|
return Biome.builder(key)
|
||||||
.specialEffects(effects.build())
|
.attributes(attributes)
|
||||||
.generationSettings(BiomeGenerationSettings.builder()
|
.climateSettings(ClimateSettings.builder()
|
||||||
|
.hasPrecipitation(Objects.requireNonNullElse(properties.getPrecipitation(), climate.hasPrecipitation()))
|
||||||
|
.temperature(Objects.requireNonNullElse(properties.getTemperature(), climate.temperature()))
|
||||||
|
.temperatureModifier(Objects.requireNonNullElse(properties.getTemperatureModifier(), climate.temperatureModifier()))
|
||||||
|
.downfall(Objects.requireNonNullElse(properties.getDownfall(), climate.downfall()))
|
||||||
|
.build())
|
||||||
|
.specialEffects(BiomeSpecialEffects.builder()
|
||||||
|
.waterColor(Objects.requireNonNullElse(properties.getWaterColor(), effects.waterColor()))
|
||||||
|
.grassColorModifier(Objects.requireNonNullElse(properties.getGrassColorModifier(), effects.grassColorModifier()))
|
||||||
|
.grassColorOverride(orElse(properties.getGrassColor(), effects.grassColorOverride().orElse(null)))
|
||||||
|
.foliageColorOverride(orElse(properties.getFoliageColor(), effects.foliageColorOverride().orElse(null)))
|
||||||
|
.dryFoliageColorOverride(orElse(properties.getDryFoliageColor(), effects.dryFoliageColorOverride().orElse(null)))
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -86,7 +159,12 @@ public class BiomeHandler {
|
|||||||
+ "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
+ "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void setAttributeOrDefault(Biome.Builder builder, Biome def, EnvironmentAttributeSupplier<T> attribute, T value) {
|
private static <T> EnvironmentAttributeMap override(EnvironmentAttributeMap map, EnvironmentAttributeSupplier<T> attribute,
|
||||||
builder.attribute(attribute, Objects.requireNonNullElse(value, def.attributes().get(attribute)));
|
@Nullable T value) {
|
||||||
|
return value == null ? map : map.with(attribute, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @Nullable Integer orElse(@Nullable Integer value, @Nullable Integer fallback) {
|
||||||
|
return value != null ? value : fallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -5,5 +5,5 @@ import dev.wyck.keys.ResourceKey;
|
|||||||
import com.dfsek.terra.api.properties.Properties;
|
import com.dfsek.terra.api.properties.Properties;
|
||||||
|
|
||||||
|
|
||||||
public record BukkitBiomeInfo(ResourceKey biomeKey) implements Properties {
|
public record BukkitBiomeInfo(ResourceKey biomeKey, ResourceKey vanillaKey, org.bukkit.block.Biome bukkitBiome) implements Properties {
|
||||||
}
|
}
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+12
-4
@@ -17,31 +17,39 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.bukkit.world.block.state;
|
package com.dfsek.terra.bukkit.world.block.state;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.bukkit.block.sign.Side;
|
||||||
|
import org.bukkit.block.sign.SignSide;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.dfsek.terra.api.block.entity.SerialState;
|
import com.dfsek.terra.api.block.entity.SerialState;
|
||||||
import com.dfsek.terra.api.block.entity.Sign;
|
import com.dfsek.terra.api.block.entity.Sign;
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class BukkitSign extends BukkitBlockEntity implements Sign {
|
public class BukkitSign extends BukkitBlockEntity implements Sign {
|
||||||
|
private static final LegacyComponentSerializer LEGACY = LegacyComponentSerializer.legacySection();
|
||||||
|
|
||||||
protected BukkitSign(org.bukkit.block.Sign block) {
|
protected BukkitSign(org.bukkit.block.Sign block) {
|
||||||
super(block);
|
super(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||||
((org.bukkit.block.Sign) getHandle()).setLine(index, line);
|
front().line(index, LEGACY.deserialize(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String[] getLines() {
|
public @NotNull String[] getLines() {
|
||||||
return ((org.bukkit.block.Sign) getHandle()).getLines();
|
return front().lines().stream().map(LEGACY::serialize).toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getLine(int index) throws IndexOutOfBoundsException {
|
public @NotNull String getLine(int index) throws IndexOutOfBoundsException {
|
||||||
return ((org.bukkit.block.Sign) getHandle()).getLine(index);
|
return LEGACY.serialize(front().line(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SignSide front() {
|
||||||
|
return ((org.bukkit.block.Sign) getHandle()).getSide(Side.FRONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,15 +5,9 @@ load: "STARTUP"
|
|||||||
authors: [ "dfsek", "duplexsystem", "Astrash", "solonovamax", "Sancires", "Aureus", "RogueShade", "OakLoaf" ]
|
authors: [ "dfsek", "duplexsystem", "Astrash", "solonovamax", "Sancires", "Aureus", "RogueShade", "OakLoaf" ]
|
||||||
website: "@WIKI@"
|
website: "@WIKI@"
|
||||||
api-version: "26.3"
|
api-version: "26.3"
|
||||||
bootstrapper: "com.dfsek.terra.bukkit.TerraBootstrapper"
|
|
||||||
description: "@DESCRIPTION@"
|
description: "@DESCRIPTION@"
|
||||||
folia-supported: true
|
folia-supported: true
|
||||||
depend:
|
dependencies:
|
||||||
bootstrap:
|
|
||||||
Wyck:
|
|
||||||
load: BEFORE
|
|
||||||
required: true
|
|
||||||
join-classpath: true
|
|
||||||
server:
|
server:
|
||||||
Wyck:
|
Wyck:
|
||||||
load: BEFORE
|
load: BEFORE
|
||||||
|
|||||||
Reference in new issue
Block a user