mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-11-27 00:14:19 +00:00
feat: hacks for 26.1.2
This commit is contained in:
5 files changed
+93
-20
No files matched your search
@@ -67,9 +67,9 @@ object Versions {
|
||||
const val paperLib = "1.0.8"
|
||||
const val reflectionRemapper = "0.1.3"
|
||||
const val paperDevBundle = paperBuild
|
||||
const val runPaper = "2.3.1"
|
||||
const val runPaper = "3.0.2"
|
||||
const val paperWeight = "2.0.0-beta.21"
|
||||
const val cloud = "2.0.0-beta.12"
|
||||
const val cloud = "2.0.0-beta.15"
|
||||
const val multiverse = "5.3.0"
|
||||
}
|
||||
|
||||
|
||||
+17
-3
@@ -19,6 +19,7 @@ package com.dfsek.terra.bukkit.handles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,6 +30,9 @@ import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
public class BukkitWorldHandle implements WorldHandle {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BukkitWorldHandle.class);
|
||||
@@ -40,9 +44,19 @@ public class BukkitWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public synchronized @NotNull BlockState createBlockState(@NotNull String data) {
|
||||
org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(
|
||||
data); // somehow bukkit managed to make this not thread safe! :)
|
||||
return BukkitBlockState.newInstance(bukkitData);
|
||||
try {
|
||||
org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(data); // somehow bukkit managed to make this not thread safe! :)
|
||||
return BukkitBlockState.newInstance(bukkitData);
|
||||
} catch (Exception ignored) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,13 @@ public class BukkitUtils {
|
||||
if(!id.startsWith("minecraft:")) throw new IllegalArgumentException("Invalid entity identifier " + id);
|
||||
String entityID = id.toUpperCase(Locale.ROOT).substring(10);
|
||||
|
||||
// TODO: remove this
|
||||
// the default end seems to use this, this should be removed otherwise
|
||||
// or replaced by a proper entity & NBT loader
|
||||
if (entityID.contains("END_CRYSTAL")) {
|
||||
entityID = "END_CRYSTAL";
|
||||
}
|
||||
|
||||
return new BukkitEntityType(switch(entityID) {
|
||||
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.END_CRYSTAL;
|
||||
case "ENDER_CRYSTAL" -> throw new IllegalArgumentException(
|
||||
|
||||
+23
-3
@@ -1,18 +1,29 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.arguments.blocks.BlockStateParser;
|
||||
import net.minecraft.commands.arguments.blocks.BlockStateParser.BlockResult;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Holder.Reference;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.HolderSet.Named;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.RegistrationInfo;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -120,7 +131,7 @@ public class AwfulBukkitHacks {
|
||||
}
|
||||
|
||||
private static <T> void bindTags(MappedRegistry<T> registry, Map<TagKey<T>, List<Holder<T>>> tagEntries) {
|
||||
Map<Holder.Reference<T>, List<TagKey<T>>> map = new IdentityHashMap<>();
|
||||
Map<Reference<T>, List<TagKey<T>>> map = new IdentityHashMap<>();
|
||||
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(entry -> map.put(entry, new ArrayList<>()));
|
||||
tagEntries.forEach((tag, entries) -> {
|
||||
for(Holder<T> holder : entries) {
|
||||
@@ -145,7 +156,7 @@ public class AwfulBukkitHacks {
|
||||
// );
|
||||
// }
|
||||
|
||||
Map<TagKey<T>, HolderSet.Named<T>> map2 = new IdentityHashMap<>(registry.getTags().collect(Collectors.toMap(
|
||||
Map<TagKey<T>, Named<T>> map2 = new IdentityHashMap<>(registry.getTags().collect(Collectors.toMap(
|
||||
Named::key,
|
||||
(named) -> named
|
||||
)));
|
||||
@@ -160,5 +171,14 @@ public class AwfulBukkitHacks {
|
||||
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(
|
||||
entry -> Reflection.HOLDER_REFERENCE.invokeBindTags(entry, Set.of()));
|
||||
}
|
||||
|
||||
// used by BukkitWorldHandle
|
||||
public static BlockData createBlockState(@NotNull String data) throws CommandSyntaxException {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
HolderLookup.Provider lookup = server.registryAccess();
|
||||
final HolderLookup<Block> blocks = lookup.lookupOrThrow(Registries.BLOCK);
|
||||
BlockResult result = BlockStateParser.parseForBlock(blocks, new StringReader(data), true);
|
||||
return CraftBlockData.createData(result.blockState());
|
||||
}
|
||||
}
|
||||
|
||||
+44
-12
@@ -11,11 +11,13 @@ import net.minecraft.world.attribute.AmbientMoodSettings;
|
||||
import net.minecraft.world.attribute.AmbientParticle;
|
||||
import net.minecraft.world.attribute.AmbientSounds;
|
||||
import net.minecraft.world.attribute.BackgroundMusic;
|
||||
import net.minecraft.world.attribute.EnvironmentAttribute;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributeMap;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributeMap.Entry;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributes;
|
||||
import net.minecraft.world.attribute.modifier.AttributeModifier;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
|
||||
@@ -42,19 +44,22 @@ public class NMSBiomeInjector {
|
||||
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
|
||||
EnvironmentAttributeMap attributes = vanilla.getAttributes();
|
||||
|
||||
Integer vanillaFogColour = (Integer) Objects.requireNonNull(attributes.get(EnvironmentAttributes.FOG_COLOR)).argument();
|
||||
Integer vanillaWaterFogColour = (Integer) Objects.requireNonNull(attributes.get(EnvironmentAttributes.WATER_FOG_COLOR)).argument();
|
||||
Integer vanillaSkyColour = (Integer) Objects.requireNonNull(attributes.get(EnvironmentAttributes.SKY_COLOR)).argument();
|
||||
Float vanillaMusicVolume = (Float) Objects.requireNonNull(attributes.get(EnvironmentAttributes.MUSIC_VOLUME)).argument();
|
||||
Integer vanillaFogColour = extractInt(attributes, EnvironmentAttributes.FOG_COLOR);
|
||||
Integer vanillaWaterFogColour = extractInt(attributes, EnvironmentAttributes.WATER_FOG_COLOR);
|
||||
Integer vanillaSkyColour = extractInt(attributes, EnvironmentAttributes.SKY_COLOR);
|
||||
Float vanillaMusicVolume = extractFloat(attributes, EnvironmentAttributes.MUSIC_VOLUME);
|
||||
|
||||
builder.modifyAttribute(EnvironmentAttributes.FOG_COLOR, AttributeModifier.override(),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanillaFogColour));
|
||||
builder.modifyAttribute(EnvironmentAttributes.WATER_FOG_COLOR, AttributeModifier.override(),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanillaWaterFogColour));
|
||||
builder.modifyAttribute(EnvironmentAttributes.SKY_COLOR, AttributeModifier.override(),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanillaSkyColour));
|
||||
builder.modifyAttribute(EnvironmentAttributes.MUSIC_VOLUME, AttributeModifier.override(),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getMusicVolume(), vanillaMusicVolume));
|
||||
applyIfPresent(builder, EnvironmentAttributes.FOG_COLOR,
|
||||
vanillaBiomeProperties.getFogColor(), vanillaFogColour);
|
||||
|
||||
applyIfPresent(builder, EnvironmentAttributes.WATER_FOG_COLOR,
|
||||
vanillaBiomeProperties.getWaterFogColor(), vanillaWaterFogColour);
|
||||
|
||||
applyIfPresent(builder, EnvironmentAttributes.SKY_COLOR,
|
||||
vanillaBiomeProperties.getSkyColor(), vanillaSkyColour);
|
||||
|
||||
applyIfPresent(builder, EnvironmentAttributes.MUSIC_VOLUME,
|
||||
vanillaBiomeProperties.getMusicVolume(), vanillaMusicVolume);
|
||||
|
||||
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()));
|
||||
effects.grassColorModifier(
|
||||
@@ -152,4 +157,31 @@ public class NMSBiomeInjector {
|
||||
return pack.getID().toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(
|
||||
Locale.ROOT);
|
||||
}
|
||||
|
||||
private static Integer extractInt(EnvironmentAttributeMap attributes,
|
||||
EnvironmentAttribute<Integer> key) {
|
||||
Entry<Integer, ?> attr = attributes.get(key);
|
||||
return attr != null ? (Integer) attr.argument() : null;
|
||||
}
|
||||
|
||||
private static Float extractFloat(EnvironmentAttributeMap attributes,
|
||||
EnvironmentAttribute<Float> key) {
|
||||
Entry<Float, ?> attr = attributes.get(key);
|
||||
return attr != null ? (Float) attr.argument() : null;
|
||||
}
|
||||
|
||||
private static <T> void applyIfPresent(
|
||||
BiomeBuilder builder,
|
||||
EnvironmentAttribute<T> attr,
|
||||
T overrideValue,
|
||||
T fallbackValue
|
||||
) {
|
||||
T value = overrideValue != null ? overrideValue : fallbackValue;
|
||||
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.modifyAttribute(attr, AttributeModifier.override(), value);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user