Added a small method in the Block.java to specify the amount of enchanting power it can supply to an enchanting table. Closes #508

This commit is contained in:
LexManos 2013-04-10 16:56:31 -07:00
parent b66d3b6b0f
commit cb67c72cd7
3 changed files with 96 additions and 1 deletions

View file

@ -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));
}
}

View file

@ -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;
+ }
}

View file

@ -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();