summaryrefslogtreecommitdiffstats
path: root/nms-patches/ContainerEnchantTable.patch
diff options
context:
space:
mode:
Diffstat (limited to 'nms-patches/ContainerEnchantTable.patch')
-rw-r--r--nms-patches/ContainerEnchantTable.patch71
1 files changed, 33 insertions, 38 deletions
diff --git a/nms-patches/ContainerEnchantTable.patch b/nms-patches/ContainerEnchantTable.patch
index b9a813f1..7d47a3f3 100644
--- a/nms-patches/ContainerEnchantTable.patch
+++ b/nms-patches/ContainerEnchantTable.patch
@@ -1,6 +1,6 @@
---- ../work/decompile-8eb82bde//net/minecraft/server/ContainerEnchantTable.java Sat Jan 31 16:10:54 2015
-+++ src/main/java/net/minecraft/server/ContainerEnchantTable.java Sat Jan 31 16:10:54 2015
-@@ -3,15 +3,31 @@
+--- /home/matt/mc-dev-private//net/minecraft/server/ContainerEnchantTable.java 2015-02-27 17:02:15.091159962 +0000
++++ src/main/java/net/minecraft/server/ContainerEnchantTable.java 2015-02-27 17:02:15.091159962 +0000
+@@ -3,9 +3,21 @@
import java.util.List;
import java.util.Random;
@@ -17,12 +17,13 @@
+
public class ContainerEnchantTable extends Container {
-- public IInventory enchantSlots = new ContainerEnchantTableInventory(this, "Enchant", true, 2);
+- public IInventory enchantSlots = new InventorySubcontainer("Enchant", true, 2) {
+ // CraftBukkit - make type specific (changed from IInventory)
-+ public ContainerEnchantTableInventory enchantSlots = new ContainerEnchantTableInventory(this, "Enchant", true, 2);
- private World world;
- private BlockPosition position;
- private Random k = new Random();
++ public InventorySubcontainer enchantSlots = new InventorySubcontainer("Enchant", true, 2) {
+ public int getMaxStackSize() {
+ return 64;
+ }
+@@ -21,6 +33,10 @@
public int f;
public int[] costs = new int[3];
public int[] h = new int[] { -1, -1, -1};
@@ -33,33 +34,29 @@
public ContainerEnchantTable(PlayerInventory playerinventory, World world, BlockPosition blockposition) {
this.world = world;
-@@ -31,7 +47,11 @@
- for (i = 0; i < 9; ++i) {
+@@ -53,6 +69,9 @@
this.a(new Slot(playerinventory, i, 8 + i * 18, 142));
}
--
-+
+
+ // CraftBukkit start
+ player = (Player) playerinventory.player.getBukkitEntity();
-+ enchantSlots.player = player;
+ // CraftBukkit end
}
public void addSlotListener(ICrafting icrafting) {
-@@ -67,7 +87,7 @@
+@@ -88,7 +107,7 @@
ItemStack itemstack = iinventory.getItem(0);
int i;
- if (itemstack != null && itemstack.v()) {
+ if (itemstack != null) { // CraftBukkit - relax condition
- if (!this.world.isStatic) {
+ if (!this.world.isClientSide) {
i = 0;
-@@ -114,6 +134,20 @@
- this.costs[j] = 0;
+@@ -136,6 +155,20 @@
}
}
-+
+
+ // CraftBukkit start
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
+ PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), this.world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), item, this.costs, i);
@@ -73,12 +70,13 @@
+ return;
+ }
+ // CraftBukkit end
-
++
for (j = 0; j < 3; ++j) {
if (this.costs[j] > 0) {
-@@ -149,24 +183,56 @@
+ List list = this.a(itemstack, j, this.costs[j]);
+@@ -170,24 +203,55 @@
} else if (this.costs[i] > 0 && itemstack != null && (entityhuman.expLevel >= j && entityhuman.expLevel >= this.costs[i] || entityhuman.abilities.canInstantlyBuild)) {
- if (!this.world.isStatic) {
+ if (!this.world.isClientSide) {
List list = this.a(itemstack, i, this.costs[i]);
+ // CraftBukkit start - Provide an empty enchantment list
+ if (list == null) {
@@ -96,19 +94,20 @@
+ enchants.put(org.bukkit.enchantments.Enchantment.getById(instance.enchantment.id), instance.level);
+ }
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
-+
++
+ EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.getBukkitEntity(), this.getBukkitView(), this.world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), item, this.costs[i], enchants, i);
+ this.world.getServer().getPluginManager().callEvent(event);
-+
++
+ int level = event.getExpLevelCost();
+ if (event.isCancelled() || (level > entityhuman.expLevel && !entityhuman.abilities.canInstantlyBuild) || event.getEnchantsToAdd().isEmpty()) {
+ return false;
+ }
-+
if (flag) {
itemstack.setItem(Items.ENCHANTED_BOOK);
}
-+
+
+- 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) {
@@ -117,15 +116,12 @@
+ continue;
+ }
-- for (int k = 0; k < list.size(); ++k) {
-- WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) list.get(k);
--
- if (flag) {
- Items.ENCHANTED_BOOK.a(itemstack, weightedrandomenchant);
- } else {
- itemstack.addEnchantment(weightedrandomenchant.enchantment, weightedrandomenchant.level);
+ WeightedRandomEnchant enchantment = new WeightedRandomEnchant(Enchantment.getById(enchantId), entry.getValue());
-+ Items.ENCHANTED_BOOK.a(itemstack, enchantment);
++ Items.ENCHANTED_BOOK.a(itemstack, enchantment);
+ } else {
+ item.addUnsafeEnchantment(entry.getKey(), entry.getValue());
+ }
@@ -133,15 +129,15 @@
+ /* Just swallow invalid enchantments */
}
}
-+
+
+ entityhuman.b(j);
+ // CraftBukkit end
-
++
+ // CraftBukkit - TODO: let plugins change this
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack1.count -= j;
if (itemstack1.count <= 0) {
-@@ -199,6 +265,11 @@
+@@ -221,6 +285,11 @@
public void b(EntityHuman entityhuman) {
super.b(entityhuman);
@@ -150,10 +146,10 @@
+ this.world = entityhuman.getWorld();
+ }
+ // CraftBukkit end
- if (!this.world.isStatic) {
+ if (!this.world.isClientSide) {
for (int i = 0; i < this.enchantSlots.getSize(); ++i) {
ItemStack itemstack = this.enchantSlots.splitWithoutUpdate(i);
-@@ -212,6 +283,7 @@
+@@ -234,6 +303,7 @@
}
public boolean a(EntityHuman entityhuman) {
@@ -161,11 +157,10 @@
return this.world.getType(this.position).getBlock() != Blocks.ENCHANTING_TABLE ? false : entityhuman.e((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D) <= 64.0D;
}
-@@ -263,5 +335,18 @@
- }
+@@ -286,4 +356,17 @@
return itemstack;
-+ }
+ }
+
+ // CraftBukkit start
+ @Override
@@ -177,6 +172,6 @@
+ CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.enchantSlots);
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
+ return bukkitEntity;
- }
++ }
+ // CraftBukkit end
}