Update to Minecraft 1.20.5

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-04-24 01:15:00 +10:00
parent 4deda9501f
commit 65bc2541a3
524 changed files with 7788 additions and 6181 deletions

View File

@@ -0,0 +1,52 @@
package org.bukkit.craftbukkit.map;
import com.google.common.base.Preconditions;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.saveddata.maps.MapDecorationType;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.map.MapCursor;
public final class CraftMapCursor {
public static final class CraftType {
public static MapCursor.Type minecraftToBukkit(MapDecorationType minecraft) {
Preconditions.checkArgument(minecraft != null);
IRegistry<MapDecorationType> registry = CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE);
MapCursor.Type bukkit = Registry.MAP_DECORATION_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
Preconditions.checkArgument(bukkit != null);
return bukkit;
}
public static MapCursor.Type minecraftHolderToBukkit(Holder<MapDecorationType> minecraft) {
return minecraftToBukkit(minecraft.value());
}
public static MapDecorationType bukkitToMinecraft(MapCursor.Type bukkit) {
Preconditions.checkArgument(bukkit != null);
return CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE)
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
}
public static Holder<MapDecorationType> bukkitToMinecraftHolder(MapCursor.Type bukkit) {
Preconditions.checkArgument(bukkit != null);
IRegistry<MapDecorationType> registry = CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE);
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<MapDecorationType> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own map cursor type without properly registering it.");
}
}
}

View File

@@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapCursor;
import org.bukkit.map.MapCursorCollection;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
@@ -42,7 +43,7 @@ public class CraftMapRenderer extends MapRenderer {
}
MapIcon decoration = worldMap.decorations.get(key);
cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, CraftChatMessage.fromComponent(decoration.name()));
cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, CraftChatMessage.fromComponent(decoration.name().orElse(null))));
}
}

View File

@@ -1,6 +1,5 @@
package org.bukkit.craftbukkit.map;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -32,13 +31,7 @@ public final class CraftMapView implements MapView {
@Override
public int getId() {
String text = worldMap.id;
Preconditions.checkState(text.startsWith("map_"), "Map has a invalid ID");
try {
return Integer.parseInt(text.substring("map_".length()));
} catch (NumberFormatException ex) {
throw new IllegalStateException("Map has non-numeric ID");
}
return worldMap.id.id();
}
@Override