Search in sources :

Example 6 with ItemDropper

use of com.skelril.nitro.item.ItemDropper in project Skree by Skelril.

the class WildernessWorldWrapper method onEntityDeath.

@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    Entity entity = event.getTargetEntity();
    Location<World> loc = entity.getLocation();
    Optional<Integer> optLevel = getLevel(loc);
    if (!optLevel.isPresent()) {
        return;
    }
    int level = optLevel.get();
    if (entity instanceof Monster) {
        DropTable dropTable;
        if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
            dropTable = netherMobDropTable;
        } else {
            dropTable = commonDropTable;
        }
        Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
        if (optDamageSource.isPresent()) {
            Entity srcEntity;
            if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
                srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            } else {
                srcEntity = optDamageSource.get().getSource();
            }
            int dropTier = level;
            if (srcEntity instanceof Player) {
                Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
                if (optHeldItem.isPresent()) {
                    Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
                    if (optLooting.isPresent()) {
                        dropTier += optLooting.get().getLevel();
                    }
                }
                dropTier = getDropTier(dropTier);
                Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
                int times = 1;
                Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
                if (optService.isPresent()) {
                    ModifierService service = optService.get();
                    if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
                        times *= 2;
                    }
                }
                ItemDropper dropper = new ItemDropper(loc);
                for (int i = 0; i < times; ++i) {
                    dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
                }
            }
        }
        if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
            entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
        }
    }
    GRAVE_STONE.createGraveFromDeath(event);
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Player(org.spongepowered.api.entity.living.player.Player) ItemDropper(com.skelril.nitro.item.ItemDropper) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) DropTable(com.skelril.nitro.droptable.DropTable) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) Boss(org.spongepowered.api.entity.living.monster.Boss) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Monster(org.spongepowered.api.entity.living.monster.Monster) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 7 with ItemDropper

use of com.skelril.nitro.item.ItemDropper in project Skree by Skelril.

the class MarketImplUtil method setBalanceTo.

public static boolean setBalanceTo(Player player, BigDecimal decimal, Cause cause) {
    EntityPlayer playerEnt = tf(player);
    net.minecraft.item.ItemStack[] mainInv = playerEnt.inventory.mainInventory;
    Collection<ItemStack> results = CofferValueMap.inst().satisfy(decimal.toBigInteger());
    Iterator<ItemStack> resultIt = results.iterator();
    // Loop through replacing empty slots and the old coffers with the new balance
    for (int i = 0; i < mainInv.length; ++i) {
        Optional<BigInteger> value = CofferValueMap.inst().getValue(Lists.newArrayList(tf(mainInv[i])));
        if (value.isPresent()) {
            mainInv[i] = null;
        }
        if (mainInv[i] == null && resultIt.hasNext()) {
            mainInv[i] = tf(resultIt.next());
            resultIt.remove();
        }
    }
    // Add remaining currency
    new ItemDropper(player.getLocation()).dropStacks(results, SpawnTypes.PLUGIN);
    return true;
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BigInteger(java.math.BigInteger) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 8 with ItemDropper

use of com.skelril.nitro.item.ItemDropper in project Skree by Skelril.

the class MarketImplUtil method giveItems.

public static Clause<Boolean, List<Clause<ItemStack, Integer>>> giveItems(Player player, Collection<ItemStack> stacks, Cause cause) {
    List<Clause<ItemStack, Integer>> transactions = new ArrayList<>(stacks.size());
    List<ItemStackSnapshot> itemBuffer = new ArrayList<>();
    itemBuffer.addAll(stacks.stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
    PlayerInventory playerInventory = player.getInventory().query(PlayerInventory.class);
    List<Inventory> inventories = new ArrayList<>();
    inventories.add(playerInventory.getHotbar());
    inventories.add(playerInventory.getMain());
    // Loop through replacing empty space with the requested items
    for (Inventory inventory : inventories) {
        List<ItemStackSnapshot> newBuffer = new ArrayList<>();
        for (ItemStackSnapshot snapshot : itemBuffer) {
            ItemStack stack = snapshot.createStack();
            InventoryTransactionResult result = inventory.offer(stack);
            newBuffer.addAll(result.getRejectedItems());
            transactions.add(new Clause<>(stack, stack.getQuantity()));
        }
        itemBuffer = newBuffer;
    }
    // Drop remaining items
    new ItemDropper(player.getLocation()).dropStackSnapshots(itemBuffer, SpawnTypes.PLUGIN);
    return new Clause<>(true, transactions);
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Clause(com.skelril.nitro.Clause) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 9 with ItemDropper

use of com.skelril.nitro.item.ItemDropper in project Skree by Skelril.

the class WaveDropInstruction method apply.

@Override
public Optional<Instruction<UnbindCondition, Boss<Zombie, CatacombsBossDetail>>> apply(UnbindCondition condition, Boss<Zombie, CatacombsBossDetail> boss) {
    int wave = boss.getDetail().getWave();
    Collection<ItemStack> drops = dropTable.getDrops(wave, wave * .5 * modifier);
    drops.addAll(foodDropTable.getDrops(1, .5 * modifier));
    Optional<Zombie> optEnt = boss.getTargetEntity();
    if (optEnt.isPresent()) {
        Task.builder().execute(() -> {
            new ItemDropper(optEnt.get().getLocation()).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
        }).delayTicks(1).submit(SkreePlugin.inst());
    }
    return Optional.empty();
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) Zombie(org.spongepowered.api.entity.living.monster.Zombie) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 10 with ItemDropper

use of com.skelril.nitro.item.ItemDropper in project Skree by Skelril.

the class InventoryCurse method accept.

@Override
public void accept(Player player) {
    ItemStack stack = newItemStack(targetType, Probability.getRandom(targetAmt));
    Optional<ItemStack> optHeld = player.getItemInHand(HandTypes.MAIN_HAND);
    if (optHeld.isPresent() && !isSimilar(optHeld.get(), stack)) {
        new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(optHeld.get()), SpawnTypes.DROPPED_ITEM);
    }
    player.setItemInHand(HandTypes.MAIN_HAND, stack);
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Aggregations

ItemDropper (com.skelril.nitro.item.ItemDropper)14 ItemStack (org.spongepowered.api.item.inventory.ItemStack)9 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)5 Listener (org.spongepowered.api.event.Listener)4 Vector3d (com.flowpowered.math.vector.Vector3d)3 Player (org.spongepowered.api.entity.living.player.Player)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 ModifierService (com.skelril.skree.service.ModifierService)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 Entity (org.spongepowered.api.entity.Entity)2 Monster (org.spongepowered.api.entity.living.monster.Monster)2 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)2 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 Location (org.spongepowered.api.world.Location)2 World (org.spongepowered.api.world.World)2 EditSession (com.sk89q.worldedit.EditSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Vector (com.sk89q.worldedit.Vector)1