本文整理汇总了Java中net.minecraft.init.Items.ENCHANTED_BOOK属性的典型用法代码示例。如果您正苦于以下问题:Java Items.ENCHANTED_BOOK属性的具体用法?Java Items.ENCHANTED_BOOK怎么用?Java Items.ENCHANTED_BOOK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.minecraft.init.Items
的用法示例。
在下文中一共展示了Items.ENCHANTED_BOOK属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRecipeIngredients
private ItemStack[] getRecipeIngredients(ItemStackHandler inputStacks) {
List<ItemStack> enchantedBooks = new ItemStackHandlerIterable(inputStacks)
.stream()
.filter(book -> book.getItem() == Items.ENCHANTED_BOOK)
.collect(Collectors.toList());
if (enchantedBooks.isEmpty()) return null;
for (ItemStack inputStack : new ItemStackHandlerIterable(inputStacks)) {
if ((inputStack.isItemEnchantable() || inputStack.isItemEnchanted()) && inputStack.getItem() != Items.ENCHANTED_BOOK) {
for (ItemStack enchantedBook : enchantedBooks) {
Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
for (Map.Entry<Enchantment, Integer> entry : bookMap.entrySet()) {
if (entry.getKey().canApply(inputStack)) {
return new ItemStack[]{ inputStack, enchantedBook};
}
}
}
}
}
return null;
}
示例2: craftRecipe
@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
ItemStack enchantedStack = getDisenchantableItem(inputStacks);
getBook(inputStacks).shrink(1);
// take a random enchantment off the enchanted item...
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedStack);
List<Enchantment> l = new ArrayList<>(enchantments.keySet());
Enchantment strippedEnchantment = l.get(new Random().nextInt(l.size()));
int level = enchantments.get(strippedEnchantment);
enchantments.remove(strippedEnchantment);
EnchantmentHelper.setEnchantments(enchantments, enchantedStack);
// ...and create an enchanted book with it
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
EnchantmentHelper.setEnchantments(ImmutableMap.of(strippedEnchantment, level), enchantedBook);
return NonNullList.from(ItemStack.EMPTY, enchantedBook);
}
示例3: performWork
@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;
}
示例4: matches
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
boolean hasSlingshot = false, hasBook = false;
for (int i = inv.getSizeInventory(); --i >= 0; ) {
ItemStack stack = inv.getStackInSlot(i);
if (null != stack) {
Item item = stack.getItem();
if (item == ModItems.slingshot) {
if (hasSlingshot)
return false;
hasSlingshot = true;
} else if (item == Items.ENCHANTED_BOOK) {
if (hasBook)
return false;
if (getBookLootingLevel(stack) <= 0)
return false;
hasBook = true;
} else
return false;
}
}
return hasSlingshot && hasBook;
}
示例5: getEnchantments
public static Map<Enchantment, Integer> getEnchantments(ItemStack stack)
{
Map<Enchantment, Integer> map = Maps.<Enchantment, Integer>newLinkedHashMap();
NBTTagList nbttaglist = stack.getItem() == Items.ENCHANTED_BOOK ? Items.ENCHANTED_BOOK.getEnchantments(stack) : stack.getEnchantmentTagList();
if (nbttaglist != null)
{
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
Enchantment enchantment = Enchantment.getEnchantmentByID(nbttaglist.getCompoundTagAt(i).getShort("id"));
int j = nbttaglist.getCompoundTagAt(i).getShort("lvl");
map.put(enchantment, Integer.valueOf(j));
}
}
return map;
}
示例6: getEnchantmentIdLevels
private static int[][] getEnchantmentIdLevels(ItemStack p_getEnchantmentIdLevels_0_)
{
Item item = p_getEnchantmentIdLevels_0_.getItem();
NBTTagList nbttaglist = item == Items.ENCHANTED_BOOK ? Items.ENCHANTED_BOOK.getEnchantments(p_getEnchantmentIdLevels_0_) : p_getEnchantmentIdLevels_0_.getEnchantmentTagList();
if (nbttaglist != null && nbttaglist.tagCount() > 0)
{
int[][] aint = new int[nbttaglist.tagCount()][2];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getShort("id");
int k = nbttagcompound.getShort("lvl");
aint[i][0] = j;
aint[i][1] = k;
}
return aint;
}
else
{
return EMPTY_INT2_ARRAY;
}
}
示例7: getAllEnchantedBooks
private void getAllEnchantedBooks(Enchantment enchantment, NonNullList<ItemStack> list) {
for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); ++i) {
ItemStack itemstack = new ItemStack(Items.ENCHANTED_BOOK);
itemstack.addEnchantment(enchantment, i);
list.add(itemstack);
}
}
示例8: updateCooldownCap
public void updateCooldownCap() {
int cap = this.worker.getMaxWork();
if (this.world.getBlockState(pos).getValue(BlockBreaker.TYPE) == ChipTypes.BASIC)
cap = VExConfig.machineCooldownBasic;
else
cap = VExConfig.machineCooldownAdvanced;
if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) {
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(this.handler.getStackInSlot(9));
if (enchantments.containsKey(Enchantments.EFFICIENCY)) {
cap -= Math.pow(enchantments.get(Enchantments.EFFICIENCY), 2) % cap;
}
}
this.worker.setMaxCooldown(cap);
}
示例9: transferStackInSlot
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
ItemStack previous = ItemStack.EMPTY;
Slot slot = (Slot) this.inventorySlots.get(fromSlot);
if (slot != null && slot.getHasStack()) {
ItemStack current = slot.getStack();
previous = current.copy();
if (fromSlot < this.handler.getSlots()) {
// From the block breaker inventory to player's inventory
if (!this.mergeItemStack(current, handler.getSlots(), handler.getSlots() + 36, true))
return ItemStack.EMPTY;
} else {
// From the player's inventory to block breaker's inventory
if (current.getItem() == Items.ENCHANTED_BOOK) {
if (!this.mergeItemStack(current, 9, handler.getSlots(), false))
return ItemStack.EMPTY;
}
if (!this.mergeItemStack(current, 0, handler.getSlots(), false))
return ItemStack.EMPTY;
}
if (current.getCount() == 0)
slot.putStack(ItemStack.EMPTY);
else
slot.onSlotChanged();
if (current.getCount() == previous.getCount())
return null;
slot.onTake(playerIn, current);
}
return previous;
}
示例10: getSellingStack
@Override
public ItemStack getSellingStack(ITradeList t)
{
ListEnchantedBookForEmeralds trade = (ListEnchantedBookForEmeralds)t;
ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK, 1, 0);
return stack;
}
示例11: setEnchantments
/**
* Set the enchantments for the specified stack.
*/
public static void setEnchantments(Map<Enchantment, Integer> enchMap, ItemStack stack)
{
NBTTagList nbttaglist = new NBTTagList();
for (Entry<Enchantment, Integer> entry : enchMap.entrySet())
{
Enchantment enchantment = (Enchantment)entry.getKey();
if (enchantment != null)
{
int i = ((Integer)entry.getValue()).intValue();
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setShort("id", (short)Enchantment.getEnchantmentID(enchantment));
nbttagcompound.setShort("lvl", (short)i);
nbttaglist.appendTag(nbttagcompound);
if (stack.getItem() == Items.ENCHANTED_BOOK)
{
Items.ENCHANTED_BOOK.addEnchantment(stack, new EnchantmentData(enchantment, i));
}
}
}
if (nbttaglist.hasNoTags())
{
if (stack.hasTagCompound())
{
stack.getTagCompound().removeTag("ench");
}
}
else if (stack.getItem() != Items.ENCHANTED_BOOK)
{
stack.setTagInfo("ench", nbttaglist);
}
}
示例12: breakBlock
@SuppressWarnings("deprecation")
public void breakBlock(EnumFacing facing) {
BlockPos newPos = pos.offset(facing, 1);
IBlockState state = this.world.getBlockState(newPos);
Block block = state.getBlock();
if (!block.isAir(state, this.world, newPos) && block.getBlockHardness(state, this.world, newPos) >= 0
&& !(block instanceof BlockDynamicLiquid) && !(block instanceof BlockStaticLiquid)) {
// Creates a fake player which will berak the block
EntityPlayer player = new EntityPlayer(world, new GameProfile(null, "BlockBreaker")) {
@Override
public boolean isSpectator() {
return true;
}
@Override
public boolean isCreative() {
return false;
}
};
List<ItemStack> drops = new ArrayList<ItemStack>();
boolean customDrops = false;
if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) {
ItemStack enchantedBook = this.handler.getStackInSlot(9);
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedBook);
if (enchantments.containsKey(Enchantments.FORTUNE)) {
int fortune = enchantments.get(Enchantments.FORTUNE);
drops.add(new ItemStack(block.getItemDropped(state, this.random, fortune),
block.quantityDroppedWithBonus(fortune, this.random), block.damageDropped(state)));
customDrops = true;
}
if (enchantments.containsKey(Enchantments.SILK_TOUCH)
&& block.canSilkHarvest(world, newPos, state, player)) {
// HARD FIX FOR LAPIS
if (block == Blocks.LAPIS_ORE)
drops.add(new ItemStack(block, 1));
else
drops.add(new ItemStack(block, 1, block.damageDropped(state)));
customDrops = true;
}
}
if (!customDrops)
drops = block.getDrops(world, newPos, state, 0);
for (ItemStack stack : drops) {
Utils.addStackToInventory(this.handler, 9, stack, false);
}
if (!Utils.isInventoryFull(this.handler, 9)) {
this.world.playEvent(2001, pos, Block.getStateId(state));
this.world.playSound(null, pos, block.getSoundType(state, world, newPos, player).getBreakSound(),
SoundCategory.BLOCKS, 1, 1);
this.world.setBlockToAir(newPos);
if (block == Blocks.ICE)
this.world.setBlockState(newPos, Blocks.FLOWING_WATER.getDefaultState());
}
}
}
示例13: renderToolTip
protected void renderToolTip(ItemStack stack, int x, int y)
{
if (selectedTabIndex == CreativeTabs.SEARCH.getTabIndex())
{
List<String> list = stack.getTooltip(this.mc.player, this.mc.gameSettings.advancedItemTooltips);
CreativeTabs creativetabs = stack.getItem().getCreativeTab();
if (creativetabs == null && stack.getItem() == Items.ENCHANTED_BOOK)
{
Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(stack);
if (map.size() == 1)
{
Enchantment enchantment = (Enchantment)map.keySet().iterator().next();
for (CreativeTabs creativetabs1 : CreativeTabs.CREATIVE_TAB_ARRAY)
{
if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
{
creativetabs = creativetabs1;
break;
}
}
}
}
if (creativetabs != null)
{
list.add(1, "" + TextFormatting.BOLD + TextFormatting.BLUE + I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]));
}
for (int i = 0; i < list.size(); ++i)
{
if (i == 0)
{
list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
}
else
{
list.set(i, TextFormatting.GRAY + (String)list.get(i));
}
}
this.drawHoveringText(list, x, y);
}
else
{
super.renderToolTip(stack, x, y);
}
}
示例14: renderToolTip
protected void renderToolTip(ItemStack stack, int x, int y)
{
if (selectedTabIndex == CreativeTabs.SEARCH.getTabIndex())
{
List<String> list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
CreativeTabs creativetabs = stack.getItem().getCreativeTab();
if (creativetabs == null && stack.getItem() == Items.ENCHANTED_BOOK)
{
Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(stack);
if (map.size() == 1)
{
Enchantment enchantment = (Enchantment)map.keySet().iterator().next();
for (CreativeTabs creativetabs1 : CreativeTabs.CREATIVE_TAB_ARRAY)
{
if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
{
creativetabs = creativetabs1;
break;
}
}
}
}
if (creativetabs != null)
{
list.add(1, "" + TextFormatting.BOLD + TextFormatting.BLUE + I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]));
}
for (int i = 0; i < list.size(); ++i)
{
if (i == 0)
{
list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
}
else
{
list.set(i, TextFormatting.GRAY + (String)list.get(i));
}
}
net.minecraftforge.fml.client.config.GuiUtils.preItemToolTip(stack);
this.drawHoveringText(list, x, y);
net.minecraftforge.fml.client.config.GuiUtils.postItemToolTip();
}
else
{
super.renderToolTip(stack, x, y);
}
}