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