本文整理匯總了Java中net.minecraft.enchantment.EnchantmentHelper.getEnchantments方法的典型用法代碼示例。如果您正苦於以下問題:Java EnchantmentHelper.getEnchantments方法的具體用法?Java EnchantmentHelper.getEnchantments怎麽用?Java EnchantmentHelper.getEnchantments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.enchantment.EnchantmentHelper
的用法示例。
在下文中一共展示了EnchantmentHelper.getEnchantments方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRecipeIngredients
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
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
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
@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: improveEnchants
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
private static boolean improveEnchants(ItemStack item) {
boolean improved = false;
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(item);
if (enchantments.isEmpty()) {
return false;
}
for (Entry<Enchantment, Integer> enchant : enchantments.entrySet()) {
if (shouldImproveEnchantment(rand, enchant.getKey(), enchant.getValue())) {
enchantments.put(enchant.getKey(), enchant.getValue() + 1);
improved = true;
}
}
if (improved) {
EnchantmentHelper.setEnchantments(enchantments, item);
}
return improved;
}
示例4: getUpgradableStack
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
/** Gets an upgradeable stack */
public @Nonnull ItemStack getUpgradableStack(@Nonnull List<ItemStack> s) {
if(ACUtils.doesItemStackListContain(s, upgrade, true)) {
ItemStack toUpgrade = s.get(0);
if(enchant.canApply(toUpgrade) && toUpgrade.getItem() instanceof ItemSword) {
Map<Enchantment, Integer> activeEnchs = EnchantmentHelper.getEnchantments(toUpgrade);
for(Enchantment i : activeEnchs.keySet()) {
if(i == enchant) {
int level = activeEnchs.get(i);
if(level >= maxLevel) {
return ItemStack.EMPTY;
}
}
}
return toUpgrade.copy();
}
}
return ItemStack.EMPTY;
}
示例5: getUpgradableStack
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
/** Gets an upgradeable stack */
@Override
public @Nonnull ItemStack getUpgradableStack(List<ItemStack> s) {
if(ACUtils.doesItemStackListContain(s, upgrade, true)) {
ItemStack toUpgrade = s.get(0);
if(enchant.canApply(toUpgrade)) { // no sword needed now!
Map<Enchantment, Integer> activeEnchs = EnchantmentHelper.getEnchantments(toUpgrade);
for(Enchantment i : activeEnchs.keySet()) {
if(i == enchant) {
int level = activeEnchs.get(i);
if(level >= maxLevel) {
return ItemStack.EMPTY;
}
}
}
return toUpgrade.copy();
}
}
return ItemStack.EMPTY;
}
示例6: craftRecipe
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
ItemStack[] recipeIngredients = getRecipeIngredients(inputStacks);
ItemStack enchantedTool = recipeIngredients[0];
ItemStack enchantedBook = recipeIngredients[1];
Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
bookMap.forEach((enchant, lvl) -> enchantedTool.addEnchantment(enchant, lvl));
enchantedBook.shrink(1);
return NonNullList.from(ItemStack.EMPTY, new ItemStack(Items.BOOK));
}
示例7: performWork
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
if (!canWork()) return 0;
int xp = (int) (getLevels() * 100);
if (experienceTank.getFluidAmount() >= xp && ItemHandlerHelper.insertItem(outEnchantedItem, inItem.getStackInSlot(0), true).isEmpty()) {
Map<Enchantment, Integer> mapFirst = EnchantmentHelper.getEnchantments(inEnchantedBook.getStackInSlot(0));
Map<Enchantment, Integer> mapSecond = EnchantmentHelper.getEnchantments(inItem.getStackInSlot(0));
for (Enchantment enchantmentFirst : mapFirst.keySet()) {
if (enchantmentFirst != null) {
if (mapSecond.containsKey(enchantmentFirst) && mapFirst.get(enchantmentFirst) == mapSecond.get(enchantmentFirst) && mapFirst.get(enchantmentFirst) >= enchantmentFirst.getMaxLevel())
return 0;
int value = mapSecond.containsKey(enchantmentFirst) && mapFirst.get(enchantmentFirst) == mapSecond.get(enchantmentFirst) ? Math.min(mapFirst.get(enchantmentFirst) + 1, enchantmentFirst.getMaxLevel()) : mapFirst.get(enchantmentFirst);
if (mapSecond.replace(enchantmentFirst, value) == null) {
mapSecond.put(enchantmentFirst, value);
}
}
}
ItemStack stack = inItem.getStackInSlot(0).copy();
EnchantmentHelper.setEnchantments(mapSecond, stack);
ItemHandlerHelper.insertItem(outEnchantedItem, stack, false);
inItem.getStackInSlot(0).setCount(0);
inEnchantedBook.getStackInSlot(0).setCount(0);
experienceTank.drain(xp, true);
return 500;
}
return 0;
}
示例8: updateCooldownCap
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
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: renderToolTip
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
protected void renderToolTip(ItemStack stack, int x, int y)
{
if (selectedTabIndex == CreativeTabs.tabAllSearch.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<Integer, Integer> map = EnchantmentHelper.getEnchantments(stack);
if (map.size() == 1)
{
Enchantment enchantment = Enchantment.getEnchantmentById(((Integer)map.keySet().iterator().next()).intValue());
for (CreativeTabs creativetabs1 : CreativeTabs.creativeTabArray)
{
if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
{
creativetabs = creativetabs1;
break;
}
}
}
}
if (creativetabs != null)
{
list.add(1, "" + EnumChatFormatting.BOLD + EnumChatFormatting.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, EnumChatFormatting.GRAY + (String)list.get(i));
}
}
this.drawHoveringText(list, x, y);
}
else
{
super.renderToolTip(stack, x, y);
}
}
示例10: breakBlock
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
@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());
}
}
}
示例11: renderToolTip
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
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);
}
}
示例12: renderToolTip
import net.minecraft.enchantment.EnchantmentHelper; //導入方法依賴的package包/類
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);
}
}