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;
}
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();
});
}
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());
}
}
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);
}
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);
}
Aggregations