当前位置: 首页>>代码示例>>Java>>正文


Java ItemType类代码示例

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


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

示例1: performRemoval

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
private void performRemoval(LookupLine line) {
	World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
	if (w == null) return;
	
	if (line.getTarget() instanceof ItemType) {
		
		Optional<TileEntity> te = w.getTileEntity(line.getPos());
		if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
			TileEntityCarrier c = (TileEntityCarrier) te.get();
			Inventory i = c.getInventory();
			
			Inventory slot = i.query(new SlotIndex(line.getSlot()));
			slot.set(ItemStack.of(ItemTypes.NONE, 0));
		}
		
	} else if (line.getTarget() instanceof BlockType) {
		
		BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
		w.setBlock(line.getPos(), block, Cause.source(container).build());
		
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:23,代码来源:RollbackManager.java

示例2: getCatalogType

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
private static CatalogType getCatalogType(String id, LookupType lookupType) throws CommandException {
	switch (lookupType) {
		case BLOCK_LOOKUP:
			Optional<BlockType> block = Sponge.getRegistry().getType(BlockType.class, id);
			if (block.isPresent())
				return block.get();
			throw new CommandException(Text.of(TextColors.RED, "Unknown block id: " + id));
		case ITEM_LOOKUP:
			Optional<ItemType> item = Sponge.getRegistry().getType(ItemType.class, id);
			if (item.isPresent())
				return item.get();
			throw new CommandException(Text.of(TextColors.RED, "Unknown item id: " + id));
		default:
			throw new CommandException(Text.of(TextColors.RED, "Could not determine lookup type!"));
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:17,代码来源:FilterParser.java

示例3: makeSpongeStack

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
    final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
            .orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
    final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
    final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
            .orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
    final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    view.set(DATA_VALUE, baseItemStack.getData());
    store.deserialize(itemStack, view);
    final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
    if (!enchantments.isEmpty()) {
        itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
                .map(entry -> {
                    final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
                            .orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
                    return new ItemEnchantment(enchantment, entry.getValue());
                })
                .collect(Collectors.toList()));
    }
    return itemStack;
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:23,代码来源:LanternImplAdapter.java

示例4: commandItem

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
private CompletableFuture<Boolean> commandItem(final EPlayer player, String type_string) {
	Optional<ItemType> type = UtilsItemType.getItemType(type_string);
	
	// Le type n'existe pas
	if (!type.isPresent()) {
		EEMessages.ITEM_ERROR_ITEM_NOT_FOUND.sender()
			.replace("{item}", type_string)
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	// L'item est dans la BlackList
	if (this.blacklist.contains(type.get())) {
		EEMessages.ITEM_ERROR_ITEM_BLACKLIST.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	this.commandGive(player, ItemStack.of(type.get(), 1), type.get().getMaxStackQuantity());
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:21,代码来源:EEItem.java

示例5: onItemDrop

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) {

    PermHandler ph = PermHandler.getInstance();
    
    event.filterEntities(entity -> {
        if (entity.getType().equals(EntityTypes.ITEM)) {
            Item item = (Item) entity;
            ItemType itemType = item.getItemType();
            String itemId = itemType.getId();
            if (!ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".dispense")) {
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!'));
                return false;
            }
        }
        return true;
    });
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:19,代码来源:DropItemDispenseListener.java

示例6: onInteractBlockPrimaryMain

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:PrimaryBlockListener.java

示例7: onInteractBlockSecondaryMain

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:SecondaryBlockListener.java

示例8: onInteractEntitySecondaryMain

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        EntityType entityType = event.getTargetEntity().getType();
        String entityId = entityType.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:21,代码来源:SecondaryEntityListener.java

示例9: onInteractEntityPrimaryMain

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        EntityType entityType = event.getTargetEntity().getType();
        String entityId = entityType.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:21,代码来源:PrimaryEntityListener.java

示例10: onItemEquip

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {

    if (inventory.getArchetype() == InventoryArchetypes.PLAYER) {

        Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class));

        equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {

            ItemType itemType = itemStack.getType();
            String itemId = itemType.getId();

            PermHandler ph = PermHandler.getInstance();

            if (!ph.checkPerm(player, "protectionperms.item.equip." + itemId + ".on.self")) {
                event.setCancelled(true);
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!'));
            }
        }));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:EquipItemListener.java

示例11: onItemCraft

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Listener
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {

    if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {

        Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));

        craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {

            ItemType itemType = itemStack.getType();
            String itemId = itemType.getId();

            PermHandler ph = PermHandler.getInstance();

            if (!ph.checkPerm(player, "protectionperms.item.craft." + itemId)) {
                event.setCancelled(true);
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
            }
        }));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:CraftItemListener.java

示例12: register

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
public void register(ItemType itemType, PluginContainer pluginContainer, Iterable<String> models, String modelDirectoryName) {
    models.forEach(model -> {
        BiMap<Integer, Identifier> durabilityToModelId = typeToDurabilityToModelId.computeIfAbsent(itemType, k -> HashBiMap.create());
        Identifier modelId = new Identifier(pluginContainer.getId(), model);

        // Is the model already registered? If so, skip.
        Integer registeredDurability = durabilityToModelId.inverse().get(modelId);

        if(registeredDurability == null) {
            registeredDurability = getAvailableDurability(itemType);
        }

        DurabilityIdentifier durabilityId = new DurabilityIdentifier(itemType, registeredDurability);

        durabilityIdToDirectoryName.put(durabilityId, modelDirectoryName);
        durabilityIdToModelId.put(durabilityId, modelId);
        durabilityToModelId.put(registeredDurability, modelId);
    });
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:20,代码来源:DurabilityRegistry.java

示例13: createItem

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Override
public CustomTool createItem(Cause cause) {
    PluginContainer plugin = getPluginContainer();
    ItemStack itemStack = itemStackSnapshot.createStack();
    ItemType itemType = itemStack.getItem();
    int durability = DurabilityRegistry.getInstance().getDurability(itemType, plugin, getDefaultModel())
            .orElseThrow(() -> new IllegalStateException("Could not get the durability for the default models."));

    itemStack.offer(Keys.UNBREAKABLE, true);
    itemStack.offer(Keys.ITEM_DURABILITY, durability);
    itemStack.offer(Keys.HIDE_UNBREAKABLE, true);
    itemStack.offer(Keys.HIDE_ATTRIBUTES, true);
    itemStack.offer(createDefaultCustomFeatureData());

    CustomTool tool = new CustomTool(itemStack, this);
    CustomItemCreationEvent event = new CustomItemCreationEvent(tool, cause);

    Sponge.getEventManager().post(event);

    return tool;
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:22,代码来源:CustomToolDefinition.java

示例14: setItem

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
private void setItem(Player player, BiFunction<PlayerMountDataMutable, ItemType, Boolean> operation)
{
    Optional<PlayerMountDataMutable> optional = player.get(PlayerMountDataMutable.class);
    if (optional.isPresent())
    {
        Optional<ItemStack> inHand = player.getItemInHand();
        if (inHand.isPresent())
        {
            String item = inHand.get().getItem().getName();
            if (operation.apply(optional.get(), inHand.get().getItem()))
            {
                player.offer(optional.get());
                messenger().info("Item set to: ").stress(item).tell(player);
            }
            return;
        }
        messenger().error("You must be holding an item to use this command!").tell(player);
        return;
    }
    messenger().error("You must first create a mount before your can change its properties!").tell(player);
}
 
开发者ID:dags-,项目名称:Mounts,代码行数:22,代码来源:UserCommands.java

示例15: configurationToItemStacks

import org.spongepowered.api.item.ItemType; //导入依赖的package包/类
@Override
public List<ItemStack> configurationToItemStacks(SkillData skillData) {
    List<ItemStack> list = new ArrayList<>();
    ItemAccessSkillData data = (ItemAccessSkillData) skillData;
    for (Map.Entry<Integer, Map<ItemType, Set<ConfigRPGItemType>>> entry : data.items.entrySet()) {
        for (Set<ConfigRPGItemType> configRPGItemTypes : entry.getValue().values()) {
            list.addAll(configRPGItemTypes.stream()
                    .map(GuiHelper::rpgItemTypeToItemStack)
                    .map(a -> {
                        List<Text> texts = a.get(Keys.ITEM_LORE).get();
                        texts.add(Text.EMPTY);
                        texts.add(Text.builder(Localization.SKILL_LEVEL)
                                .color(TextColors.GREEN)
                                .append(Text.builder(": " + entry.getKey())
                                        .build()
                                )
                                .build());
                        a.offer(Keys.ITEM_LORE, texts);
                        a.offer(new MenuInventoryData(true));
                        return a;
                    }).collect(Collectors.toList()));

        }
    }
    return list;
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:27,代码来源:ItemAccessSkill.java


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