Search in sources :

Example 1 with ItemEnchantment

use of org.spongepowered.api.data.meta.ItemEnchantment 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 2 with ItemEnchantment

use of org.spongepowered.api.data.meta.ItemEnchantment in project Skree by Skelril.

the class JungleRaidInstance method giveBaseEquipment.

private void giveBaseEquipment(Player player, JungleRaidClass jrClass) {
    player.getInventory().clear();
    List<ItemStack> gear = new ArrayList<>();
    switch(jrClass) {
        case MELEE:
            {
                ItemStack enchantedSword = newItemStack(ItemTypes.IRON_SWORD);
                enchantedSword.offer(Keys.ITEM_ENCHANTMENTS, Lists.newArrayList(new ItemEnchantment(Enchantments.FIRE_ASPECT, 2), new ItemEnchantment(Enchantments.KNOCKBACK, 2)));
                gear.add(enchantedSword);
                ItemStack shield = newItemStack(ItemTypes.SHIELD);
                gear.add(shield);
                break;
            }
        case LUMBERJACK:
            {
                ItemStack enchantedAxe = newItemStack(ItemTypes.DIAMOND_AXE);
                enchantedAxe.offer(Keys.ITEM_ENCHANTMENTS, Lists.newArrayList(new ItemEnchantment(Enchantments.SHARPNESS, 3), new ItemEnchantment(Enchantments.KNOCKBACK, 2)));
                gear.add(enchantedAxe);
                break;
            }
        case ARCHER:
            {
                ItemStack dmgBow = newItemStack(ItemTypes.BOW);
                dmgBow.offer(Keys.ITEM_ENCHANTMENTS, Lists.newArrayList(new ItemEnchantment(Enchantments.PUNCH, 2)));
                gear.add(dmgBow);
                ItemStack fireBow = newItemStack(ItemTypes.BOW);
                fireBow.offer(Keys.ITEM_ENCHANTMENTS, Lists.newArrayList(new ItemEnchantment(Enchantments.FLAME, 1)));
                gear.add(fireBow);
                break;
            }
        case SNIPER:
            {
                ItemStack superBow = newItemStack(ItemTypes.BOW);
                superBow.offer(Keys.ITEM_ENCHANTMENTS, Lists.newArrayList(new ItemEnchantment(Enchantments.POWER, 5), new ItemEnchantment(Enchantments.FLAME, 1)));
                superBow.offer(Keys.ITEM_DURABILITY, jrClass.getArrowAmount());
                gear.add(superBow);
                ItemStack woodSword = newItemStack(ItemTypes.WOODEN_SWORD);
                gear.add(woodSword);
                break;
            }
        case ENGINEER:
            {
                ItemStack ironSword = newItemStack(ItemTypes.IRON_SWORD);
                gear.add(ironSword);
                ItemStack diamondPickaxe = newItemStack(ItemTypes.DIAMOND_PICKAXE);
                gear.add(diamondPickaxe);
                ItemStack shield = newItemStack(ItemTypes.SHIELD);
                gear.add(shield);
                break;
            }
        case BALANCED:
            {
                ItemStack standardSword = newItemStack(ItemTypes.IRON_SWORD);
                gear.add(standardSword);
                ItemStack standardBow = newItemStack(ItemTypes.BOW);
                gear.add(standardBow);
                break;
            }
    }
    int tntAmt = jrClass.getTNTAmount();
    int tntStacks = tntAmt / 64;
    int tntRemainder = tntAmt % 64;
    for (int i = 0; i < tntStacks; ++i) {
        gear.add(newItemStack(BlockTypes.TNT, 64));
    }
    if (tntRemainder > 0) {
        gear.add(newItemStack(BlockTypes.TNT, tntRemainder));
    }
    if (jrClass.hasFlintAndSteel()) {
        gear.add(newItemStack(ItemTypes.FLINT_AND_STEEL));
    }
    if (jrClass.hasShears()) {
        gear.add(newItemStack(ItemTypes.SHEARS));
    }
    if (jrClass.hasAxe()) {
        gear.add(newItemStack(ItemTypes.IRON_AXE));
    }
    gear.add(newItemStack(ItemTypes.COOKED_BEEF, 64));
    gear.add(newItemStack(ItemTypes.COMPASS));
    int arrowAmt = jrClass.getArrowAmount();
    int arrowStacks = arrowAmt / 64;
    int arrowRemainder = arrowAmt % 64;
    for (int i = 0; i < arrowStacks; ++i) {
        gear.add(newItemStack(ItemTypes.ARROW, 64));
    }
    if (arrowRemainder > 0) {
        gear.add(newItemStack(ItemTypes.ARROW, arrowRemainder));
    }
    for (ItemStack stack : gear) {
        player.getInventory().offer(stack);
    }
    tf(player).inventoryContainer.detectAndSendChanges();
}
Also used : ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 3 with ItemEnchantment

use of org.spongepowered.api.data.meta.ItemEnchantment in project HuskyCrates-Sponge by codeHusky.

the class CrateRewardHolderParser method itemToNode.

private static ConfigurationNode itemToNode(ItemStack stack) {
    ConfigurationNode node = HoconConfigurationLoader.builder().build().createEmptyNode();
    if (stack.get(Keys.DISPLAY_NAME).isPresent()) {
        node.getNode("name").setValue(TextSerializers.FORMATTING_CODE.serialize(stack.get(Keys.DISPLAY_NAME).get()));
    } else {
        node.getNode("name").setValue(stack.getItem().getName());
    }
    node.getNode("id").setValue(stack.getItem().getId());
    if (stack.get(Keys.ITEM_LORE).isPresent()) {
        ArrayList<Text> lore = (ArrayList<Text>) stack.get(Keys.ITEM_LORE).get();
        if (lore.size() > 0) {
            ArrayList<String> loreStrings = new ArrayList<>();
            for (Text e : lore) {
                loreStrings.add(TextSerializers.FORMATTING_CODE.serialize(e));
            }
            node.getNode("lore").setValue(loreStrings);
        }
    }
    node.getNode("count").setValue(stack.getQuantity());
    if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()) {
        List<ItemEnchantment> encs = stack.get(Keys.ITEM_ENCHANTMENTS).get();
        for (ItemEnchantment e : encs) {
            node.getNode("enchants", e.getEnchantment().getId()).setValue(e.getLevel());
        }
    }
    return node;
}
Also used : ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text)

Example 4 with ItemEnchantment

use of org.spongepowered.api.data.meta.ItemEnchantment in project HuskyCrates-Sponge by codeHusky.

the class CrateRewardHolderParser method itemFromNode.

private static ItemStack itemFromNode(ConfigurationNode itemRoot) {
    try {
        ItemStack item = ItemStack.builder().itemType(itemRoot.getNode("id").getValue(TypeToken.of(ItemType.class))).quantity(itemRoot.getNode("count").getInt(1)).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(itemRoot.getNode("name").getString())).build();
        if (!itemRoot.getNode("variant").isVirtual()) {
        //if(Sponge.getRegistry().getType(TreeType.class,itemRoot.getNode("variant").getString()).isPresent()) {
        //System.out.println(item.offer(Keys.TREE_TYPE,getTreeType(itemRoot.getNode("variant").getString("oak"))));
        //System.out.println(itemRoot.getNode("variant").getValue());
        //}
        }
        if (!itemRoot.getNode("lore").isVirtual()) {
            ArrayList<Text> lore = new ArrayList<>();
            for (String ll : itemRoot.getNode("lore").getList(TypeToken.of(String.class))) {
                lore.add(TextSerializers.FORMATTING_CODE.deserialize(ll));
            }
            item.offer(Keys.ITEM_LORE, lore);
        }
        if (!itemRoot.getNode("name").isVirtual()) {
            item.offer(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(itemRoot.getNode("name").getString()));
        }
        if (!itemRoot.getNode("enchants").isVirtual()) {
            ArrayList<ItemEnchantment> enchantments = new ArrayList<>();
            for (Object key : itemRoot.getNode("enchants").getChildrenMap().keySet()) {
                int level = itemRoot.getNode("enchants").getChildrenMap().get(key).getInt();
                String enchantID = (String) key;
                // STRINGS ONLY!
                Enchantment enc = getEnchantment(enchantID);
                ItemEnchantment itemEnchantment = new ItemEnchantment(enc, level);
                enchantments.add(itemEnchantment);
            }
            item.offer(Keys.ITEM_ENCHANTMENTS, enchantments);
        }
        if (!itemRoot.getNode("damage").isVirtual()) {
            //HuskyCrates.instance.logger.info("damage override called");
            item = ItemStack.builder().fromContainer(//OVERRIDE DAMAGE VAL! :)
            item.toContainer().set(DataQuery.of("UnsafeDamage"), itemRoot.getNode("damage").getInt(0))).build();
        }
        if (!itemRoot.getNode("nbt").isVirtual()) {
            //nbt overrrides
            LinkedHashMap items = (LinkedHashMap) itemRoot.getNode("nbt").getValue();
            if (item.toContainer().get(DataQuery.of("UnsafeData")).isPresent()) {
                BiMap real = ((BiMap) item.toContainer().getMap(DataQuery.of("UnsafeData")).get());
                items.putAll(real);
            }
            //System.out.println(item.toContainer().get(DataQuery.of("UnsafeData")).get().getClass());
            item = ItemStack.builder().fromContainer(item.toContainer().set(DataQuery.of("UnsafeData"), items)).build();
        }
        //item.offer(Keys.PICKUP_DELAY,itemRoot.getNode("pickupdelay").getInt())
        return item;
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ItemType(org.spongepowered.api.item.ItemType) BiMap(com.google.common.collect.BiMap) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) LinkedHashMap(java.util.LinkedHashMap) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Enchantment(org.spongepowered.api.item.Enchantment) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Aggregations

ItemEnchantment (org.spongepowered.api.data.meta.ItemEnchantment)4 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)2 ArrayList (java.util.ArrayList)2 Text (org.spongepowered.api.text.Text)2 BiMap (com.google.common.collect.BiMap)1 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 ItemDropper (com.skelril.nitro.item.ItemDropper)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 ModifierService (com.skelril.skree.service.ModifierService)1 LinkedHashMap (java.util.LinkedHashMap)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)1 Boss (org.spongepowered.api.entity.living.monster.Boss)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Wither (org.spongepowered.api.entity.living.monster.Wither)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)1