Search in sources :

Example 1 with TagKey

use of net.minecraft.tags.TagKey in project assemblylinemachines by HaydenBelanger.

the class TagMaster method tagAllInMaster.

@SuppressWarnings("unchecked")
static <T> void tagAllInMaster(DataProviderContainer provider, TagType type) {
    for (WrappedTagKey wn : Stream.concat(TAG_SINGLE_MASTER.keySet().stream(), TAG_GROUP_MASTER.keySet().stream()).collect(Collectors.toSet())) {
        for (Object x : Stream.concat(TAG_SINGLE_MASTER.get(wn).stream(), TAG_GROUP_MASTER.get(wn).stream()).collect(Collectors.toList())) {
            x = x instanceof Pair ? new ResourceLocation(((Pair<String, String>) x).getFirst(), ((Pair<String, String>) x).getSecond()) : x;
            if (x instanceof String) {
                String[] split = ((String) x).split(":");
                if (split.length == 1) {
                    split = new String[] { AssemblyLineMachines.MODID, split[0] };
                }
                x = wn.type == TagType.BLOCK ? ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0], split[1])) : ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0], split[1]));
            }
            switch(wn.type) {
                case BLOCK:
                    if (type == wn.type)
                        provider.blockProvider.passback(x, (TagKey<Block>) wn.named);
                    if (wn.copy && type == TagType.ITEM)
                        provider.itemProvider.passback((TagKey<Block>) wn.named, wn.namedItemCopy.orElseThrow());
                    break;
                case ITEM:
                    if (type == wn.type)
                        provider.itemProvider.passback(x, (TagKey<Item>) wn.named);
            }
        }
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) TagKey(net.minecraft.tags.TagKey) Pair(com.mojang.datafixers.util.Pair)

Example 2 with TagKey

use of net.minecraft.tags.TagKey in project Mohist by MohistMC.

the class TagsCommand method listTagElements.

private static int listTagElements(final CommandContext<CommandSourceStack> ctx, final int page) throws CommandSyntaxException {
    final ResourceKey<? extends Registry<?>> registryKey = getResourceKey(ctx, "registry", ROOT_REGISTRY_KEY).orElseThrow();
    final Registry<?> registry = ctx.getSource().getServer().registryAccess().registry(registryKey).orElseThrow(() -> UNKNOWN_REGISTRY.create(registryKey.location()));
    final ResourceLocation tagLocation = ResourceLocationArgument.getId(ctx, "tag");
    final TagKey<?> tagKey = TagKey.create(cast(registryKey), tagLocation);
    final HolderSet.Named<?> tag = registry.getTag(cast(tagKey)).orElseThrow(() -> UNKNOWN_TAG.create(tagKey.location(), registryKey.location()));
    ctx.getSource().sendSuccess(createMessage(new TranslatableComponent("commands.forge.tags.tag_key", new TextComponent(tagKey.registry().location().toString()).withStyle(ChatFormatting.GOLD), new TextComponent(tagKey.location().toString()).withStyle(ChatFormatting.DARK_GREEN)), "commands.forge.tags.element_count", "commands.forge.tags.copy_element_names", tag.size(), page, ChatFormatting.YELLOW, () -> tag.stream().map(s -> s.unwrap().map(k -> k.location().toString(), Object::toString))), false);
    return tag.size();
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ComponentUtils(net.minecraft.network.chat.ComponentUtils) ResourceLocation(net.minecraft.resources.ResourceLocation) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) CommandSourceStack(net.minecraft.commands.CommandSourceStack) HolderSet(net.minecraft.core.HolderSet) CompletableFuture(java.util.concurrent.CompletableFuture) MutableComponent(net.minecraft.network.chat.MutableComponent) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Registry(net.minecraft.core.Registry) TagKey(net.minecraft.tags.TagKey) ResourceLocationArgument(net.minecraft.commands.arguments.ResourceLocationArgument) Dynamic2CommandExceptionType(com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType) Holder(net.minecraft.core.Holder) ChatFormatting(net.minecraft.ChatFormatting) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) SuggestionsBuilder(com.mojang.brigadier.suggestion.SuggestionsBuilder) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Suggestions(com.mojang.brigadier.suggestion.Suggestions) ResourceKeyArgument(net.minecraft.commands.arguments.ResourceKeyArgument) CommandContext(com.mojang.brigadier.context.CommandContext) Commands(net.minecraft.commands.Commands) ResourceKey(net.minecraft.resources.ResourceKey) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) HoverEvent(net.minecraft.network.chat.HoverEvent) TextComponent(net.minecraft.network.chat.TextComponent) Stream(java.util.stream.Stream) DynamicCommandExceptionType(com.mojang.brigadier.exceptions.DynamicCommandExceptionType) Optional(java.util.Optional) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Mth(net.minecraft.util.Mth) ArgumentBuilder(com.mojang.brigadier.builder.ArgumentBuilder) ClickEvent(net.minecraft.network.chat.ClickEvent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ResourceLocation(net.minecraft.resources.ResourceLocation) HolderSet(net.minecraft.core.HolderSet)

Example 3 with TagKey

use of net.minecraft.tags.TagKey in project forge-autofish by North-West-Wind.

the class FilterSelectionScreen method init.

@Override
protected void init() {
    reducedHeight = this.height - 90;
    reducedWidth = this.width - 30;
    max = /* (int) Math.round(300 * (reducedWidth / 550.0 + reducedHeight / 330.0) / 2.0) */
    300;
    maxPage = (int) Math.ceil(original.size() / (double) max);
    searching = original;
    search = new EditBox(this.font, this.width / 2 - 75, 35, 150, 20, new TranslatableComponent("gui.superfilterscreen.search")) {

        @Override
        public boolean mouseClicked(double mouseX, double mouseY, int button) {
            if (button == GLFW.GLFW_MOUSE_BUTTON_2)
                this.setValue("");
            return super.mouseClicked(mouseX, mouseY, button);
        }
    };
    search.setResponder(s -> {
        String[] args = s.split("/ +/");
        String[] mods = Arrays.stream(args).filter(s1 -> s1.startsWith("@")).toArray(String[]::new);
        String[] tags = Arrays.stream(args).filter(s1 -> s1.startsWith("#")).toArray(String[]::new);
        String[] finalArgs = Arrays.stream(args).filter(s1 -> !s1.startsWith("@") && !s1.startsWith("#")).toArray(String[]::new);
        ;
        searching = original.stream().filter(item -> {
            boolean matchmod = mods.length < 1, matchtag = tags.length < 1, matcharg = finalArgs.length < 1;
            for (String mod : mods) {
                mod = mod.toLowerCase().substring(1);
                matchmod = item.getRegistryName().getNamespace().toLowerCase().contains(mod);
            }
            Optional<IReverseTag<Item>> reverseTagsOptional = ForgeRegistries.ITEMS.tags().getReverseTag(item);
            if (reverseTagsOptional.isPresent())
                for (String tag : tags) {
                    String finalTag = tag.toLowerCase().substring(1);
                    matchtag = reverseTagsOptional.get().getTagKeys().anyMatch(tagKey -> tagKey.location().getPath().contains(finalTag));
                }
            for (String arg : finalArgs) {
                arg = arg.toLowerCase();
                matcharg = item.getRegistryName().getPath().contains(arg) || item.getDescription().getString().contains(arg);
            }
            return matchmod && matchtag && matcharg;
        }).collect(Collectors.toList());
        maxPage = (int) Math.ceil(searching.size() / (double) max);
        if (page > maxPage - 1)
            page = maxPage - 1;
    });
    addRenderableWidget(search);
    Button add = new Button(this.width / 2 - 75, 60, 72, 20, new TranslatableComponent("gui.filterselection.save"), button -> {
        List<String> items = selected.stream().map(item -> item.getRegistryName().toString()).collect(Collectors.toList());
        Config.setFILTER(items);
        Minecraft.getInstance().setScreen(parent);
    });
    addRenderableWidget(add);
    Button done = new Button(this.width / 2 + 3, 60, 72, 20, new TranslatableComponent("gui.filterselection.cancel"), button -> Minecraft.getInstance().setScreen(parent));
    addRenderableWidget(done);
    previous = new Button(this.width / 2 - 100, 60, 20, 20, new TextComponent("<"), button -> {
        if (page > 0)
            page--;
    });
    previous.visible = false;
    addRenderableWidget(previous);
    next = new Button(this.width / 2 + 80, 60, 20, 20, new TextComponent(">"), button -> {
        if (page < maxPage - 1)
            page++;
    });
    next.visible = false;
    addRenderableWidget(next);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) java.util(java.util) Item(net.minecraft.world.item.Item) Screen(net.minecraft.client.gui.screens.Screen) Collectors(java.util.stream.Collectors) GLFW(org.lwjgl.glfw.GLFW) PoseStack(com.mojang.blaze3d.vertex.PoseStack) TagKey(net.minecraft.tags.TagKey) java.awt(java.awt) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Lists(com.google.common.collect.Lists) Stream(java.util.stream.Stream) Minecraft(net.minecraft.client.Minecraft) IReverseTag(net.minecraftforge.registries.tags.IReverseTag) EditBox(net.minecraft.client.gui.components.EditBox) Config(ml.northwestwind.forgeautofish.config.Config) ItemStack(net.minecraft.world.item.ItemStack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) Button(net.minecraft.client.gui.components.Button) TextComponent(net.minecraft.network.chat.TextComponent) IReverseTag(net.minecraftforge.registries.tags.IReverseTag) EditBox(net.minecraft.client.gui.components.EditBox) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Button(net.minecraft.client.gui.components.Button)

Example 4 with TagKey

use of net.minecraft.tags.TagKey in project ItemPhysic by CreativeMD.

the class ItemPhysicServer method updateFluidHeightAndDoFluidPushing.

public static boolean updateFluidHeightAndDoFluidPushing(ItemEntity item, TagKey<Fluid> fluidTag, double p_210500_2_) {
    double size = -0.001D;
    if (fluidTag == FluidTags.WATER && ItemPhysic.CONFIG.general.swimmingItems.canPass(item.getItem()))
        size = 0.3;
    if (item.touchingUnloadedChunk()) {
        return false;
    } else {
        AABB aabb = item.getBoundingBox().inflate(size);
        int i = Mth.floor(aabb.minX);
        int j = Mth.ceil(aabb.maxX);
        int k = Mth.floor(aabb.minY);
        int l = Mth.ceil(aabb.maxY);
        int i1 = Mth.floor(aabb.minZ);
        int j1 = Mth.ceil(aabb.maxZ);
        double d0 = 0.0D;
        boolean flag = item.isPushedByFluid();
        boolean flag1 = false;
        Vec3 vec3 = Vec3.ZERO;
        int k1 = 0;
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
        for (int l1 = i; l1 < j; ++l1) {
            for (int i2 = k; i2 < l; ++i2) {
                for (int j2 = i1; j2 < j1; ++j2) {
                    blockpos$mutableblockpos.set(l1, i2, j2);
                    FluidState fluidstate = item.level.getFluidState(blockpos$mutableblockpos);
                    if (fluidstate.is(fluidTag)) {
                        double d1 = i2 + fluidstate.getHeight(item.level, blockpos$mutableblockpos);
                        if (d1 >= aabb.minY) {
                            flag1 = true;
                            d0 = Math.max(d1 - aabb.minY, d0);
                            if (flag) {
                                Vec3 vec31 = fluidstate.getFlow(item.level, blockpos$mutableblockpos);
                                if (d0 < 0.4D) {
                                    vec31 = vec31.scale(d0);
                                }
                                vec3 = vec3.add(vec31);
                                ++k1;
                            }
                        }
                    }
                }
            }
        }
        if (vec3.length() > 0.0D) {
            if (k1 > 0)
                vec3 = vec3.scale(1.0D / k1);
            vec3 = vec3.normalize();
            Vec3 vec32 = item.getDeltaMovement();
            vec3 = vec3.scale(p_210500_2_ * 1.0D);
            if (Math.abs(vec32.x) < 0.003D && Math.abs(vec32.z) < 0.003D && vec3.length() < 0.0045D)
                vec3 = vec3.normalize().scale(0.0045D);
            item.setDeltaMovement(item.getDeltaMovement().add(vec3));
        }
        try {
            Set<TagKey<Fluid>> map = (Set<TagKey<Fluid>>) fluidOnEyesField.get(item);
            map.add(fluidTag);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return flag1;
    }
}
Also used : Set(java.util.Set) Fluid(net.minecraft.world.level.material.Fluid) Vec3(net.minecraft.world.phys.Vec3) TagKey(net.minecraft.tags.TagKey) BlockPos(net.minecraft.core.BlockPos) AABB(net.minecraft.world.phys.AABB) FluidState(net.minecraft.world.level.material.FluidState)

Example 5 with TagKey

use of net.minecraft.tags.TagKey in project Silent-Gear by SilentChaos512.

the class GearDiggerItem method isCorrectToolForDrops.

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
    for (Map.Entry<ToolAction, TagKey<Block>> entry : TOOL_TYPES.entrySet()) {
        ToolAction action = entry.getKey();
        TagKey<Block> tag = entry.getValue();
        if (canPerformAction(stack, action) && GearHelper.isCorrectToolForDrops(stack, state, tag, extraMaterials)) {
            return true;
        }
    }
    return false;
}
Also used : ToolAction(net.minecraftforge.common.ToolAction) TagKey(net.minecraft.tags.TagKey) Block(net.minecraft.world.level.block.Block) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

TagKey (net.minecraft.tags.TagKey)5 ResourceLocation (net.minecraft.resources.ResourceLocation)3 Pair (com.mojang.datafixers.util.Pair)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 TextComponent (net.minecraft.network.chat.TextComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)1 ArgumentBuilder (com.mojang.brigadier.builder.ArgumentBuilder)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 Dynamic2CommandExceptionType (com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType)1 DynamicCommandExceptionType (com.mojang.brigadier.exceptions.DynamicCommandExceptionType)1 SuggestionProvider (com.mojang.brigadier.suggestion.SuggestionProvider)1 Suggestions (com.mojang.brigadier.suggestion.Suggestions)1 SuggestionsBuilder (com.mojang.brigadier.suggestion.SuggestionsBuilder)1 java.awt (java.awt)1