mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-20 11:32:33 +00:00
Merge branch 'master' into dev/7.0-2
This commit is contained in:
commit
78707468c5
@ -1,10 +1,10 @@
|
|||||||
bool thing1 = 2 > (2+2) || false;
|
bool thing1 = 2 > (2 + 2) || false;
|
||||||
|
|
||||||
if(2 > 2 || 3 + 4 <= 2 && 4 + 5 > 2 / 3) {
|
if (2 > 2 || 3 + 4 <= 2 && 4 + 5 > 2 / 3) {
|
||||||
test("ok", 2);
|
test("ok", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
test("minecraft:green_w" + "ool", (2 * (3+1) * (2 * (1+1))));
|
test("minecraft:green_w" + "ool", (2 * (3 + 1) * (2 * (1 + 1))));
|
||||||
//
|
//
|
||||||
|
|
||||||
num testVar = 3.4;
|
num testVar = 3.4;
|
||||||
@ -21,7 +21,7 @@ bool iftest = false;
|
|||||||
bool truetest = false;
|
bool truetest = false;
|
||||||
|
|
||||||
num iterator = 0;
|
num iterator = 0;
|
||||||
num thing = 4 - 2-2+2-2+2;
|
num thing = 4 - 2 - 2 + 2 - 2 + 2;
|
||||||
test("4 - 2 = " + thing, 2);
|
test("4 - 2 = " + thing, 2);
|
||||||
|
|
||||||
thing = -2;
|
thing = -2;
|
||||||
@ -31,54 +31,54 @@ test("--2 = " + thing, 2);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(num i = 0; i < 5; i = i + 1) {
|
for (num i = 0; i < 5; i = i + 1) {
|
||||||
test("i = " + i, iterator);
|
test("i = " + i, iterator);
|
||||||
if(i > 1 + 1) {
|
if (i > 1 + 1) {
|
||||||
test("more than 2", iterator);
|
test("more than 2", iterator);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(num i = 0; i < 5; i = i + 1) {
|
for (num i = 0; i < 5; i = i + 1) {
|
||||||
test("i = " + i, iterator);
|
test("i = " + i, iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(num j = 0; j < 5; j = j + 1) test("single statement j = " + j, iterator);
|
for (num j = 0; j < 5; j = j + 1) test("single statement j = " + j, iterator);
|
||||||
|
|
||||||
if(4 + 2 == 2 + 4) {
|
if (4 + 2 == 2 + 4) {
|
||||||
test("new thing " + 2, iterator);
|
test("new thing " + 2, iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(iterator < 5) {
|
while (iterator < 5) {
|
||||||
test("always, even after " + 2, iterator);
|
test("always, even after " + 2, iterator);
|
||||||
iterator = iterator + 1;
|
iterator = iterator + 1;
|
||||||
if(iterator > 2) {
|
if (iterator > 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
test("not after " + 2, iterator);
|
test("not after " + 2, iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(true) test("single statement" + 2, iterator);
|
if (true) test("single statement" + 2, iterator);
|
||||||
else if(true) test("another single statement" + 2, iterator);
|
else if (true) test("another single statement" + 2, iterator);
|
||||||
|
|
||||||
if(true) {
|
if (true) {
|
||||||
test("true!" + 2, iterator);
|
|
||||||
} else {
|
|
||||||
test("false!" + 2, iterator);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(false) {
|
|
||||||
test("true!" + 2, iterator);
|
test("true!" + 2, iterator);
|
||||||
} else {
|
} else {
|
||||||
test("false!" + 2, iterator);
|
test("false!" + 2, iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(false) {
|
if (false) {
|
||||||
test("true again!" + 2, iterator);
|
test("true!" + 2, iterator);
|
||||||
} else if(true == true) {
|
|
||||||
test("false again!" + 2, iterator);
|
|
||||||
} else {
|
} else {
|
||||||
test("not logged!" + 2, iterator);
|
test("false!" + 2, iterator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false) {
|
||||||
|
test("true again!" + 2, iterator);
|
||||||
|
} else if (true == true) {
|
||||||
|
test("false again!" + 2, iterator);
|
||||||
|
} else {
|
||||||
|
test("not logged!" + 2, iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ fsdfsd
|
|||||||
|
|
||||||
test("fdsgdf" + 2, 1 + testVar);
|
test("fdsgdf" + 2, 1 + testVar);
|
||||||
|
|
||||||
if(true && !(boolean && false) && true) {
|
if (true && !(boolean && false) && true) {
|
||||||
num scopedVar = 2;
|
num scopedVar = 2;
|
||||||
test("if statement" + 2 + stringVar, 1 + testVar + scopedVar);
|
test("if statement" + 2 + stringVar, 1 + testVar + scopedVar);
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ package com.dfsek.terra.bukkit;
|
|||||||
import com.dfsek.tectonic.api.TypeRegistry;
|
import com.dfsek.tectonic.api.TypeRegistry;
|
||||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||||
import com.dfsek.tectonic.api.exception.LoadException;
|
import com.dfsek.tectonic.api.exception.LoadException;
|
||||||
|
|
||||||
import io.papermc.paper.registry.RegistryAccess;
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
import io.papermc.paper.registry.RegistryKey;
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -30,10 +31,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dfsek.terra.AbstractPlatform;
|
import com.dfsek.terra.AbstractPlatform;
|
||||||
import com.dfsek.terra.api.addon.BaseAddon;
|
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.handle.ItemHandle;
|
import com.dfsek.terra.api.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
@ -41,7 +40,6 @@ 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.nms.Initializer;
|
|
||||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||||
|
|
||||||
|
|
||||||
@ -96,11 +94,6 @@ public class PlatformImpl extends AbstractPlatform {
|
|||||||
plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
|
plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Iterable<BaseAddon> platformAddon() {
|
|
||||||
return List.of(Initializer.nmsAddon(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull WorldHandle getWorldHandle() {
|
public @NotNull WorldHandle getWorldHandle() {
|
||||||
return handle;
|
return handle;
|
||||||
@ -130,7 +123,7 @@ public class PlatformImpl extends AbstractPlatform {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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));
|
return new BukkitPlatformBiome(RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).getOrThrow(key));
|
||||||
|
@ -51,7 +51,7 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
|||||||
public class TerraBukkitPlugin extends JavaPlugin {
|
public class TerraBukkitPlugin extends JavaPlugin {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||||
|
|
||||||
private final PlatformImpl platform = new PlatformImpl(this);
|
private PlatformImpl platform;
|
||||||
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
|
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
|
||||||
|
|
||||||
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
|
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
|
||||||
@ -64,13 +64,14 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
platform = Initializer.init(this);
|
||||||
|
if(platform == null) {
|
||||||
if(!Initializer.init(platform)) {
|
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LegacyPaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
|
LegacyPaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.dfsek.terra.bukkit.nms;
|
package com.dfsek.terra.bukkit.nms;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -12,13 +14,11 @@ public interface Initializer {
|
|||||||
String NMS = VersionUtil.getMinecraftVersionInfo().toString().replace(".", "_");
|
String NMS = VersionUtil.getMinecraftVersionInfo().toString().replace(".", "_");
|
||||||
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
||||||
|
|
||||||
static boolean init(PlatformImpl platform) {
|
static PlatformImpl init(TerraBukkitPlugin plugin) {
|
||||||
Logger logger = LoggerFactory.getLogger(Initializer.class);
|
Logger logger = LoggerFactory.getLogger(Initializer.class);
|
||||||
|
|
||||||
Initializer initializer = constructInitializer();
|
PlatformImpl platform = constructPlatform(plugin);
|
||||||
if(initializer != null) {
|
if (platform == null) {
|
||||||
initializer.initialize(platform);
|
|
||||||
} else {
|
|
||||||
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
|
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
|
||||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||||
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + NMS + "ButIWillProceedAnyway";
|
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + NMS + "ButIWillProceedAnyway";
|
||||||
@ -26,7 +26,7 @@ public interface Initializer {
|
|||||||
logger.error("Because of this **TERRA HAS BEEN DISABLED**.");
|
logger.error("Because of this **TERRA HAS BEEN DISABLED**.");
|
||||||
logger.error("Do not come ask us why it is not working.");
|
logger.error("Do not come ask us why it is not working.");
|
||||||
logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey);
|
logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey);
|
||||||
return false;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
logger.error("");
|
logger.error("");
|
||||||
logger.error("");
|
logger.error("");
|
||||||
@ -42,24 +42,21 @@ public interface Initializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BukkitAddon nmsAddon(PlatformImpl platform) {
|
private static PlatformImpl constructPlatform(TerraBukkitPlugin plugin) {
|
||||||
Initializer initializer = constructInitializer();
|
|
||||||
return initializer != null ? initializer.getNMSAddon(platform) : new BukkitAddon(platform);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Initializer constructInitializer() {
|
|
||||||
try {
|
try {
|
||||||
String packageVersion = NMS;
|
String packageVersion = NMS;
|
||||||
if (NMS.equals("v1_21_5") || NMS.equals("v1_21_6")) {
|
if (NMS.equals("v1_21_5") || NMS.equals("v1_21_6")) {
|
||||||
packageVersion = "v1_21_7";
|
packageVersion = "v1_21_7";
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer");
|
Class<?> platformClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSPlatform");
|
||||||
try {
|
try {
|
||||||
return (Initializer) initializerClass.getConstructor().newInstance();
|
return (PlatformImpl) platformClass
|
||||||
|
.getConstructor(TerraBukkitPlugin.class)
|
||||||
|
.newInstance(plugin);
|
||||||
} catch(ReflectiveOperationException e) {
|
} catch(ReflectiveOperationException e) {
|
||||||
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
|
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
|
||||||
}
|
}
|
||||||
@ -67,8 +64,4 @@ public interface Initializer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize(PlatformImpl plugin);
|
|
||||||
|
|
||||||
BukkitAddon getNMSAddon(PlatformImpl plugin);
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import net.minecraft.core.registries.Registries;
|
|||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.entity.npc.VillagerType;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -24,6 +25,7 @@ import java.util.HashMap;
|
|||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -49,6 +51,7 @@ public class AwfulBukkitHacks {
|
|||||||
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
||||||
try {
|
try {
|
||||||
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||||
|
|
||||||
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
||||||
ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(),
|
ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(),
|
||||||
vanillaBukkitKey.getKey());
|
vanillaBukkitKey.getKey());
|
||||||
@ -68,6 +71,12 @@ public class AwfulBukkitHacks {
|
|||||||
platformBiome.getContext().put(new BukkitBiomeInfo(delegateBukkitKey));
|
platformBiome.getContext().put(new BukkitBiomeInfo(delegateBukkitKey));
|
||||||
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
||||||
|
|
||||||
|
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.location());
|
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location());
|
||||||
|
|
||||||
LOGGER.debug("Registered biome: " + delegateKey);
|
LOGGER.debug("Registered biome: " + delegateKey);
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package com.dfsek.terra.bukkit.nms.v1_21_7;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.dfsek.terra.bukkit.BukkitAddon;
|
|
||||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
|
||||||
import com.dfsek.terra.bukkit.nms.Initializer;
|
|
||||||
|
|
||||||
|
|
||||||
public class NMSInitializer implements Initializer {
|
|
||||||
@Override
|
|
||||||
public void initialize(PlatformImpl platform) {
|
|
||||||
AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry());
|
|
||||||
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BukkitAddon getNMSAddon(PlatformImpl plugin) {
|
|
||||||
return new NMSAddon(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.dfsek.terra.bukkit.nms.v1_21_7;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.api.TypeRegistry;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.api.exception.LoadException;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.addon.BaseAddon;
|
||||||
|
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||||
|
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||||
|
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.BiomeAdditionsSoundTemplate;
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.BiomeMoodSoundTemplate;
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.BiomeParticleConfigTemplate;
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.EntityTypeTemplate;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.MusicSoundTemplate;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.SoundEventTemplate;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.SpawnCostConfig;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.SpawnEntryConfig;
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.SpawnSettingsTemplate;
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.SpawnTypeConfig;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VillagerTypeTemplate;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.Music;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import net.minecraft.world.entity.MobCategory;
|
||||||
|
import net.minecraft.world.entity.npc.VillagerType;
|
||||||
|
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
|
||||||
|
import net.minecraft.world.level.biome.AmbientMoodSettings;
|
||||||
|
import net.minecraft.world.level.biome.AmbientParticleSettings;
|
||||||
|
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||||
|
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||||
|
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
|
||||||
|
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||||
|
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
|
public class NMSPlatform extends PlatformImpl {
|
||||||
|
|
||||||
|
public NMSPlatform(TerraBukkitPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
AwfulBukkitHacks.registerBiomes(this.getRawConfigRegistry());
|
||||||
|
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(TypeRegistry registry) {
|
||||||
|
super.register(registry);
|
||||||
|
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||||
|
.registerLoader(ResourceLocation.class, (type, o, loader, depthTracker) -> {
|
||||||
|
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
|
||||||
|
if(identifier == null)
|
||||||
|
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||||
|
return identifier;
|
||||||
|
})
|
||||||
|
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
|
||||||
|
Locale.ROOT)))
|
||||||
|
.registerLoader(GrassColorModifier.class,
|
||||||
|
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||||
|
Locale.ROOT)))
|
||||||
|
.registerLoader(GrassColorModifier.class,
|
||||||
|
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||||
|
Locale.ROOT)))
|
||||||
|
.registerLoader(MobCategory.class, (type, o, loader, depthTracker) -> MobCategory.valueOf((String) o))
|
||||||
|
.registerLoader(AmbientParticleSettings.class, BiomeParticleConfigTemplate::new)
|
||||||
|
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
|
||||||
|
.registerLoader(AmbientMoodSettings.class, BiomeMoodSoundTemplate::new)
|
||||||
|
.registerLoader(AmbientAdditionsSettings.class, BiomeAdditionsSoundTemplate::new)
|
||||||
|
.registerLoader(Music.class, MusicSoundTemplate::new)
|
||||||
|
.registerLoader(EntityType.class, EntityTypeTemplate::new)
|
||||||
|
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
|
||||||
|
.registerLoader(SpawnEntryConfig.class, SpawnEntryConfig::new)
|
||||||
|
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
|
||||||
|
.registerLoader(MobSpawnSettings.class, SpawnSettingsTemplate::new)
|
||||||
|
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Iterable<BaseAddon> platformAddon() {
|
||||||
|
return List.of(new NMSAddon(this));
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import net.minecraft.core.MappedRegistry;
|
|||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.level.ChunkMap;
|
import net.minecraft.server.level.ChunkMap;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.entity.npc.VillagerType;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.StructureManager;
|
import net.minecraft.world.level.StructureManager;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
@ -36,6 +37,7 @@ public class Reflection {
|
|||||||
public static final HolderReferenceProxy HOLDER_REFERENCE;
|
public static final HolderReferenceProxy HOLDER_REFERENCE;
|
||||||
public static final HolderSetNamedProxy HOLDER_SET;
|
public static final HolderSetNamedProxy HOLDER_SET;
|
||||||
public static final BiomeProxy BIOME;
|
public static final BiomeProxy BIOME;
|
||||||
|
public static final VillagerTypeProxy VILLAGER_TYPE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
|
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
|
||||||
@ -50,6 +52,7 @@ public class Reflection {
|
|||||||
HOLDER_REFERENCE = reflectionProxyFactory.reflectionProxy(HolderReferenceProxy.class);
|
HOLDER_REFERENCE = reflectionProxyFactory.reflectionProxy(HolderReferenceProxy.class);
|
||||||
HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetNamedProxy.class);
|
HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetNamedProxy.class);
|
||||||
BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class);
|
BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class);
|
||||||
|
VILLAGER_TYPE = reflectionProxyFactory.reflectionProxy(VillagerTypeProxy.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,4 +129,11 @@ public class Reflection {
|
|||||||
@MethodName("getGrassColorFromTexture")
|
@MethodName("getGrassColorFromTexture")
|
||||||
int invokeGrassColorFromTexture(Biome instance);
|
int invokeGrassColorFromTexture(Biome instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Proxies(VillagerType.class)
|
||||||
|
public interface VillagerTypeProxy {
|
||||||
|
@Static
|
||||||
|
@FieldGetter("BY_BIOME")
|
||||||
|
Map<ResourceKey<Biome>, ResourceKey<VillagerType>> getByBiome();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientPartic
|
|||||||
|
|
||||||
@Value("probability")
|
@Value("probability")
|
||||||
@Default
|
@Default
|
||||||
private Integer probability = null;
|
private Float probability = 0.1f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AmbientParticleSettings get() {
|
public AmbientParticleSettings get() {
|
||||||
if(particle == null || probability == null) {
|
if(particle == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package com.dfsek.terra.bukkit.nms.v1_21_7.config;
|
|||||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.sounds.Music;
|
import net.minecraft.sounds.Music;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.entity.npc.VillagerType;
|
import net.minecraft.world.entity.npc.VillagerType;
|
||||||
@ -95,7 +97,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
|||||||
|
|
||||||
@Value("villager-type")
|
@Value("villager-type")
|
||||||
@Default
|
@Default
|
||||||
private VillagerType villagerType = null;
|
private ResourceKey<VillagerType> villagerType = null;
|
||||||
|
|
||||||
public Integer getFogColor() {
|
public Integer getFogColor() {
|
||||||
return fogColor;
|
return fogColor;
|
||||||
@ -173,7 +175,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
|||||||
return spawnSettings;
|
return spawnSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VillagerType getVillagerType() {
|
public ResourceKey<VillagerType> getVillagerType() {
|
||||||
return villagerType;
|
return villagerType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,18 @@ 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 net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.npc.VillagerType;
|
import net.minecraft.world.entity.npc.VillagerType;
|
||||||
|
|
||||||
|
|
||||||
public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
|
public class VillagerTypeTemplate implements ObjectTemplate<ResourceKey<VillagerType>> {
|
||||||
@Value("id")
|
@Value("id")
|
||||||
@Default
|
@Default
|
||||||
private ResourceLocation id = null;
|
private ResourceLocation id = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VillagerType get() {
|
public ResourceKey<VillagerType> get() {
|
||||||
return BuiltInRegistries.VILLAGER_TYPE.get(id).orElseThrow().value();
|
return ResourceKey.create(BuiltInRegistries.VILLAGER_TYPE.key(), id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,32 +5,36 @@ 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.StringReader;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.minecraft.client.particle.Particle;
|
|
||||||
import net.minecraft.command.argument.ParticleEffectArgumentType;
|
import net.minecraft.command.argument.ParticleEffectArgumentType;
|
||||||
import net.minecraft.particle.ParticleEffect;
|
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.RegistryWrapper;
|
import net.minecraft.registry.RegistryWrapper;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.world.biome.Biome;
|
|
||||||
import net.minecraft.world.biome.BiomeParticleConfig;
|
import net.minecraft.world.biome.BiomeParticleConfig;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticleConfig> {
|
public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticleConfig> {
|
||||||
@Value("particle")
|
@Value("particle")
|
||||||
@Default
|
@Default
|
||||||
private Identifier particle = null;
|
private String particle = null;
|
||||||
|
|
||||||
@Value("probability")
|
@Value("probability")
|
||||||
@Default
|
@Default
|
||||||
private Integer probability = null;
|
private Float probability = 0.1f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeParticleConfig get() {
|
public BiomeParticleConfig get() {
|
||||||
if(particle == null || probability == null) {
|
if(particle == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BiomeParticleConfig((ParticleEffect) Registries.PARTICLE_TYPE.get(particle),
|
try {
|
||||||
|
return new BiomeParticleConfig(
|
||||||
|
ParticleEffectArgumentType.readParameters(new StringReader(particle),
|
||||||
|
RegistryWrapper.WrapperLookup.of(Stream.of(Registries.PARTICLE_TYPE))),
|
||||||
probability);
|
probability);
|
||||||
|
} catch(CommandSyntaxException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user