use of net.minecraft.inventory.IInventory 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 net.minecraft.inventory.IInventory in project Skree by Skelril.
the class GoldRushInstance method populateChest.
private void populateChest() {
for (Location<World> chest : chestBlocks) {
// TODO Sponge port
Optional<TileEntity> optTileEnt = chest.getTileEntity();
if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
IInventory inventory = ((IInventory) optTileEnt.get());
int iterationTimes = Probability.getRandom(27);
for (int i = iterationTimes; i > 0; --i) {
ItemStack targetStack;
int goldRand = Probability.getRandom(Probability.getRandom(Probability.getRandom(64)));
if (Probability.getChance(1000)) {
targetStack = makePrizeBox(newItemStack(BlockTypes.GOLD_BLOCK, goldRand));
} else {
targetStack = makePrizeBox(newItemStack(ItemTypes.GOLD_INGOT, goldRand));
}
inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, tf(targetStack));
}
if (Probability.getChance(10000 / iterationTimes)) {
inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, tf(makePrizeBox(newItemStack(CustomItemTypes.PHANTOM_HYMN))));
}
}
}
for (int i = 0; i < 2; i++) {
Optional<TileEntity> optTileEnt = Probability.pickOneOf(chestBlocks).getTileEntity();
if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
IInventory inventory = ((IInventory) optTileEnt.get());
inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, new net.minecraft.item.ItemStack(CustomItemTypes.GOLD_RUSH_KEY, 1, i));
}
}
}
use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.
the class EntityLocomotive method processTicket.
private void processTicket() {
IInventory invTicket = getTicketInventory();
ItemStack stack = invTicket.getStackInSlot(0);
if (stack != null)
if (stack.getItem() instanceof ItemTicket) {
if (setDestination(stack))
invTicket.setInventorySlotContents(0, InvTools.depleteItem(stack));
} else
invTicket.setInventorySlotContents(0, null);
}
use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.
the class InvTools method calcRedstoneFromInventory.
/**
* @see Container#calcRedstoneFromInventory(IInventory)
*/
public static int calcRedstoneFromInventory(@Nullable InventoryComposite inv) {
if (inv == null)
return 0;
int numStacks = 0;
float average = 0.0F;
for (IInventoryObject inventoryObject : inv) {
int stackLimit = inventoryObject.getBackingObject() instanceof IInventory ? ((IInventory) inventoryObject.getBackingObject()).getInventoryStackLimit() : 64;
for (ItemStack stack : InventoryIterator.getRailcraft(inventoryObject).getStacks()) {
average += (float) stack.stackSize / (float) Math.min(stackLimit, stack.getMaxStackSize());
numStacks++;
}
}
average = average / (float) inv.slotCount();
return MathHelper.floor_float(average * 14.0F) + (numStacks > 0 ? 1 : 0);
}
use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.
the class SchematicTile method storeRequirements.
@Override
public void storeRequirements(IBuilderContext context, BlockPos pos) {
super.storeRequirements(context, pos);
if (state.getBlock().hasTileEntity(state)) {
TileEntity tile = context.world().getTileEntity(pos);
if (tile instanceof IInventory) {
IInventory inv = (IInventory) tile;
ArrayList<ItemStack> rqs = new ArrayList<ItemStack>();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
if (inv.getStackInSlot(i) != null) {
rqs.add(inv.getStackInSlot(i));
}
}
storedRequirements = JavaTools.concat(storedRequirements, rqs.toArray(new ItemStack[rqs.size()]));
}
}
}
Aggregations