本文整理汇总了Java中org.spongepowered.api.item.inventory.Slot类的典型用法代码示例。如果您正苦于以下问题:Java Slot类的具体用法?Java Slot怎么用?Java Slot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Slot类属于org.spongepowered.api.item.inventory包,在下文中一共展示了Slot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CachedInventory
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
public CachedInventory(Inventory inv) {
super(inv, false);
this.name = inv.getName().get();
this.capacity = inv.capacity();
this.totalItems = inv.totalItems();
this.type = new CachedCatalogType(inv.getArchetype());
items = new ArrayList<>();
try {
for (Inventory subInv : inv.slots()) {
Slot slot = (Slot) subInv;
Optional<ItemStack> optItem = slot.peek();
optItem.ifPresent(itemStack -> items.add(itemStack.copy()));
}
} catch (AbstractMethodError ignored) {}
}
示例2: onClickInventory
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
@Listener
public void onClickInventory(final ClickInventoryEvent event, @First Player player) {
//Make sure we have a transaction to validate
if (event.getTransactions().size() <= 0) {
return;
}
//Get the first transaction of this event
final SlotTransaction slotTransaction = event.getTransactions().get(0);
final Slot slot = slotTransaction.getSlot();
//If the player is interacting with a TileEntityCarrier
if (slot.parent() instanceof TileEntityCarrier) {
//If the final item is NONE (or amount is less) person is trying to withdraw (so we care about it)
if (slotTransaction.getFinal().getType() == ItemTypes.NONE || slotTransaction.getFinal().getCount() < slotTransaction.getOriginal().getCount()) {
//Then check to see if there's a lock
final Optional<Lock> lock = Latch.getLockManager().getLock(((TileEntityCarrier) slot.parent()).getLocation());
//If there's a donation lock the player CANNOT access
if (lock.isPresent() && lock.get().getLockType() == LockType.DONATION && !lock.get().canAccess(player.getUniqueId())) {
event.setCancelled(true);
}
}
}
}
示例3: getItemStack
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
public Optional<ItemStack> getItemStack() {
Optional<Slot> slot = getSlot();
if(slot.isPresent()) {
return slot.get().peek();
}
if(definition.isPersistent()) {
CustomInventoryData data = customInventoryDefinition.getCustomInventoryData(dataHolder);
String definitionId = definition.getId()
.orElseThrow(() -> new IllegalStateException("Could not access the ID of a persistent CustomSlot."));
return Optional.ofNullable(data.getSlotIdToItemStack().get(definitionId))
.map(ItemStackSnapshot::createStack);
}
return Optional.ofNullable(definition.createDefaultItemStack());
}
示例4: serialize
import org.spongepowered.api.item.inventory.Slot; //导入依赖的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);
}
示例5: handleCreativeClick
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
@Override
public void handleCreativeClick(ClientContainer clientContainer, @Nullable ClientSlot clientSlot, @Nullable ItemStack itemStack) {
final LanternPlayer player = clientContainer.getPlayer();
final CauseStack causeStack = CauseStack.current();
if (clientSlot == null) {
if (itemStack != null) {
causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
LanternEventHelper.handleDroppedItemSpawning(player.getTransform(), itemStack.createSnapshot());
}
} else if (clientSlot instanceof ClientSlot.Slot) {
final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
final PeekedSetTransactionResult result = slot.peekSet(itemStack);
// We do not know the remaining stack in the cursor,
// so just use none as new item
final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(
LanternItemStack.toSnapshot(itemStack), ItemStackSnapshot.NONE);
final ClickInventoryEvent.Creative event = SpongeEventFactory.createClickInventoryEventCreative(
causeStack.getCurrentCause(), cursorTransaction, this.container,
this.container.transformSlots(result.getTransactions()));
finishInventoryEvent(event);
}
}
示例6: bindSlot
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
protected ClientSlot.Slot bindSlot(int index, AbstractInventorySlot slot) {
populate();
final SlotClientSlot clientSlot = new SlotClientSlot(index, slot);
removeSlot(index);
if (index == CURSOR_SLOT_INDEX) {
this.cursor = clientSlot;
} else {
this.slots[index] = clientSlot;
}
this.slotMap.put(slot, clientSlot);
if (this.player != null) {
slot.addTracker(this);
}
queueSilentSlotChange(clientSlot);
return clientSlot;
}
示例7: canEnterWithItens
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
public boolean canEnterWithItens(Player p) {
if (!flagExists("allow-enter-items")){
return true;
}
if (checkAllowedPlayer(p)){
return true;
}
String[] items = flags.get("allow-enter-items").toString().replace(" ", "").split(",");
Iterable<Slot> SlotItems = p.getInventory().slots();
for (Slot slot:SlotItems) {
if (slot.peek().isPresent()) {
String SlotType = slot.peek().get().getItem().getName();
for (String comp:items){
if (SlotType.equalsIgnoreCase(comp)){
return true;
}
}
}
}
return false;
}
示例8: denyEnterWithItens
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
public boolean denyEnterWithItens(Player p) {
if (!flagExists("deny-enter-items")){
return true;
}
if (checkAllowedPlayer(p)){
return true;
}
Iterable<Slot> SlotItems = p.getInventory().slots();
String[] items = flags.get("deny-enter-items").toString().replace(" ", "").split(",");
for (Slot slot:SlotItems){
if (slot.peek().isPresent()) {
String SlotType = slot.peek().get().getItem().getName();
for (String comp:items){
if (SlotType.equalsIgnoreCase(comp)){
return false;
}
}
}
}
return true;
}
示例9: onItemPickup
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup event, @First(typeFilter = {Player.class}) Player player) {
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (character.isStub()) {
return;
}
if (player.get(Keys.GAME_MODE).get() != GameModes.SURVIVAL)
return;
for (SlotTransaction slotTransaction : event.getTransactions()) {
Slot i = slotTransaction.getSlot();
int index = ((SlotAdapter) i).getOrdinal();
if (Utils.isHotbar(index)) {
ItemStack a = slotTransaction.getFinal().createStack();
if (inventoryService.canUse(a, character) != CannotUseItemReson.OK) {
event.setCancelled(true);
return;
} else {
inventoryService.initializeHotbar(character, index, a);
}
}
}
}
示例10: clear
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public int clear(int id, int data) {
int removed = 0;
for (Slot slot : this.getHandle().<Slot>slots()) {
Optional<org.spongepowered.api.item.inventory.ItemStack> stackOptional = slot.peek();
if (stackOptional.isPresent()) {
org.spongepowered.api.item.inventory.ItemStack stack = stackOptional.get();
if (id == -1 || stack.getItem() == MaterialConverter.asItem(Material.getMaterial(id))) {
int damage = DurabilityConverter.getDamageValue(stack.getContainers());
if (data == -1 || damage == data) {
removed += stack.getQuantity();
slot.clear();
}
}
}
}
return removed;
}
示例11: updateInventory
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
public void updateInventory(Inventory inv, boolean forceUpdate){
if (inv instanceof Slot) {
updateItem((Slot) inv, inv, forceUpdate);
} else if (inv instanceof GridInventory){
inv.slots().forEach(i -> {
if (i instanceof Slot){
updateItem((Slot) i, inv, forceUpdate);
}
});
} else {
for (Inventory child : inv){
updateInventory(child, forceUpdate);
}
}
}
示例12: countItems
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
public int countItems(Inventory i, ItemType type){
int count = 0;
for (Inventory isl : i.query(QueryOperationTypes.ITEM_TYPE.of(type)).slots()){
Slot sl = (Slot) isl;
Optional<ItemStack> ois = sl.peek();
if (ois.isPresent()){
count += ois.get().getQuantity();
}
}
return count;
}
示例13: getSlotOrdinal
import org.spongepowered.api.item.inventory.Slot; //导入依赖的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();
}
示例14: commandRepairHotBar
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
private CompletableFuture<Boolean> commandRepairHotBar(final EPlayer player) {
UtilsInventory.repair(player.getInventory().query(Hotbar.class));
UtilsInventory.repair(player.getInventory().query(Slot.class));
EEMessages.REPAIR_HOTBAR_PLAYER.sendTo(player);
return CompletableFuture.completedFuture(true);
}
示例15: commandRepairAll
import org.spongepowered.api.item.inventory.Slot; //导入依赖的package包/类
private CompletableFuture<Boolean> commandRepairAll(final EPlayer player) {
UtilsInventory.repair(player.getInventory().query(Hotbar.class));
UtilsInventory.repair(player.getInventory().query(GridInventory.class));
UtilsInventory.repair(player.getInventory().query(EquipmentInventory.class));
UtilsInventory.repair(player.getInventory().query(Slot.class));
EEMessages.REPAIR_ALL_PLAYER.sendTo(player);
return CompletableFuture.completedFuture(true);
}