use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.
the class CursedMineInstance method drain.
public void drain() {
for (Entity e : getContained(Carrier.class)) {
// TODO Inventory API not fully implemented
if (!(e instanceof Player)) {
continue;
}
Inventory eInventory = ((Carrier) e).getInventory();
if (e instanceof Player) {
Location<World> playerLoc = e.getLocation();
// Emerald
long diff = System.currentTimeMillis() - lastActivation;
if (playerLoc.getY() < 30 && (lastActivation == 0 || diff <= timeTilPumpShutoff * .35 || diff >= timeTilPumpShutoff * 5)) {
PositionRandomizer randomizer = new PositionRandomizer(5);
for (int i = 0; i < Probability.getRangedRandom(2, 5); i++) {
Vector3i targetPos;
do {
targetPos = randomizer.createPosition3i(playerLoc.getPosition());
} while (getRegion().getExtent().getBlockType(targetPos) != BlockTypes.AIR);
Entity entity = getRegion().getExtent().createEntity(EntityTypes.BLAZE, targetPos);
getRegion().getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.MOB_SPAWNER).build()).build());
}
}
}
for (int i = 0; i < (eInventory.size() / 2) - 2 || i < 1; i++) {
if (e instanceof Player) {
if (Probability.getChance(15) && checkInventory((Player) e)) {
((Player) e).sendMessage(Text.of(TextColors.YELLOW, "Divine intervention protects some of your items."));
continue;
}
}
// Iron
eInventory.query(ItemTypes.IRON_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.IRON_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.IRON_INGOT).poll(Probability.getRandom(8));
// Gold
eInventory.query(ItemTypes.GOLD_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.GOLD_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.GOLD_INGOT).poll(Probability.getRandom(10));
eInventory.query(ItemTypes.GOLD_NUGGET).poll(Probability.getRandom(80));
// Redstone
eInventory.query(ItemTypes.REDSTONE_ORE).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.REDSTONE).poll(Probability.getRandom(34));
// Lap
eInventory.query(ItemTypes.LAPIS_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.LAPIS_ORE).poll(Probability.getRandom(4));
eInventory.query(LAPIS_DYE).poll(Probability.getRandom(34));
// Diamond
eInventory.query(ItemTypes.DIAMOND_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.DIAMOND_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.DIAMOND).poll(Probability.getRandom(16));
}
}
}
use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.
the class GoldRushListener method onChestClose.
@Listener
public void onChestClose(InteractInventoryEvent.Close event) {
Inventory inventory = event.getTargetInventory();
if (inventory instanceof ContainerChest) {
IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
if (chestInv instanceof ILockableContainer) {
String lockCode = ((ILockableContainer) chestInv).getLockCode().getLock();
Optional<Player> optPlayer = Optional.ofNullable(tileEntityClaimMap.remove(lockCode));
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
((ILockableContainer) chestInv).setLockCode(LockCode.EMPTY_CODE);
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent())
return;
// TODO Sponge port
GoldRushInstance inst = optInst.get();
List<org.spongepowered.api.item.inventory.ItemStack> toEvaluate = new ArrayList<>();
ArrayDeque<org.spongepowered.api.item.inventory.ItemStack> toReturn = new ArrayDeque<>();
for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
ItemStack stack = chestInv.getStackInSlot(i);
if (stack == null) {
continue;
}
if (stack.getItem() instanceof CofferItem) {
toEvaluate.add(tf(stack));
} else {
toReturn.add(tf(stack));
}
chestInv.setInventorySlotContents(i, null);
}
BigDecimal value = BigDecimal.ZERO;
for (org.spongepowered.api.item.inventory.ItemStack stack : toEvaluate) {
value = value.add(new BigDecimal(CofferValueMap.inst().getValue(Collections.singleton(stack)).orElse(BigInteger.ZERO)));
}
inst.cofferRisk.put(player.getUniqueId(), value);
for (Inventory slot : player.getInventory().slots()) {
if (toReturn.isEmpty()) {
break;
}
if (slot.size() == 0) {
slot.set(toReturn.poll());
}
}
if (!toReturn.isEmpty()) {
new ItemDropper(player.getLocation()).dropStacks(toReturn, SpawnTypes.PLUGIN);
}
player.sendMessage(Text.of(TextColors.YELLOW, "You are now risking ", format(value), " coffers."));
MessageChannel targetChannel = inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
targetChannel.send(Text.of(TextColors.YELLOW, "Group risk of ", format(inst.getTotalRisk()), " coffers."));
targetChannel.send(Text.of(TextColors.YELLOW, "Risk of lava ", inst.getChanceOfLava(), " / 100."));
targetChannel.send(Text.of(TextColors.YELLOW, "Security system delay ", inst.getBaseTime(), " +/- ", inst.getTimeVariance(), " seconds."));
}
}
}
}
use of org.spongepowered.api.item.inventory.Inventory 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 org.spongepowered.api.item.inventory.Inventory in project HuskyCrates-Sponge by codeHusky.
the class NullCrateView method getInventory.
@Override
public Inventory getInventory() {
Inventory woop = Inventory.builder().property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 1)).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(TextColors.DARK_RED, "INVALID CRATE TYPE!"))).listener(ClickInventoryEvent.class, evt -> evt.setCancelled(true)).build(plugin);
woop.offer(ItemStack.of(ItemTypes.BARRIER, 256 * 2 + 64));
for (Inventory e : woop.slots()) {
ItemStack b = e.peek().get();
b.setQuantity(1);
e.set(b);
}
return woop;
}
use of org.spongepowered.api.item.inventory.Inventory in project HuskyCrates-Sponge by codeHusky.
the class SpinnerCrateView method updateInv.
private void updateInv(int state) {
ItemStack border = ItemStack.builder().itemType(ItemTypes.STAINED_GLASS_PANE).add(Keys.DYE_COLOR, DyeColors.BLACK).build();
border.offer(Keys.DISPLAY_NAME, Text.of(TextStyles.RESET, "HuskyCrates"));
//border.offer(Keys.ITEM_LORE,lore);
ItemStack selector = ItemStack.of(ItemTypes.REDSTONE_TORCH, 1);
selector.offer(Keys.DISPLAY_NAME, Text.of(TextStyles.RESET, "HuskyCrates"));
//selector.offer(Keys.ITEM_LORE,lore);
int slotnum = 0;
for (Inventory e : disp.slots()) {
if (state == 0 && (slotnum == 4 || slotnum == 22)) {
e.set(selector);
} else if (slotnum > 9 && slotnum < 17 && state != 2) {
//int itemNum = items.size() - 1 - Math.abs(((slotnum - 10) + (clicks)) % items.size());
int itemNum = Math.abs((clicks + (slotnum - 9) - 3) % items.size());
//System.out.println(itemNum);
e.set(((CrateRewardHolder) items.get(itemNum)[1]).getDisplayItem());
if (slotnum == 13) {
giveToPlayer = (CrateRewardHolder) items.get(itemNum)[1];
}
} else if (slotnum != 13) {
if (state == 2) {
e.set(confettiBorder());
} else if (state == 0) {
e.set(border);
}
} else if (slotnum == 13 && state == 2) {
e.set(giveToPlayer.getDisplayItem());
}
slotnum++;
}
if (!ourplr.isViewingInventory()) {
ourplr.openInventory(disp, plugin.genericCause);
}
}
Aggregations