From cb67c72cd733b504ee3a0edf11a5d41b5df3692f Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 10 Apr 2013 16:56:31 -0700 Subject: [PATCH] Added a small method in the Block.java to specify the amount of enchanting power it can supply to an enchanting table. Closes #508 --- .../net/minecraftforge/common/ForgeHooks.java | 11 +++ .../net/minecraft/block/Block.java.patch | 15 +++- .../inventory/ContainerEnchantment.java.patch | 71 +++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 patches/minecraft/net/minecraft/inventory/ContainerEnchantment.java.patch diff --git a/common/net/minecraftforge/common/ForgeHooks.java b/common/net/minecraftforge/common/ForgeHooks.java index 430ef35cbf..ee2e00bd71 100644 --- a/common/net/minecraftforge/common/ForgeHooks.java +++ b/common/net/minecraftforge/common/ForgeHooks.java @@ -370,4 +370,15 @@ public class ForgeHooks player.joinEntityItemWithWorld(event.entityItem); return event.entityItem; } + + public static float getEnchantPower(World world, int x, int y, int z) + { + if (world.isAirBlock(x, y, z)) + { + return 0; + } + + Block block = Block.blocksList[world.getBlockId(x, y, z)]; + return (block == null ? 0 : block.getEnchantPower(world, x, y, z)); + } } diff --git a/patches/minecraft/net/minecraft/block/Block.java.patch b/patches/minecraft/net/minecraft/block/Block.java.patch index 0f401ac6e9..241ab095b7 100644 --- a/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/patches/minecraft/net/minecraft/block/Block.java.patch @@ -155,7 +155,7 @@ } /** -@@ -1439,4 +1459,898 @@ +@@ -1439,4 +1459,911 @@ canBlockGrass[0] = true; StatList.initBreakableStats(); } @@ -1052,5 +1052,18 @@ + public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z) + { + return RotationHelper.getValidVanillaBlockRotations(this); ++ } ++ ++ /** ++ * Determines the amount of enchanting power this block can provide to an enchanting table. ++ * @param world The World ++ * @param x X position ++ * @param y Y position ++ * @param z Z position ++ * @return The amount of enchanting power this block produces. ++ */ ++ public int getEnchantPower(World world, int x, int y, int z) ++ { ++ return blockID == bookShelf.blockID ? 1 : 0; + } } diff --git a/patches/minecraft/net/minecraft/inventory/ContainerEnchantment.java.patch b/patches/minecraft/net/minecraft/inventory/ContainerEnchantment.java.patch new file mode 100644 index 0000000000..d216107cef --- /dev/null +++ b/patches/minecraft/net/minecraft/inventory/ContainerEnchantment.java.patch @@ -0,0 +1,71 @@ +--- ../src_base/minecraft/net/minecraft/inventory/ContainerEnchantment.java ++++ ../src_work/minecraft/net/minecraft/inventory/ContainerEnchantment.java +@@ -12,6 +12,7 @@ + import net.minecraft.item.Item; + import net.minecraft.item.ItemStack; + import net.minecraft.world.World; ++import net.minecraftforge.common.ForgeHooks; + + public class ContainerEnchantment extends Container + { +@@ -109,6 +110,7 @@ + { + i = 0; + int j; ++ float power = 0; + + for (j = -1; j <= 1; ++j) + { +@@ -116,37 +118,15 @@ + { + if ((j != 0 || k != 0) && this.worldPointer.isAirBlock(this.posX + k, this.posY, this.posZ + j) && this.worldPointer.isAirBlock(this.posX + k, this.posY + 1, this.posZ + j)) + { +- if (this.worldPointer.getBlockId(this.posX + k * 2, this.posY, this.posZ + j * 2) == Block.bookShelf.blockID) +- { +- ++i; +- } +- +- if (this.worldPointer.getBlockId(this.posX + k * 2, this.posY + 1, this.posZ + j * 2) == Block.bookShelf.blockID) +- { +- ++i; +- } ++ power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY, posZ + j * 2); ++ power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY + 1, posZ + j * 2); + + if (k != 0 && j != 0) + { +- if (this.worldPointer.getBlockId(this.posX + k * 2, this.posY, this.posZ + j) == Block.bookShelf.blockID) +- { +- ++i; +- } +- +- if (this.worldPointer.getBlockId(this.posX + k * 2, this.posY + 1, this.posZ + j) == Block.bookShelf.blockID) +- { +- ++i; +- } +- +- if (this.worldPointer.getBlockId(this.posX + k, this.posY, this.posZ + j * 2) == Block.bookShelf.blockID) +- { +- ++i; +- } +- +- if (this.worldPointer.getBlockId(this.posX + k, this.posY + 1, this.posZ + j * 2) == Block.bookShelf.blockID) +- { +- ++i; +- } ++ power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY, posZ + j ); ++ power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY + 1, posZ + j ); ++ power += ForgeHooks.getEnchantPower(worldPointer, posX + k, posY, posZ + j * 2); ++ power += ForgeHooks.getEnchantPower(worldPointer, posX + k, posY + 1, posZ + j * 2); + } + } + } +@@ -154,7 +134,7 @@ + + for (j = 0; j < 3; ++j) + { +- this.enchantLevels[j] = EnchantmentHelper.calcItemStackEnchantability(this.rand, j, i, itemstack); ++ this.enchantLevels[j] = EnchantmentHelper.calcItemStackEnchantability(this.rand, j, (int)power, itemstack); + } + + this.detectAndSendChanges();