Search in sources :

Example 56 with Identifier

use of net.minecraft.util.Identifier in project EdenClient by HahaOO7.

the class AntiStrip method onInteractBlock.

private ActionResult onInteractBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult blockHitResult) {
    if (!enabled)
        return ActionResult.PASS;
    if (!axeItems.contains((hand == Hand.MAIN_HAND ? player.getMainHandStack() : player.getOffHandStack()).getItem()))
        return ActionResult.PASS;
    Identifier id = Registry.BLOCK.getId(world.getBlockState(blockHitResult.getBlockPos()).getBlock());
    RegistryKey<? extends Registry<Block>> registry = BlockTags.LOGS.registry();
    DynamicRegistryManager registryManager = world.getRegistryManager();
    return registryManager.get(registry).containsId(id) ? ActionResult.FAIL : ActionResult.PASS;
}
Also used : Identifier(net.minecraft.util.Identifier) DynamicRegistryManager(net.minecraft.util.registry.DynamicRegistryManager) Block(net.minecraft.block.Block)

Example 57 with Identifier

use of net.minecraft.util.Identifier in project beebuddy by queenofthebees.

the class HeadFriendFeatureRenderer method render.

@Override
public void render(MatrixStack matrices, VertexConsumerProvider vcp, int light, T player, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
    IFriendlyPlayer friend = (IFriendlyPlayer) (Object) player;
    if (friend.beebuddy$hasHeadFriend()) {
        CompoundTag t = friend.beebuddy$getHeadFriendNbt();
        if (fake == null) {
            fake = new FakeBeeEntity(player.world);
        }
        Identifier tex = null;
        if (t.contains("BeeBuddyNectar")) {
            String type = t.getString("BeeBuddyNectar");
            if (!t.getString("BeeBuddyNectar").equals("default")) {
                String texture = "textures/entity/bee/" + type + "_bee.png";
                tex = new Identifier("beebuddy", texture);
            }
        }
        if (tex == null) {
            tex = new Identifier("textures/entity/bee/bee.png");
        }
        VertexConsumer v = vcp.getBuffer(bee.getLayer(tex));
        ModelPart h = this.getContextModel().getHead();
        matrices.push();
        if (player.isInSneakingPose()) {
            // offsets from BipedEntityModel
            matrices.translate(0F, 0.2625F, 0F);
        }
        matrices.multiply(Vector3f.POSITIVE_Z.getRadialQuaternion(h.roll));
        matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(h.yaw));
        matrices.multiply(Vector3f.POSITIVE_X.getRadialQuaternion(h.pitch));
        float ageMod = t.getInt("Age") >= 0 ? 2F : 1F;
        float headPos = player.isInSneakingPose() ? -1.4875F : -1.5F;
        matrices.translate(0F, ageMod * headPos - 0.4375, 0F);
        matrices.scale(ageMod, ageMod, ageMod);
        BeeEntityModelAccessor bea = (BeeEntityModelAccessor) (Object) bee;
        bee.setAngles(fake, 0F, 0F, animationProgress, 0F, 0F);
        bea.beebuddy$getBody().pitch = 0F;
        bea.beebuddy$getBody().pivotY = 19F;
        bee.render(matrices, v, light, OverlayTexture.DEFAULT_UV, 1F, 1F, 1F, 1F);
        matrices.pop();
    }
}
Also used : IFriendlyPlayer(nomble.beebuddy.duck.IFriendlyPlayer) Identifier(net.minecraft.util.Identifier) ModelPart(net.minecraft.client.model.ModelPart) BeeEntityModelAccessor(nomble.beebuddy.client.mixin.accessor.BeeEntityModelAccessor) VertexConsumer(net.minecraft.client.render.VertexConsumer) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 58 with Identifier

use of net.minecraft.util.Identifier in project map-canvas-api by Patbox.

the class TestMod method onInitialize.

public void onInitialize() {
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
        dispatcher.register(literal("test").then(argument("dir", IntegerArgumentType.integer(0, Direction.values().length)).then(argument("rot", IntegerArgumentType.integer(0, 4)).executes(this::test))));
        dispatcher.register(literal("setfps").then(argument("fps", IntegerArgumentType.integer(1)).executes((ctx) -> {
            this.msPerFrame = 1000 / IntegerArgumentType.getInteger(ctx, "fps");
            return 0;
        })));
        dispatcher.register(literal("saveimage").executes((ctx -> {
            var image = CanvasUtils.toImage(this.lastImage);
            try {
                ImageIO.write(image, "png", Files.newOutputStream(FabricLoader.getInstance().getGameDir().resolve("output.png"), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return 0;
        })));
    });
    ServerPlayConnectionEvents.JOIN.register((ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server) -> {
        this.canvas.addPlayer(handler);
    });
    ServerPlayConnectionEvents.DISCONNECT.register((ServerPlayNetworkHandler handler, MinecraftServer server) -> {
        this.canvas.removePlayer(handler);
    });
    try {
        var image = ImageIO.read(new URL("https://cdn.discordapp.com/attachments/552976908070027270/854881217950122024/tinypotato.png"));
        for (int i = 0; i < 10; i++) {
            long start = System.currentTimeMillis();
            this.tater = CanvasImage.from(image);
            System.out.println("Buildin time passed = " + (System.currentTimeMillis() - start));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        this.logo = CanvasImage.from(ImageIO.read(Files.newInputStream(FabricLoader.getInstance().getModContainer("map-canvas-api").get().getPath("assets/icon.png"))));
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        var vanillaZip = PolymerUtils.getClientJar();
        var compPath = FabricLoader.getInstance().getGameDir().resolve("coml.zip");
        var unsPath = FabricLoader.getInstance().getGameDir().resolve("uns.zip");
        var vanillaJsonPath = FabricLoader.getInstance().getGameDir().resolve("../vanilla-font-json.zip");
        if (!Files.exists(compPath)) {
            FileUtils.copyURLToFile(new URL("https://github.com/Compliance-Resource-Pack/Compliance-Java-32x/releases/download/beta-20/Compliance-32x-Java-Beta-20.zip"), compPath.toFile(), 10000, 10000);
        }
        if (!Files.exists(unsPath)) {
            FileUtils.copyURLToFile(new URL("https://media.forgecdn.net/files/3354/621/Unsanded-1.1.zip"), unsPath.toFile(), 10000, 10000);
        }
        var hdPack = new ZipFile(compPath.toFile());
        var unsPack = new ZipFile(unsPath.toFile());
        var jsonPack = new ZipFile(vanillaJsonPath.toFile());
        this.font = FontUtils.fromVanillaFormat(new Identifier("minecraft:default"), vanillaZip);
        this.fontHd = FontUtils.fromVanillaFormat(new Identifier("minecraft:default"), hdPack, vanillaZip);
        this.fontUnsanded = FontUtils.fromVanillaFormat(new Identifier("minecraft:default"), unsPack, jsonPack);
        var path = FabricLoader.getInstance().getGameDir().resolve("fonts_export");
        Files.createDirectories(path);
        {
            var stream = new FileOutputStream(path.resolve("vanilla.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) this.font, stream);
            stream.close();
        }
        {
            var stream = new FileOutputStream(path.resolve("unsanded.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) this.fontUnsanded, stream);
            stream.close();
        }
        {
            var stream = new FileOutputStream(path.resolve("alt.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) FontUtils.fromVanillaFormat(new Identifier("minecraft:alt"), vanillaZip), stream);
            stream.close();
        }
        {
            var stream = new FileOutputStream(path.resolve("illageralt.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) FontUtils.fromVanillaFormat(new Identifier("minecraft:illageralt"), vanillaZip), stream);
            stream.close();
        }
        vanillaZip.close();
        hdPack.close();
        unsPack.close();
        jsonPack.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
    } catch (Exception e) {
        e.printStackTrace();
    }
    ServerLifecycleEvents.SERVER_STARTED.register((s) -> {
        this.setCurrentRenderer(this.menuRenderer);
        this.renderers.add(new Pair<>("TaterDemo", new TaterDemoRenderer(this.tater, this.fontHd, this.logo)));
        this.renderers.add(new Pair<>("SimpleSurface", new SurfaceRenderer()));
        this.renderers.add(new Pair<>("Raycast", new RaycastRenderer(s)));
        if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
            this.renderers.add(new Pair<>("Client Framebuffer", new ClientRenderer()));
        }
        this.startUpdateThread();
    });
    ServerLifecycleEvents.SERVER_STOPPED.register((s) -> {
        this.setCurrentRenderer(this.menuRenderer);
        this.renderers.clear();
        this.activeRenderer = false;
    });
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) MinecraftServer(net.minecraft.server.MinecraftServer) Identifier(net.minecraft.util.Identifier) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) BitmapFont(eu.pb4.mapcanvas.impl.font.BitmapFont)

Example 59 with Identifier

use of net.minecraft.util.Identifier in project fabric by FabricMC.

the class ModNioResourcePack method findResources.

@Override
public Collection<Identifier> findResources(ResourceType type, String path, int depth, Predicate<String> predicate) {
    List<Identifier> ids = new ArrayList<>();
    String nioPath = path.replace("/", separator);
    for (String namespace : getNamespaces(type)) {
        Path namespacePath = getPath(type.getName() + "/" + namespace);
        if (namespacePath != null) {
            Path searchPath = namespacePath.resolve(nioPath).toAbsolutePath().normalize();
            if (Files.exists(searchPath)) {
                try {
                    Files.walk(searchPath, depth).filter(Files::isRegularFile).filter((p) -> {
                        String filename = p.getFileName().toString();
                        return !filename.endsWith(".mcmeta") && predicate.test(filename);
                    }).map(namespacePath::relativize).map((p) -> p.toString().replace(separator, "/")).forEach((s) -> {
                        try {
                            ids.add(new Identifier(namespace, s));
                        } catch (InvalidIdentifierException e) {
                            LOGGER.error(e.getMessage());
                        }
                    });
                } catch (IOException e) {
                    LOGGER.warn("findResources at " + path + " in namespace " + namespace + ", mod " + modInfo.getId() + " failed!", e);
                }
            }
        }
    }
    return ids;
}
Also used : Path(java.nio.file.Path) java.util(java.util) Files(java.nio.file.Files) ModResourcePack(net.fabricmc.fabric.api.resource.ModResourcePack) Predicate(java.util.function.Predicate) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DirectoryStream(java.nio.file.DirectoryStream) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) InvalidIdentifierException(net.minecraft.util.InvalidIdentifierException) Logger(org.apache.logging.log4j.Logger) ResourceType(net.minecraft.resource.ResourceType) Identifier(net.minecraft.util.Identifier) Pattern(java.util.regex.Pattern) LogManager(org.apache.logging.log4j.LogManager) Path(java.nio.file.Path) AbstractFileResourcePack(net.minecraft.resource.AbstractFileResourcePack) InputStream(java.io.InputStream) Identifier(net.minecraft.util.Identifier) InvalidIdentifierException(net.minecraft.util.InvalidIdentifierException) IOException(java.io.IOException) Files(java.nio.file.Files)

Example 60 with Identifier

use of net.minecraft.util.Identifier in project fabric by FabricMC.

the class ResourceManagerHelperImpl method sort.

protected void sort(List<ResourceReloadListener> listeners) {
    listeners.removeAll(addedListeners);
    // General rules:
    // - We *do not* touch the ordering of vanilla listeners. Ever.
    // While dependency values are provided where possible, we cannot
    // trust them 100%. Only code doesn't lie.
    // - We addReloadListener all custom listeners after vanilla listeners. Same reasons.
    List<IdentifiableResourceReloadListener> listenersToAdd = Lists.newArrayList(addedListeners);
    Set<Identifier> resolvedIds = new HashSet<>();
    for (ResourceReloadListener listener : listeners) {
        if (listener instanceof IdentifiableResourceReloadListener) {
            resolvedIds.add(((IdentifiableResourceReloadListener) listener).getFabricId());
        }
    }
    int lastSize = -1;
    while (listeners.size() != lastSize) {
        lastSize = listeners.size();
        Iterator<IdentifiableResourceReloadListener> it = listenersToAdd.iterator();
        while (it.hasNext()) {
            IdentifiableResourceReloadListener listener = it.next();
            if (resolvedIds.containsAll(listener.getFabricDependencies())) {
                resolvedIds.add(listener.getFabricId());
                listeners.add(listener);
                it.remove();
            }
        }
    }
    for (IdentifiableResourceReloadListener listener : listenersToAdd) {
        LOGGER.warn("Could not resolve dependencies for listener: " + listener.getFabricId() + "!");
    }
}
Also used : ResourceReloadListener(net.minecraft.resource.ResourceReloadListener) IdentifiableResourceReloadListener(net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener) Identifier(net.minecraft.util.Identifier) IdentifiableResourceReloadListener(net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener)

Aggregations

Identifier (net.minecraft.util.Identifier)343 NbtList (net.minecraft.nbt.NbtList)36 ItemStack (net.minecraft.item.ItemStack)31 Item (net.minecraft.item.Item)28 NbtCompound (net.minecraft.nbt.NbtCompound)22 NbtElement (net.minecraft.nbt.NbtElement)22 Inject (org.spongepowered.asm.mixin.injection.Inject)22 IOException (java.io.IOException)18 Block (net.minecraft.block.Block)18 MinecraftClient (net.minecraft.client.MinecraftClient)15 BlockItem (net.minecraft.item.BlockItem)15 BlockPos (net.minecraft.util.math.BlockPos)15 Map (java.util.Map)12 BlockState (net.minecraft.block.BlockState)12 ArrayList (java.util.ArrayList)11 VertexConsumer (net.minecraft.client.render.VertexConsumer)11 ResourceManager (net.minecraft.resource.ResourceManager)11 SoundEvent (net.minecraft.sound.SoundEvent)11 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)10 LiteralText (net.minecraft.text.LiteralText)10