@@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/world/inventory/ContainerEnchantTable.java
|
||||
+++ b/net/minecraft/world/inventory/ContainerEnchantTable.java
|
||||
@@ -25,6 +25,22 @@
|
||||
@@ -31,6 +31,22 @@
|
||||
import net.minecraft.world.level.block.BlockEnchantmentTable;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
+
|
||||
public class ContainerEnchantTable extends Container {
|
||||
|
||||
static final MinecraftKey EMPTY_SLOT_LAPIS_LAZULI = new MinecraftKey("item/empty_slot_lapis_lazuli");
|
||||
@@ -35,6 +51,10 @@
|
||||
static final MinecraftKey EMPTY_SLOT_LAPIS_LAZULI = MinecraftKey.withDefaultNamespace("item/empty_slot_lapis_lazuli");
|
||||
@@ -41,6 +57,10 @@
|
||||
public final int[] costs;
|
||||
public final int[] enchantClue;
|
||||
public final int[] levelClue;
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
public ContainerEnchantTable(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.NULL);
|
||||
@@ -48,6 +68,13 @@
|
||||
@@ -54,6 +74,13 @@
|
||||
super.setChanged();
|
||||
ContainerEnchantTable.this.slotsChanged(this);
|
||||
}
|
||||
@@ -48,7 +48,7 @@
|
||||
};
|
||||
this.random = RandomSource.create();
|
||||
this.enchantmentSeed = ContainerProperty.standalone();
|
||||
@@ -55,13 +82,13 @@
|
||||
@@ -61,13 +88,13 @@
|
||||
this.enchantClue = new int[]{-1, -1, -1};
|
||||
this.levelClue = new int[]{-1, -1, -1};
|
||||
this.access = containeraccess;
|
||||
@@ -64,7 +64,7 @@
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack itemstack) {
|
||||
return itemstack.is(Items.LAPIS_LAZULI);
|
||||
@@ -95,6 +122,9 @@
|
||||
@@ -101,6 +128,9 @@
|
||||
this.addDataSlot(ContainerProperty.shared(this.levelClue, 0));
|
||||
this.addDataSlot(ContainerProperty.shared(this.levelClue, 1));
|
||||
this.addDataSlot(ContainerProperty.shared(this.levelClue, 2));
|
||||
@@ -74,16 +74,16 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +132,7 @@
|
||||
@@ -108,7 +138,7 @@
|
||||
if (iinventory == this.enchantSlots) {
|
||||
ItemStack itemstack = iinventory.getItem(0);
|
||||
|
||||
- if (!itemstack.isEmpty() && itemstack.isEnchantable()) {
|
||||
+ if (!itemstack.isEmpty()) { // CraftBukkit - relax condition
|
||||
this.access.execute((world, blockposition) -> {
|
||||
Registry<Holder<Enchantment>> registry = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT).asHolderIdMap();
|
||||
int i = 0;
|
||||
Iterator iterator = BlockEnchantmentTable.BOOKSHELF_OFFSETS.iterator();
|
||||
@@ -141,6 +171,41 @@
|
||||
@@ -148,6 +178,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
|
||||
+ org.bukkit.enchantments.EnchantmentOffer[] offers = new EnchantmentOffer[3];
|
||||
+ for (j = 0; j < 3; ++j) {
|
||||
+ org.bukkit.enchantments.Enchantment enchantment = (this.enchantClue[j] >= 0) ? CraftEnchantment.minecraftToBukkit(Enchantment.byId(this.enchantClue[j])) : null;
|
||||
+ org.bukkit.enchantments.Enchantment enchantment = (this.enchantClue[j] >= 0) ? CraftEnchantment.minecraftHolderToBukkit(registry.byId(this.enchantClue[j])) : null;
|
||||
+ offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.levelClue[j], this.costs[j]) : null;
|
||||
+ }
|
||||
+
|
||||
@@ -112,7 +112,7 @@
|
||||
+ EnchantmentOffer offer = event.getOffers()[j];
|
||||
+ if (offer != null) {
|
||||
+ this.costs[j] = offer.getCost();
|
||||
+ this.enchantClue[j] = BuiltInRegistries.ENCHANTMENT.getId(CraftEnchantment.bukkitToMinecraft(offer.getEnchantment()));
|
||||
+ this.enchantClue[j] = registry.getId(CraftEnchantment.bukkitToMinecraftHolder(offer.getEnchantment()));
|
||||
+ this.levelClue[j] = offer.getEnchantmentLevel();
|
||||
+ } else {
|
||||
+ this.costs[j] = 0;
|
||||
@@ -125,22 +125,23 @@
|
||||
this.broadcastChanges();
|
||||
});
|
||||
} else {
|
||||
@@ -168,21 +233,46 @@
|
||||
@@ -175,21 +240,46 @@
|
||||
ItemStack itemstack2 = itemstack;
|
||||
List<WeightedRandomEnchant> list = this.getEnchantmentList(world.enabledFeatures(), itemstack, i, this.costs[i]);
|
||||
List<WeightedRandomEnchant> list = this.getEnchantmentList(world.registryAccess(), itemstack, i, this.costs[i]);
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
- entityhuman.onEnchantmentPerformed(itemstack, j);
|
||||
+ // CraftBukkit start
|
||||
+ Registry<Holder<Enchantment>> registry = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT).asHolderIdMap();
|
||||
+ if (true || !list.isEmpty()) {
|
||||
+ // entityhuman.onEnchantmentPerformed(itemstack, j); // Moved down
|
||||
+ Map<org.bukkit.enchantments.Enchantment, Integer> enchants = new java.util.HashMap<org.bukkit.enchantments.Enchantment, Integer>();
|
||||
+ for (WeightedRandomEnchant instance : list) {
|
||||
+ enchants.put(CraftEnchantment.minecraftToBukkit(instance.enchantment), instance.level);
|
||||
+ enchants.put(CraftEnchantment.minecraftHolderToBukkit(instance.enchantment), instance.level);
|
||||
+ }
|
||||
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2);
|
||||
+
|
||||
+ org.bukkit.enchantments.Enchantment hintedEnchantment = CraftEnchantment.minecraftToBukkit(Enchantment.byId(enchantClue[i]));
|
||||
+ org.bukkit.enchantments.Enchantment hintedEnchantment = CraftEnchantment.minecraftHolderToBukkit(registry.byId(enchantClue[i]));
|
||||
+ int hintedEnchantmentLevel = levelClue[i];
|
||||
+ EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.getBukkitEntity(), this.getBukkitView(), access.getLocation().getBlock(), item, this.costs[i], enchants, hintedEnchantment, hintedEnchantmentLevel, i);
|
||||
+ world.getCraftServer().getPluginManager().callEvent(event);
|
||||
@@ -151,7 +152,7 @@
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (itemstack.is(Items.BOOK)) {
|
||||
itemstack2 = itemstack.transmuteCopy(Items.ENCHANTED_BOOK, 1);
|
||||
itemstack2 = itemstack.transmuteCopy(Items.ENCHANTED_BOOK);
|
||||
this.enchantSlots.setItem(0, itemstack2);
|
||||
}
|
||||
|
||||
@@ -161,8 +162,7 @@
|
||||
- WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) iterator.next();
|
||||
+ // CraftBukkit start
|
||||
+ for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
|
||||
+ NamespacedKey enchantId = entry.getKey().getKey();
|
||||
+ Enchantment nms = BuiltInRegistries.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(enchantId));
|
||||
+ Holder<Enchantment> nms = CraftEnchantment.bukkitToMinecraftHolder(entry.getKey());
|
||||
+ if (nms == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
@@ -175,10 +175,10 @@
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ // CraftBukkit - TODO: let plugins change this
|
||||
if (!entityhuman.hasInfiniteMaterials()) {
|
||||
itemstack1.shrink(j);
|
||||
if (itemstack1.isEmpty()) {
|
||||
@@ -245,6 +335,7 @@
|
||||
itemstack1.consume(j, entityhuman);
|
||||
if (itemstack1.isEmpty()) {
|
||||
this.enchantSlots.setItem(1, ItemStack.EMPTY);
|
||||
@@ -256,6 +346,7 @@
|
||||
|
||||
@Override
|
||||
public boolean stillValid(EntityHuman entityhuman) {
|
||||
@@ -186,7 +186,7 @@
|
||||
return stillValid(this.access, entityhuman, Blocks.ENCHANTING_TABLE);
|
||||
}
|
||||
|
||||
@@ -295,4 +386,17 @@
|
||||
@@ -306,4 +397,17 @@
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user