[1.21.5] Template fixes

Signed-off-by: Irmo van den Berge <irmo.vandenberge@ziggo.nl>
This commit is contained in:
Irmo van den Berge committed 2025-04-20 18:28:31 +02:00
1 parent cd9c97fa43
commit faaab15329
8 files changed
+81 -13

No files matched your search

@@ -14,7 +14,11 @@ class Vector3f {
#endif
public org.bukkit.util.Vector toBukkit() {
#if version >= 1.21.5
return new org.bukkit.util.Vector(instance.x(), instance.y(), instance.z());
#else
return new org.bukkit.util.Vector(instance.getX(), instance.getY(), instance.getZ());
#endif
}
public (Vector3fHandle) Vector3f(float x, float y, float z);
@@ -650,7 +650,9 @@ class NBTTagCompound extends NBTBase {
public static (NBTBaseHandle) NBTBase fromMojangson(String mojangson) {
try {
#if version >= 1.18
#if version >= 1.21.5
return MojangsonParser.parseCompoundFully(mojangson);
#elseif version >= 1.18
return MojangsonParser.parseTag(mojangson);
#else
return MojangsonParser.parse(mojangson);
@@ -90,7 +90,17 @@ class IChatBaseComponent {
public (IChatBaseComponentHandle) IChatBaseComponent setClickableURL(String url) {
ChatModifier modifier = instance.getStyle();
#if version >= 1.18
#if version >= 1.21.5
java.net.URI parsedURI = null;
try {
parsedURI = new java.net.URI(url);
} catch (Throwable t) {
// Not a valid URL at all
}
if (parsedURI != null) {
modifier = modifier.withClickEvent(new ChatClickable$OpenUrl(parsedURI));
}
#elseif version >= 1.18
modifier = modifier.withClickEvent(new ChatClickable(ChatClickable$EnumClickAction.OPEN_URL, url));
#else
modifier = modifier.setChatClickable(new ChatClickable(ChatClickable$EnumClickAction.OPEN_URL, url));
@@ -101,7 +111,9 @@ class IChatBaseComponent {
public (IChatBaseComponentHandle) IChatBaseComponent setClickableContent(String content) {
#if version >= 1.15
ChatModifier modifier = instance.getStyle();
#if version >= 1.18
#if version >= 1.21.5
modifier = modifier.withClickEvent(new ChatClickable$CopyToClipboard(content));
#elseif version >= 1.18
modifier = modifier.withClickEvent(new ChatClickable(ChatClickable$EnumClickAction.COPY_TO_CLIPBOARD, content));
#else
modifier = modifier.setChatClickable(new ChatClickable(ChatClickable$EnumClickAction.COPY_TO_CLIPBOARD, content));
@@ -115,7 +127,9 @@ class IChatBaseComponent {
public (IChatBaseComponentHandle) IChatBaseComponent setClickableSuggestedCommand(String command) {
ChatModifier modifier = instance.getStyle();
#if version >= 1.18
#if version >= 1.21.5
modifier = modifier.withClickEvent(new ChatClickable$SuggestCommand(command));
#elseif version >= 1.18
modifier = modifier.withClickEvent(new ChatClickable(ChatClickable$EnumClickAction.SUGGEST_COMMAND, command));
#else
modifier = modifier.setChatClickable(new ChatClickable(ChatClickable$EnumClickAction.SUGGEST_COMMAND, command));
@@ -125,7 +139,9 @@ class IChatBaseComponent {
public (IChatBaseComponentHandle) IChatBaseComponent setClickableRunCommand(String command) {
ChatModifier modifier = instance.getStyle();
#if version >= 1.18
#if version >= 1.21.5
modifier = modifier.withClickEvent(new ChatClickable$RunCommand(command));
#elseif version >= 1.18
modifier = modifier.withClickEvent(new ChatClickable(ChatClickable$EnumClickAction.RUN_COMMAND, command));
#else
modifier = modifier.setChatClickable(new ChatClickable(ChatClickable$EnumClickAction.RUN_COMMAND, command));
@@ -135,7 +151,9 @@ class IChatBaseComponent {
public (IChatBaseComponentHandle) IChatBaseComponent setHoverText((IChatBaseComponentHandle) IChatBaseComponent hoverText) {
ChatModifier modifier = instance.getStyle();
#if version >= 1.18
#if version >= 1.21.5
modifier = modifier.withHoverEvent(new ChatHoverable$e(hoverText));
#elseif version >= 1.18
modifier = modifier.withHoverEvent(new ChatHoverable(ChatHoverable$EnumHoverAction.SHOW_TEXT, hoverText));
#else
modifier = modifier.setChatHoverable(new ChatHoverable(ChatHoverable$EnumHoverAction.SHOW_TEXT, hoverText));
@@ -1519,7 +1519,7 @@ class PacketPlayOutMapChunk extends Packet {
java.util.Iterator iter = heightmaps.entrySet().iterator();
while (iter.hasNext()) {
java.util.Map$Entry entry = (java.util.Map$Entry) iter.next();
HeightMap$Type heightmapType = (HeightMap$Type) entry.getKey();
net.minecraft.world.level.levelgen.HeightMap$Type heightmapType = (net.minecraft.world.level.levelgen.HeightMap$Type) entry.getKey();
long[] heightmapData = (long[]) entry.getValue();
heightmapsNBT.putLongArray(heightmapType.getSerializedName(), heightmapData);
}
@@ -1543,7 +1543,7 @@ class PacketPlayOutMapChunk extends Packet {
// Convert NBT into Map<HeightMap.Type, long[]>
java.util.Map heightmaps = new java.util.HashMap(heightmapsData.size());
HeightMap$Type[] heightmapTypes = HeightMap$Type.values();
net.minecraft.world.level.levelgen.HeightMap$Type[] heightmapTypes = net.minecraft.world.level.levelgen.HeightMap$Type.values();
// public Set<Map.Entry<String, NBTBase>> entrySet() {
java.util.Iterator nbtEntryIter = heightmapsData.entrySet().iterator();
@@ -1553,7 +1553,7 @@ class PacketPlayOutMapChunk extends Packet {
// Key -> HeightMap.Type
// TODO: Use the Codec to avoid a for loop here
String serializedName = (String) entry.getKey();
HeightMap$Type heightmapType = null;
net.minecraft.world.level.levelgen.HeightMap$Type heightmapType = null;
for (int i = 0; i < heightmapTypes.length; i++) {
if (heightmapTypes[i].getSerializedName().equals(serializedName)) {
heightmapType = heightmapTypes[i];
@@ -9,6 +9,7 @@ import net.minecraft.world.level.IMaterial;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.item.ItemWorldMap;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.TooltipDisplay;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
@@ -216,10 +217,40 @@ class ItemStack {
}
#endif
#if version >= 1.21.5
#require ItemStack public java.util.LinkedHashSet getHiddenToolTipComponents() {
TooltipDisplay display = (TooltipDisplay) instance.get(DataComponents.TOOLTIP_DISPLAY);
java.util.LinkedHashSet hiddenDataComponents = new java.util.LinkedHashSet();
if (display.hideTooltip()) {
hiddenDataComponents.addAll(display.hiddenComponents());
}
return hiddenDataComponents;
}
#if version >= 1.20.5
public void hideTooltip() {
java.util.LinkedHashSet hiddenDataComponents = instance#getHiddenToolTipComponents();
hiddenDataComponents.add(DataComponents.ITEM_NAME);
hiddenDataComponents.add(DataComponents.CUSTOM_NAME);
instance.set(DataComponents.TOOLTIP_DISPLAY, new TooltipDisplay(true, hiddenDataComponents));
}
public void hideAllAttributes() {
java.util.LinkedHashSet hiddenDataComponents = instance#getHiddenToolTipComponents();
java.util.Iterator allDataComponentsIter = net.minecraft.core.registries.BuiltInRegistries.DATA_COMPONENT_TYPE.iterator();
while (allDataComponentsIter.hasNext()) {
hiddenDataComponents.add(allDataComponentsIter.next());
}
instance.set(DataComponents.TOOLTIP_DISPLAY, new TooltipDisplay(true, hiddenDataComponents));
}
#elseif version >= 1.20.5
public void hideTooltip() {
#if version >= 1.21.5
instance.set(DataComponents.HIDE_TOOLTIP, new TooltipDisplay(true, ));
#else
instance.set(DataComponents.HIDE_TOOLTIP, net.minecraft.util.Unit.INSTANCE);
#endif
}
public void hideAllAttributes() {
@@ -481,7 +512,13 @@ class ItemStack {
#endif
}
public void setUnbreakable(boolean unbreakable) {
#if version >= 1.20.5
#if version >= 1.21.5
if (unbreakable) {
instance.set(DataComponents.UNBREAKABLE, net.minecraft.util.Unit.INSTANCE);
} else {
instance.remove(DataComponents.UNBREAKABLE);
}
#elseif version >= 1.20.5
// Preserve tooltip yes/no by only checking it changed
if (unbreakable != instance.has(DataComponents.UNBREAKABLE)) {
if (unbreakable) {
@@ -368,7 +368,9 @@ class Chunk {
// Since MC 1.13 updateFlags are used (See World.java setTypeAndData)
public (BlockData) IBlockData setBlockData((IntVector3) BlockPosition blockposition, (BlockData) IBlockData iblockdata, int updateFlags) {
#if version >= 1.18
#if version >= 1.21.5
return instance.setBlockState(blockposition, iblockdata, updateFlags);
#elseif version >= 1.18
return instance.setBlockState(blockposition, iblockdata, (updateFlags & 64) != 0);
#elseif version >= 1.13.2
return instance.setType(blockposition, iblockdata, (updateFlags & 64) != 0);
@@ -52,7 +52,11 @@ class MobSpawnerAbstract {
public (MinecraftKeyHandle) MinecraftKey getMobName() {
// No API :( will need to read NBT directly
NBTTagCompound spawnedEntityNBT = instance.nextSpawnData.getEntityToSpawn();
#if version >= 1.21.5
return MinecraftKey.tryParse(spawnedEntityNBT.getStringOr("id", ""));
#else
return MinecraftKey.tryParse(spawnedEntityNBT.getString("id"));
#endif
}
public void setMobName((MinecraftKeyHandle) MinecraftKey nameKey) {
// Set NBT directly
@@ -7,6 +7,7 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import com.bergerkiller.generated.net.minecraft.nbt.NBTTagCompoundHandle;
import com.bergerkiller.generated.net.minecraft.world.effect.MobEffectHandle;
import com.bergerkiller.generated.net.minecraft.world.effect.MobEffectListHandle;
import com.bergerkiller.bukkit.common.nbt.CommonTagCompound;
@@ -52,7 +53,7 @@ class MobEffect {
// RegistryOps<NBTBase> registryops = this.registryAccess().<NBTBase>createSerializationContext(DynamicOpsNBT.INSTANCE);
com.mojang.serialization.DynamicOps dynamicops = net.minecraft.nbt.DynamicOpsNBT.INSTANCE;
return (MobEffect) MobEffect.CODEC.parse(dynamicops, compound)
.resultOrPartial(CommonTagCompound.createPartialErrorLogger(compound))
.resultOrPartial(NBTTagCompoundHandle.createPartialErrorLogger(compound))
.orElse(null);
}
#elseif version >= 1.18