本文整理汇总了Java中net.minecraft.item.ItemEnchantedBook类的典型用法代码示例。如果您正苦于以下问题:Java ItemEnchantedBook类的具体用法?Java ItemEnchantedBook怎么用?Java ItemEnchantedBook使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ItemEnchantedBook类属于net.minecraft.item包,在下文中一共展示了ItemEnchantedBook类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAnvilUpdate
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@SubscribeEvent
public void onAnvilUpdate(AnvilUpdateEvent event)
{
ItemStack left = event.getLeft();
ItemStack right = event.getRight();
if (left.getItem() instanceof IAnvilRepairable)
{
IAnvilRepairable repairable = (IAnvilRepairable) left.getItem();
// Advanced Ender Alloy
if (repairable.isRepairItem(left, right))
{
this.fullyRepairItem(event, repairable, 1, 15);
}
else if (right.getItem() == Items.ENCHANTED_BOOK)
{
this.enchantItem(event, repairable, (ItemEnchantedBook) right.getItem());
}
else
{
// Cancel vanilla behaviour, otherwise it would allow repairing tools with another tool (and lose the modules)
event.setCanceled(true);
}
}
}
示例2: performWork
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
if (!hasBooks() || getItem().isEmpty()) return 0;
ItemStack enchantedItem = getItem();
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
if (ItemHandlerHelper.insertItem(outEnchanted, enchantedBook, true).isEmpty() && ItemHandlerHelper.insertItem(outItem, enchantedItem, true).isEmpty()) {
NBTTagCompound base = (NBTTagCompound) enchantedItem.getEnchantmentTagList().get(0);
((ItemEnchantedBook) Items.ENCHANTED_BOOK).addEnchantment(enchantedBook, new EnchantmentData(Enchantment.getEnchantmentByID(base.getShort("id")), base.getShort("lvl")));
enchantedItem.getEnchantmentTagList().removeTag(0);
ItemHandlerHelper.insertItem(outEnchanted, enchantedBook, false);
ItemHandlerHelper.insertItem(outItem, enchantedItem.copy(), false);
inBook.getStackInSlot(0).setCount(inBook.getStackInSlot(0).getCount() - 1);
enchantedItem.setCount(enchantedItem.getCount() - 1);
return 500;
}
return 0;
}
示例3: process
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@Override
public void process(List<String> list, ItemStack stack) {
if (stack.getItem() instanceof ItemEnchantedBook) {
ItemEnchantedBook book = (ItemEnchantedBook) stack.getItem();
list.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("smartcursor.item.enchBook") + EnumChatFormatting.RESET);
NBTTagList nbttaglist = book.func_92110_g(stack);
if (nbttaglist != null) {
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
short short1 = nbttaglist.getCompoundTagAt(i).getShort("id");
short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl");
if (Enchantment.enchantmentsList[short1] != null) {
list.add(" * " + Enchantment.enchantmentsList[short1].getTranslatedName(short2));
}
}
}
}
}
示例4: enchant
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@Nonnull
public ItemStack enchant() {
if (toEnchant.isEmpty())
return ItemStack.EMPTY;
ItemStack enchantedItem = toEnchant.copy();
final boolean isBook = enchantedItem.getItem() == Items.BOOK;
final List<EnchantmentData> enchantmentsToApply = getEnchantmentList(toEnchant, level, xpLevels);
if (!enchantmentsToApply.isEmpty()) {
if (isBook) {
enchantedItem = new ItemStack(Items.ENCHANTED_BOOK);
}
for (EnchantmentData enchantment : enchantmentsToApply) {
if (isBook) {
ItemEnchantedBook.addEnchantment(enchantedItem, enchantment);
} else {
enchantedItem.addEnchantment(enchantment.enchantment, enchantment.enchantmentLevel);
}
}
}
return enchantedItem;
}
示例5: getLevels
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public double getLevels() {
NBTTagList list = ((ItemEnchantedBook) inEnchantedBook.getStackInSlot(0).getItem()).getEnchantments(inEnchantedBook.getStackInSlot(0));
double amount = 0;
for (int i = 0; i < list.tagCount(); ++i) {
NBTTagCompound compound = ((NBTTagCompound) list.get(i));
amount += EnchantmentHelper.calcItemStackEnchantability(this.world.rand, compound.getInteger("id"), compound.getShort("lvl"), inItem.getStackInSlot(0));
}
return amount;
}
示例6: updateScreen
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@Override
public void updateScreen()
{
super.updateScreen();
if (te.getStackInSlot(0) != null && te.getStackInSlot(0).getEnchantmentTagList() != null && !(te.getStackInSlot(0).getItem() instanceof ItemEnchantedBook)) {
this.buttons[0].enabled = true;
NBTTagList enchantmentList = te.getStackInSlot(0).getEnchantmentTagList();
Enchantment enchantment = Enchantment.getEnchantmentByID(enchantmentList.getCompoundTagAt(0).getShort("id"));
int levelCost = enchantment.getMinEnchantability(enchantmentList.getCompoundTagAt(0).getShort("lvl"));
this.buttons[0].displayString = (int) Math.floor(levelCost / 2) + " Levels";
} else {
this.buttons[0].enabled = false;
this.buttons[0].displayString = "???";
}
}
示例7: AnvilRecipe
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public AnvilRecipe(ItemStack left, ItemStack right, Enchantment out, int enchantLevel, int cost, boolean showRecipe){
ItemStack output = new ItemStack(Items.ENCHANTED_BOOK, 1);
ItemEnchantedBook.addEnchantment(output, new EnchantmentData(out, enchantLevel));
this.left = left;
this.right = right;
this.output = output;
this.cost = cost;
this.showRecipe = showRecipe;
}
示例8: buildEnchantedBook
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public static ItemStack buildEnchantedBook(Enchantment ench, short level) {
ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
//NOT THIS: if you are putting it on a normal stack (sword/weapon) yeah then that way
// stack.addEnchantment(ench, level);
ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(ench, level));
//just to test it
return stack;
}
示例9: canItemAcceptSockets
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public static boolean canItemAcceptSockets(ItemStack stack) {
Item item = stack.getItem();
if (item == PhysisItems.socketable) {
return false;
}
if (item instanceof ItemBlock
|| item instanceof ItemReed
|| item instanceof ItemBed
|| item instanceof ItemFood
|| item instanceof ItemPotion
|| item instanceof ItemMinecart
|| item instanceof ItemBoat
|| item instanceof ItemEnchantedBook
|| item instanceof ItemWritableBook
|| item instanceof ItemBucket
|| item instanceof ItemBucketMilk
|| item instanceof ItemDoor) {
return false;
}
if (item.getItemStackLimit(stack) > 1) {
return false;
}
if (item.hasContainerItem(stack)){
ItemStack container = item.getContainerItem(stack);
if (container != null && container.getItem() instanceof ItemBucket) {
return false;
}
}
if (item.getUnlocalizedName(stack).toLowerCase().contains("bucket")) {
return false;
}
return true;
}
示例10: getBookWith
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public static ItemStack getBookWith(Enchantment enchantment, int level)
{
return ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchantment, level));
}
示例11: getResultItem
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public ItemStack getResultItem(List<ItemStack> requiredItems) {
boolean isEnchanted = requiredItems.stream().anyMatch((item) -> item != null && item.getItem() instanceof ItemEnchantedBook);
boolean isMossy = requiredItems.stream().anyMatch((item) -> item != null && Block.getBlockFromItem(item.getItem()) instanceof BlockVine);
return this.getResultItem(isEnchanted, isMossy);
}
示例12: getEnchantmentBook
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
public static final ItemStack getEnchantmentBook(Enchantment enchantment) {
ItemStack book = new ItemStack(Items.BOOK);
ItemEnchantedBook.addEnchantment(book, new EnchantmentData(enchantment, 1));
return book;
}
示例13: displayAllRelevantItems
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@Override
@SideOnly(Side.CLIENT)
public void displayAllRelevantItems(NonNullList<ItemStack> list) {
super.displayAllRelevantItems(list);
Iterator<ItemStack> i = list.iterator();
Item guidebook = Item.getByNameOrId("guideapi:" + Const.MODID + "-guide");
while (i.hasNext()) {
Item s = i.next().getItem(); // must be called before you can call i.remove()
if (s == Items.ENCHANTED_BOOK
|| s == Items.LINGERING_POTION
|| s == Items.POTIONITEM
|| s == Items.SPLASH_POTION
|| s == Items.TIPPED_ARROW
|| s == guidebook) {
i.remove();
}
}
Collections.sort(list, comparator);
for (Enchantment e : EnchantRegistry.enchants) {
ItemStack ebook = new ItemStack(Items.ENCHANTED_BOOK);
ItemEnchantedBook.addEnchantment(ebook, new EnchantmentData(e, e.getMaxLevel()));
list.add(ebook);
}
//fluids and potions that I add are under minecraft: prefix so copy them in here
//TODO: add fluid registry arraylist
if (FluidsRegistry.fluid_poison != null) {
list.add(FluidUtil.getFilledBucket(new FluidStack(FluidsRegistry.fluid_poison, Fluid.BUCKET_VOLUME)));
}
if (FluidsRegistry.fluid_exp != null) {
list.add(FluidUtil.getFilledBucket(new FluidStack(FluidsRegistry.fluid_exp, Fluid.BUCKET_VOLUME)));
}
if (FluidsRegistry.fluid_milk != null) {
list.add(FluidUtil.getFilledBucket(new FluidStack(FluidsRegistry.fluid_milk, Fluid.BUCKET_VOLUME)));
}
for (PotionTypeCyclic pt : PotionTypeRegistry.potions) {
list.add(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), pt));
list.add(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), pt));
list.add(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION), pt));
list.add(PotionUtils.addPotionToItemStack(new ItemStack(Items.TIPPED_ARROW), pt));
}
if (guidebook != null) {
list.add(new ItemStack(guidebook));
}
}
示例14: getMeta
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
@Override
public Object getMeta(ItemEnchantedBook target, ItemStack stack) {
NBTTagList ench = target.func_92110_g(stack);
return ench != null? ModuleVanilla.listEnchantments(ench) : null;
}
示例15: enchantItem
import net.minecraft.item.ItemEnchantedBook; //导入依赖的package包/类
private void enchantItem(AnvilUpdateEvent event, IAnvilRepairable repairable, ItemEnchantedBook book)
{
ItemStack toolStack = event.getLeft().copy();
ItemStack bookStack = event.getRight().copy();
NBTTagList bookEnchantmentList = ItemEnchantedBook.getEnchantments(bookStack);
if (bookEnchantmentList.tagCount() <= 0 || toolStack.getItem().isBookEnchantable(toolStack, bookStack) == false)
{
return;
}
Map<Enchantment, Integer> oldEnchantments = EnchantmentHelper.getEnchantments(toolStack);
Map<Enchantment, Integer> bookEnchantments = EnchantmentHelper.getEnchantments(bookStack);
Iterator<Map.Entry<Enchantment, Integer>> iterBookEnchantments = bookEnchantments.entrySet().iterator();
int cost = oldEnchantments.size() * 2;
boolean levelIncreased = false;
while (iterBookEnchantments.hasNext())
{
Map.Entry<Enchantment, Integer> enchantmentEntry = iterBookEnchantments.next();
Enchantment enchBook = enchantmentEntry.getKey();
if (enchBook != null)
{
int oldEnchLvl = oldEnchantments.containsKey(enchBook) ? oldEnchantments.get(enchBook).intValue() : 0;
int bookEnchLvl = enchantmentEntry.getValue();
int newLvl = bookEnchLvl == oldEnchLvl ? oldEnchLvl + 1 : Math.max(oldEnchLvl, bookEnchLvl);
newLvl = Math.min(newLvl, enchBook.getMaxLevel());
if (repairable.canApplyEnchantment(toolStack, enchBook) == false)
{
event.setCanceled(true);
return;
}
if (newLvl > oldEnchLvl)
{
levelIncreased = true;
}
Iterator<Map.Entry<Enchantment, Integer>> iterOldEnchantments = oldEnchantments.entrySet().iterator();
// Check that the new enchantment doesn't conflict with any of the existing enchantments
while (iterOldEnchantments.hasNext())
{
Enchantment enchOld = iterOldEnchantments.next().getKey();
if (enchOld.equals(enchBook) == false && enchOld.isCompatibleWith(enchBook) == false)
{
event.setCanceled(true);
return;
}
}
oldEnchantments.put(enchBook, newLvl);
cost += newLvl * 2;
}
}
// Check that at least some new enchantments would be added, or some of the existing levels increased
if (levelIncreased == false)
{
event.setCanceled(true);
return;
}
EnchantmentHelper.setEnchantments(oldEnchantments, toolStack);
event.setOutput(toolStack);
event.setCost(cost);
this.updateItemName(event, toolStack);
event.setCost(Math.min(event.getCost(), 39));
}