Search in sources :

Example 1 with ResourceManager

use of net.minecraft.resource.ResourceManager in project Primeval by devs-immortal.

the class PrimevalFluids method setupFluidRendering.

/*
     * Fluid rendering setup from Spectrum,
     * Made by DaFaqs, credit to him for this
     * method
     */
@Environment(EnvType.CLIENT)
private static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
    final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath());
    final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
    // If they're not already present, add the sprites to the block atlas
    ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
        registry.register(stillSpriteId);
        registry.register(flowingSpriteId);
    });
    final Identifier fluidId = Registry.FLUID.getId(still);
    final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
    final Sprite[] fluidSprites = { null, null };
    ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {

        /**
         * Get the sprites from the block atlas when resources are reloaded
         */
        @Override
        public void reload(ResourceManager manager) {
            final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
            fluidSprites[0] = atlas.apply(stillSpriteId);
            fluidSprites[1] = atlas.apply(flowingSpriteId);
        }

        @Override
        public Identifier getFabricId() {
            return listenerId;
        }
    });
    // The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
    final FluidRenderHandler renderHandler = new FluidRenderHandler() {

        @Override
        public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
            return fluidSprites;
        }

        @Override
        public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
            return color;
        }
    };
    FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
// FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler); // Temp removed because of flowing shenanigans
}
Also used : SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) Function(java.util.function.Function) Identifier(net.minecraft.util.Identifier) BlockRenderView(net.minecraft.world.BlockRenderView) Sprite(net.minecraft.client.texture.Sprite) BlockPos(net.minecraft.util.math.BlockPos) ResourceManager(net.minecraft.resource.ResourceManager) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) FluidState(net.minecraft.fluid.FluidState) Environment(net.fabricmc.api.Environment)

Example 2 with ResourceManager

use of net.minecraft.resource.ResourceManager in project BleachHack by BleachDrinker420.

the class ShaderLoader method loadEffect.

public static ShaderEffect loadEffect(Framebuffer framebuffer, Identifier id) throws JsonSyntaxException, IOException {
    ResourceManager resMang = MinecraftClient.getInstance().getResourceManager();
    TextureManager texMang = MinecraftClient.getInstance().getTextureManager();
    return new ShaderEffect(texMang, new OpenResourceManager(resMang), framebuffer, id);
}
Also used : TextureManager(net.minecraft.client.texture.TextureManager) ResourceManager(net.minecraft.resource.ResourceManager) ShaderEffect(net.minecraft.client.gl.ShaderEffect)

Example 3 with ResourceManager

use of net.minecraft.resource.ResourceManager in project fabric by FabricMC.

the class ResourceReloadModClient method onInitializeClient.

@Override
public void onInitializeClient() {
    for (int i = 64; i >= 2; i--) {
        final int _i = i;
        ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {

            @Override
            public void apply(ResourceManager var1) {
                System.out.println("Reloading (should run as #" + _i + ")");
            }

            @Override
            public Identifier getFabricId() {
                return new Identifier("fabric:rrmc" + _i);
            }

            @Override
            public Collection<Identifier> getFabricDependencies() {
                return Collections.singletonList(new Identifier("fabric:rrmc" + (_i - 1)));
            }
        });
    }
    ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {

        @Override
        public Identifier getFabricId() {
            return new Identifier("fabric:rrmc1");
        }

        @Override
        public void apply(ResourceManager var1) {
            System.out.println("Reloading (should run as #1)");
        }
    });
    ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {

        @Override
        public Identifier getFabricId() {
            return new Identifier("fabric:rrmc_should_not_resolve");
        }

        @Override
        public Collection<Identifier> getFabricDependencies() {
            return Collections.singletonList(new Identifier("fabric:rrmc_nonexistent"));
        }

        @Override
        public void apply(ResourceManager var1) {
        }
    });
}
Also used : SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) Identifier(net.minecraft.util.Identifier) Collection(java.util.Collection) ResourceManager(net.minecraft.resource.ResourceManager)

Example 4 with ResourceManager

use of net.minecraft.resource.ResourceManager in project quilt-standard-libraries by QuiltMC.

the class ResourceReloaderTestMod method setupClientReloadListeners.

private void setupClientReloadListeners() {
    ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(new SimpleSynchronousResourceReloader() {

        @Override
        public Identifier getQuiltId() {
            return ResourceLoaderTestMod.id("client_second");
        }

        @Override
        public void reload(ResourceManager manager) {
            if (!clientResources) {
                throw new AssertionError("Second resource reloader was called before the first!");
            }
            LOGGER.info("Second client resource reloader is called.");
        }

        @Override
        public Collection<Identifier> getQuiltDependencies() {
            return Collections.singletonList(ResourceLoaderTestMod.id("client_first"));
        }
    });
    ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(new SimpleSynchronousResourceReloader() {

        @Override
        public Identifier getQuiltId() {
            return ResourceLoaderTestMod.id("client_first");
        }

        @Override
        public void reload(ResourceManager manager) {
            clientResources = true;
            LOGGER.info("First client resource reloader is called.");
        }
    });
}
Also used : Identifier(net.minecraft.util.Identifier) SimpleSynchronousResourceReloader(org.quiltmc.qsl.resource.loader.api.reloader.SimpleSynchronousResourceReloader) Collection(java.util.Collection) ResourceManager(net.minecraft.resource.ResourceManager)

Example 5 with ResourceManager

use of net.minecraft.resource.ResourceManager in project tweed-api by Siphalor.

the class Tweed method onInitialize.

@Override
public void onInitialize() {
    ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() {

        @Override
        public Identifier getFabricId() {
            return new Identifier(Tweed.MOD_ID, "resource_reload");
        }

        @Override
        public void apply(ResourceManager resourceManager) {
            try {
                ConfigLoader.loadConfigs(resourceManager, ConfigEnvironment.SERVER, ConfigScope.SMALLEST);
            } catch (Throwable e) {
                Tweed.LOGGER.error("Tweed failed to load config files:");
                e.printStackTrace();
            }
        }
    });
    ServerSidePacketRegistry.INSTANCE.register(REQUEST_SYNC_C2S_PACKET, (packetContext, packetByteBuf) -> {
        String fileName = packetByteBuf.readString(32767);
        for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
            if (configFile.getName().equals(fileName)) {
                if (Objects.requireNonNull(packetContext.getPlayer().getServer()).getPermissionLevel(packetContext.getPlayer().getGameProfile()) == 4) {
                    configFile.syncToClient((ServerPlayerEntity) packetContext.getPlayer(), packetByteBuf.readEnumConstant(ConfigEnvironment.class), packetByteBuf.readEnumConstant(ConfigScope.class), packetByteBuf.readEnumConstant(ConfigOrigin.class));
                } else {
                    packetByteBuf.readEnumConstant(ConfigEnvironment.class);
                    ConfigScope scope = packetByteBuf.readEnumConstant(ConfigScope.class);
                    packetByteBuf.readEnumConstant(ConfigOrigin.class);
                    configFile.syncToClient((ServerPlayerEntity) packetContext.getPlayer(), ConfigEnvironment.SYNCED, scope, ConfigOrigin.DATAPACK);
                }
                break;
            }
        }
    });
    ServerSidePacketRegistry.INSTANCE.register(TWEED_CLOTH_SYNC_C2S_PACKET, ((packetContext, packetByteBuf) -> {
        String fileName = packetByteBuf.readString(32767);
        for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
            if (configFile.getName().equals(fileName)) {
                if (Objects.requireNonNull(packetContext.getPlayer().getServer()).getPermissionLevel(packetContext.getPlayer().getGameProfile()) == 4) {
                    ConfigEnvironment environment = packetByteBuf.readEnumConstant(ConfigEnvironment.class);
                    ConfigScope scope = packetByteBuf.readEnumConstant(ConfigScope.class);
                    configFile.read(packetByteBuf, environment, ConfigScope.SMALLEST, ConfigOrigin.MAIN);
                    ConfigLoader.updateMainConfigFile(configFile, environment, scope);
                } else {
                    packetByteBuf.clear();
                }
                break;
            }
        }
    }));
}
Also used : SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) FabricLoader(net.fabricmc.loader.api.FabricLoader) ResourceManagerHelper(net.fabricmc.fabric.api.resource.ResourceManagerHelper) ModInitializer(net.fabricmc.api.ModInitializer) ResourceManager(net.minecraft.resource.ResourceManager) File(java.io.File) Objects(java.util.Objects) MinecraftServer(net.minecraft.server.MinecraftServer) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Logger(org.apache.logging.log4j.Logger) ResourceType(net.minecraft.resource.ResourceType) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) ClientCore(de.siphalor.tweed.client.ClientCore) de.siphalor.tweed.config(de.siphalor.tweed.config) ServerSidePacketRegistry(net.fabricmc.fabric.api.network.ServerSidePacketRegistry) SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) LogManager(org.apache.logging.log4j.LogManager) Identifier(net.minecraft.util.Identifier) ResourceManager(net.minecraft.resource.ResourceManager)

Aggregations

ResourceManager (net.minecraft.resource.ResourceManager)11 Identifier (net.minecraft.util.Identifier)10 SimpleSynchronousResourceReloadListener (net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener)6 BlockPos (net.minecraft.util.math.BlockPos)4 Collection (java.util.Collection)3 Function (java.util.function.Function)3 FluidRenderHandler (net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler)3 Sprite (net.minecraft.client.texture.Sprite)3 FluidState (net.minecraft.fluid.FluidState)3 BlockRenderView (net.minecraft.world.BlockRenderView)3 File (java.io.File)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Pair (com.mojang.datafixers.util.Pair)1 FontManagerAccessor (com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor)1 MinecraftClientAccessor (com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor)1 ClientCore (de.siphalor.tweed.client.ClientCore)1 de.siphalor.tweed.config (de.siphalor.tweed.config)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1