本文整理汇总了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();
}
示例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) {}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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());
}
}
示例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);
}
}
示例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);
*/
}
}
}
}
示例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));
}
}
}
}
示例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;
}
};
}
示例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;
}