@@ -1,8 +1,8 @@
|
||||
--- a/net/minecraft/world/inventory/Container.java
|
||||
+++ b/net/minecraft/world/inventory/Container.java
|
||||
@@ -30,6 +30,20 @@
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -32,6 +32,20 @@
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import com.google.common.base.Preconditions;
|
||||
@@ -20,8 +20,8 @@
|
||||
+
|
||||
public abstract class Container {
|
||||
|
||||
public static final int SLOT_CLICKED_OUTSIDE = -999;
|
||||
@@ -59,6 +73,27 @@
|
||||
private static Logger LOGGER = LogUtils.getLogger();
|
||||
@@ -62,6 +76,27 @@
|
||||
private ContainerSynchronizer synchronizer;
|
||||
private boolean suppressRemoteUpdates;
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
protected Container(@Nullable Containers<?> containers, int i) {
|
||||
this.carried = ItemStack.EMPTY;
|
||||
this.remoteSlots = NonNullList.create();
|
||||
@@ -156,6 +191,15 @@
|
||||
@@ -163,6 +198,15 @@
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
public void removeSlotListener(ICrafting icrafting) {
|
||||
this.containerListeners.remove(icrafting);
|
||||
}
|
||||
@@ -370,7 +414,7 @@
|
||||
@@ -381,7 +425,7 @@
|
||||
}
|
||||
} else if (this.quickcraftStatus == 2) {
|
||||
if (!this.quickcraftSlots.isEmpty()) {
|
||||
@@ -74,7 +74,7 @@
|
||||
k = ((Slot) this.quickcraftSlots.iterator().next()).index;
|
||||
this.resetQuickCraft();
|
||||
this.doClick(k, this.quickcraftType, InventoryClickType.PICKUP, entityhuman);
|
||||
@@ -381,6 +425,7 @@
|
||||
@@ -392,6 +436,7 @@
|
||||
l = this.getCarried().getCount();
|
||||
Iterator iterator = this.quickcraftSlots.iterator();
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
Slot slot1 = (Slot) iterator.next();
|
||||
ItemStack itemstack2 = this.getCarried();
|
||||
@@ -397,12 +442,48 @@
|
||||
@@ -408,12 +453,48 @@
|
||||
}
|
||||
|
||||
l -= itemstack3.getCount() - j1;
|
||||
@@ -134,7 +134,7 @@
|
||||
}
|
||||
|
||||
this.resetQuickCraft();
|
||||
@@ -420,8 +501,11 @@
|
||||
@@ -431,8 +512,11 @@
|
||||
if (i == -999) {
|
||||
if (!this.getCarried().isEmpty()) {
|
||||
if (clickaction == ClickAction.PRIMARY) {
|
||||
@@ -147,7 +147,7 @@
|
||||
} else {
|
||||
entityhuman.drop(this.getCarried().split(1), true);
|
||||
}
|
||||
@@ -484,6 +568,15 @@
|
||||
@@ -495,6 +579,15 @@
|
||||
}
|
||||
|
||||
slot.setChanged();
|
||||
@@ -163,7 +163,7 @@
|
||||
}
|
||||
} else {
|
||||
Slot slot2;
|
||||
@@ -591,13 +684,14 @@
|
||||
@@ -602,13 +695,14 @@
|
||||
ItemStack itemstack = this.getCarried();
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
@@ -179,7 +179,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -811,6 +905,11 @@
|
||||
@@ -822,6 +916,11 @@
|
||||
}
|
||||
|
||||
public ItemStack getCarried() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
--- a/net/minecraft/world/inventory/ContainerAnvil.java
|
||||
+++ b/net/minecraft/world/inventory/ContainerAnvil.java
|
||||
@@ -18,12 +18,16 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -17,12 +17,16 @@
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
@@ -10,7 +10,7 @@
|
||||
+
|
||||
public class ContainerAnvil extends ContainerAnvilAbstract {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final boolean DEBUG_COST = false;
|
||||
public static final int MAX_NAME_LENGTH = 50;
|
||||
- private int repairItemCountCost;
|
||||
@@ -18,7 +18,7 @@
|
||||
public String itemName;
|
||||
public final ContainerProperty cost;
|
||||
private static final int COST_FAIL = 0;
|
||||
@@ -33,6 +37,10 @@
|
||||
@@ -32,6 +36,10 @@
|
||||
private static final int COST_REPAIR_SACRIFICE = 2;
|
||||
private static final int COST_INCOMPATIBLE_PENALTY = 1;
|
||||
private static final int COST_RENAME = 1;
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
public ContainerAnvil(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.NULL);
|
||||
@@ -105,7 +113,7 @@
|
||||
@@ -104,7 +112,7 @@
|
||||
byte b1 = 0;
|
||||
|
||||
if (itemstack.isEmpty()) {
|
||||
@@ -38,7 +38,7 @@
|
||||
this.cost.set(0);
|
||||
} else {
|
||||
ItemStack itemstack1 = itemstack.copy();
|
||||
@@ -123,7 +131,7 @@
|
||||
@@ -122,7 +130,7 @@
|
||||
if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) {
|
||||
k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4);
|
||||
if (k <= 0) {
|
||||
@@ -47,7 +47,7 @@
|
||||
this.cost.set(0);
|
||||
return;
|
||||
}
|
||||
@@ -138,7 +146,7 @@
|
||||
@@ -137,7 +145,7 @@
|
||||
this.repairItemCountCost = i1;
|
||||
} else {
|
||||
if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) {
|
||||
@@ -56,7 +56,7 @@
|
||||
this.cost.set(0);
|
||||
return;
|
||||
}
|
||||
@@ -228,7 +236,7 @@
|
||||
@@ -227,7 +235,7 @@
|
||||
}
|
||||
|
||||
if (flag2 && !flag1) {
|
||||
@@ -65,7 +65,7 @@
|
||||
this.cost.set(0);
|
||||
return;
|
||||
}
|
||||
@@ -252,11 +260,11 @@
|
||||
@@ -251,11 +259,11 @@
|
||||
itemstack1 = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
itemstack1 = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@@ -275,7 +283,8 @@
|
||||
@@ -274,7 +282,8 @@
|
||||
EnchantmentManager.setEnchantments(map, itemstack1);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
this.broadcastChanges();
|
||||
}
|
||||
}
|
||||
@@ -302,4 +311,18 @@
|
||||
@@ -301,4 +310,18 @@
|
||||
public int getCost() {
|
||||
return this.cost.get();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/world/inventory/ContainerBeacon.java
|
||||
+++ b/net/minecraft/world/inventory/ContainerBeacon.java
|
||||
@@ -11,6 +11,11 @@
|
||||
@@ -10,6 +10,11 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
public class ContainerBeacon extends Container {
|
||||
|
||||
private static final int PAYMENT_SLOT = 0;
|
||||
@@ -24,6 +29,10 @@
|
||||
@@ -23,6 +28,10 @@
|
||||
private final ContainerBeacon.SlotBeacon paymentSlot;
|
||||
private final ContainerAccess access;
|
||||
private final IContainerProperties beaconData;
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
public ContainerBeacon(int i, IInventory iinventory) {
|
||||
this(i, iinventory, new ContainerProperties(3), ContainerAccess.NULL);
|
||||
@@ -31,6 +40,7 @@
|
||||
@@ -30,6 +39,7 @@
|
||||
|
||||
public ContainerBeacon(int i, IInventory iinventory, IContainerProperties icontainerproperties, ContainerAccess containeraccess) {
|
||||
super(Containers.BEACON, i);
|
||||
@@ -31,7 +31,7 @@
|
||||
this.beacon = new InventorySubcontainer(1) {
|
||||
@Override
|
||||
public boolean canPlaceItem(int j, ItemStack itemstack) {
|
||||
@@ -80,6 +90,7 @@
|
||||
@@ -79,6 +89,7 @@
|
||||
|
||||
@Override
|
||||
public boolean stillValid(EntityHuman entityhuman) {
|
||||
@@ -39,7 +39,7 @@
|
||||
return stillValid(this.access, entityhuman, Blocks.BEACON);
|
||||
}
|
||||
|
||||
@@ -180,4 +191,17 @@
|
||||
@@ -179,4 +190,17 @@
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
--- a/net/minecraft/world/inventory/ContainerEnchantTable.java
|
||||
+++ b/net/minecraft/world/inventory/ContainerEnchantTable.java
|
||||
@@ -20,6 +20,21 @@
|
||||
import net.minecraft.world.item.enchantment.WeightedRandomEnchant;
|
||||
@@ -25,6 +25,21 @@
|
||||
import net.minecraft.world.level.block.BlockEnchantmentTable;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
+// CraftBukkit start
|
||||
@@ -22,7 +22,7 @@
|
||||
public class ContainerEnchantTable extends Container {
|
||||
|
||||
private final IInventory enchantSlots;
|
||||
@@ -29,6 +44,10 @@
|
||||
@@ -34,6 +49,10 @@
|
||||
public final int[] costs;
|
||||
public final int[] enchantClue;
|
||||
public final int[] levelClue;
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
public ContainerEnchantTable(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.NULL);
|
||||
@@ -42,6 +61,13 @@
|
||||
@@ -47,6 +66,13 @@
|
||||
super.setChanged();
|
||||
ContainerEnchantTable.this.slotsChanged(this);
|
||||
}
|
||||
@@ -47,7 +47,7 @@
|
||||
};
|
||||
this.random = new Random();
|
||||
this.enchantmentSeed = ContainerProperty.standalone();
|
||||
@@ -89,6 +115,9 @@
|
||||
@@ -94,6 +120,9 @@
|
||||
this.addDataSlot(ContainerProperty.shared(this.levelClue, 0));
|
||||
this.addDataSlot(ContainerProperty.shared(this.levelClue, 1));
|
||||
this.addDataSlot(ContainerProperty.shared(this.levelClue, 2));
|
||||
@@ -57,7 +57,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +125,7 @@
|
||||
@@ -101,7 +130,7 @@
|
||||
if (iinventory == this.enchantSlots) {
|
||||
ItemStack itemstack = iinventory.getItem(0);
|
||||
|
||||
@@ -65,8 +65,8 @@
|
||||
+ if (!itemstack.isEmpty()) { // CraftBukkit - relax condition
|
||||
this.access.execute((world, blockposition) -> {
|
||||
int i = 0;
|
||||
|
||||
@@ -158,6 +187,41 @@
|
||||
Iterator iterator = BlockEnchantmentTable.BOOKSHELF_OFFSETS.iterator();
|
||||
@@ -140,6 +169,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,70 +108,71 @@
|
||||
this.broadcastChanges();
|
||||
});
|
||||
} else {
|
||||
@@ -184,9 +248,24 @@
|
||||
ItemStack itemstack2 = itemstack;
|
||||
List<WeightedRandomEnchant> list = this.getEnchantmentList(itemstack, i, this.costs[i]);
|
||||
@@ -167,9 +231,24 @@
|
||||
ItemStack itemstack2 = itemstack;
|
||||
List<WeightedRandomEnchant> list = this.getEnchantmentList(itemstack, i, this.costs[i]);
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
- entityhuman.onEnchantmentPerformed(itemstack, j);
|
||||
+ // CraftBukkit start
|
||||
+ if (true || !list.isEmpty()) {
|
||||
+ // entityhuman.onEnchantmentPerformed(itemstack, j); // Moved down
|
||||
boolean flag = itemstack.is(Items.BOOK);
|
||||
+ Map<org.bukkit.enchantments.Enchantment, Integer> enchants = new java.util.HashMap<org.bukkit.enchantments.Enchantment, Integer>();
|
||||
+ for (Object obj : list) {
|
||||
+ WeightedRandomEnchant instance = (WeightedRandomEnchant) obj;
|
||||
+ enchants.put(org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(instance.enchantment))), instance.level);
|
||||
+ }
|
||||
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2);
|
||||
- if (!list.isEmpty()) {
|
||||
- entityhuman.onEnchantmentPerformed(itemstack, j);
|
||||
+ // CraftBukkit start
|
||||
+ if (true || !list.isEmpty()) {
|
||||
+ // entityhuman.onEnchantmentPerformed(itemstack, j); // Moved down
|
||||
boolean flag = itemstack.is(Items.BOOK);
|
||||
+ Map<org.bukkit.enchantments.Enchantment, Integer> enchants = new java.util.HashMap<org.bukkit.enchantments.Enchantment, Integer>();
|
||||
+ for (Object obj : list) {
|
||||
+ WeightedRandomEnchant instance = (WeightedRandomEnchant) obj;
|
||||
+ enchants.put(org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(instance.enchantment))), instance.level);
|
||||
+ }
|
||||
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2);
|
||||
+
|
||||
+ EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.getBukkitEntity(), this.getBukkitView(), access.getLocation().getBlock(), item, this.costs[i], enchants, i);
|
||||
+ world.getCraftServer().getPluginManager().callEvent(event);
|
||||
+ EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.getBukkitEntity(), this.getBukkitView(), access.getLocation().getBlock(), item, this.costs[i], enchants, i);
|
||||
+ world.getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ int level = event.getExpLevelCost();
|
||||
+ if (event.isCancelled() || (level > entityhuman.experienceLevel && !entityhuman.getAbilities().instabuild) || event.getEnchantsToAdd().isEmpty()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ int level = event.getExpLevelCost();
|
||||
+ if (event.isCancelled() || (level > entityhuman.experienceLevel && !entityhuman.getAbilities().instabuild) || event.getEnchantsToAdd().isEmpty()) {
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
if (flag) {
|
||||
itemstack2 = new ItemStack(Items.ENCHANTED_BOOK);
|
||||
@@ -199,16 +278,29 @@
|
||||
this.enchantSlots.setItem(0, itemstack2);
|
||||
}
|
||||
|
||||
- for (int k = 0; k < list.size(); ++k) {
|
||||
- WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) list.get(k);
|
||||
+ for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
|
||||
+ try {
|
||||
+ if (flag) {
|
||||
+ NamespacedKey enchantId = entry.getKey().getKey();
|
||||
+ Enchantment nms = IRegistry.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(enchantId));
|
||||
+ if (nms == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
|
||||
- if (flag) {
|
||||
- ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
|
||||
- } else {
|
||||
- itemstack2.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level);
|
||||
+ WeightedRandomEnchant weightedrandomenchant = new WeightedRandomEnchant(nms, entry.getValue());
|
||||
+ ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
|
||||
+ } else {
|
||||
+ item.addUnsafeEnchantment(entry.getKey(), entry.getValue());
|
||||
+ }
|
||||
+ } catch (IllegalArgumentException e) {
|
||||
+ /* Just swallow invalid enchantments */
|
||||
if (flag) {
|
||||
itemstack2 = new ItemStack(Items.ENCHANTED_BOOK);
|
||||
@@ -182,16 +261,29 @@
|
||||
this.enchantSlots.setItem(0, itemstack2);
|
||||
}
|
||||
}
|
||||
|
||||
+ entityhuman.onEnchantmentPerformed(itemstack, j);
|
||||
+ // CraftBukkit end
|
||||
- for (int k = 0; k < list.size(); ++k) {
|
||||
- WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) list.get(k);
|
||||
-
|
||||
- if (flag) {
|
||||
- ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
|
||||
- } else {
|
||||
- itemstack2.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level);
|
||||
+ for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
|
||||
+ try {
|
||||
+ if (flag) {
|
||||
+ NamespacedKey enchantId = entry.getKey().getKey();
|
||||
+ Enchantment nms = IRegistry.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(enchantId));
|
||||
+ if (nms == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit - TODO: let plugins change this
|
||||
if (!entityhuman.getAbilities().instabuild) {
|
||||
itemstack1.shrink(j);
|
||||
if (itemstack1.isEmpty()) {
|
||||
@@ -265,6 +357,7 @@
|
||||
+ WeightedRandomEnchant weightedrandomenchant = new WeightedRandomEnchant(nms, entry.getValue());
|
||||
+ ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
|
||||
+ } else {
|
||||
+ item.addUnsafeEnchantment(entry.getKey(), entry.getValue());
|
||||
+ }
|
||||
+ } catch (IllegalArgumentException e) {
|
||||
+ /* Just swallow invalid enchantments */
|
||||
}
|
||||
}
|
||||
|
||||
+ entityhuman.onEnchantmentPerformed(itemstack, j);
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ // CraftBukkit - TODO: let plugins change this
|
||||
if (!entityhuman.getAbilities().instabuild) {
|
||||
itemstack1.shrink(j);
|
||||
if (itemstack1.isEmpty()) {
|
||||
@@ -254,6 +346,7 @@
|
||||
|
||||
@Override
|
||||
public boolean stillValid(EntityHuman entityhuman) {
|
||||
@@ -179,7 +180,7 @@
|
||||
return stillValid(this.access, entityhuman, Blocks.ENCHANTING_TABLE);
|
||||
}
|
||||
|
||||
@@ -316,4 +409,17 @@
|
||||
@@ -305,4 +398,17 @@
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user