本文整理汇总了Java中org.spongepowered.api.item.inventory.Container类的典型用法代码示例。如果您正苦于以下问题:Java Container类的具体用法?Java Container怎么用?Java Container使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Container类属于org.spongepowered.api.item.inventory包,在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.spongepowered.api.item.inventory.Container; //导入依赖的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));
}
示例2: run
import org.spongepowered.api.item.inventory.Container; //导入依赖的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());
}
}
示例3: openInventory
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
@Override
public Optional<Container> openInventory(Inventory inventory) {
checkNotNull(inventory, "inventory");
final LanternContainer container;
if (inventory instanceof LanternContainer) {
// You cannot open a player inventory container
if (inventory instanceof PlayerInventoryContainer) {
return Optional.empty();
}
container = (LanternContainer) inventory;
} else {
inventory.getInventoryProperty(GuiIdProperty.class).map(GuiIdProperty::getValue).orElseThrow(() ->
new UnsupportedOperationException("Unsupported inventory type: " + inventory.getArchetype().getId()));
container = LanternContainer.construct(this.inventory, (AbstractOrderedInventory) inventory);
}
if (this.containerSession.setOpenContainer(container)) {
return Optional.of(container);
}
return Optional.empty();
}
示例4: cancelClick
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void cancelClick(ClickInventoryEvent event) {
Container container = event.getTargetInventory();
if (FirstGuiPreview.FIRST_GUI_CONTAINERS.containsKey(container) ||
SecondGuiPreview.SECOND_GUI_CONTAINERS.containsKey(container)) {
event.setCancelled(true);
}
}
示例5: manageClose
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
@Listener
public void manageClose(InteractInventoryEvent.Close event) {
Container container = event.getTargetInventory();
if (FirstGuiPreview.FIRST_GUI_CONTAINERS.containsKey(container)) {
FirstGuiPreview.FIRST_GUI_CONTAINERS.remove(container);
} else if (SecondGuiPreview.SECOND_GUI_CONTAINERS.containsKey(container)) {
SecondGuiPreview.SECOND_GUI_CONTAINERS.remove(container);
}
}
示例6: cancelClick
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void cancelClick(ClickInventoryEvent event) {
Container container = event.getTargetInventory();
if (FirstOpenManager.FIRST_GUI_CONTAINERS.containsKey(container)) {
event.setCancelled(true);
}
}
示例7: cancelClose
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
@Listener
public void cancelClose(InteractInventoryEvent.Close event) {
Container container = event.getTargetInventory();
if (!FirstOpenManager.SHOWN_GUI.contains(container) &&
FirstOpenManager.FIRST_GUI_CONTAINERS.containsKey(container) &&
FirstOpenManager.FIRST_GUI_CONTAINERS.get(container).getKey().isForbidClose()) {
event.setCancelled(true);
}
}
示例8: preview
import org.spongepowered.api.item.inventory.Container; //导入依赖的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());
}
示例9: DropChangeRunnable
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
public DropChangeRunnable(Player player, Container container, OrderedInventory ordered,
List<ItemStack> decorative_items,
DecorativeItemsChangeMode decorative_items_change_mode) {
this.player = player;
this.container = container;
this.ordered = ordered;
this.decorative_items = decorative_items;
this.decorative_items_change_mode = decorative_items_change_mode;
}
示例10: createOpenWindow
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
public static PacketOpenWindow createOpenWindow(Container container) {
net.minecraft.inventory.Container nativeContainer = ContainerUtil.toNative(container);
ITextComponent title = SpongeTexts.toComponent(container.getArchetype().getProperty(InventoryTitle.class).get().getValue());
return (PacketOpenWindow)new SPacketOpenWindow(
nativeContainer.windowId, container.getArchetype().getId(),
title, nativeContainer.inventorySlots.size());
}
示例11: createWindowItems
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
public static PacketSetSlot createWindowItems(Container container) {
net.minecraft.inventory.Container nativeContainer = ContainerUtil.toNative(container);
return (PacketSetSlot)new SPacketWindowItems(
nativeContainer.windowId,
nativeContainer.inventoryItemStacks);
}
示例12: clickInventory
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
/** return true to cancel the event in the parent */
static boolean clickInventory(Player source, int slot) {
//assume width of 9
// int column=slot%9, row=slot/9;
if (!VillagerShops.openShops.containsKey(source.getUniqueId())) {
// VillagerShops.l("No openShop");
return false;
}
Optional<NPCguard> shop = VillagerShops.getNPCfromShopUUID(VillagerShops.openShops.get(source.getUniqueId()));
if (!shop.isPresent()) {
// VillagerShops.l("No NPCguard");
return false;
}
int type = InvPrep.isSlotBuySell(slot);
int index = InvPrep.slotToIndex(slot);
if (type < 2) {
// stock.itemClicked(source, index, type);
shopItemClicked(shop.get(), source, index, type);
// ItemStack item = stock.getItem(index).getItem();
// source.sendMessage(Text.of("You ", type==0?"bought":"sold", " ", itemcount, " ", item.get(Keys.DISPLAY_NAME).orElse(Text.of(item.getItem().getTranslation()))));
Sponge.getScheduler().createSyncExecutor(VillagerShops.instance).schedule(()-> {
Optional<Container> stockinv = source.getOpenInventory();
if (stockinv.isPresent()) {
//is the first child (not clean coding, but working, so whatever)
shop.get().updateStock();
shop.get().getPreparator().updateInventory(stockinv.get().iterator().next(), source.getUniqueId());
}
},21,TimeUnit.MILLISECONDS);
}
return true;
}
示例13: open
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
@Override
public Container open(Player player, Cause cause) {
if(container != null) {
container.open(player, cause);
} else {
container = player.openInventory(inventory, cause)
.orElseThrow(() -> new IllegalStateException("Could not open the inventory."));
}
return container;
}
示例14: addContainer
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
public void addContainer(Container container) {
InventoryTracker.startTracking(container)
.on(ClickInventoryEvent.class,
slotFilter(slot -> slot.parent() == this.inventory.getAPIInventory(),
(slotTransaction, cursorTransaction) -> {
int slotNumber = ImplUtil.slotNumber(slotTransaction.getSlot());
if (slotNumber == 0) {
handleOutputClick(slotTransaction, cursorTransaction);
} else {
handleGridClick(slotTransaction, cursorTransaction);
}
}));
this.containers.add(container);
}
示例15: setOutput
import org.spongepowered.api.item.inventory.Container; //导入依赖的package包/类
private void setOutput(ItemStack stack) {
// System.out.println("Output: " + stack);
this.inventory.setStack(0, stack);
for (Container container : this.containers) {
ImplUtil.forceSlotUpdate(container, 0, stack);
}
}