本文整理汇总了Java中org.spongepowered.api.item.ItemType.getId方法的典型用法代码示例。如果您正苦于以下问题:Java ItemType.getId方法的具体用法?Java ItemType.getId怎么用?Java ItemType.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.ItemType
的用法示例。
在下文中一共展示了ItemType.getId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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() + '!'));
}
}
}
示例2: 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() + '!'));
}
}
}
示例3: 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!"));
}
}
}
示例4: 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!"));
}
}
}
示例5: BlockChunkLoaderConfig
import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
public BlockChunkLoaderConfig(String name, String duration, boolean afk, BlockType block, ItemType item, ItemType fuel, String fuelDuration) {
super(name, duration, afk);
this.blockId = block.getId();
this.itemId = item.getId();
this.fuel = fuel.getId();
this.fuelDuration = fuelDuration;
}
示例6: onItemUse
import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onItemUse(UseItemStackEvent.Start event, @Root Player player) {
ItemType itemType = event.getItemStackInUse().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + '!'));
}
}
示例7: onItemPickup
import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
ItemType itemType = event.getOriginalStack().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.pickup." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to pick up " + itemType.getName() + '!'));
}
}
示例8: ItemTypeView
import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
public ItemTypeView(ItemType value) {
super(value);
this.id = value.getId();
this.name = value.getTranslation().get();
}
示例9: generateResourcePack
import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
public void generateResourcePack(Path directory) {
for (Map.Entry<ItemType, BiMap<Integer, Identifier>> entry : typeToDurabilityToModelId.entrySet()) {
ItemType itemType = entry.getKey();
BiMap<Integer, Identifier> durabilityToModelId = entry.getValue();
JsonArray modelOverrides = new JsonArray();
List<Integer> durabilities = Lists.newArrayList(durabilityToModelId.keySet());
Collections.sort(durabilities, Collections.reverseOrder());
for (int durability : durabilities) {
Identifier modelId = durabilityToModelId.get(durability);
String pluginId = modelId.getNamespace();
String model = modelId.getValue();
double damage = 1.0 - (double) durability / (double) CustomToolDefinition.getNumberOfUses(itemType)
.orElseThrow(() -> new IllegalStateException("Could not access the max number of uses."));
JsonObject modelPredicate = new JsonObject();
modelPredicate.addProperty("damaged", 0);
modelPredicate.addProperty("damage", damage);
JsonObject modelJson = new JsonObject();
DurabilityIdentifier durabilityId = new DurabilityIdentifier(itemType, durability);
String modelDirectory = durabilityIdToDirectoryName.get(durabilityId);
modelJson.add("predicate", modelPredicate);
modelJson.addProperty("model", getFileIdentifier(pluginId, modelDirectory, model));
modelOverrides.add(modelJson);
}
String typeId = itemType.getId();
String namespace = Identifier.getNamespaceFromIdString(typeId);
String typeName = Identifier.getValueFromIdString(typeId);
JsonObject defaultModelPredicate = new JsonObject();
defaultModelPredicate.addProperty("damaged", 1);
defaultModelPredicate.addProperty("damage", 0.0);
JsonObject defaultModel = new JsonObject();
defaultModel.add("predicate", defaultModelPredicate);
defaultModel.addProperty("model", getItemModelIdentifier(null, typeName));
modelOverrides.add(defaultModel);
JsonObject modelTextures = new JsonObject();
modelTextures.addProperty("layer0", getItemTextureIdentifier(null, typeName));
JsonObject descriptorRoot = new JsonObject();
descriptorRoot.addProperty("parent", getItemModelIdentifier(null, "handheld"));
descriptorRoot.add("textures", modelTextures);
descriptorRoot.add("overrides", modelOverrides);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Path modelPath = CustomItemServiceImpl.getDirectoryResourcePack()
.resolve("assets").resolve(namespace).resolve("models")
.resolve("item").resolve(typeName + ".json");
try {
Files.createDirectories(modelPath.getParent());
try (Writer writer = new FileWriter(modelPath.toFile())) {
gson.toJson(descriptorRoot, writer);
}
} catch (IOException e) {
CustomItemLibrary.getInstance().getLogger()
.error("Could not write a model file for custom tools.");
e.printStackTrace();
}
}
}
示例10: convertToDatabaseColumn
import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Override
public String convertToDatabaseColumn(ItemType attribute) {
return attribute.getId();
}