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


Java SlotIndex类代码示例

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


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

示例1: run

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
@Override
public void run() {
    if (!FIRST_GUI_CONTAINERS.containsKey(container)) {
        return;
    }
    for (int i = 10; i < 16; i++) {
        inventory.getSlot(new SlotIndex(i)).get().
                set(inventory.getSlot(new SlotIndex(i + 1)).get().peek().
                        orElse(ItemStack.of(ItemTypes.NONE, 1)));
    }
    if (index == drops.size()) {
        index = 0;
    }
    inventory.getSlot(new SlotIndex(16)).get().
            set(drops.get(index).getDropItem().orElse(ItemStack.of(ItemTypes.NONE, 1)));
    index++;
    Sponge.getScheduler().createTaskBuilder().delayTicks(scroll_delay).execute(this).submit(GWMCrates.getInstance());
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:19,代码来源:FirstGuiPreview.java

示例2: open

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
@Override
public void open(Player player, Manager manager) {
    PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
    Sponge.getEventManager().post(open_event);
    if (open_event.isCancelled()) return;
    Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
            property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
            property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
            build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
            property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
            build(GWMCrates.getInstance()));
    OrderedInventory ordered = Utils.castToOrdered(inventory);
    int hidden_item_quantity = hidden_item.getQuantity();
    for (int i = 0; i < 9 * rows; i++) {
        int quantity = increase_hidden_item_quantity ? i + 1 : hidden_item_quantity;
        ItemStack copy = hidden_item.copy();
        copy.setQuantity(quantity);
        ordered.getSlot(new SlotIndex(i)).get().set(copy);
    }
    Container container = player.openInventory(inventory).get();
    getOpenSound().ifPresent(open_sound -> player.playSound(open_sound, player.getLocation().getPosition(), 1.));
    SECOND_GUI_INVENTORIES.put(container, new Pair<SecondOpenManager, Manager>(this, manager));
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:24,代码来源:SecondOpenManager.java

示例3: run

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
@Override
public void run() {
    Optional<Container> open_inventory = player.getOpenInventory();
    if (open_inventory.isPresent() && open_inventory.get().equals(container)) {
        decorative_items = decorative_items_change_mode.shuffle(decorative_items);
        for (int i = 0; i < 10; i++) {
            ordered.getSlot(new SlotIndex(i)).get().set(decorative_items.get(i));
        }
        for (int i = 17; i < 27; i++) {
            ordered.getSlot(new SlotIndex(i)).get().set(decorative_items.get(i - 7));
        }
        Sponge.getScheduler().createTaskBuilder().
                delayTicks(decorative_items_change_mode.getChangeDelay()).
                execute(this).submit(GWMCrates.getInstance());
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:17,代码来源:FirstOpenManager.java

示例4: performRemoval

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的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

示例5: setInventory

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
public boolean setInventory(Player player, Inventory inventory, SlotIndex pos)
{
    if (!this.plugin.getScriptManager().execute(player, this.requirements))
    {
        return false;
    }
    try
    {
        inventory.set(this.serializer.apply(player, this.serializedStack));
        return true;
    }
    catch (InvalidDataException e)
    {
        String posString = VirtualChestInventory.slotIndexToKey(pos);
        throw new InvalidDataException("Find error when generating item at " + posString, e);
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:18,代码来源:VirtualChestItem.java

示例6: updateInventory

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
/** dealing with open inventories this will target a OrderedInventory 
 * (more precisely a OrderedInventoryAdapter at runtime) */
public void updateInventory(Inventory view, UUID player) {
	if (!(view instanceof OrderedInventory)) {
		VillagerShops.w("Can't update view");
		return;
	}
	OrderedInventory oi = (OrderedInventory)view;
	int row=0, col=0;
	for (int i = 0; i < items.size(); i++) {
		
		oi.set(new SlotIndex(row*9+col),		items.get(i).getBuyDisplayItem(row*9+col, player));
		oi.set(new SlotIndex((row+1)*9+col),	items.get(i).getSellDisplayItem((row+1)*9+col, player));
		
		if (++col>=9) { col=0; row+=3; }
	}
}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:18,代码来源:InvPrep.java

示例7: deserializePlayerInventory

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
private static void deserializePlayerInventory(AbstractUserInventory<?> inventory, List<DataView> itemViews) {
    final LanternMainPlayerInventory mainInventory = inventory.getMain();
    final LanternPlayerEquipmentInventory equipmentInventory = inventory.getEquipment();
    final AbstractSlot offHandSlot = inventory.getOffhand();

    for (DataView itemView : itemViews) {
        final int slot = itemView.getByte(SLOT).get() & 0xff;
        final LanternItemStack itemStack = ItemStackStore.INSTANCE.deserialize(itemView);

        if (slot >= 0 && slot < mainInventory.capacity()) {
            mainInventory.set(new SlotIndex(slot), itemStack);
        } else if (slot >= 100 && slot - 100 < equipmentInventory.capacity()) {
            equipmentInventory.set(new SlotIndex(slot - 100), itemStack);
        } else if (slot == 150) {
            offHandSlot.set(itemStack);
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:UserStore.java

示例8: serialize

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
@Override
public void serialize(T object, DataView dataView) {
    super.serialize(object, dataView);
    final ObjectSerializer<LanternItemStack> itemStackSerializer =  ObjectSerializerRegistry.get().get(LanternItemStack.class).get();
    final List<DataView> itemViews = new ArrayList<>();
    final Inventory inventory = object.getInventory();
    final Iterable<Slot> slots = inventory.slots();
    for (Slot slot : slots) {
        final Optional<ItemStack> optItemStack = slot.peek();
        if (!optItemStack.isPresent()) {
            continue;
        }
        final DataView itemView = itemStackSerializer.serialize((LanternItemStack) optItemStack.get());
        //noinspection ConstantConditions
        itemView.set(SLOT, (byte) inventory.getProperty(slot, SlotIndex.class, null).get().getValue().intValue());
        itemViews.add(itemView);
    }
    dataView.set(ITEMS, itemViews);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:ContainerTileEntityStore.java

示例9: preview

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
@Override
public void preview(Player player, Manager manager) {
    Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
            property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
            build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
            build(GWMCrates.getInstance()));
    OrderedInventory ordered = Utils.castToOrdered(inventory);
    for (int i = 0; i < 10; i++) {
        ordered.getSlot(new SlotIndex(i)).get().set(decorative_items.get(i));
    }
    List<Drop> drops = manager.getDrops();
    int index = 0;
    for (int i = 10; i < 17; i++) {
        if (index > drops.size() - 1) {
            index = 0;
        }
        ordered.getSlot(new SlotIndex(i)).get().set(drops.get(index).getDropItem().orElse(ItemStack.of(ItemTypes.NONE, 1)));
        index++;
    }
    for (int i = 17; i < 27; i++) {
        ordered.getSlot(new SlotIndex(i)).get().set(decorative_items.get(i - 7));
    }
    Container container = player.openInventory(inventory).get();
    FIRST_GUI_CONTAINERS.put(container, new Pair<FirstGuiPreview, Manager>(this, manager));
    decorative_items_change_mode.ifPresent(mode -> Sponge.getScheduler().
            createTaskBuilder().delayTicks(mode.getChangeDelay()).
            execute(new FirstOpenManager.DropChangeRunnable(player, container, ordered, new ArrayList<ItemStack>(decorative_items), mode)).
            submit(GWMCrates.getInstance()));
    Sponge.getScheduler().createTaskBuilder().delayTicks(scroll_delay).
            execute(new DropChangeRunnable(container, drops, index)).
            submit(GWMCrates.getInstance());
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:33,代码来源:FirstGuiPreview.java

示例10: performAddition

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
private void performAddition(LookupLine line) {
	//TODO: Debug this function, blocks are not being added
	
	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();
			
			ItemType type = (ItemType) line.getTarget();
			ItemStack stack = ItemStack.builder()
					.fromContainer(line.getDataAsView())
					.itemType(type)
					.quantity(line.getCount())
					.build();
			Inventory slot = i.query(new SlotIndex(line.getSlot()));
			slot.set(stack);
		}
		
	} else if (line.getTarget() instanceof BlockType) {
		
		BlockState block = BlockState.builder().build(line.getDataAsView()).orElse(null);
		if (block != null)
			w.setBlock(line.getPos(), block, Cause.source(container).build());
		
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:32,代码来源:RollbackManager.java

示例11: getSlotOrdinal

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
public static SlotIndex getSlotOrdinal(Slot slot)
{
    Collection<SlotIndex> properties = slot.parent().getProperties(slot, SlotIndex.class);
    if (properties.isEmpty())
    {
        throw new UnsupportedOperationException("Not recognized");
    }
    return properties.iterator().next();
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:10,代码来源:SpongeUnimplemented.java

示例12: updateInventory

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
private Map<SlotIndex, VirtualChestItem> updateInventory(Player player, Inventory chestInventory)
{
    int i = 0;
    ImmutableMap.Builder<SlotIndex, VirtualChestItem> itemBuilder = ImmutableMap.builder();
    for (Slot slot : chestInventory.<Slot>slots())
    {
        SlotIndex pos = SlotIndex.of(i++);
        this.setItemInInventory(player, slot, pos).ifPresent(item -> itemBuilder.put(pos, item));
    }
    return itemBuilder.build();
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:12,代码来源:VirtualChestInventory.java

示例13: setItemInInventory

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
private Optional<VirtualChestItem> setItemInInventory(Player player, Slot slot, SlotIndex pos)
{
    Collection<VirtualChestItem> items = this.items.get(pos);
    for (VirtualChestItem i : items)
    {
        if (i.setInventory(player, slot, pos))
        {
            return Optional.of(i);
        }
    }
    slot.clear();
    return Optional.empty();
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:14,代码来源:VirtualChestInventory.java

示例14: VirtualChestEventListener

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
private VirtualChestEventListener(Player player)
{
    this.itemsInSlots = new TreeMap<>();
    this.parsedOpenAction = VirtualChestActionDispatcher.parseCommand(openActionCommand.orElse(""));
    this.parsedCloseAction = VirtualChestActionDispatcher.parseCommand(closeActionCommand.orElse(""));
    this.slotToListen = SlotIndex.lessThan(height * 9);
    this.playerUniqueId = player.getUniqueId();
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:9,代码来源:VirtualChestInventory.java

示例15: processClickEvent

import org.spongepowered.api.item.inventory.property.SlotIndex; //导入依赖的package包/类
private boolean processClickEvent(ClickInventoryEvent e, Player player, SlotIndex pos)
{
    VirtualChestItem item = itemsInSlots.get(pos);
    String log = "Player {} tries to click the chest GUI at {}, primary: {}, secondary: {}, shift: {}";

    boolean isShift = e instanceof ClickInventoryEvent.Shift;
    boolean isPrimary = e instanceof ClickInventoryEvent.Primary;
    boolean isSecondary = e instanceof ClickInventoryEvent.Secondary;

    logger.debug(log, player.getName(), slotIndexToKey(pos), isPrimary, isSecondary, isShift);
    Optional<VirtualChestActionDispatcher> optional = item.getAction(isPrimary, isSecondary, isShift);
    return optional.map(d -> d.runCommand(plugin, player, item.getIgnoredPermissions())).orElse(Boolean.TRUE);
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:14,代码来源:VirtualChestInventory.java


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