Search in sources :

Example 1 with ItemList

use of at.haha007.edenclient.utils.config.wrappers.ItemList in project EdenClient by HahaOO7.

the class ItemListLoader method save.

public NbtList save(Object value) {
    ItemList list = cast(value);
    NbtList tag = new NbtList();
    list.forEach(item -> tag.add(PerWorldConfig.get().toNbt(item)));
    return tag;
}
Also used : ItemList(at.haha007.edenclient.utils.config.wrappers.ItemList) NbtList(net.minecraft.nbt.NbtList)

Example 2 with ItemList

use of at.haha007.edenclient.utils.config.wrappers.ItemList in project EdenClient by HahaOO7.

the class ContainerInfo method onOpenInventory.

private void onOpenInventory(List<ItemStack> itemStacks) {
    if (lastInteractedBlock == null)
        return;
    // smallest only chests and shulkerboxes!
    if (itemStacks.size() < 27)
        return;
    ChunkPos cp = new ChunkPos(new BlockPos(lastInteractedBlock));
    Registry<Block> registry = PlayerUtils.getPlayer().world.getRegistryManager().get(BlockTags.SHULKER_BOXES.registry());
    Map<Item, List<ItemStack>> items = itemStacks.stream().flatMap(stack -> registry.containsId(Registry.BLOCK.getId(Block.getBlockFromItem(stack.getItem()))) ? mapShulkerBox(stack) : Stream.of(stack)).collect(Collectors.groupingBy(ItemStack::getItem));
    items.remove(Items.AIR);
    Map<Item, Integer> counts = new HashMap<>();
    items.forEach((item, stacks) -> counts.put(item, stacks.stream().mapToInt(ItemStack::getCount).sum()));
    ItemList list = new ItemList();
    list.addAll(counts.keySet());
    list.sort(Comparator.comparingInt(i -> -counts.get(i)));
    ChestMap map = chunkMap.computeIfAbsent(cp, chunkPos -> new ChestMap());
    if (list.isEmpty())
        map.remove(lastInteractedBlock);
    else
        map.put(lastInteractedBlock, list);
}
Also used : java.util(java.util) BlockEntity(net.minecraft.block.entity.BlockEntity) NbtElement(net.minecraft.nbt.NbtElement) PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) Item(net.minecraft.item.Item) NbtList(net.minecraft.nbt.NbtList) ClientChunkManager(net.minecraft.client.world.ClientChunkManager) Inventory(net.minecraft.inventory.Inventory) at.haha007.edenclient.callbacks(at.haha007.edenclient.callbacks) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) ConfigLoader(at.haha007.edenclient.utils.config.loaders.ConfigLoader) RegistryKey(net.minecraft.util.registry.RegistryKey) Hand(net.minecraft.util.Hand) ItemList(at.haha007.edenclient.utils.config.wrappers.ItemList) ChestBlock(net.minecraft.block.ChestBlock) BlockState(net.minecraft.block.BlockState) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ScreenHandler(net.minecraft.screen.ScreenHandler) Predicate(java.util.function.Predicate) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) ChestType(net.minecraft.block.enums.ChestType) Items(net.minecraft.item.Items) Collectors(java.util.stream.Collectors) Registry(net.minecraft.util.registry.Registry) ActionResult(net.minecraft.util.ActionResult) WorldChunk(net.minecraft.world.chunk.WorldChunk) NbtCompound(net.minecraft.nbt.NbtCompound) Stream(java.util.stream.Stream) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) Identifier(net.minecraft.util.Identifier) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) ShulkerBoxScreenHandler(net.minecraft.screen.ShulkerBoxScreenHandler) BlockTags(net.minecraft.tag.BlockTags) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) ClientWorld(net.minecraft.client.world.ClientWorld) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) Item(net.minecraft.item.Item) ItemList(at.haha007.edenclient.utils.config.wrappers.ItemList) Block(net.minecraft.block.Block) ChestBlock(net.minecraft.block.ChestBlock) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) NbtList(net.minecraft.nbt.NbtList) ItemList(at.haha007.edenclient.utils.config.wrappers.ItemList)

Example 3 with ItemList

use of at.haha007.edenclient.utils.config.wrappers.ItemList in project EdenClient by HahaOO7.

the class ItemListLoader method load.

public ItemList load(NbtList tag) {
    ItemList list = new ItemList();
    tag.forEach(entry -> list.add(PerWorldConfig.get().toObject(entry, Item.class)));
    return list;
}
Also used : ItemList(at.haha007.edenclient.utils.config.wrappers.ItemList)

Aggregations

ItemList (at.haha007.edenclient.utils.config.wrappers.ItemList)3 NbtList (net.minecraft.nbt.NbtList)2 at.haha007.edenclient.callbacks (at.haha007.edenclient.callbacks)1 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)1 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)1 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)1 ConfigLoader (at.haha007.edenclient.utils.config.loaders.ConfigLoader)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 ChestBlock (net.minecraft.block.ChestBlock)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)1 ChestType (net.minecraft.block.enums.ChestType)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 ClientChunkManager (net.minecraft.client.world.ClientChunkManager)1 ClientWorld (net.minecraft.client.world.ClientWorld)1