Search in sources :

Example 56 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class CursedMineInstance method sweepFloor.

public void sweepFloor() {
    for (Item item : getContained(Item.class)) {
        if (!contains(item))
            continue;
        ItemType id = item.getItemType();
        for (ItemType aItem : items) {
            if (aItem == id) {
                ItemStackSnapshot snapshot = item.get(Keys.REPRESENTED_ITEM).get();
                int newAmt = (int) (snapshot.getCount() * .8);
                if (newAmt < 1) {
                    item.remove();
                } else {
                    ItemStack newStack = snapshot.createStack();
                    newStack.setQuantity(newAmt);
                    item.offer(Keys.REPRESENTED_ITEM, newStack.createSnapshot());
                }
                break;
            }
        }
    }
}
Also used : Item(org.spongepowered.api.entity.Item) ItemType(org.spongepowered.api.item.ItemType) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 57 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class JungleRaidEffectListener method createFor.

private PlayerCombatParser createFor(Cancellable event, JungleRaidInstance inst) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
            final boolean isDamageEntityEvent = event instanceof DamageEntityEvent;
            // Do Death Touch before anything else
            if (inst.isFlagEnabled(JungleRaidFlag.DEATH_TOUCH) && isDamageEntityEvent) {
                ((DamageEntityEvent) event).setBaseDamage(Math.pow(defender.get(Keys.MAX_HEALTH).orElse(20D), 3));
                return;
            }
            Optional<JungleRaidClass> optClass = inst.getClass(attacker);
            if (optClass.isPresent()) {
                JungleRaidClass jrClass = optClass.get();
                if (jrClass == JungleRaidClass.SNIPER) {
                    Optional<ItemStack> optHeld = attacker.getItemInHand(HandTypes.MAIN_HAND);
                    boolean hasWoodenSword = optHeld.isPresent() && optHeld.get().getItem() == ItemTypes.WOODEN_SWORD;
                    if (indirectSource != null || !hasWoodenSword) {
                        double distSq = attacker.getLocation().getPosition().distanceSquared(defender.getLocation().getPosition());
                        double targetDistSq = Math.pow(70, 2);
                        double ratio = Math.min(distSq, targetDistSq) / targetDistSq;
                        if (isDamageEntityEvent) {
                            // Handle damage modification
                            ((DamageEntityEvent) event).setBaseDamage(((DamageEntityEvent) event).getBaseDamage() * ratio);
                        } else {
                            // Disable the arrow fire in the Impact event
                            if (ratio < .7 && indirectSource != null) {
                                indirectSource.offer(Keys.FIRE_TICKS, 0);
                            }
                        }
                    }
                }
            }
            if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && attacker.getUniqueId().equals(inst.getFlagData().titan) && isDamageEntityEvent) {
                ((DamageEntityEvent) event).setBaseDamage(((DamageEntityEvent) event).getBaseDamage() * 2);
            }
        }

        @Override
        public void processNonLivingAttack(DamageSource attacker, Player defender) {
            if (!(event instanceof DamageEntityEvent)) {
                return;
            }
            if (attacker.getType() == DamageTypes.FALL) {
                BlockType belowType = defender.getLocation().add(0, -1, 0).getBlockType();
                if (inst.isFlagEnabled(JungleRaidFlag.TRAMPOLINE)) {
                    Vector3d oldVel = defender.getVelocity();
                    Vector3d newVel = new Vector3d(oldVel.getX(), 0, oldVel.getZ());
                    defender.setVelocity(new Vector3d(0, .1, 0).mul(((DamageEntityEvent) event).getBaseDamage()).add(newVel));
                    event.setCancelled(true);
                } else if (belowType == BlockTypes.LEAVES || belowType == BlockTypes.LEAVES2) {
                    if (Probability.getChance(2)) {
                        Vector3d oldVel = defender.getVelocity();
                        Vector3d newVel = new Vector3d(oldVel.getX() > 0 ? -.5 : .5, 0, oldVel.getZ() > 0 ? -.5 : .5);
                        defender.setVelocity(new Vector3d(0, .1, 0).mul(((DamageEntityEvent) event).getBaseDamage()).add(newVel));
                    }
                    event.setCancelled(true);
                }
            } else if (attacker.getType() == DamageTypes.CUSTOM) {
                if (inst.isFlagEnabled(JungleRaidFlag.EXPLOSIVE_ARROWS) || inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
                    ((DamageEntityEvent) event).setBaseDamage(Math.min(((DamageEntityEvent) event).getBaseDamage(), 2));
                }
            }
        }
    };
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Nullable(javax.annotation.Nullable)

Example 58 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class GoldRushInstance method checkFloodType.

private void checkFloodType() {
    if (foundPhantomHymn) {
        return;
    }
    for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
        net.minecraft.item.ItemStack[] itemStacks = tf(player).inventory.mainInventory;
        for (net.minecraft.item.ItemStack is : itemStacks) {
            if (is == null || is.getItem() != CustomItemTypes.PRIZE_BOX) {
                continue;
            }
            Optional<ItemStack> optContained = PrizeBox.getPrizeStack(is);
            if (optContained.isPresent() && optContained.get().getItem() == CustomItemTypes.PHANTOM_HYMN) {
                // Force away all water
                drainAll();
                floodBlockType = BlockTypes.FLOWING_LAVA;
                multiplier = multiplier.multiply(new BigDecimal(1.35));
                foundPhantomHymn = true;
                break;
            }
        }
    /*for (Inventory slot : player.getInventory().query((ItemType) CustomItemTypes.PRIZE_BOX)) {
                Optional<ItemStack> optStack = slot.peek();
                if (optStack.isPresent()) {
                    Optional<ItemStack> optContained = PrizeBox.getPrizeStack(optStack.get());
                    if (optContained.isPresent() && optContained.get().getItem() == CustomItemTypes.PHANTOM_HYMN) {
                        drainAll(); // Force away all water
                        floodBlockType = BlockTypes.FLOWING_LAVA;
                        break;
                    }
                }
            }*/
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) BigDecimal(java.math.BigDecimal)

Example 59 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class JungleRaidEffectListener method onPlayerInteract.

@Listener
public void onPlayerInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<JungleRaidInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    JungleRaidInstance inst = optInst.get();
    Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optStack.isPresent()) {
        return;
    }
    ItemStack stack = optStack.get();
    if (stack.getItem() == ItemTypes.COMPASS) {
        event.setUseBlockResult(Tristate.FALSE);
        if (inst.getState() == JungleRaidState.IN_PROGRESS && inst.isFlagEnabled(JungleRaidFlag.ENHANCED_COMPASS)) {
            Set<Text> resultSet = new HashSet<>();
            for (Player aPlayer : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
                // Check validity
                if (player.equals(aPlayer))
                    continue;
                // Check team
                if (inst.isFriendlyFire(player, aPlayer))
                    continue;
                TextColor color = tf(player).canEntityBeSeen(tf(aPlayer)) ? TextColors.DARK_RED : TextColors.RED;
                resultSet.add(Text.of(color, aPlayer.getName(), " - ", player.getLocation().getPosition().distance(aPlayer.getLocation().getPosition())));
            }
            if (resultSet.isEmpty()) {
                player.sendMessage(Text.of(TextColors.RED, "No players found."));
            }
            player.sendMessage(Text.of(TextColors.YELLOW, "Player - Distance"));
            player.sendMessages(resultSet);
        } else if (inst.getState() == JungleRaidState.INITIALIZE) {
            player.setLocation(inst.getRandomLocation());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) HashSet(java.util.HashSet) Listener(org.spongepowered.api.event.Listener)

Example 60 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class PlayerStateServiceImpl method load.

@Override
public void load(Player player, String saveName) {
    Iterator<Inventory> slots = player.getInventory().slots().iterator();
    List<JsonElement> persistedInventoryContents = getInventoryContents(player, saveName);
    for (int i = 0; slots.hasNext(); ++i) {
        Inventory slot = slots.next();
        if (i < persistedInventoryContents.size()) {
            try {
                ItemStack stack = deserializeItemStack(persistedInventoryContents.get(i));
                slot.set(stack);
                continue;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        slot.set(newItemStack(ItemTypes.NONE));
    }
}
Also used : JsonElement(com.google.gson.JsonElement) IOException(java.io.IOException) ItemSerializer.serializeItemStack(com.skelril.nitro.item.ItemSerializer.serializeItemStack) ItemSerializer.deserializeItemStack(com.skelril.nitro.item.ItemSerializer.deserializeItemStack) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Aggregations

ItemStack (org.spongepowered.api.item.inventory.ItemStack)76 Player (org.spongepowered.api.entity.living.player.Player)30 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)29 Listener (org.spongepowered.api.event.Listener)17 ArrayList (java.util.ArrayList)12 Text (org.spongepowered.api.text.Text)10 ItemDropper (com.skelril.nitro.item.ItemDropper)9 MarketService (com.skelril.skree.service.MarketService)9 World (org.spongepowered.api.world.World)9 VirtualCrate (pw.codehusky.huskycrates.crate.VirtualCrate)9 BigDecimal (java.math.BigDecimal)8 Entity (org.spongepowered.api.entity.Entity)8 Vector3d (com.flowpowered.math.vector.Vector3d)5 Clause (com.skelril.nitro.Clause)5 InventoryTransactionResult (org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)5 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)3