Posted May 1, 201411 yr Okay, so, I have my coding for my treasure chests, and I can get anything I want into it, but I can't figure out enchanted books. I can add books with enchants on them, but I can't get Enchanted Books (that you can put into an anvil and put the enchantment on your item) into them. TileEntityChest chest20 = (TileEntityChest) world.getTileEntity(i + 46, j + 19, k + 13); if (chest20 == null) { System.err.printf("TileEntityChest20 is null!?!\n"); } else { for (int slot = 0; slot < chest20.getSizeInventory(); slot++) { int slotran = random1.nextInt(30); int itemran = random2.nextInt(3); if (slotran == 20){ ItemStack stack = new ItemStack(Items.enchanted_book); stack.addEnchantment(Enchantment.featherFalling, itemran+1); //this just adds a book with an enchant, not an enchanted book. chest21.setInventorySlotContents(slot, stack); } if (slotran == 25){ ItemStack stack = new ItemStack(Items.enchanted_book, 1, 0); WeightedRandomChestContent tmp = new WeightedRandomChestContent(stack, 1, 1, 1); //This adds an "Enchanted Book" that has no enchants. chest21.setInventorySlotContents(slot, stack); } } }
May 1, 201411 yr Are you giving example code to help others, or are you having an error? What is the actual problem if there is one? -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
May 1, 201411 yr Author -facehoof- ugh...it only posted half of my post...sorry about that. I edited it.
May 2, 201411 yr You should use Items.enchanted_book.addEnchantment(stack, enchantment) instead of stack.addEnchantment(enchantment) Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
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.