mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
net.minecraft.world.item.enchantment
This commit is contained in:
parent
729c6e5369
commit
5eb4ceb6a4
1 changed files with 15 additions and 21 deletions
|
@ -1,60 +1,54 @@
|
||||||
--- a/net/minecraft/world/item/enchantment/ItemEnchantments.java
|
--- a/net/minecraft/world/item/enchantment/ItemEnchantments.java
|
||||||
+++ b/net/minecraft/world/item/enchantment/ItemEnchantments.java
|
+++ b/net/minecraft/world/item/enchantment/ItemEnchantments.java
|
||||||
@@ -26,12 +26,25 @@
|
@@ -28,10 +_,19 @@
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
|
||||||
import net.minecraft.world.item.component.TooltipProvider;
|
import net.minecraft.world.item.component.TooltipProvider;
|
||||||
+// Paper start
|
|
||||||
+import it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap;
|
|
||||||
+// Paper end
|
|
||||||
|
|
||||||
public class ItemEnchantments implements TooltipProvider {
|
public class ItemEnchantments implements TooltipProvider {
|
||||||
- public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntOpenHashMap<>(), true);
|
- public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntOpenHashMap<>(), true);
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
+ private static final java.util.Comparator<Holder<Enchantment>> ENCHANTMENT_ORDER = java.util.Comparator.comparing(Holder::getRegisteredName);
|
+ private static final java.util.Comparator<Holder<Enchantment>> ENCHANTMENT_ORDER = java.util.Comparator.comparing(Holder::getRegisteredName);
|
||||||
+ public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true);
|
+ public static final ItemEnchantments EMPTY = new ItemEnchantments(new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true);
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
private static final Codec<Integer> LEVEL_CODEC = Codec.intRange(1, 255);
|
private static final Codec<Integer> LEVEL_CODEC = Codec.intRange(1, 255);
|
||||||
- private static final Codec<Object2IntOpenHashMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC)
|
- private static final Codec<Object2IntOpenHashMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC)
|
||||||
- .xmap(Object2IntOpenHashMap::new, Function.identity());
|
- .xmap(Object2IntOpenHashMap::new, Function.identity());
|
||||||
+ private static final Codec<Object2IntAVLTreeMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(
|
+ // Paper start - sort enchantments
|
||||||
+ Enchantment.CODEC, LEVEL_CODEC
|
+ private static final Codec<it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC)
|
||||||
+ )// Paper start - sort enchantments
|
|
||||||
+ .xmap(m -> {
|
+ .xmap(m -> {
|
||||||
+ final Object2IntAVLTreeMap<Holder<Enchantment>> map = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER);
|
+ final it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<Holder<Enchantment>> map = new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER);
|
||||||
+ map.putAll(m);
|
+ map.putAll(m);
|
||||||
+ return map;
|
+ return map;
|
||||||
+ }, Function.identity());
|
+ }, Function.identity());
|
||||||
+ // Paper end - sort enchantments
|
+ // Paper end - sort enchantments
|
||||||
private static final Codec<ItemEnchantments> FULL_CODEC = RecordCodecBuilder.create(
|
private static final Codec<ItemEnchantments> FULL_CODEC = RecordCodecBuilder.create(
|
||||||
instance -> instance.group(
|
instance -> instance.group(
|
||||||
LEVELS_CODEC.fieldOf("levels").forGetter(component -> component.enchantments),
|
LEVELS_CODEC.fieldOf("levels").forGetter(itemEnchantments -> itemEnchantments.enchantments),
|
||||||
@@ -41,16 +54,16 @@
|
@@ -41,16 +_,16 @@
|
||||||
);
|
);
|
||||||
public static final Codec<ItemEnchantments> CODEC = Codec.withAlternative(FULL_CODEC, LEVELS_CODEC, map -> new ItemEnchantments(map, true));
|
public static final Codec<ItemEnchantments> CODEC = Codec.withAlternative(FULL_CODEC, LEVELS_CODEC, map -> new ItemEnchantments(map, true));
|
||||||
public static final StreamCodec<RegistryFriendlyByteBuf, ItemEnchantments> STREAM_CODEC = StreamCodec.composite(
|
public static final StreamCodec<RegistryFriendlyByteBuf, ItemEnchantments> STREAM_CODEC = StreamCodec.composite(
|
||||||
- ByteBufCodecs.map(Object2IntOpenHashMap::new, Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
|
- ByteBufCodecs.map(Object2IntOpenHashMap::new, Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
|
||||||
+ ByteBufCodecs.map((v) -> new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
|
+ ByteBufCodecs.map((v) -> new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT), // Paper
|
||||||
component -> component.enchantments,
|
itemEnchantments -> itemEnchantments.enchantments,
|
||||||
ByteBufCodecs.BOOL,
|
ByteBufCodecs.BOOL,
|
||||||
component -> component.showInTooltip,
|
itemEnchantments -> itemEnchantments.showInTooltip,
|
||||||
ItemEnchantments::new
|
ItemEnchantments::new
|
||||||
);
|
);
|
||||||
- final Object2IntOpenHashMap<Holder<Enchantment>> enchantments;
|
- final Object2IntOpenHashMap<Holder<Enchantment>> enchantments;
|
||||||
+ final Object2IntAVLTreeMap<Holder<Enchantment>> enchantments; // Paper
|
+ final it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<Holder<Enchantment>> enchantments; // Paper
|
||||||
public final boolean showInTooltip;
|
public final boolean showInTooltip;
|
||||||
|
|
||||||
- ItemEnchantments(Object2IntOpenHashMap<Holder<Enchantment>> enchantments, boolean showInTooltip) {
|
- ItemEnchantments(Object2IntOpenHashMap<Holder<Enchantment>> enchantments, boolean showInTooltip) {
|
||||||
+ ItemEnchantments(Object2IntAVLTreeMap<Holder<Enchantment>> enchantments, boolean showInTooltip) { // Paper
|
+ ItemEnchantments(it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<Holder<Enchantment>> enchantments, boolean showInTooltip) { // Paper
|
||||||
this.enchantments = enchantments;
|
this.enchantments = enchantments;
|
||||||
this.showInTooltip = showInTooltip;
|
this.showInTooltip = showInTooltip;
|
||||||
|
|
||||||
@@ -139,7 +152,7 @@
|
@@ -139,7 +_,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Mutable {
|
public static class Mutable {
|
||||||
- private final Object2IntOpenHashMap<Holder<Enchantment>> enchantments = new Object2IntOpenHashMap<>();
|
- private final Object2IntOpenHashMap<Holder<Enchantment>> enchantments = new Object2IntOpenHashMap<>();
|
||||||
+ private final Object2IntAVLTreeMap<Holder<Enchantment>> enchantments = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); // Paper
|
+ private final it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<Holder<Enchantment>> enchantments = new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); // Paper
|
||||||
public boolean showInTooltip;
|
public boolean showInTooltip;
|
||||||
|
|
||||||
public Mutable(ItemEnchantments enchantmentsComponent) {
|
public Mutable(ItemEnchantments enchantments) {
|
Loading…
Reference in a new issue