From 0cbb25b5699b0b1aa771a4f7b06d4f61f71ee785 Mon Sep 17 00:00:00 2001 From: toastedtruth Date: Sun, 1 Dec 2013 23:18:16 +0000 Subject: [PATCH] Fix some recipe book bugs Fix written books crashing the server. Fixes BUKKIT-4945 Fix BlockCanBuildEvent returning null. Fixes BUKKIT-4972 Due to obfuscation changes in 1.7.2, "l" is now the Material ID. i j and k became the x y z coordinates, resulting in no ID being matched for the Material. This is corrected by swapping the values into the correct order. diff --git a/src/main/java/net/minecraft/server/RecipeBookClone.java b/src/main/java/net/minecraft/server/RecipeBookClone.java new file mode 100644 index 0000000..8182a5f --- /dev/null +++ b/src/main/java/net/minecraft/server/RecipeBookClone.java @@ -0,0 +1,68 @@ +package net.minecraft.server; + +public class RecipeBookClone extends ShapelessRecipes implements IRecipe { // CraftBukkit - added extends + + // CraftBukkit start - Delegate to new parent class + public RecipeBookClone() { + super(new ItemStack(Items.WRITTEN_BOOK, 0, -1), java.util.Arrays.asList(new ItemStack(Items.BOOK_AND_QUILL, 0, 0))); + } + // CraftBukkit end + + public boolean a(InventoryCrafting inventoryCrafting, World paramWorld) { + int i = 0; + ItemStack itemStack = null; + for (int j = 0; j < inventoryCrafting.getSize(); j++) { + ItemStack itemStack1 = inventoryCrafting.getItem(j); + if (itemStack1 != null) { + if (itemStack1.getItem() == Items.WRITTEN_BOOK) { + if (itemStack != null) { + return false; + } + itemStack = itemStack1; + } else if (itemStack1.getItem() == Items.BOOK_AND_QUILL) { + i++; + } else { + return false; + } + } + } + return (itemStack != null) && (i > 0); + } + + public ItemStack a(InventoryCrafting inventoryCrafting) { + int i = 0; + ItemStack itemStack = null; + for (int j = 0; j < inventoryCrafting.getSize(); j++) { + ItemStack itemStack2 = inventoryCrafting.getItem(j); + if (itemStack2 != null) { + if (itemStack2.getItem() == Items.WRITTEN_BOOK) { + if (itemStack != null) { + return null; + } + itemStack = itemStack2; + } else if (itemStack2.getItem() == Items.BOOK_AND_QUILL) { + i++; + } else { + return null; + } + } + } + if ((itemStack == null) || (i < 1)) { + return null; + } + ItemStack itemStack1 = new ItemStack(Items.WRITTEN_BOOK, i + 1); + itemStack1.setTag((NBTTagCompound) itemStack.getTag().clone()); + if (itemStack.hasName()) { + itemStack1.c(itemStack.getName()); + } + return itemStack1; + } + + public int a() { + return 9; + } + + public ItemStack b() { + return null; + } +} diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index 81534e3..858004e 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -2483,7 +2483,7 @@ public abstract class World implements IBlockAccess { boolean defaultReturn = axisalignedbb != null && !this.a(axisalignedbb, entity) ? false : (block1.getMaterial() == Material.ORIENTABLE && block == Blocks.ANVIL ? true : block1.getMaterial().isReplaceable() && block.canPlace(this, i, j, k, l, itemstack)); // CraftBukkit start - BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(j, k, l), i, defaultReturn); + BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(i, j, k), l, defaultReturn); this.getServer().getPluginManager().callEvent(event); return event.isBuildable(); -- 1.8.3.2