Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Basically, I want to replace the code in ContainerEnchantment.class that references bookshelves with an array of possible blocks.

 

Something along the lines of the following:

 

In ContainerEnchantment.class

public static Block[] enchantmentBlocks = new int[4096];
enchantmentBlocks[0] = Block.bookShelf;
private static int currentNumber = 1;

 

In GameRegistry.class

public static void addEnchantmentBlock(Block block)
{
  enchantmentBlocks[currentNumber] = block;
  currentNumber++;
}

 

Then replace all of this

if (this.worldPointer.getBlockId(this.posX + var5 * 2, this.posY, this.posZ + var4 * 2) == Block.bookShelf.blockID)
{
  ++var3;
}

 

with something like this.

for (int i = 0; i < currentNumber; i++)
{
  if (this.worldPointer.getBlockId(this.posX + var5 * 2, this.posY, this.posZ + var4 * 2) == enchantmentBlocks[i].blockID)
  {
        ++var3;
  }
}

 

And the same thing in TileEntityEnchantmentTable.class.

 

Of course, I'm not sure if ContainerEnchantment is the place to put this; it should be somewhere where the array gets initialized once during startup and the testing for blockIDs only happens per table.

  • Author

So I tried to implement this myself. Here's what I did:

EnchantmentHelper.java

public static boolean[] enchantBlocks = new boolean[4096];

public static void setBlock(int par1, boolean par2)
{
	enchantBlocks[par1] = par2;
}

public static boolean isEnchantmentBlock(int par1)
{
	if (enchantBlocks[par1]||par1 == Block.bookShelf.blockID)
	{
		return true;
	}
	return false;
}

 

ContainerEnchantment.java

public void onCraftMatrixChanged(IInventory par1IInventory)
    {
        if (par1IInventory == this.tableInventory)
        {
            ItemStack var2 = par1IInventory.getStackInSlot(0);
            int var3;

            if (var2 != null && var2.isItemEnchantable())
            {
                this.nameSeed = this.rand.nextLong();

                if (!this.worldPointer.isRemote)
                {
                    var3 = 0;
                    int var4;

                    for (var4 = -1; var4 <= 1; ++var4)
                    {
                        for (int var5 = -1; var5 <= 1; ++var5)
                        {
                            if ((var4 != 0 || var5 != 0) && this.worldPointer.isAirBlock(this.posX + var5, this.posY, this.posZ + var4) && 
this.worldPointer.isAirBlock(this.posX + var5, this.posY + 1, this.posZ + var4))
                            {
                                if (EnchantmentHelper.isEnchantmentBlock(this.worldPointer.getBlockId(this.posX + var5 * 2, this.posY, this.posZ + var4 * 2)))
                                {
                                    ++var3;
                                }

                                if (EnchantmentHelper.isEnchantmentBlock(this.worldPointer.getBlockId(this.posX + var5 * 2, this.posY + 1, this.posZ + var4 * 2)))
                                {
                                    ++var3;
                                }

                                if (var5 != 0 && var4 != 0)
                                {
                                    if (EnchantmentHelper.isEnchantmentBlock(this.worldPointer.getBlockId(this.posX + var5 * 2, this.posY, this.posZ + var4)))
                                    {
                                        ++var3;
                                    }

                                    if (EnchantmentHelper.isEnchantmentBlock(this.worldPointer.getBlockId(this.posX + var5 * 2, this.posY + 1, this.posZ + var4)))
                                    {
                                        ++var3;
                                    }

                                    if (EnchantmentHelper.isEnchantmentBlock(this.worldPointer.getBlockId(this.posX + var5, this.posY, this.posZ + var4 * 2)))
                                    {
                                        ++var3;
                                    }

                                    if (EnchantmentHelper.isEnchantmentBlock(this.worldPointer.getBlockId(this.posX + var5, this.posY + 1, this.posZ + var4 * 2)))
                                    {
                                        ++var3;
                                    }
                                }
                            }
                        }
                    }

                    for (var4 = 0; var4 < 3; ++var4)
                    {
                        this.enchantLevels[var4] = EnchantmentHelper.calcItemStackEnchantability(this.rand, var4, var3, var2);
                    }

                    this.updateCraftingResults();
                }
            }
            else
            {
                for (var3 = 0; var3 < 3; ++var3)
                {
                    this.enchantLevels[var3] = 0;
                }
            }
        }
    }

 

BlockEnchantmentTable.java

public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        super.randomDisplayTick(par1World, par2, par3, par4, par5Random);

        for (int var6 = par2 - 2; var6 <= par2 + 2; ++var6)
        {
            for (int var7 = par4 - 2; var7 <= par4 + 2; ++var7)
            {
                if (var6 > par2 - 2 && var6 < par2 + 2 && var7 == par4 - 1)
                {
                    var7 = par4 + 2;
                }

                if (par5Random.nextInt(16) == 0)
                {
                    for (int var8 = par3; var8 <= par3 + 1; ++var8)
                    {
                        if (EnchantmentHelper.isEnchantmentBlock(par1World.getBlockId(var6, var8, var7)))
                        {
                            if (!par1World.isAirBlock((var6 - par2) / 2 + par2, var8, (var7 - par4) / 2 + par4))
                            {
                                break;
                            }

                            par1World.spawnParticle("enchantmenttable", (double)par2 + 0.5D, (double)par3 + 2.0D, (double)par4 + 0.5D, 
(double)((float)(var6 - par2) + par5Random.nextFloat()) - 0.5D, (double)((float)(var8 - par3) - par5Random.nextFloat() - 1.0F), 
(double)((float)(var7 - par4) + par5Random.nextFloat()) - 0.5D);
                        }
                    }
                }
            }
        }
    }

 

Though I don't know if ContainerEnchantment is the best place to put those hooks...

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.