Search in sources :

Example 1 with Registry

use of net.minecraft.util.registry.Registry in project frame-fabric by moddingplayground.

the class AbstractLootTableGenerator method accept.

@SuppressWarnings("ConstantConditions")
@Override
public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) {
    this.generate();
    Set<Identifier> set = Sets.newHashSet();
    Registry<T> registry = this.getRegistry();
    Iterable<T> objects = registry.stream().filter(obj -> registry.getId(obj).getNamespace().equals(this.modId))::iterator;
    for (T obj : objects) {
        Identifier id = ((ObjectLootTableAccess) obj).access_getLootTableId();
        this.testObject(id, obj);
        if (id != LootTables.EMPTY && set.add(id)) {
            LootTable.Builder builder = this.map.remove(id);
            if (builder == null) {
                throw new IllegalStateException(String.format("Missing loottable '%s' for '%s'", id, registry.getId(obj)));
            }
            biConsumer.accept(id, builder);
        }
    }
    this.map.forEach(biConsumer);
}
Also used : LootTable(net.minecraft.loot.LootTable) LootPoolEntry(net.minecraft.loot.entry.LootPoolEntry) UniformLootNumberProvider(net.minecraft.loot.provider.number.UniformLootNumberProvider) Function(java.util.function.Function) BoundedIntUnaryOperator(net.minecraft.loot.operator.BoundedIntUnaryOperator) Block(net.minecraft.block.Block) BinomialLootNumberProvider(net.minecraft.loot.provider.number.BinomialLootNumberProvider) BiConsumer(java.util.function.BiConsumer) ObjectLootTableAccess(net.moddingplayground.frame.impl.toymaker.ObjectLootTableAccess) StatePredicate(net.minecraft.predicate.StatePredicate) BlockStatePropertyLootCondition(net.minecraft.loot.condition.BlockStatePropertyLootCondition) LootCondition(net.minecraft.loot.condition.LootCondition) LootTables(net.minecraft.loot.LootTables) Property(net.minecraft.state.property.Property) AbstractGenerator(net.moddingplayground.frame.api.toymaker.v0.generator.AbstractGenerator) Set(java.util.Set) ConstantLootNumberProvider(net.minecraft.loot.provider.number.ConstantLootNumberProvider) ItemEntry(net.minecraft.loot.entry.ItemEntry) Sets(com.google.common.collect.Sets) Registry(net.minecraft.util.registry.Registry) RandomChanceLootCondition(net.minecraft.loot.condition.RandomChanceLootCondition) LootPool(net.minecraft.loot.LootPool) SetCountLootFunction(net.minecraft.loot.function.SetCountLootFunction) ItemConvertible(net.minecraft.item.ItemConvertible) Identifier(net.minecraft.util.Identifier) ConditionalLootFunction(net.minecraft.loot.function.ConditionalLootFunction) LootNumberProvider(net.minecraft.loot.provider.number.LootNumberProvider) LootTable(net.minecraft.loot.LootTable) ObjectLootTableAccess(net.moddingplayground.frame.impl.toymaker.ObjectLootTableAccess) Identifier(net.minecraft.util.Identifier)

Example 2 with Registry

use of net.minecraft.util.registry.Registry in project meteor-client by MeteorDevelopment.

the class LeftRightListSettingScreen method initWidgets.

private void initWidgets(Registry<T> registry) {
    // Left (all)
    WTable left = abc(pairs -> registry.forEach(t -> {
        if (skipValue(t) || collection.contains(t))
            return;
        int words = Utils.search(getValueName(t), filterText);
        if (words > 0)
            pairs.add(new Pair<>(t, words));
    }), true, t -> {
        addValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            addValue(registry, v);
    });
    if (left.cells.size() > 0)
        table.add(theme.verticalSeparator()).expandWidgetY();
    // Right (selected)
    abc(pairs -> {
        for (T value : collection) {
            if (skipValue(value))
                continue;
            int words = Utils.search(getValueName(value), filterText);
            if (words > 0)
                pairs.add(new Pair<>(value, words));
        }
    }, false, t -> {
        removeValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            removeValue(registry, v);
    });
}
Also used : WTextBox(meteordevelopment.meteorclient.gui.widgets.input.WTextBox) Setting(meteordevelopment.meteorclient.settings.Setting) Pair(net.minecraft.util.Pair) GuiTheme(meteordevelopment.meteorclient.gui.GuiTheme) WPressable(meteordevelopment.meteorclient.gui.widgets.pressable.WPressable) Collection(java.util.Collection) Cell(meteordevelopment.meteorclient.gui.utils.Cell) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) WindowScreen(meteordevelopment.meteorclient.gui.WindowScreen) Comparator(java.util.Comparator) WWidget(meteordevelopment.meteorclient.gui.widgets.WWidget) Utils(meteordevelopment.meteorclient.utils.Utils) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) Pair(net.minecraft.util.Pair)

Example 3 with Registry

use of net.minecraft.util.registry.Registry in project Client by MatHax.

the class LeftRightListSettingScreen method initWidgets.

private void initWidgets(Registry<T> registry) {
    // Left (all)
    WTable left = abc(pairs -> registry.forEach(t -> {
        if (skipValue(t) || collection.contains(t))
            return;
        int words = Utils.search(getValueName(t), filterText);
        if (words > 0)
            pairs.add(new Pair<>(t, words));
    }), true, t -> {
        addValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            addValue(registry, v);
    });
    if (left.cells.size() > 0)
        table.add(theme.verticalSeparator()).expandWidgetY();
    // Right (selected)
    abc(pairs -> {
        for (T value : collection) {
            if (skipValue(value))
                continue;
            int words = Utils.search(getValueName(value), filterText);
            if (words > 0)
                pairs.add(new Pair<>(value, words));
        }
    }, false, t -> {
        removeValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            removeValue(registry, v);
    });
}
Also used : Utils(mathax.client.utils.Utils) Pair(net.minecraft.util.Pair) GuiTheme(mathax.client.gui.GuiTheme) Collection(java.util.Collection) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Cell(mathax.client.gui.utils.Cell) WTable(mathax.client.gui.widgets.containers.WTable) List(java.util.List) Setting(mathax.client.settings.Setting) WTextBox(mathax.client.gui.widgets.input.WTextBox) WPressable(mathax.client.gui.widgets.pressable.WPressable) Comparator(java.util.Comparator) WindowScreen(mathax.client.gui.WindowScreen) WWidget(mathax.client.gui.widgets.WWidget) WTable(mathax.client.gui.widgets.containers.WTable) Pair(net.minecraft.util.Pair)

Example 4 with Registry

use of net.minecraft.util.registry.Registry 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 5 with Registry

use of net.minecraft.util.registry.Registry in project EdenClient by HahaOO7.

the class AutoSell method registerCommand.

private void registerCommand(String cmd) {
    LiteralArgumentBuilder<ClientCommandSource> node = literal(cmd);
    node.then(literal("toggle").executes(c -> {
        enabled = !enabled;
        sendModMessage(enabled ? "AutoSell enabled" : "AutoSell disabled");
        return 1;
    }));
    node.then(literal("clear").executes(c -> {
        autoSellItems.clear();
        sendModMessage("Removed all entries");
        return 1;
    }));
    node.then(literal("list").executes(c -> {
        sendModMessage(autoSellItems.toString());
        return 1;
    }));
    DefaultedRegistry<Item> registry = Registry.ITEM;
    for (Item item : registry) {
        node.then(literal("add").then(literal(registry.getId(item).toString().replace("minecraft:", "")).executes(c -> {
            autoSellItems.add(item);
            sendModMessage("Added /sell " + item.getName().getString());
            return 1;
        })));
    }
    node.then(literal("remove").then(argument("item", StringArgumentType.greedyString()).suggests(this::suggestRemoveItems).executes(c -> {
        Optional<Item> opt = Registry.ITEM.getOrEmpty(new Identifier(c.getArgument("item", String.class).replace(" ", "_")));
        if (opt.isEmpty()) {
            sendModMessage("No item with this name exists.");
            return 1;
        }
        if (autoSellItems.remove(opt.get()))
            sendModMessage("Removed /sell " + opt.get().getName().getString());
        else {
            sendModMessage("Couldn't remove /sell " + opt.get().getName().getString() + " because it wasn't in your sell list.");
        }
        return 1;
    })));
    node.then(literal("stats").executes(c -> {
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        entityPlayer.sendChatMessage("/esellstatstracker global");
        return 1;
    }));
    node.executes(c -> {
        sendModMessage("/autosell clear");
        sendModMessage("/autosell list");
        sendModMessage("/autosell toggle");
        sendModMessage("/autosell add");
        sendModMessage("/autosell remove");
        return 1;
    });
    register(node, "AutoSell allows for automatic selling of items in any kind of command-accessible public server shop.", "It will always toggle when your inventory is full and execute the sell-command. You can select the items you want to sell yourself.");
}
Also used : PlayerInventory(net.minecraft.entity.player.PlayerInventory) Suggestions(com.mojang.brigadier.suggestion.Suggestions) PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) CommandContext(com.mojang.brigadier.context.CommandContext) Item(net.minecraft.item.Item) CompletableFuture(java.util.concurrent.CompletableFuture) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Registry(net.minecraft.util.registry.Registry) DefaultedRegistry(net.minecraft.util.registry.DefaultedRegistry) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) CommandManager(at.haha007.edenclient.command.CommandManager) PlayerUtils.sendModMessage(at.haha007.edenclient.utils.PlayerUtils.sendModMessage) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) ItemSet(at.haha007.edenclient.utils.config.wrappers.ItemSet) Identifier(net.minecraft.util.Identifier) Optional(java.util.Optional) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) Comparator(java.util.Comparator) PlayerInvChangeCallback(at.haha007.edenclient.callbacks.PlayerInvChangeCallback) Collections(java.util.Collections) SuggestionsBuilder(com.mojang.brigadier.suggestion.SuggestionsBuilder) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) Item(net.minecraft.item.Item) Identifier(net.minecraft.util.Identifier) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Aggregations

Registry (net.minecraft.util.registry.Registry)5 Comparator (java.util.Comparator)3 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)2 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)2 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Block (net.minecraft.block.Block)2 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 Item (net.minecraft.item.Item)2 Identifier (net.minecraft.util.Identifier)2 Pair (net.minecraft.util.Pair)2 at.haha007.edenclient.callbacks (at.haha007.edenclient.callbacks)1 PlayerInvChangeCallback (at.haha007.edenclient.callbacks.PlayerInvChangeCallback)1 CommandManager (at.haha007.edenclient.command.CommandManager)1 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)1 ConfigLoader (at.haha007.edenclient.utils.config.loaders.ConfigLoader)1