Search in sources :

Example 21 with LanternItemStack

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

the class CommandParticleEffect method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.catalogedElement(Text.of("type"), ParticleType.class), GenericArguments.vector3d(Text.of("position")), GenericArguments.optional(GenericArguments.world(Text.of("world"))), // TODO: Tab complaining is currently throwing errors, but it's a small bug in SpongeAPI
    GenericArguments.flags().valueFlag(GenericArguments.integer(Text.of("quantity")), "-quantity", "q").valueFlag(GenericArguments.vector3d(Text.of("offset")), "-offset", "o").valueFlag(GenericArguments.vector3d(Text.of("velocity")), "-velocity", "v").valueFlag(GenericArguments.vector3d(Text.of("color")), "-color", "c").valueFlag(GenericArguments.doubleNum(Text.of("scale")), "-scale", "s").valueFlag(GenericArguments.catalogedElement(Text.of("note"), NotePitch.class), "-note", "n").valueFlag(GenericArguments.catalogedElement(Text.of("block"), BlockState.class), "-block", "b").valueFlag(GenericArguments.catalogedElement(Text.of("item"), ItemType.class), "-item", "i").valueFlag(GenericArguments.catalogedElement(Text.of("potion"), PotionEffectType.class), "-potion", "p").buildWith(GenericArguments.none())).executor((src, args) -> {
        final ParticleType particleType = args.<ParticleType>getOne("type").get();
        final Vector3d position = args.<Vector3d>getOne("position").get();
        final World world = args.<WorldProperties>getOne("world").map(props -> Sponge.getServer().getWorld(props.getUniqueId()).get()).orElseGet(((Locatable) src)::getWorld);
        final ParticleEffect.Builder builder = ParticleEffect.builder().type(particleType);
        args.<Integer>getOne("quantity").ifPresent(builder::quantity);
        args.<Vector3d>getOne("offset").ifPresent(builder::offset);
        args.<Vector3d>getOne("velocity").ifPresent(builder::velocity);
        args.<Vector3d>getOne("color").ifPresent(color -> builder.option(ParticleOptions.COLOR, Color.of(color.toInt())));
        args.<NotePitch>getOne("note").ifPresent(note -> builder.option(ParticleOptions.NOTE, note));
        args.<Double>getOne("scale").ifPresent(scale -> builder.option(ParticleOptions.SCALE, scale));
        args.<BlockState>getOne("block").ifPresent(blockState -> builder.option(ParticleOptions.BLOCK_STATE, blockState));
        args.<ItemType>getOne("item").ifPresent(item -> builder.option(ParticleOptions.ITEM_STACK_SNAPSHOT, new LanternItemStack(item).createSnapshot()));
        args.<PotionEffectType>getOne("potion").ifPresent(type -> builder.option(ParticleOptions.POTION_EFFECT_TYPE, type));
        world.spawnParticles(builder.build(), position);
        src.sendMessage(t("Successfully spawned the particle %s", particleType.getName()));
        return CommandResult.success();
    });
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) ParticleOptions(org.spongepowered.api.effect.particle.ParticleOptions) BlockTypes(org.spongepowered.api.block.BlockTypes) Sponge(org.spongepowered.api.Sponge) Vector3d(com.flowpowered.math.vector.Vector3d) GenericArguments(org.spongepowered.api.command.args.GenericArguments) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) BlockState(org.spongepowered.api.block.BlockState) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) ParticleType(org.spongepowered.api.effect.particle.ParticleType) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) Locatable(org.spongepowered.api.world.Locatable) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) NotePitch(org.spongepowered.api.data.type.NotePitch) Color(org.spongepowered.api.util.Color) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ItemType(org.spongepowered.api.item.ItemType) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Vector3d(com.flowpowered.math.vector.Vector3d) ItemType(org.spongepowered.api.item.ItemType) ParticleType(org.spongepowered.api.effect.particle.ParticleType) World(org.spongepowered.api.world.World) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) NotePitch(org.spongepowered.api.data.type.NotePitch)

Example 22 with LanternItemStack

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

the class PlayerEntityProtocol method update.

@Override
protected void update(EntityProtocolUpdateContext context) {
    final GameMode gameMode = this.entity.get(Keys.GAME_MODE).get();
    final boolean canFly = canFly();
    final float flySpeed = getFlySpeed();
    final float fieldOfView = getFovModifier();
    if (gameMode != this.lastGameMode) {
        context.sendToSelf(() -> new MessagePlayOutSetGameMode((LanternGameMode) gameMode));
        context.sendToSelf(() -> new MessagePlayOutPlayerAbilities(this.entity.get(Keys.IS_FLYING).orElse(false), canFly, false, gameMode == GameModes.CREATIVE, flySpeed, fieldOfView));
        this.lastGameMode = gameMode;
        this.lastCanFly = canFly;
        this.lastFlySpeed = flySpeed;
        this.lastFieldOfView = fieldOfView;
    } else if (canFly != this.lastCanFly || flySpeed != this.lastFlySpeed || fieldOfView != this.lastFieldOfView) {
        context.sendToSelf(() -> new MessagePlayOutPlayerAbilities(this.entity.get(Keys.IS_FLYING).orElse(false), canFly, false, gameMode == GameModes.CREATIVE, flySpeed, fieldOfView));
        this.lastCanFly = canFly;
        this.lastFlySpeed = flySpeed;
        this.lastFieldOfView = fieldOfView;
    }
    final float health = this.entity.get(Keys.HEALTH).get().floatValue();
    final int foodLevel = this.entity.get(Keys.FOOD_LEVEL).get();
    final float saturation = this.entity.get(Keys.SATURATION).get().floatValue();
    if (health != this.lastHealth || foodLevel != this.lastFoodLevel || saturation == 0.0f != this.lastHungry) {
        context.sendToSelf(() -> new MessagePlayOutPlayerHealthUpdate(health, foodLevel, saturation));
        this.lastHealth = health;
        this.lastFoodLevel = foodLevel;
        this.lastHungry = saturation == 0.0f;
    }
    super.update(context);
    final TopHat topHat = getTopHat();
    if (topHat != this.lastTopHat) {
        if (this.lastTopHat == null) {
            sendPassengerStack(context);
            sendHat(context, topHat);
        } else if (topHat == null) {
            removePassengerStack(context);
        } else {
            sendHat(context, topHat);
        }
        this.lastTopHat = topHat;
    }
    if (this.lastYaw0 != this.lastYaw || this.lastPitch0 != this.lastPitch || this.lastFlags0 != this.lastFlags) {
        for (final int id : this.passengerStack) {
            context.sendToSelf(() -> new MessagePlayOutEntityLook(id, this.lastYaw, this.lastPitch, this.entity.isOnGround()));
        }
        if (this.lastTopHat != null) {
            context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[10], this.lastYaw));
            context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[11], this.lastYaw));
            context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[12], this.lastYaw));
            // context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[14], this.lastYaw));
            if (this.lastFlags0 != this.lastFlags) {
                final boolean glow = (this.lastFlags & 0x40) != 0;
                final ParameterList parameterList = new ByteBufParameterList(ByteBufferAllocator.unpooled());
                parameterList.add(EntityParameters.Base.FLAGS, (byte) (0x20 | (glow ? 0x40 : 0x00)));
                context.sendToAll(() -> new MessagePlayOutEntityMetadata(this.passengerStack[10], parameterList));
                context.sendToAll(() -> new MessagePlayOutEntityMetadata(this.passengerStack[11], parameterList));
            }
        }
        this.lastYaw0 = this.lastYaw;
        this.lastPitch0 = this.lastPitch;
        this.lastFlags0 = this.lastFlags;
    }
    // Some 1.11.2 magic, ultra secret stuff...
    final boolean elytraFlying = this.entity.get(LanternKeys.IS_ELYTRA_FLYING).orElse(false);
    final boolean elytraSpeedBoost = this.entity.get(LanternKeys.ELYTRA_SPEED_BOOST).orElse(false);
    if (this.lastElytraFlying != elytraFlying || this.lastElytraSpeedBoost != elytraSpeedBoost) {
        if (this.lastElytraFlying && this.lastElytraSpeedBoost) {
            context.sendToAll(() -> new MessagePlayOutDestroyEntities(this.elytraRocketId));
        } else if (elytraFlying && elytraSpeedBoost) {
            // Create the fireworks data item
            final LanternItemStack itemStack = new LanternItemStack(ItemTypes.FIREWORKS);
            // Write the item to a parameter list
            final ByteBufParameterList parameterList = new ByteBufParameterList(ByteBufferAllocator.unpooled());
            parameterList.add(EntityParameters.Fireworks.ITEM, itemStack);
            parameterList.add(EntityParameters.Fireworks.ELYTRA_BOOST_PLAYER, getRootEntityId());
            context.sendToAll(() -> new MessagePlayOutSpawnObject(this.elytraRocketId, UUID.randomUUID(), 76, 0, this.entity.getPosition(), 0, 0, Vector3d.ZERO));
            context.sendToAll(() -> new MessagePlayOutEntityMetadata(this.elytraRocketId, parameterList));
        }
        this.lastElytraSpeedBoost = elytraSpeedBoost;
        this.lastElytraFlying = elytraFlying;
    }
}
Also used : TopHat(org.lanternpowered.server.extra.accessory.TopHat) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) MessagePlayOutSpawnObject(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnObject) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) MessagePlayOutSetGameMode(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) MessagePlayOutPlayerHealthUpdate(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerHealthUpdate) MessagePlayOutEntityLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityLook) MessagePlayOutSetGameMode(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode) MessagePlayOutDestroyEntities(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutDestroyEntities) ParameterList(org.lanternpowered.server.network.entity.parameter.ParameterList) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) MessagePlayOutEntityMetadata(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata) MessagePlayOutPlayerAbilities(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerAbilities) MessagePlayOutEntityHeadLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)

Example 23 with LanternItemStack

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

the class PlayerEntityProtocol method sendHat.

private void sendHat(EntityProtocolUpdateContext context, TopHat hat) {
    final LanternItemStack paneItem;
    final LanternItemStack blockItem;
    final Optional<DyeColor> dyeColor = hat.getDyeColor();
    if (dyeColor.isPresent()) {
        paneItem = new LanternItemStack(BlockTypes.CARPET);
        paneItem.offer(Keys.DYE_COLOR, dyeColor.get());
        blockItem = new LanternItemStack(BlockTypes.WOOL);
        blockItem.offer(Keys.DYE_COLOR, dyeColor.get());
    } else if (hat == TopHats.GOLD) {
        paneItem = new LanternItemStack(BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.GOLD_BLOCK);
    } else if (hat == TopHats.IRON) {
        paneItem = new LanternItemStack(BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.IRON_BLOCK);
    } else if (hat == TopHats.WOOD) {
        paneItem = new LanternItemStack(BlockTypes.WOODEN_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.PLANKS);
    } else if (hat == TopHats.STONE) {
        paneItem = new LanternItemStack(BlockTypes.STONE_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.STONE);
    } else if (hat == TopHats.SNOW) {
        paneItem = new LanternItemStack(BlockTypes.SNOW_LAYER);
        blockItem = new LanternItemStack(BlockTypes.SNOW);
    } else {
        throw new IllegalStateException();
    }
    byte flags = 0x20;
    if (getEntity().get(Keys.GLOWING).get()) {
        flags |= 0x40;
    }
    final ParameterList parameterList1 = new ByteBufParameterList(ByteBufferAllocator.unpooled());
    parameterList1.add(EntityParameters.ArmorStand.FLAGS, (byte) (0x08 | 0x10));
    parameterList1.add(EntityParameters.Base.FLAGS, flags);
    final int id1 = this.passengerStack[10];
    context.sendToAll(() -> new MessagePlayOutSpawnObject(id1, UUID.randomUUID(), 78, 0, getEntity().getPosition(), 0, 0, Vector3d.ZERO));
    context.sendToAll(() -> new MessagePlayOutEntityMetadata(id1, parameterList1));
    context.sendToAll(() -> new MessagePlayOutEntityEquipment(id1, 5, paneItem));
    final ParameterList parameterList2 = new ByteBufParameterList(ByteBufferAllocator.unpooled());
    parameterList2.add(EntityParameters.ArmorStand.FLAGS, (byte) (0x08 | 0x10 | 0x01));
    parameterList2.add(EntityParameters.Base.FLAGS, flags);
    final int id2 = this.passengerStack[11];
    context.sendToAll(() -> new MessagePlayOutSpawnObject(id2, UUID.randomUUID(), 78, 0, getEntity().getPosition(), 0, 0, Vector3d.ZERO));
    context.sendToAll(() -> new MessagePlayOutEntityMetadata(id2, parameterList2));
    context.sendToAll(() -> new MessagePlayOutEntityEquipment(id2, 5, blockItem));
    sendPassengers(context, 8, 10);
    sendPassengers(context, 9, 11);
/*
        final LanternItemStack boneItem = new LanternItemStack(ItemTypes.BONE);

        float angleA = 250f;
        float angleB = 250f;
        for (int i = 12; i <= 14; i++) {
            final ParameterList parameterList3 = new ByteBufParameterList(ByteBufferAllocator.unpooled());
            parameterList3.add(EntityParameters.ArmorStand.FLAGS, (byte) (0x08 | 0x10 | 0x01 | 0x04));
            parameterList3.add(EntityParameters.ArmorStand.LEFT_ARM_ROTATION, new Vector3f(50f, 360f - angleA, angleB));
            parameterList3.add(EntityParameters.ArmorStand.RIGHT_ARM_ROTATION, new Vector3f(50f, angleA, 360f - angleB));
            parameterList3.add(EntityParameters.Base.FLAGS, flags);
            final int id3 = this.passengerStack[i];

            context.sendToAll(() -> new MessagePlayOutSpawnObject(id3, UUID.randomUUID(), 78, 0,
                    getEntity().getPosition(), 0, 0, Vector3d.ZERO));
            context.sendToAll(() -> new MessagePlayOutEntityMetadata(id3, parameterList3));
            context.sendToAll(() -> new MessagePlayOutEntityEquipment(id3, 0, boneItem));
            context.sendToAll(() -> new MessagePlayOutEntityEquipment(id3, 1, boneItem));

            angleA -= 15f;
            angleB -= 15f;
        }

        sendPassengers(context, 7, 9, 12, 13, 14);
        */
}
Also used : ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) ParameterList(org.lanternpowered.server.network.entity.parameter.ParameterList) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) MessagePlayOutEntityMetadata(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata) MessagePlayOutEntityEquipment(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityEquipment) DyeColor(org.spongepowered.api.data.type.DyeColor) MessagePlayOutSpawnObject(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnObject) 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