• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ItemStackTools类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中mcjty.lib.tools.ItemStackTools的典型用法代码示例。如果您正苦于以下问题:Java ItemStackTools类的具体用法?Java ItemStackTools怎么用?Java ItemStackTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ItemStackTools类属于mcjty.lib.tools包,在下文中一共展示了ItemStackTools类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parseStack

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
public static ItemStack parseStack(String name) {
    if (name.contains("/")) {
        String[] split = StringUtils.split(name, "/");
        ItemStack stack = parseStackNoNBT(split[0]);
        if (ItemStackTools.isEmpty(stack)) {
            return stack;
        }
        NBTTagCompound nbt;
        try {
            nbt = JsonToNBT.getTagFromJson(split[1]);
        } catch (NBTException e) {
            InControl.logger.log(Level.ERROR, "Error parsing NBT in '" + name + "'!");
            return ItemStackTools.getEmptyStack();
        }
        stack.setTagCompound(nbt);
        return stack;
    } else {
        return parseStackNoNBT(name);
    }
}
 
开发者ID:McJty,项目名称:InControl,代码行数:21,代码来源:Tools.java


示例2: addHeldItemCheck

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
public void addHeldItemCheck(AttributeMap map) {
    List<Item> items = getItems(map.getList(HELDITEM));
    checks.add((event,query) -> {
        DamageSource source = query.getSource(event);
        if (source == null) {
            return false;
        }
        Entity entity = source.getEntity();
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            ItemStack mainhand = player.getHeldItemMainhand();
            if (ItemStackTools.isValid(mainhand)) {
                for (Item item : items) {
                    if (mainhand.getItem() == item) {
                        return true;
                    }
                }
            }
        }
        return false;
    });
}
 
开发者ID:McJty,项目名称:InControl,代码行数:23,代码来源:GenericRuleEvaluator.java


示例3: dropItemsFromInventory

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
public static void dropItemsFromInventory(World world, BlockPos pos, CompatItemHandler inventoryItemHandler){
    for (int i = 0; i < inventoryItemHandler.getSlots(); i++) {
        ItemStack stack = inventoryItemHandler.getStackInSlot(i);
        if(!ItemStackTools.isEmpty(stack) && ItemStackTools.getStackSize(stack) != 0){
            float dX = world.rand.nextFloat()*0.8F+0.1F;
            float dY = world.rand.nextFloat()*0.8F+0.1F;
            float dZ = world.rand.nextFloat()*0.8F+0.1F;
            EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, stack.copy());
            float factor = 0.05F;
            entityItem.motionX = world.rand.nextGaussian()*factor;
            entityItem.motionY = world.rand.nextGaussian()*factor+0.2F;
            entityItem.motionZ = world.rand.nextGaussian()*factor;
            WorldTools.spawnEntity(world, entityItem);
        }
    }
}
 
开发者ID:MasterEric,项目名称:ChatBomb,代码行数:17,代码来源:ItemUtility.java


示例4: giveItemToPlayer

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
/**
 * This function will first try to set the item at the 'heldItem' position if possible.
 * Otherwise it will try to find a suitable place elsewhere. If that fails it will spawn
 * the item in the world. The stack parameter may be modified
 */
public static void giveItemToPlayer(EntityPlayer player, ItemStack stack) {
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (ItemStackTools.isEmpty(heldItem)) {
        player.setHeldItem(EnumHand.MAIN_HAND, stack);
        player.openContainer.detectAndSendChanges();
        return;
    } else if (isItemStackConsideredEqual(heldItem, stack)) {
        if (ItemStackTools.getStackSize(heldItem) < heldItem.getMaxStackSize()) {
            int itemsToAdd = Math.min(ItemStackTools.getStackSize(stack), heldItem.getMaxStackSize() - ItemStackTools.getStackSize(heldItem));
            ItemStackTools.incStackSize(heldItem, itemsToAdd);
            ItemStackTools.incStackSize(stack, -itemsToAdd);
            if (ItemStackTools.isEmpty(stack)) {
                player.openContainer.detectAndSendChanges();
                return;
            }
        }
    }
    // We have items remaining. Add them elsewhere
    if (player.inventory.addItemStackToInventory(stack)) {
        player.openContainer.detectAndSendChanges();
        return;
    }
    // Spawn in world
    spawnItemStack(player.getEntityWorld(), player.getPosition(), stack);
}
 
开发者ID:McJty,项目名称:interactionwheel,代码行数:31,代码来源:InventoryHelper.java


示例5: matchStack

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
private boolean matchStack(ItemStack stack, Set<Integer> ores, ItemStack s) {
    if (ItemStackTools.isValid(s)) {
        if (s.getItem() == stack.getItem()) {
            return true;
        }
        if (!ores.isEmpty()) {
            int[] iDs = OreDictionary.getOreIDs(s);
            for (int d : iDs) {
                if (ores.contains(d)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:McJty,项目名称:interactionwheel,代码行数:17,代码来源:DumpSimilarInventoryAction.java


示例6: spawnItemStack

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
public static void spawnItemStack(World world, int x, int y, int z, ItemStack itemstack) {
    if (ItemStackTools.isValid(itemstack)) {
        float f = random.nextFloat() * 0.8F + 0.1F;
        float f1 = random.nextFloat() * 0.8F + 0.1F;
        EntityItem entityitem;

        float f2 = random.nextFloat() * 0.8F + 0.1F;
        while (ItemStackTools.isValid(itemstack)) {
            int j = random.nextInt(21) + 10;

            if (j > ItemStackTools.getStackSize(itemstack)) {
                j = ItemStackTools.getStackSize(itemstack);
            }

            ItemStack toSpawn = itemstack.splitStack(j);
            entityitem = new EntityItem(world, (x + f), (y + f1), (z + f2), toSpawn);
            float f3 = 0.05F;
            entityitem.motionX = ((float) random.nextGaussian() * f3);
            entityitem.motionY = ((float) random.nextGaussian() * f3 + 0.2F);
            entityitem.motionZ = ((float) random.nextGaussian() * f3);

            WorldTools.spawnEntity(world, entityitem);
        }
    }
}
 
开发者ID:McJty,项目名称:interactionwheel,代码行数:26,代码来源:InventoryHelper.java


示例7: clOnBlockActivated

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
public boolean clOnBlockActivated(World worldIn, BlockPos pos,
		IBlockState state, EntityPlayer playerIn, EnumHand hand,
		EnumFacing side, float hitX, float hitY, float hitZ) {
	TileEntitySofa sofa = (TileEntitySofa) worldIn.getTileEntity(pos);
	
	if (playerIn.getHeldItem(hand) != ItemStackTools.getEmptyStack()) {
		ItemStack heldItem = playerIn.getHeldItem(hand);
		if (heldItem.getItem() instanceof ItemDye && sofa.getColor() != 15 - heldItem.getItemDamage()) {
			sofa.setColor(heldItem.getItemDamage());
			if (!playerIn.capabilities.isCreativeMode) {
				ItemStackTools.incStackSize(playerIn.getHeldItem(hand), -1);
			}
			if (worldIn.isRemote) {
				worldIn.setBlockState(pos, state.withProperty(COLOR, sofa.getColor()));
			}
			return true;
		}
	}
	
	return SittableUtil.sitOnBlock(worldIn, pos.getX(), pos.getY(), pos.getZ(), playerIn, 0.351);
}
 
开发者ID:Zundrel,项目名称:How-Bout-That-Furniture,代码行数:23,代码来源:BlockSofa.java


示例8: clOnBlockActivated

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
public boolean clOnBlockActivated(World worldIn, BlockPos pos,
		IBlockState state, EntityPlayer playerIn, EnumHand hand,
		EnumFacing side, float hitX, float hitY, float hitZ) {
	if (playerIn.getHeldItem(hand) != ItemStackTools.getEmptyStack()) {
		ItemStack heldItem = playerIn.getHeldItem(hand);
		if (heldItem.getItem() instanceof ItemDye && state.getValue(COLOR) != 15 - heldItem.getItemDamage()) {
			if (!playerIn.capabilities.isCreativeMode) {
				ItemStackTools.incStackSize(playerIn.getHeldItem(hand), -1);
			}
			worldIn.setBlockState(pos, state.withProperty(COLOR, 15 - heldItem.getItemDamage()), 2);
			return true;
		}
	}
	
	return SittableUtil.sitOnBlock(worldIn, pos.getX(), pos.getY(), pos.getZ(), playerIn, 0.351);
}
 
开发者ID:Zundrel,项目名称:How-Bout-That-Furniture,代码行数:18,代码来源:BlockStool.java


示例9: clOnBlockActivated

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
public boolean clOnBlockActivated(World worldIn, BlockPos pos,
		IBlockState state, EntityPlayer playerIn, EnumHand hand,
		EnumFacing side, float hitX, float hitY, float hitZ) {
	TileEntityChair chair = (TileEntityChair) worldIn.getTileEntity(pos);
	
	if (playerIn.getHeldItem(hand) != ItemStackTools.getEmptyStack()) {
		ItemStack heldItem = playerIn.getHeldItem(hand);
		if (heldItem.getItem() instanceof ItemDye && chair.getColor() != 15 - heldItem.getItemDamage()) {
			System.out.println(chair.getColor());
			chair.setColor(heldItem.getItemDamage());
			if (!playerIn.capabilities.isCreativeMode) {
				ItemStackTools.incStackSize(playerIn.getHeldItem(hand), -1);
			}
			if (worldIn.isRemote) {
				worldIn.setBlockState(pos, state.withProperty(COLOR, chair.getColor()), 2);
			}
			return true;
		}
	}
	
	return SittableUtil.sitOnBlock(worldIn, pos.getX(), pos.getY(), pos.getZ(), playerIn, 0.351);
}
 
开发者ID:Zundrel,项目名称:How-Bout-That-Furniture,代码行数:24,代码来源:BlockChair.java


示例10: getRecipe

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Nullable
public static CuttingBoardRecipe getRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack3) {
    if (ItemStackTools.isEmpty(stack1) && ItemStackTools.isEmpty(stack2) && ItemStackTools.isEmpty(stack3)) {
        return null;
    }
    ItemStack[] items = new ItemStack[] { stack1, stack2, stack3 };
    CuttingBoardRecipe.sortItems(items);
    KeyResourceLocations key = new KeyResourceLocations(items);
    if (recipeMap.containsKey(key)) {
        CuttingBoardRecipe recipe = recipeMap.get(key);
        for (int i = 0 ; i < items.length ; i++) {
            ItemStack item = items[i];
            if (ItemStackTools.isValid(item)) {
                if (!InventoryHelper.isItemStackConsideredEqual(recipe.getInputItems()[i], item)) {
                    return null;
                }
            }
        }
        return recipe;
    }
    return null;
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:23,代码来源:CuttingBoardRecipeRepository.java


示例11: fillFromContainer

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
private void fillFromContainer(EntityPlayer player, World world, Tank tank) {
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (ItemStackTools.isEmpty(heldItem)) {
        return;
    }
    ItemStack container = heldItem.copy().splitStack(1);
    FluidStack fluidStack = FluidTools.convertBucketToFluid(container);
    if (fluidStack != null) {
        if (tank.getFluid() == fluidStack.getFluid() || tank.getFluid() == null) {
            int newAmount = tank.getContents() + fluidStack.amount;
            if (newAmount <= tank.getMaxContents()) {
                tank.setContents(newAmount);
                tank.setFluid(fluidStack.getFluid());
                ImmersiveCraftHandler.tankNetwork.save(world);
                if (!player.capabilities.isCreativeMode) {
                    heldItem.splitStack(1);
                    ItemStack emptyContainer = FluidTools.drainContainer(container);
                    InventoryHelper.giveItemToPlayer(player, emptyContainer);
                }
            }
        }
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:24,代码来源:TankBlock.java


示例12: clOnBlockActivated

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
        if (ItemStackTools.isValid(heldItem)) {
            TankTE tankTE = getTE(world, pos);
            int id = tankTE.getID();

            Tank tank = ImmersiveCraftHandler.tankNetwork.getOrCreateMultiBlock(id);

            if (FluidTools.isEmptyContainer(heldItem)) {
                extractIntoContainer(player, tank);
                return true;
            } else if (FluidTools.isFilledContainer(heldItem)) {
                fillFromContainer(player, world, tank);
                return true;
            }
        }
    }
    return true;
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:22,代码来源:TankBlock.java


示例13: addProbeInfo

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
    super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
    TileEntity te = world.getTileEntity(data.getPos());
    if (te instanceof CuttingBoardTE) {
        CuttingBoardTE cuttingBoardTE = (CuttingBoardTE) te;

        IInterfaceHandle selectedHandle = cuttingBoardTE.getHandle(player);
        if (selectedHandle != null) {
            ItemStack currentStack = selectedHandle.getCurrentStack(te);
            if (ItemStackTools.isValid(currentStack)) {
                probeInfo.text(TextFormatting.GREEN + currentStack.getDisplayName() + " (" + ItemStackTools.getStackSize(currentStack) + ")");
            }
        }

        int chopCounter = cuttingBoardTE.getChopCounter();
        int maxChopCounter = cuttingBoardTE.getMaxChopCounter();
        if (chopCounter >= 0) {
            probeInfo.progress(chopCounter, maxChopCounter);
        }
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:23,代码来源:CuttingBoardBlock.java


示例14: grind

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
public void grind(EntityPlayer player) {
    ItemStack input = getStackInSlot(SLOT_INPUT);
    GrindstoneRecipe recipe = GrindstoneRecipeRepository.getRecipe(input);
    if (recipe == null) {
        ChatTools.addChatMessage(player, new TextComponentString(TextFormatting.YELLOW + "You cannot grind this!"));
        return;
    }

    ItemStack outputItem = recipe.getOutputItem();
    if (ItemStackTools.isValid(getStackInSlot(SLOT_OUTPUT)) && !InventoryHelper.isItemStackConsideredEqual(outputItem, getStackInSlot(SLOT_OUTPUT))) {
        ChatTools.addChatMessage(player, new TextComponentString(TextFormatting.YELLOW + "Clean up the grinder first!"));
    } else {
        grindCounter = 0;
        maxGrindCounter = recipe.getGrindTime();
        markDirtyClient();
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:18,代码来源:GrindStoneTE.java


示例15: addProbeInfo

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
    super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
    TileEntity te = world.getTileEntity(data.getPos());
    if (te instanceof GrindStoneTE) {
        GrindStoneTE grindStoneTE = (GrindStoneTE) te;

        IInterfaceHandle selectedHandle = grindStoneTE.getHandle(player);
        if (selectedHandle != null) {
            ItemStack currentStack = selectedHandle.getCurrentStack(te);
            if (ItemStackTools.isValid(currentStack)) {
                probeInfo.text(TextFormatting.GREEN + currentStack.getDisplayName() + " (" + ItemStackTools.getStackSize(currentStack) + ")");
            }
        }
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:17,代码来源:GrindStoneBlock.java


示例16: addProbeInfo

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
    super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
    TileEntity te = world.getTileEntity(data.getPos());
    if (te instanceof CookerTE) {
        CookerTE cookerTE = (CookerTE) te;

        IInterfaceHandle selectedHandle = cookerTE.getHandle(player);
        if (selectedHandle != null) {
            ItemStack currentStack = selectedHandle.getCurrentStack(te);
            if (ItemStackTools.isValid(currentStack)) {
                probeInfo.text(TextFormatting.GREEN + currentStack.getDisplayName() + " (" + ItemStackTools.getStackSize(currentStack) + ")");
            }
        }
        DecimalFormat decimalFormat = new DecimalFormat("#.#");

        probeInfo.text(TextFormatting.GREEN + "Filled: " + cookerTE.getFilledPercentage() + "%");
        probeInfo.text(TextFormatting.GREEN + "Temperature: " + decimalFormat.format(cookerTE.getTemperature()));
        int cookTime = cookerTE.getCookTime();
        int maxCookTime = cookerTE.getMaxCookTime();
        if (cookTime >= 0) {
            probeInfo.progress(cookTime, maxCookTime);
        }
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:26,代码来源:CookerBlock.java


示例17: fillFromContainer

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
private void fillFromContainer(EntityPlayer player, World world, CookerTE cooker) {
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (ItemStackTools.isEmpty(heldItem)) {
        return;
    }
    FluidStack fluidStack = FluidTools.convertBucketToFluid(heldItem);
    if (fluidStack != null) {
        if (fluidStack.getFluid() != FluidSetup.freshWater) {
            return;
        }

        int newAmount = cooker.getAmount() + fluidStack.amount;
        if (newAmount <= CookerTE.MAX_AMOUNT) {
            cooker.setAmount(newAmount);
            if (!player.capabilities.isCreativeMode) {
                ItemStack emptyContainer = FluidTools.drainContainer(heldItem);
                player.inventory.setInventorySlotContents(player.inventory.currentItem, emptyContainer);
            }
        }
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:22,代码来源:CookerBlock.java


示例18: itemToString

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
private static String itemToString(ItemStack stack) {
    if (ItemStackTools.isEmpty(stack)) {
        return "-";
    } else {
        String s;
        if (ItemStackTools.getStackSize(stack) > 1) {
            s = Integer.toString(ItemStackTools.getStackSize(stack)) + "x";
        } else {
            s = "";
        }

        s += stack.getItem().getRegistryName().toString();
        if (stack.getItemDamage() != 0) {
            s += "@" + stack.getItemDamage();
        }
        return s;
    }
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:19,代码来源:GeneralConfiguration.java


示例19: addItemToHandle

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
public boolean addItemToHandle(TileEntity te, EntityPlayer player, ItemStack heldItem, IInterfaceHandle handle, int amount) {
    if (!player.getEntityWorld().isRemote) {
        ItemStack itemStack;
        if (amount == -1) {
            itemStack = heldItem;
            player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStackTools.getEmptyStack());
        } else {
            itemStack = player.inventory.decrStackSize(player.inventory.currentItem, amount);
        }
        int remaining = handle.insertInput(te, itemStack);
        if (remaining != 0) {
            ItemStackTools.setStackSize(itemStack, remaining);
            player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);
            player.openContainer.detectAndSendChanges();
            return false;
        } else {
            player.openContainer.detectAndSendChanges();
            return true;
        }
    }
    return false;
}
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:23,代码来源:HandleSupport.java


示例20: getItemFromHandle

import mcjty.lib.tools.ItemStackTools; //导入依赖的package包/类
private boolean getItemFromHandle(TileEntity te, EntityPlayer player, IInterfaceHandle handle, int amount, boolean exactSlot) {
        if (!player.getEntityWorld().isRemote) {
            ItemStack itemStack = handle.extractOutput(te, player, amount);
            if (ItemStackTools.isEmpty(itemStack)) {
                return false;
            }
            // @todo check and test!
            InventoryHelper.giveItemToPlayer(player, itemStack);
//            if (exactSlot) {
//                player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);
//            } else {
//                if (!player.inventory.addItemStackToInventory(itemStack)) {
//                    InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition(), itemStack);
//                }
//            }
//            player.openContainer.detectAndSendChanges();
        }
        return true;
    }
 
开发者ID:McJty,项目名称:AquaMunda,代码行数:20,代码来源:HandleSupport.java



注:本文中的mcjty.lib.tools.ItemStackTools类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SkipThisScenarioException类代码示例发布时间:2022-05-23
下一篇:
Java SaslTransportPlugin类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap