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