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