From 0039e7059113cf764cdbdb42d526dea03cceb3d1 Mon Sep 17 00:00:00 2001 From: QuImUfu Date: Sun, 2 Jul 2023 18:59:13 +0200 Subject: [PATCH] add transparent blocks --- blockPropertyDocumentation.txt | 23 ++++- build.gradle | 17 +--- settings.gradle | 2 +- .../simple_creator/BlockResourceLoader.java | 2 + .../simple_creator/BlockSettingsPojo.java | 3 +- .../simple_creator/SimpleCreatorMod.java | 6 ++ .../SimpleCreatorModClient.java | 88 +++++++++++++++++++ src/main/resources/fabric.mod.json | 7 +- 8 files changed, 127 insertions(+), 21 deletions(-) create mode 100644 src/main/java/quimufu/simple_creator/SimpleCreatorModClient.java diff --git a/blockPropertyDocumentation.txt b/blockPropertyDocumentation.txt index d4933b4..f561cfd 100644 --- a/blockPropertyDocumentation.txt +++ b/blockPropertyDocumentation.txt @@ -136,4 +136,25 @@ dull_red (0xBD3031), dull_pink (0x943F61), dark_crimson (0x5C191D), teal (0x167E86), dark_aqua (0x3A8E8C), dark_dull_pink (0x562C3E), bright_teal (0x14B485), deepslate_gray (0x646464), - raw_iron_pink (0xD8AF93), lichen_green (0x7FA796) \ No newline at end of file + raw_iron_pink (0xD8AF93), lichen_green (0x7FA796) + +"renderLayer" ~ string + one of: + solid, cutout_mipped, cutout, translucent, + translucent_moving_block, translucent_no_crumbling, + leash, water_mask, armor_glint, armor_entity_glint, glint_translucent, + glint, direct_glint, entity_glint, direct_entity_glint, text_background, + text_background_see_through, lightning, tripwire, end_portal, + end_gateway, lines, line_strip, debug_filled_box, debug_quads, + debug_section_quads, gui, gui_overlay, gui_text_highlight, + gui_ghost_recipe_overlay + different renderLayers allow different graphical effects. + Only the first 4 are interesting + solid = solid block no transparency + stone ... + cutout_mipped = 100% or no transparency, ?gets softened far away when mipmapping is enabled? + glass, leaves and similar + cutout = 100% or no transparency + flowers, saplings... + translucent = full alpha support + ice, stained glass, portal... diff --git a/build.gradle b/build.gradle index 50fc489..afc5f55 100644 --- a/build.gradle +++ b/build.gradle @@ -35,17 +35,6 @@ repositories { } } -loom { - splitEnvironmentSourceSets() - - mods { - "modid" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } - -} dependencies { // To change the versions see the gradle.properties file @@ -70,15 +59,13 @@ dependencies { include(modApi("de.siphalor.tweed4:tweed4-tailor-screen-$project.minecraft_major_version")) - modImplementation("me.shedaniel.cloth:cloth-config-fabric:$project.cloth_config_version") { - exclude(group: "net.fabricmc.fabric-api") - } + modImplementation("me.shedaniel.cloth:cloth-config-fabric:$project.cloth_config_version") // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" } configurations.include.transitive = true configurations.include.dependencies.each { - if (!it.name.contains("bom")) { + if (!it.name.contains("bom") && !it.name.contains("fabric")) { it.transitive = false } } diff --git a/settings.gradle b/settings.gradle index 89fa615..56266b4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,10 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' } + mavenCentral() gradlePluginPortal() } } \ No newline at end of file diff --git a/src/main/java/quimufu/simple_creator/BlockResourceLoader.java b/src/main/java/quimufu/simple_creator/BlockResourceLoader.java index 0d0bc33..ba6cddf 100644 --- a/src/main/java/quimufu/simple_creator/BlockResourceLoader.java +++ b/src/main/java/quimufu/simple_creator/BlockResourceLoader.java @@ -78,6 +78,8 @@ public class BlockResourceLoader extends GenericManualResourceLoader(resB, bspj.renderLayer)); return new Pair<>(resB, resI); } diff --git a/src/main/java/quimufu/simple_creator/BlockSettingsPojo.java b/src/main/java/quimufu/simple_creator/BlockSettingsPojo.java index ff2dfe0..c1b9221 100644 --- a/src/main/java/quimufu/simple_creator/BlockSettingsPojo.java +++ b/src/main/java/quimufu/simple_creator/BlockSettingsPojo.java @@ -29,5 +29,6 @@ public class BlockSettingsPojo { public boolean noBlockBreakParticles = false; public boolean requiresTool = false; public boolean breaksInstantly = false; - String mapColor = "stone"; + public String renderLayer = "solid"; + public String mapColor = "stone"; } diff --git a/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java b/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java index 56d220b..919438e 100644 --- a/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java +++ b/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java @@ -1,12 +1,18 @@ package quimufu.simple_creator; import net.fabricmc.api.ModInitializer; +import net.minecraft.block.Block; +import net.minecraft.util.Pair; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.ArrayList; +import java.util.List; + public class SimpleCreatorMod implements ModInitializer { + public static List> BLOCKS_RENDER_LAYER = new ArrayList<>(); public static Logger LOGGER = LogManager.getLogger(); public static ItemResourceLoader irl = new ItemResourceLoader(); public static BlockResourceLoader brl = new BlockResourceLoader(); diff --git a/src/main/java/quimufu/simple_creator/SimpleCreatorModClient.java b/src/main/java/quimufu/simple_creator/SimpleCreatorModClient.java new file mode 100644 index 0000000..f1c249d --- /dev/null +++ b/src/main/java/quimufu/simple_creator/SimpleCreatorModClient.java @@ -0,0 +1,88 @@ +package quimufu.simple_creator; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.minecraft.block.Block; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.util.Pair; +import org.apache.logging.log4j.Level; + +@Environment(EnvType.CLIENT) +public class SimpleCreatorModClient implements ClientModInitializer { + @Override + public void onInitializeClient() { + for (Pair blockRenderLayerPair : SimpleCreatorMod.BLOCKS_RENDER_LAYER) { + BlockRenderLayerMap.INSTANCE.putBlock(blockRenderLayerPair.getLeft(), getRenderLayer(blockRenderLayerPair.getRight())); + } + } + + private net.minecraft.client.render.RenderLayer getRenderLayer(String renderLayer) { + switch (renderLayer.toUpperCase()){ + case "SOLID": + return RenderLayer.getSolid(); + case "CUTOUT_MIPPED": + return RenderLayer.getCutoutMipped(); + case "CUTOUT": + return RenderLayer.getCutout(); + case "TRANSLUCENT": + return RenderLayer.getTranslucent(); + case "TRANSLUCENT_MOVING_BLOCK": + return RenderLayer.getTranslucentMovingBlock(); + case "TRANSLUCENT_NO_CRUMBLING": + return RenderLayer.getTranslucentNoCrumbling(); + case "LEASH": + return RenderLayer.getLeash(); + case "WATER_MASK": + return RenderLayer.getWaterMask(); + case "ARMOR_GLINT": + return RenderLayer.getArmorGlint(); + case "ARMOR_ENTITY_GLINT": + return RenderLayer.getArmorEntityGlint(); + case "GLINT_TRANSLUCENT": + return RenderLayer.getGlintTranslucent(); + case "GLINT": + return RenderLayer.getGlint(); + case "DIRECT_GLINT": + return RenderLayer.getDirectGlint(); + case "ENTITY_GLINT": + return RenderLayer.getEntityGlint(); + case "DIRECT_ENTITY_GLINT": + return RenderLayer.getDirectEntityGlint(); + case "TEXT_BACKGROUND": + return RenderLayer.getTextBackground(); + case "TEXT_BACKGROUND_SEE_THROUGH": + return RenderLayer.getTextBackgroundSeeThrough(); + case "LIGHTNING": + return RenderLayer.getLightning(); + case "TRIPWIRE": + return RenderLayer.getTripwire(); + case "END_PORTAL": + return RenderLayer.getEndPortal(); + case "END_GATEWAY": + return RenderLayer.getEndGateway(); + case "LINES": + return RenderLayer.getLines(); + case "LINE_STRIP": + return RenderLayer.getLineStrip(); + case "DEBUG_FILLED_BOX": + return RenderLayer.getDebugFilledBox(); + case "DEBUG_QUADS": + return RenderLayer.getDebugQuads(); + case "DEBUG_SECTION_QUADS": + return RenderLayer.getDebugSectionQuads(); + case "GUI": + return RenderLayer.getGui(); + case "GUI_OVERLAY": + return RenderLayer.getGuiOverlay(); + case "GUI_TEXT_HIGHLIGHT": + return RenderLayer.getGuiTextHighlight(); + case "GUI_GHOST_RECIPE_OVERLAY": + return RenderLayer.getGuiGhostRecipeOverlay(); + default: + SimpleCreatorMod.log(Level.INFO, "Could not find renderLayer " + renderLayer + " using solid"); + return RenderLayer.getSolid(); + } + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d602fc9..32ada9d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,15 +16,16 @@ "main": [ "quimufu.simple_creator.SimpleCreatorMod" ], - "client": [], - "server": [], + "client": [ + "quimufu.simple_creator.SimpleCreatorModClient" + ], "tweed4:config": [ "quimufu.simple_creator.SimpleCreatorConfig" ] }, "mixins": [], "depends": { - "fabricloader": ">=0.4.0", + "fabricloader": ">=0.14.21", "fabric": "*" } } \ No newline at end of file