Skip to content

Commit

Permalink
port to fabric (part 2), USE MODRINTH MAVEN MORE!
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Oct 3, 2023
1 parent 5ea3e89 commit 443e515
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
14 changes: 10 additions & 4 deletions src/main/java/dm/earth/cabricality/Cabricality.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.krlite.equator.visual.color.AccurateColor;
import net.krlite.equator.visual.texture.Texture;
import net.minecraft.item.ItemGroup;
Expand All @@ -34,8 +38,6 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.solid.brrp.v1.api.RuntimeResourcePack;
Expand Down Expand Up @@ -106,6 +108,8 @@ public static class RRPs {
public static final CabfConfig CONFIG = new CabfConfig();
private static long initTime = -1;

public static final ModContainer CABF_MODCONTAINER = FabricLoader.getInstance().getModContainer(ID).orElseThrow();

@Contract("_ -> new")
public static @NotNull Identifier id(String... paths) {
return new Identifier(ID, String.join("/", paths));
Expand Down Expand Up @@ -157,8 +161,10 @@ public void onInitialize() {
RRPCallback.AFTER_VANILLA.register(list -> list.add(RRPs.SERVER_RESOURCES));

// TODO: Resource loader api
ResourceLoader.registerBuiltinResourcePack(id("data_overrides"),
ResourcePackActivationType.ALWAYS_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(id("data_overrides"),
CABF_MODCONTAINER,
ResourcePackActivationType.ALWAYS_ENABLED
);
}

public static void finishLoading() {
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/dm/earth/cabricality/client/CabricalityClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import dm.earth.cabricality.Cabricality;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType;
import dm.earth.cabricality.client.listener.ColorRegistryListener;
import dm.earth.cabricality.config.key.CabfKeyBinds;
import dm.earth.cabricality.content.alchemist.core.Substrate;
Expand Down Expand Up @@ -61,12 +61,16 @@ public void onInitializeClient() {
.forEach(entry -> BlockRenderLayerMap.INSTANCE.putBlock(entry.getBlock(), entry.getLayer()));

// TODO: Resource loader api
ResourceLoader.registerBuiltinResourcePack(Cabricality.id("asset_edits"),
ResourcePackActivationType.DEFAULT_ENABLED,
Cabricality.genTranslatableText("pack", "asset_edits"));
ResourceLoader.registerBuiltinResourcePack(Cabricality.id("quests_lang"),
ResourcePackActivationType.ALWAYS_ENABLED,
Cabricality.genTranslatableText("pack", "quests_lang"));
ResourceManagerHelper.registerBuiltinResourcePack(Cabricality.id("asset_edits"),
Cabricality.CABF_MODCONTAINER,
Cabricality.genTranslatableText("pack", "asset_edits"),
ResourcePackActivationType.DEFAULT_ENABLED
);
ResourceManagerHelper.registerBuiltinResourcePack(Cabricality.id("quests_lang"),
Cabricality.CABF_MODCONTAINER,
Cabricality.genTranslatableText("pack", "quests_lang"),
ResourcePackActivationType.ALWAYS_ENABLED
);
}

public static void cubeMapRenderer(RotatingCubeMapRenderer cubeMapRenderer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import dm.earth.cabricality.Cabricality;
import dm.earth.cabricality.content.fluids.core.IFluid;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.texture.Sprite;
Expand All @@ -17,9 +20,6 @@
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.quiltmc.qsl.block.extensions.api.client.BlockRenderLayerMap;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
import org.quiltmc.qsl.resource.loader.api.reloader.SimpleSynchronousResourceReloader;

import java.util.List;
import java.util.function.Function;
Expand Down Expand Up @@ -58,19 +58,19 @@ public static void register(String name, String texture, Fluid still, Fluid flow
*/

Sprite[] fluidSprites = {null, null};
ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(new SimpleSynchronousResourceReloader() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public @NotNull Identifier getFabricId() {
return Cabricality.id(name + "_fluid_renderer_reloader");
}

@Override
public void reload(ResourceManager manager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance()
.getSpriteAtlas(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillId);
fluidSprites[1] = atlas.apply(flowingId);
}

@Override
public @NotNull Identifier getQuiltId() {
return Cabricality.id(name + "_fluid_renderer_reloader");
}
});

FluidRenderHandler handler = new FluidRenderHandler() {
Expand All @@ -87,9 +87,9 @@ public int getFluidColor(@Nullable BlockRenderView view, @Nullable BlockPos pos,

FluidRenderHandlerRegistry.INSTANCE.register(still, flowing, handler);
if (flow)
BlockRenderLayerMap.put(RenderLayer.getTranslucent(), still, flowing);
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), still, flowing);
else
BlockRenderLayerMap.put(RenderLayer.getTranslucent(), still);
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), still);
}

public static void register(String name, Fluid still, Fluid flowing, boolean flow) {
Expand Down

0 comments on commit 443e515

Please sign in to comment.