Search in sources :

Example 1 with LanternItemStack

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

the class CommandOpenTestContainer method createShulkerBox.

private static ItemStack createShulkerBox() {
    final ChestInventory inventory = VanillaInventoryArchetypes.CHEST.build();
    inventory.offer(new LanternItemStack(BlockTypes.REDSTONE_BLOCK, 64));
    inventory.offer(new LanternItemStack(BlockTypes.HOPPER, 64));
    // Create the pumpkin stacks
    LanternItemStack itemStack = new LanternItemStack(BlockTypes.LIT_PUMPKIN, 20);
    inventory.offer(itemStack);
    // Create the shulker box
    itemStack = new LanternItemStack(BlockTypes.BLACK_SHULKER_BOX);
    itemStack.tryOffer(LanternKeys.INVENTORY_SNAPSHOT, InventorySnapshot.ofInventory(inventory));
    return itemStack;
}
Also used : ChestInventory(org.lanternpowered.server.inventory.vanilla.block.ChestInventory) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Example 2 with LanternItemStack

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

the class CommandOpenTestContainer method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.executor((src, args) -> {
        if (!(src instanceof Player)) {
            throw new CommandException(t("Only players may use this command."));
        }
        final ChestInventory inventory = VanillaInventoryArchetypes.CHEST.build();
        /*
                    inventory.offer(new LanternItemStack(BlockTypes.BEDROCK, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.GLASS, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.STONE, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.SAND, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.DIRT, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.GRASS, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.PLANKS, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.LOG, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.LOG2, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.SAPLING, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.STONE_SLAB, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.STONE_SLAB2, 64));
                    inventory.offer(new LanternItemStack(BlockTypes.ENDER_CHEST, 5));
                    inventory.offer(new LanternItemStack(BlockTypes.CHEST, 5));
                    */
        inventory.offer(createShulkerBox());
        LanternItemStack itemStack = new LanternItemStack(ItemTypes.COAL, 51);
        itemStack.offer(Keys.COAL_TYPE, CoalTypes.CHARCOAL);
        inventory.offer(itemStack.copy());
        itemStack.offer(Keys.DISPLAY_NAME, Text.of("Awesome Charcoal"));
        itemStack.offer(Keys.ITEM_ENCHANTMENTS, Collections.singletonList(Enchantment.of(EnchantmentTypes.POWER, 2)));
        inventory.offer(itemStack);
        itemStack = new LanternItemStack(ItemTypes.LOG, 64);
        itemStack.offer(Keys.TREE_TYPE, TreeTypes.JUNGLE);
        inventory.offer(itemStack);
        // Custom potions
        inventory.offer(createCustomPotion("Potion of Glowing", Color.ofRgb(245, 255, 68), PotionEffect.of(PotionEffectTypes.GLOWING, 0, 500)));
        inventory.offer(createCustomPotion("Potion of Bad Luck", Color.ofRgb(130, 91, 55), PotionEffect.of(PotionEffectTypes.UNLUCK, 0, 500)));
        inventory.offer(createCustomPotion("Potion of Invisibility", Color.ofRgb(120, 255, 68), PotionEffect.of(PotionEffectTypes.INVISIBILITY, 0, 500)));
        inventory.offer(createCustomPotion("Potion of Levitation", Color.ofRgb(120, 255, 68), PotionEffect.of(PotionEffectTypes.LEVITATION, 0, 500)));
        inventory.offer(createCustomPotion("Potion of Negative Levitation", Color.ofRgb(120, 255, 68), PotionEffect.of(PotionEffectTypes.LEVITATION, -5, 500)));
        inventory.offer(createCustomPotion("Potion of Negative Levitation", Color.ofRgb(120, 255, 68), PotionEffect.of(PotionEffectTypes.LEVITATION, -10, 500)));
        ((Player) src).openInventory(inventory);
        return CommandResult.success();
    });
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ChestInventory(org.lanternpowered.server.inventory.vanilla.block.ChestInventory) CommandException(org.spongepowered.api.command.CommandException) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Example 3 with LanternItemStack

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

the class LanternTextHelper method raw.

public static RawAction raw(HoverAction<?> hoverAction) {
    if (hoverAction instanceof HoverAction.ShowText) {
        return new RawAction("show_text", ((HoverAction.ShowText) hoverAction).getResult());
    } else if (hoverAction instanceof HoverAction.ShowEntity) {
        final HoverAction.ShowEntity.Ref ref = ((HoverAction.ShowEntity) hoverAction).getResult();
        final DataContainer dataContainer = DataContainer.createNew().set(SHOW_ENTITY_ID, ref.getUniqueId().toString()).set(SHOW_ENTITY_NAME, ref.getName());
        ref.getType().ifPresent(type -> dataContainer.set(SHOW_ENTITY_TYPE, type.getId()));
        try {
            return new RawAction("show_entity", JsonDataFormat.writeAsString(dataContainer));
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    } else if (hoverAction instanceof HoverAction.ShowItem) {
        final ItemStackSnapshot itemStackSnapshot = ((HoverAction.ShowItem) hoverAction).getResult();
        final LanternItemStack itemStack = (LanternItemStack) itemStackSnapshot.createStack();
        final DataView dataView = ItemStackStore.INSTANCE.serialize(itemStack);
        try {
            return new RawAction("show_item", JsonDataFormat.writeAsString(dataView));
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    } else {
        throw new IllegalArgumentException("Unknown hover action type: " + hoverAction.getClass().getName());
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) ClickAction(org.spongepowered.api.text.action.ClickAction) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStackStore(org.lanternpowered.server.data.io.store.item.ItemStackStore) DataQuery(org.spongepowered.api.data.DataQuery) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Matcher(java.util.regex.Matcher) Text(org.spongepowered.api.text.Text) Gson(com.google.gson.Gson) HoverAction(org.spongepowered.api.text.action.HoverAction) URI(java.net.URI) LanternClickActionCallbacks(org.lanternpowered.server.text.action.LanternClickActionCallbacks) Nullable(javax.annotation.Nullable) TextActions(org.spongepowered.api.text.action.TextActions) CommandSource(org.spongepowered.api.command.CommandSource) MalformedURLException(java.net.MalformedURLException) Sponge(org.spongepowered.api.Sponge) DataContainer(org.spongepowered.api.data.DataContainer) IOException(java.io.IOException) UUID(java.util.UUID) JsonDataFormat(org.lanternpowered.server.data.persistence.json.JsonDataFormat) File(java.io.File) Consumer(java.util.function.Consumer) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) DataView(org.spongepowered.api.data.DataView) Coerce(org.spongepowered.api.util.Coerce) EntityType(org.spongepowered.api.entity.EntityType) Optional(java.util.Optional) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) IOException(java.io.IOException) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) HoverAction(org.spongepowered.api.text.action.HoverAction) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Example 4 with LanternItemStack

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

the class InventorySnapshotSerializer method deserialize.

public static InventorySnapshot deserialize(List<DataView> itemDataViews) {
    final ObjectSerializer<LanternItemStack> itemStackSerializer = ObjectSerializerRegistry.get().get(LanternItemStack.class).get();
    final Int2ObjectMap<ItemStackSnapshot> itemsByIndex = new Int2ObjectOpenHashMap<>();
    for (DataView itemDataView : itemDataViews) {
        final int slot = itemDataView.getByte(SLOT).get() & 0xff;
        final ItemStackSnapshot itemStackSnapshot = itemStackSerializer.deserialize(itemDataView).createSnapshot();
        itemsByIndex.put(slot, itemStackSnapshot);
    }
    return InventorySnapshot.ofRawMap(itemsByIndex);
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) DataView(org.spongepowered.api.data.DataView) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Example 5 with LanternItemStack

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

the class UserStore method serializeSlot.

private static void serializeSlot(int index, Slot slot, ObjectSerializer<LanternItemStack> itemStackSerializer, List<DataView> views) {
    final Optional<ItemStack> optItemStack = slot.peek();
    if (!optItemStack.isPresent()) {
        return;
    }
    final ItemStack itemStack = optItemStack.get();
    final DataView itemView = itemStackSerializer.serialize((LanternItemStack) itemStack);
    itemView.set(SLOT, (byte) index);
    views.add(itemView);
}
Also used : DataView(org.spongepowered.api.data.DataView) ItemStack(org.spongepowered.api.item.inventory.ItemStack) 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