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


Java Carrier类代码示例

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


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

示例1: execute

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	final String kitName = args.<String>getOne("kit").get();
	final Kit kit = instance.getKit(kitName);
	if (kit == null) {
		src.sendMessage(Messages.get("KitNotFound"));
		return CommandResult.empty();
	}

	Location<World> location = args.<Location<World>>getOne(Text.of("location")).get();
	if (!location.hasTileEntity() || !(location.getTileEntity().get() instanceof Carrier)) {
		src.sendMessage(Text.of("The target block has not a valid inventory"));
		return CommandResult.empty();
	}

	kit.refill((Carrier) location.getTileEntity().get());
	if (src instanceof Player) {
		src.sendMessage(Text.of(TextColors.GOLD, "The target block has been refilled"));
	}
	return CommandResult.success();
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:22,代码来源:KitRefillCommand.java

示例2: CachedEntity

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
public CachedEntity(Entity entity) {
    super(entity);

    this.type = new CachedCatalogType(entity.getType());
    this.uuid = UUID.fromString(entity.getUniqueId().toString());
    this.location = new CachedLocation(entity.getLocation());

    this.rotation = entity.getRotation().clone();
    this.velocity = entity.getVelocity().clone();
    this.scale = entity.getScale().clone();

    if (entity instanceof Carrier) {
        try {
            this.inventory = new CachedInventory(((Carrier) entity).getInventory());
        } catch (AbstractMethodError ignored) {}
    }
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:18,代码来源:CachedEntity.java

示例3: getLockOfInventory

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
/**
 * Returns the lock for given inventory it exists
 *
 * @param inventory
 * @return the lock for given inventory
 */
public Lock getLockOfInventory(CarriedInventory<?> inventory)
{
    Carrier holder = inventory.getCarrier().orElse(null);
    if (holder instanceof Entity)
    {
        return this.getLockForEntityUID(((Entity)holder).getUniqueId());
    }
    if (holder instanceof MultiBlockCarrier)
    {
        return getValidLock(((MultiBlockCarrier)holder).getLocation(), null);
    }
    if (holder instanceof BlockCarrier)
    {
        return getValidLock(((BlockCarrier)holder).getLocation(), null);
    }
    return null;
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:24,代码来源:LockManager.java

示例4: onPlayerInteractEntity

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
@Listener
public void onPlayerInteractEntity(InteractEntityEvent event, @First Player player)
{
    if (!this.module.getConfig().protectEntityFromRClick) return;
    Entity entity = event.getTargetEntity();
    if (!player.hasPermission(module.perms().ALLOW_ENTITY.getId()))
    {
        i18n.send(player, NEGATIVE, "Strong magic prevents you from reaching this entity!");
        event.setCancelled(true);
        return;
    }
    Lock lock = this.manager.getLockForEntityUID(entity.getUniqueId());
    if (lock == null) return;
    if (entity instanceof Carrier || (entity.getType() == HORSE && player.get(Keys.IS_SNEAKING).get()))
    {
        // Handled by InteractInventoryEvent.Open
        lock.handleInventoryOpen(event, ((Carrier) entity).getInventory(), null, player);
    }
    else
    {
        lock.handleEntityInteract(event, player);
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:24,代码来源:LockerListener.java

示例5: isDuctInteraction

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
private static boolean isDuctInteraction(InteractBlockEvent event)
{
    if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand))
    {
        return false;
    }
    if (!event.getTargetBlock().getLocation().isPresent())
    {
        return false;
    }
    Location<World> loc = event.getTargetBlock().getLocation().get();
    BlockType type = loc.getBlockType();
    if (!isEndPointType(type))
    {
        return false;
    }
    Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE);
    Optional<TileEntity> te = loc.getRelative(dir).getTileEntity();
    return te.isPresent() && te.get() instanceof Carrier;
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:21,代码来源:ItemDuctListener.java

示例6: transferToStorage

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
private void transferToStorage(Inventory inventory, List<ItemStack> filters)
{
    if (!filters.isEmpty()) // Only allow to extract items in the filter
    {
        inventory = queryFiltered(filters, inventory); // TODO more filters
    }
    for (Location<World> targetLoc : storage)
    {
        TileEntity te = targetLoc.getTileEntity().get();
        Inventory target =  ((Carrier) te).getInventory();
        if (te instanceof Chest)
        {
            target = ((Chest) te).getDoubleChestInventory().orElse(target);
        }
        doTransfer(inventory, target);
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:18,代码来源:Network.java

示例7: pullFromStorage

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
private void pullFromStorage(Inventory inventory, List<ItemStack> filters)
{
    for (Location<World> targetLoc : storage)
    {
        TileEntity te = targetLoc.getTileEntity().get();
        Inventory pollFrom =  ((Carrier) te).getInventory();
        if (te instanceof Chest)
        {
            pollFrom = ((Chest) te).getDoubleChestInventory().orElse(pollFrom);
        }
        if (!filters.isEmpty()) // Only allow to extract items in the filter
        {
            pollFrom = queryFiltered(filters, inventory); // TODO more filters
        }

        doTransfer(pollFrom, inventory);
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:19,代码来源:Network.java

示例8: clearContainerBlockContents

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
@Override
public boolean clearContainerBlockContents(Vector position) {
    final Optional<TileEntity> optTile = getWorld().getTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    if (optTile.isPresent() && optTile.get() instanceof Carrier) {
        final Carrier carrier = (Carrier) optTile.get();
        carrier.getInventory().clear();
        return true;
    }
    return false;
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:11,代码来源:LanternWEWorld.java

示例9: getFor

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
public static InventoryTag getFor(Action<String> error, String text) {
    List<String> split = CoreUtilities.split(text, '/');
    if (split.get(0).equals("player")) {
        Optional<Player> oplayer = Sponge.getServer().getPlayer(UUID.fromString(split.get(1)));
        if (!oplayer.isPresent()) {
            error.run("Invalid PlayerTag UUID input!");
            return null;
        }
        return new InventoryTag(oplayer.get().getInventory());
    }
    else if (split.get(0).equals("entity")) {
        UUID id = UUID.fromString(split.get(1));
        for (World world : Sponge.getServer().getWorlds()) {
            Optional<Entity> e = world.getEntity(id);
            if (e.isPresent() && e.get() instanceof Carrier) {
                return new InventoryTag(((Carrier) e.get()).getInventory());
            }
        }
        error.run("Invalid EntityTag UUID input!");
        return null;
    }
    else if (split.get(0).equals("block")) {
        LocationTag lt = LocationTag.getFor(error, split.get(1));
        return new InventoryTag(((TileEntityCarrier) lt.getInternal().toLocation().getTileEntity().get()).getInventory());
    }
    else if (split.get(0).equals("shared")) {
        return Denizen2Sponge.rememberedInventories.get(split.get(1));
    }
    else {
        error.run("Inventory type not known to the system: " + split.get(0));
        return null;
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:34,代码来源:InventoryTag.java

示例10: refill

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
public void refill(Carrier carrier) {
	this.checkCache();

	for (ItemStackSnapshot iss : itemStacksCache) {
		carrier.getInventory().clear();
		carrier.getInventory().offer(iss.createStack());
	}
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:9,代码来源:Kit.java

示例11: forCarrier

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
public static InventoryAdapter forCarrier(Carrier carrier) {
    try {
        return new SpongeInventoryAdapter(carrier.getInventory());
    } catch (AbstractMethodError e) {
        e.printStackTrace();
        return InternalInventoryAdapter.from(carrier);
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:9,代码来源:SpongeInventoryAdapter.java

示例12: onChangeInventory

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Listener
public void onChangeInventory(ChangeInventoryEvent event, @First Player player,
        @Getter("getTargetInventory") CarriedInventory<?> container) {
    if (!container.getName().get().equals("Furnace")) {
        return;
    }
    final Carrier carrier = container.getCarrier().orElse(null);
    if (!(carrier instanceof Furnace)) {
        return;
    }
    final Furnace furnace = (Furnace) carrier;
    final int passed = furnace.passedBurnTime().get();
    final int max = furnace.maxBurnTime().get();
    if (max <= 0 || passed >= max) {
        return;
    }
    for (SlotTransaction transaction : event.getTransactions()) {
        if (container.getInventoryProperty(transaction.getSlot(), SlotIndex.class).get().getValue() == 0) {
            if (transaction.getFinal().getType() == ItemTypes.DIRT) {
                player.getProgress(this.cookDirtAdvancement).grant();
            } else if (this.suicidalAdvancement != null && (transaction.getFinal().getType() == ItemTypes.TNT ||
                    transaction.getFinal().getType() == ItemTypes.TNT_MINECART)) {
                player.getProgress(this.suicidalAdvancement).grant();
                /*
                final Explosion explosion = Explosion.builder()
                        .location(furnace.getLocation())
                        .shouldBreakBlocks(true)
                        .canCauseFire(true)
                        .shouldDamageEntities(true)
                        .radius(7)
                        .build();
                explosion.getWorld().triggerExplosion(explosion);
                */
            }
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:39,代码来源:AdvancementTest.java

示例13: spawnWithEquipment

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
protected void spawnWithEquipment(EntityProtocolUpdateContext context) {
    if (hasEquipment() && this.entity instanceof Carrier) {
        final Inventory inventory = ((Carrier) this.entity).getInventory();
        for (int i = 0; i < Holder.EQUIPMENT_TYPES.length; i++) {
            final ItemStack itemStack = inventory.query(Holder.EQUIPMENT_QUERIES[i]).first().peek().orElse(null);
            final int slotIndex = i;
            if (itemStack != null) {
                context.sendToAllExceptSelf(() -> new MessagePlayOutEntityEquipment(getRootEntityId(), slotIndex, itemStack));
            }
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:13,代码来源:EntityProtocol.java

示例14: of

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
static <T> CarrierReference<T> of(Class<T> carrierType) {
    return new CarrierReference<T>() {
        @Nullable private Object obj;

        @Override
        public Optional<Carrier> asCarrier() {
            return (Optional<Carrier>) get();
        }

        @Override
        public Optional<T> get() {
            if (this.obj == null) {
                return Optional.empty();
            }
            if (this.obj instanceof WeakReference) {
                return Optional.ofNullable(carrierType.cast(((WeakReference) this.obj).get()));
            }
            return Optional.of(carrierType.cast(this.obj));
        }

        @Override
        public <R> Optional<R> as(Class<R> ret) {
            return get().filter(ret::isInstance).map(ret::cast);
        }

        @Override
        public void set(@Nullable Carrier carrier) {
            this.obj = !carrierType.isInstance(carrier) ? null : (carrier instanceof TileEntity || carrier instanceof Entity) ?
                    new WeakReference<>(carrier) : carrier;
        }
    };
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:33,代码来源:CarrierReference.java

示例15: apply

import org.spongepowered.api.item.inventory.Carrier; //导入依赖的package包/类
@Nullable
@Override
public LanternInventoryArchetype<LanternOrderedInventory> apply(Carrier carrier,
        Supplier<AbstractOrderedInventory.Builder<LanternOrderedInventory>> builderSupplier) {
    if (carrier instanceof Donkey ||
            carrier instanceof Mule) {
        return applyDonkeyMule(builderSupplier,
                ((Entity) carrier).get(LanternKeys.HAS_CHEST).orElse(false));
    } else if (carrier instanceof Horse) {
        return applyHorse(builderSupplier);
    }
    return null;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:14,代码来源:HorseCarrierBasedTransformer.java


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