Search in sources :

Example 11 with LanternItemStack

use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.

the class ProcessorPlayOutParticleEffect method preProcess.

private ICachedMessage preProcess(ParticleEffect effect0) {
    final LanternParticleEffect effect = (LanternParticleEffect) effect0;
    final LanternParticleType type = effect.getType();
    final OptionalInt internalType = type.getInternalType();
    // Special cases
    if (!internalType.isPresent()) {
        if (type == ParticleTypes.FIREWORKS) {
            // Create the fireworks data item
            final LanternItemStack itemStack = new LanternItemStack(ItemTypes.FIREWORKS);
            itemStack.tryOffer(Keys.FIREWORK_EFFECTS, effect.getOptionOrDefault(ParticleOptions.FIREWORK_EFFECTS).get());
            // Write the item to a parameter list
            final ByteBufParameterList parameterList = new ByteBufParameterList(ByteBufferAllocator.unpooled());
            parameterList.add(EntityParameters.Fireworks.ITEM, itemStack);
            return new CachedFireworksMessage(new MessagePlayOutEntityMetadata(CachedFireworksMessage.ENTITY_ID, parameterList));
        } else if (type == ParticleTypes.FERTILIZER) {
            final int quantity = effect.getOptionOrDefault(ParticleOptions.QUANTITY).get();
            return new CachedEffectMessage(2005, quantity, false);
        } else if (type == ParticleTypes.SPLASH_POTION) {
            final int potionId = this.potionEffectTypeToId.getInt(effect.getOptionOrDefault(ParticleOptions.POTION_EFFECT_TYPE).get());
            return new CachedEffectMessage(2002, potionId, false);
        } else if (type == ParticleTypes.BREAK_BLOCK) {
            final int state = getBlockState(effect, type.getDefaultOption(ParticleOptions.BLOCK_STATE));
            if (state == 0) {
                return EmptyCachedMessage.INSTANCE;
            }
            return new CachedEffectMessage(2001, state, false);
        } else if (type == ParticleTypes.MOBSPAWNER_FLAMES) {
            return new CachedEffectMessage(2004, 0, false);
        } else if (type == ParticleTypes.ENDER_TELEPORT) {
            return new CachedEffectMessage(2003, 0, false);
        } else if (type == ParticleTypes.DRAGON_BREATH_ATTACK) {
            return new CachedEffectMessage(2006, 0, false);
        } else if (type == ParticleTypes.FIRE_SMOKE) {
            final Direction direction = effect.getOptionOrDefault(ParticleOptions.DIRECTION).get();
            return new CachedEffectMessage(2000, getDirectionData(direction), false);
        }
        return EmptyCachedMessage.INSTANCE;
    }
    final int internalId = internalType.getAsInt();
    final Vector3f offset = effect.getOption(ParticleOptions.OFFSET).map(Vector3d::toFloat).orElse(Vector3f.ZERO);
    final int quantity = effect.getOption(ParticleOptions.QUANTITY).orElse(1);
    int[] extra = null;
    // The extra values, normal behavior offsetX, offsetY, offsetZ
    double f0 = 0f;
    double f1 = 0f;
    double f2 = 0f;
    // Depends on behavior
    // Note: If the count > 0 -> speed = 0f else if count = 0 -> speed = 1f
    final Optional<BlockState> defaultBlockState;
    if (type != ParticleTypes.ITEM_CRACK && (defaultBlockState = type.getDefaultOption(ParticleOptions.BLOCK_STATE)).isPresent()) {
        final int state = getBlockState(effect, defaultBlockState);
        if (state == 0) {
            return EmptyCachedMessage.INSTANCE;
        }
        extra = new int[] { state };
    }
    final Optional<ItemStackSnapshot> defaultItemStackSnapshot;
    if (extra == null && (defaultItemStackSnapshot = type.getDefaultOption(ParticleOptions.ITEM_STACK_SNAPSHOT)).isPresent()) {
        final Optional<ItemStackSnapshot> optItemStackSnapshot = effect.getOption(ParticleOptions.ITEM_STACK_SNAPSHOT);
        if (optItemStackSnapshot.isPresent()) {
            extra = toExtraItemData(optItemStackSnapshot.get().createStack());
        } else {
            final Optional<BlockState> optBlockState = effect.getOption(ParticleOptions.BLOCK_STATE);
            if (optBlockState.isPresent()) {
                final BlockState blockState = optBlockState.get();
                final Optional<ItemType> optItemType = blockState.getType().getItem();
                if (optItemType.isPresent()) {
                    // TODO: Item damage value
                    extra = new int[] { ItemRegistryModule.get().getInternalId(optItemType.get()), 0 };
                } else {
                    return EmptyCachedMessage.INSTANCE;
                }
            } else {
                extra = toExtraItemData(defaultItemStackSnapshot.get().createStack());
            }
        }
    }
    if (extra == null) {
        extra = new int[0];
    }
    final Optional<Double> defaultScale = type.getDefaultOption(ParticleOptions.SCALE);
    final Optional<Color> defaultColor;
    final Optional<NotePitch> defaultNote;
    final Optional<Vector3d> defaultVelocity;
    if (defaultScale.isPresent()) {
        double scale = effect.getOption(ParticleOptions.SCALE).orElse(defaultScale.get());
        // Server formula: sizeServer = (-sizeClient * 2) + 2
        if (type == ParticleTypes.LARGE_EXPLOSION || type == ParticleTypes.SWEEP_ATTACK) {
            scale = (-scale * 2f) + 2f;
        }
        if (scale == 0f) {
            return new CachedParticleMessage(internalId, offset, quantity, extra);
        }
        f0 = scale;
    } else if ((defaultColor = type.getDefaultOption(ParticleOptions.COLOR)).isPresent()) {
        final boolean isSpell = type == ParticleTypes.MOB_SPELL || type == ParticleTypes.AMBIENT_MOB_SPELL;
        Color color = effect.getOption(ParticleOptions.COLOR).orElse(null);
        if (!isSpell && (color == null || color.equals(defaultColor.get()))) {
            return new CachedParticleMessage(internalId, offset, quantity, extra);
        } else if (isSpell && color == null) {
            color = defaultColor.get();
        }
        f0 = color.getRed() / 255f;
        f1 = color.getGreen() / 255f;
        f2 = color.getBlue() / 255f;
        // but we already chose for the color, can't have both
        if (isSpell) {
            f0 = Math.max(f0, 0.001f);
            f2 = Math.max(f0, 0.001f);
        }
        // If the f0 value 0 is, the redstone will set it automatically to red 255
        if (f0 == 0f && type == ParticleTypes.REDSTONE_DUST) {
            f0 = 0.00001f;
        }
    } else if ((defaultNote = type.getDefaultOption(ParticleOptions.NOTE)).isPresent()) {
        final NotePitch notePitch = effect.getOption(ParticleOptions.NOTE).orElse(defaultNote.get());
        final float note = ((LanternNotePitch) notePitch).getInternalId();
        if (note == 0f) {
            return new CachedParticleMessage(internalId, offset, quantity, extra);
        }
        f0 = note / 24f;
    } else if ((defaultVelocity = type.getDefaultOption(ParticleOptions.VELOCITY)).isPresent()) {
        final Vector3d velocity = effect.getOption(ParticleOptions.VELOCITY).orElse(defaultVelocity.get());
        f0 = velocity.getX();
        f1 = velocity.getY();
        f2 = velocity.getZ();
        final Optional<Boolean> slowHorizontalVelocity = type.getDefaultOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY);
        if (slowHorizontalVelocity.isPresent() && effect.getOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY).orElse(slowHorizontalVelocity.get())) {
            f0 = 0f;
            f2 = 0f;
        }
        // The y value won't work for this effect, if the value isn't 0 the velocity won't work
        if (type == ParticleTypes.WATER_SPLASH) {
            f1 = 0f;
        }
        if (f0 == 0f && f1 == 0f && f2 == 0f) {
            return new CachedParticleMessage(internalId, offset, quantity, extra);
        }
    }
    // Is this check necessary?
    if (f0 == 0f && f1 == 0f && f2 == 0f) {
        return new CachedParticleMessage(internalId, offset, quantity, extra);
    }
    return new CachedOffsetParticleMessage(internalId, new Vector3f(f0, f1, f2), offset, quantity, extra);
}
Also used : ItemType(org.spongepowered.api.item.ItemType) LanternParticleEffect(org.lanternpowered.server.effect.particle.LanternParticleEffect) Direction(org.spongepowered.api.util.Direction) NotePitch(org.spongepowered.api.data.type.NotePitch) LanternNotePitch(org.lanternpowered.server.data.type.LanternNotePitch) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) Optional(java.util.Optional) Color(org.spongepowered.api.util.Color) OptionalInt(java.util.OptionalInt) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternNotePitch(org.lanternpowered.server.data.type.LanternNotePitch) BlockState(org.spongepowered.api.block.BlockState) Vector3d(com.flowpowered.math.vector.Vector3d) Vector3f(com.flowpowered.math.vector.Vector3f) MessagePlayOutEntityMetadata(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternParticleType(org.lanternpowered.server.effect.particle.LanternParticleType)

Example 12 with LanternItemStack

use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.

the class ProcessorPlayOutParticleEffect method toExtraItemData.

private static int[] toExtraItemData(ItemStack itemStack) {
    final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class).get();
    final DataContainer view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    store.serialize((LanternItemStack) itemStack, view);
    final int data = view.getInt(ItemStackStore.DATA).get();
    final int internalId = ItemRegistryModule.get().getInternalId(itemStack.getType());
    return new int[] { internalId, data };
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Example 13 with LanternItemStack

use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.

the class CommandOpenTestContainer method createCustomPotion.

private static ItemStack createCustomPotion(String name, Color color, PotionEffect... potionEffects) {
    final LanternItemStack itemStack = new LanternItemStack(ItemTypes.POTION, 1);
    itemStack.offer(LanternKeys.POTION_TYPE, PotionTypes.EMPTY);
    itemStack.offer(Keys.POTION_EFFECTS, ImmutableList.copyOf(potionEffects));
    itemStack.offer(Keys.DISPLAY_NAME, Text.of(TextColors.RESET, name));
    itemStack.offer(Keys.COLOR, color);
    return itemStack;
}
Also used : LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Example 14 with LanternItemStack

use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleClick.

@Override
public void handleClick(ClientContainer clientContainer, @Nullable ClientSlot clientSlot, MouseButton mouseButton) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null) || (clientSlot != null && !(clientSlot instanceof ClientSlot.Slot))) {
        return;
    }
    final CauseStack causeStack = CauseStack.current();
    if (clientSlot == null) {
        causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
        final List<Entity> entities = new ArrayList<>();
        final Transaction<ItemStackSnapshot> cursorTransaction;
        // Clicking outside the container
        ItemStackSnapshot oldItem = ItemStackSnapshot.NONE;
        ItemStackSnapshot newItem = ItemStackSnapshot.NONE;
        if (getCursorItem() != null) {
            oldItem = getCursorItem().createSnapshot();
            final ItemStackSnapshot droppedItem;
            if (mouseButton != MouseButton.LEFT) {
                final ItemStack stack = getCursorItem().copy();
                stack.setQuantity(stack.getQuantity() - 1);
                newItem = LanternItemStack.toSnapshot(stack);
                stack.setQuantity(1);
                droppedItem = LanternItemStack.toSnapshot(stack);
            } else {
                droppedItem = oldItem;
            }
            LanternEventHelper.handlePreDroppedItemSpawning(player.getTransform(), droppedItem).ifPresent(entities::add);
        }
        cursorTransaction = new Transaction<>(oldItem, newItem);
        final ClickInventoryEvent.Drop event;
        if (mouseButton == MouseButton.LEFT) {
            event = SpongeEventFactory.createClickInventoryEventDropOutsidePrimary(causeStack.getCurrentCause(), cursorTransaction, entities, this.container, new ArrayList<>());
        } else {
            event = SpongeEventFactory.createClickInventoryEventDropOutsideSecondary(causeStack.getCurrentCause(), cursorTransaction, entities, this.container, new ArrayList<>());
        }
        finishInventoryEvent(event);
        return;
    }
    // Clicking inside the container
    final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
    if (mouseButton == MouseButton.MIDDLE) {
        final ItemStackSnapshot oldItem = LanternItemStack.toSnapshot(getCursorItem());
        Transaction<ItemStackSnapshot> cursorTransaction = null;
        final Optional<GameMode> gameMode = player.get(Keys.GAME_MODE);
        if (gameMode.isPresent() && gameMode.get().equals(GameModes.CREATIVE) && getCursorItem() == null) {
            final ItemStack stack = slot.peek().orElse(null);
            if (stack != null) {
                stack.setQuantity(stack.getMaxStackQuantity());
                cursorTransaction = new Transaction<>(oldItem, stack.createSnapshot());
            }
        }
        if (cursorTransaction == null) {
            cursorTransaction = new Transaction<>(oldItem, oldItem);
        }
        final ClickInventoryEvent.Middle event = SpongeEventFactory.createClickInventoryEventMiddle(causeStack.getCurrentCause(), cursorTransaction, this.container, new ArrayList<>());
        finishInventoryEvent(event);
    } else {
        // Crafting slots have special click behavior
        if (slot instanceof CraftingOutput) {
            List<SlotTransaction> transactions = new ArrayList<>();
            Transaction<ItemStackSnapshot> cursorTransaction;
            final AbstractInventory parent = slot.parent();
            if (parent instanceof CraftingInventory) {
                ClickInventoryEvent event;
                final CraftingInventory inventory = (CraftingInventory) parent;
                final Optional<ExtendedCraftingResult> optResult = Lantern.getRegistry().getCraftingRecipeRegistry().getExtendedResult(inventory.getCraftingGrid(), player.getWorld());
                final ItemStackSnapshot originalCursorItem = LanternItemStack.toSnapshot(getCursorItem());
                if (optResult.isPresent()) {
                    final CraftingResult result = optResult.get().getResult();
                    final ItemStackSnapshot resultItem = result.getResult();
                    int quantity = -1;
                    if (getCursorItem() == null) {
                        quantity = resultItem.getQuantity();
                    } else if (LanternItemStack.areSimilar(resultItem.createStack(), getCursorItem())) {
                        final int quantity1 = resultItem.getQuantity() + getCursorItem().getQuantity();
                        if (quantity1 < getCursorItem().getMaxStackQuantity()) {
                            quantity = quantity1;
                        }
                    }
                    if (quantity == -1) {
                        cursorTransaction = new Transaction<>(originalCursorItem, originalCursorItem);
                        transactions.add(new SlotTransaction(slot, resultItem, resultItem));
                    } else {
                        final LanternItemStack itemStack = (LanternItemStack) resultItem.createStack();
                        itemStack.setQuantity(quantity);
                        cursorTransaction = new Transaction<>(originalCursorItem, itemStack.createSnapshot());
                        transactions.add(new SlotTransaction(slot, resultItem, ItemStackSnapshot.NONE));
                        updateCraftingGrid(player, inventory, optResult.get().getMatrixResult(1), transactions);
                    }
                } else {
                    cursorTransaction = new Transaction<>(originalCursorItem, originalCursorItem);
                    // No actual transaction, there shouldn't have been a item in the crafting result slot
                    transactions.add(new SlotTransaction(slot, ItemStackSnapshot.NONE, ItemStackSnapshot.NONE));
                }
                transactions = this.container.transformSlots(transactions);
                if (mouseButton == MouseButton.LEFT) {
                    event = SpongeEventFactory.createClickInventoryEventPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions);
                } else {
                    event = SpongeEventFactory.createClickInventoryEventSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions);
                }
                finishInventoryEvent(event);
                return;
            } else {
                Lantern.getLogger().warn("Found a CraftingOutput slot without a CraftingInventory as parent.");
            }
        }
        ClickInventoryEvent event;
        if (mouseButton == MouseButton.LEFT) {
            final List<SlotTransaction> transactions = new ArrayList<>();
            Transaction<ItemStackSnapshot> cursorTransaction = null;
            if (getCursorItem() != null && !(slot instanceof OutputSlot)) {
                final PeekedOfferTransactionResult result = slot.peekOffer(getCursorItem());
                if (result.isSuccess()) {
                    transactions.addAll(result.getTransactions());
                    cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), LanternItemStack.toSnapshot(result.getRejectedItem().orElse(null)));
                } else {
                    final PeekedSetTransactionResult result1 = slot.peekSet(getCursorItem());
                    if (result1.isSuccess()) {
                        cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), LanternItemStack.toSnapshot(result1.getReplacedItem().orElse(null)));
                        transactions.addAll(result1.getTransactions());
                    }
                }
            } else if (getCursorItem() == null) {
                final PeekedPollTransactionResult result = slot.peekPoll(stack -> true).orElse(null);
                if (result != null) {
                    cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, LanternItemStack.toSnapshot(result.getPolledItem()));
                    transactions.addAll(result.getTransactions());
                } else {
                    cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, ItemStackSnapshot.NONE);
                }
            }
            if (cursorTransaction == null) {
                final ItemStackSnapshot cursorItem = LanternItemStack.toSnapshot(getCursorItem());
                cursorTransaction = new Transaction<>(cursorItem, cursorItem);
            }
            event = SpongeEventFactory.createClickInventoryEventPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
        } else {
            final List<SlotTransaction> transactions = new ArrayList<>();
            Transaction<ItemStackSnapshot> cursorTransaction = null;
            if (getCursorItem() == null) {
                int stackSize = slot.getStackSize();
                if (stackSize != 0) {
                    stackSize = stackSize - (stackSize / 2);
                    final PeekedPollTransactionResult result = slot.peekPoll(stackSize, stack -> true).get();
                    transactions.addAll(result.getTransactions());
                    cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, result.getPolledItem().createSnapshot());
                }
            } else {
                final ItemStack itemStack = getCursorItem().copy();
                itemStack.setQuantity(1);
                final PeekedOfferTransactionResult result = slot.peekOffer(itemStack);
                if (result.isSuccess()) {
                    final ItemStackSnapshot oldCursor = getCursorItem().createSnapshot();
                    int quantity = getCursorItem().getQuantity() - 1;
                    if (quantity <= 0) {
                        cursorTransaction = new Transaction<>(oldCursor, ItemStackSnapshot.NONE);
                    } else {
                        final ItemStack newCursorItem = getCursorItem().copy();
                        newCursorItem.setQuantity(quantity);
                        cursorTransaction = new Transaction<>(oldCursor, newCursorItem.createSnapshot());
                    }
                    transactions.addAll(result.getTransactions());
                } else {
                    final PeekedSetTransactionResult result1 = slot.peekSet(getCursorItem());
                    if (result1.isSuccess()) {
                        final ItemStack replacedItem = result1.getReplacedItem().orElse(null);
                        if (replacedItem != null) {
                            setCursorItem(replacedItem);
                            cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), LanternItemStack.toSnapshot(replacedItem));
                        } else {
                            cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), ItemStackSnapshot.NONE);
                        }
                        transactions.addAll(result1.getTransactions());
                    }
                }
            }
            if (cursorTransaction == null) {
                final ItemStackSnapshot cursorItem = LanternItemStack.toSnapshot(getCursorItem());
                cursorTransaction = new Transaction<>(cursorItem, cursorItem);
            }
            event = SpongeEventFactory.createClickInventoryEventSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
        }
        finishInventoryEvent(event);
    }
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) Entity(org.spongepowered.api.entity.Entity) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) ArrayList(java.util.ArrayList) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) CauseStack(org.lanternpowered.server.event.CauseStack) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 15 with LanternItemStack

use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.

the class InventorySnapshotSerializer method serialize.

public static List<DataView> serialize(InventorySnapshot inventorySnapshot) {
    final ObjectSerializer<LanternItemStack> itemStackSerializer = ObjectSerializerRegistry.get().get(LanternItemStack.class).get();
    final List<DataView> itemViews = new ArrayList<>();
    for (Int2ObjectMap.Entry<ItemStackSnapshot> entry : inventorySnapshot.getItemStackSnapshots().int2ObjectEntrySet()) {
        final DataView itemView = itemStackSerializer.serialize((LanternItemStack) entry.getValue().createStack());
        // noinspection ConstantConditions
        itemView.set(SLOT, (byte) entry.getIntKey());
        itemViews.add(itemView);
    }
    return itemViews;
}
Also used : DataView(org.spongepowered.api.data.DataView) ArrayList(java.util.ArrayList) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Aggregations

LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)23 DataView (org.spongepowered.api.data.DataView)9 ItemStack (org.spongepowered.api.item.inventory.ItemStack)8 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)7 ArrayList (java.util.ArrayList)5 Optional (java.util.Optional)5 AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)5 SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)5 Sponge (org.spongepowered.api.Sponge)4 ItemType (org.spongepowered.api.item.ItemType)4 Slot (org.spongepowered.api.item.inventory.Slot)4 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 Nullable (javax.annotation.Nullable)3 Lantern (org.lanternpowered.server.game.Lantern)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 Streams (com.google.common.collect.Streams)2 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 List (java.util.List)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2