From ccfed0059bcf33c8078ffb569918c39a3f25c5da Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 17 Jun 2023 18:01:42 +0100 Subject: [PATCH] Render the computer cursor as emissive - Split the front face of the computer model into two layers - one for the main texture, and one for the cursor. This is actually a simplification of what we had before, which is nice. - Make the cursor layer render as an emissive quad, meaning it glows in the dark. This is very easy on Forge (just some model JSON) and very hard on Fabric (requires a custom model loader). --- .../cc-tweaked.java-convention.gradle.kts | 1 + .../data/BlockModelProvider.java | 25 ++- .../models/block/computer_on.json | 39 ++++ .../models/block/computer_on.json.license | 3 + .../block/computer_advanced_front_blink.png | Bin 476 -> 0 bytes .../block/computer_advanced_front_on.png | Bin 417 -> 0 bytes .../textures/block/computer_blink.png | Bin 0 -> 110 bytes ...k.png.mcmeta => computer_blink.png.mcmeta} | 0 .../block/computer_command_front_blink.png | Bin 534 -> 0 bytes .../computer_command_front_blink.png.mcmeta | 6 - .../block/computer_command_front_on.png | Bin 426 -> 0 bytes .../block/computer_normal_front_blink.png | Bin 214 -> 0 bytes .../computer_normal_front_blink.png.mcmeta | 6 - .../block/computer_normal_front_on.png | Bin 199 -> 0 bytes .../textures/block/computer_on.png | Bin 0 -> 89 bytes projects/fabric/build.gradle.kts | 1 - .../client/ComputerCraftClient.java | 6 +- .../client/model/EmissiveComputerModel.java | 172 ++++++++++++++++++ .../block/computer_advanced_blinking.json | 5 +- .../models/block/computer_advanced_on.json | 5 +- .../block/computer_command_blinking.json | 5 +- .../models/block/computer_command_on.json | 5 +- .../block/computer_normal_blinking.json | 5 +- .../models/block/computer_normal_on.json | 5 +- projects/forge/build.gradle.kts | 1 - .../block/computer_advanced_blinking.json | 5 +- .../models/block/computer_advanced_on.json | 5 +- .../block/computer_command_blinking.json | 5 +- .../models/block/computer_command_on.json | 5 +- .../block/computer_normal_blinking.json | 5 +- .../models/block/computer_normal_on.json | 5 +- 31 files changed, 276 insertions(+), 44 deletions(-) create mode 100644 projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json create mode 100644 projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json.license delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_advanced_front_blink.png delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_advanced_front_on.png create mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_blink.png rename projects/common/src/main/resources/assets/computercraft/textures/block/{computer_advanced_front_blink.png.mcmeta => computer_blink.png.mcmeta} (100%) delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png.mcmeta delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_on.png delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png.mcmeta delete mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_on.png create mode 100644 projects/common/src/main/resources/assets/computercraft/textures/block/computer_on.png create mode 100644 projects/fabric/src/client/java/dan200/computercraft/client/model/EmissiveComputerModel.java diff --git a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts index 9279f11aa..d8dfb6b4e 100644 --- a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts @@ -104,6 +104,7 @@ tasks.withType(JavaCompile::class.java).configureEach { tasks.processResources { exclude("**/*.license") + exclude(".cache") } tasks.withType(AbstractArchiveTask::class.java).configureEach { diff --git a/projects/common/src/main/java/dan200/computercraft/data/BlockModelProvider.java b/projects/common/src/main/java/dan200/computercraft/data/BlockModelProvider.java index 7b40cd2dd..d05d8c308 100644 --- a/projects/common/src/main/java/dan200/computercraft/data/BlockModelProvider.java +++ b/projects/common/src/main/java/dan200/computercraft/data/BlockModelProvider.java @@ -37,6 +37,14 @@ import static net.minecraft.data.models.model.ModelLocationUtils.getModelLocatio import static net.minecraft.data.models.model.TextureMapping.getBlockTexture; class BlockModelProvider { + private static final TextureSlot CURSOR = TextureSlot.create("cursor"); + + private static final ModelTemplate COMPUTER_ON = new ModelTemplate( + Optional.of(new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/computer_on")), + Optional.empty(), + TextureSlot.FRONT, TextureSlot.SIDE, TextureSlot.TOP, CURSOR + ); + private static final ModelTemplate MONITOR_BASE = new ModelTemplate( Optional.of(new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/monitor_base")), Optional.empty(), @@ -142,11 +150,18 @@ class BlockModelProvider { private static void registerComputer(BlockModelGenerators generators, ComputerBlock block) { generators.blockStateOutput.accept(MultiVariantGenerator.multiVariant(block) .with(createHorizontalFacingDispatch()) - .with(createModelDispatch(ComputerBlock.STATE, state -> ModelTemplates.CUBE_ORIENTABLE.createWithSuffix( - block, "_" + state.getSerializedName(), - TextureMapping.orientableCube(block).put(TextureSlot.FRONT, getBlockTexture(block, "_front" + state.getTexture())), - generators.modelOutput - ))) + .with(createModelDispatch(ComputerBlock.STATE, state -> switch (state) { + case OFF -> ModelTemplates.CUBE_ORIENTABLE.createWithSuffix( + block, "_" + state.getSerializedName(), + TextureMapping.orientableCube(block), + generators.modelOutput + ); + case ON, BLINKING -> COMPUTER_ON.createWithSuffix( + block, "_" + state.getSerializedName(), + TextureMapping.orientableCube(block).put(CURSOR, new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/computer" + state.getTexture())), + generators.modelOutput + ); + })) ); generators.delegateItemModel(block, getModelLocation(block, "_blinking")); } diff --git a/projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json b/projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json new file mode 100644 index 000000000..485bc526f --- /dev/null +++ b/projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json @@ -0,0 +1,39 @@ +{ + "parent": "minecraft:block/block", + "render_type": "cutout", + "textures": { + "particle": "#front" + }, + "display": { + "firstperson_righthand": { + "rotation": [ 0, 135, 0 ], + "translation": [ 0, 0, 0 ], + "scale": [ 0.40, 0.40, 0.40 ] + } + }, + "elements": [ + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#top", "cullface": "down" }, + "up": { "texture": "#top", "cullface": "up" }, + "north": { "texture": "#front", "cullface": "north" }, + "south": { "texture": "#side", "cullface": "south" }, + "west": { "texture": "#side", "cullface": "west" }, + "east": { "texture": "#side", "cullface": "east" } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "north": { + "texture": "#cursor", + "cullface": "north", + "forge_data": {"block_light": 15, "sky_light": 15} + } + } + } + ] +} diff --git a/projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json.license b/projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json.license new file mode 100644 index 000000000..05aed57f6 --- /dev/null +++ b/projects/common/src/main/resources/assets/computercraft/models/block/computer_on.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers + +SPDX-License-Identifier: MPL-2.0 diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_advanced_front_blink.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_advanced_front_blink.png deleted file mode 100644 index 8c29b0e49a7db4b9ff6077738b1e996fa5ec2702..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 476 zcmV<20VDp2P)4E;KzV{kb z+luJyju_5?f}-d;eK@zyal75lL<9g;MMN+&R26`>ZK|AxoP#fS*QhE!#)$I?fWzVNU;^(W zec$6(tJQp1mgU1q6jDm~rfE>zte`B*d4Gz`LI5Bx77NVWtl(EQr{Jb(`8>kNxiAx| zs>%Zk?(F+W5}b4R?RHD~=;~~OtH)1>F=hou_y-9}UDuhw`SS_19q`^~_YC3N*LRb> zKWsLfC}svIPI^odV>bYbiI7qv<_`uGneKOI@Hl6nIZ;jl6KotomCrY?a$38AloD>g-&@l(bDaO^mk1$*-?ET@;QPKOgfOrC zNNmpk@pxptUb9>-DT)FSp>11Y%#ZKV2PgXA-ZV~z`@i+UeYo_&r4RmVAAASVP;j(; SaG00?0000ADWxIWP8~Sdw24?}-RfDFw?FfaCFaGa%;`!!VFG zo6SWHnx?rK5);%~NqyhrDp!N1X>J0jtN=*s^%_Z6gIi-$MH0!~N$ClTqmj04NdPId z{QV@%jI`VBxW9k481S@xPAO$JAm1%FaM5+$1)#Ki2B(pf(!9#Td3^l%cfw|f31Yqr zlgJF{JP_ju1aha=N|6M1x_;%nC9_dVfm}#VjK5(DUcUMQz|ZgRSglr+oHM2~rhp5> z5OM=E46q1PgDmIa+Z!a|r-524b~qf=_x<&p{}*>B=loAErP=ZitgFdS6eT8w00000 LNkvXXu0mjf_rJJG diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_blink.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_blink.png new file mode 100644 index 0000000000000000000000000000000000000000..0cb8a6c95bd0a32728b056ab28277f5238132b20 GIT binary patch literal 110 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5!3HFyJAa%3Ql_3Rjv*f2$q5p159|d3-Y9qR zI9}sP3QmzY8YgL*V8Y^7#1WwSJurpCb(VY4mEK>q0xb*-yI;#c^c8#wWHB&!y85}S Ib4q9e0JG#DcmMzZ literal 0 HcmV?d00001 diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_advanced_front_blink.png.mcmeta b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_blink.png.mcmeta similarity index 100% rename from projects/common/src/main/resources/assets/computercraft/textures/block/computer_advanced_front_blink.png.mcmeta rename to projects/common/src/main/resources/assets/computercraft/textures/block/computer_blink.png.mcmeta diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png deleted file mode 100644 index be746fcb3f77c2b9589a09e09d817638e24582a1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 534 zcmV+x0_pvUP)yX#SeO>=g#aJ-&aWW^lDtQe8j3P_@vqrvHBT)6LNsnCHTfB8RVDqA^BFDcpbZoNf5<;wj6V z5W$JV2*AswD-=YbY4Hc$L=EkI!{!@J1Q`lP&z0^N=nKDCz}lsBe)?+ z6ANh&mE%o8b7qVXVxkcVF|kxfhXHqI|KJOc4!@xS)dE^P&^@r51GNTvnVEGYS;5j0 z>IBwMiFg_~*uRa{!pV9fN6_nIn2q~fM69lJ-wVv z1?!#T^+YqLn}apnj6nl2D&~f!O!a^{6pxrgO6jTx=k?%1!D$cVUp=^ps~%kS;J^0Z YC!&prAf~vKP5=M^07*qoM6N<$f|4@zLI3~& diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png.mcmeta b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png.mcmeta deleted file mode 100644 index e962dcee6..000000000 --- a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_blink.png.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "animation": { - "frametime": 8, - "frames": [ 0, 1 ] - } -} diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_on.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_command_front_on.png deleted file mode 100644 index 1d5d38f7542e156d9d1ecc56ed531a8396569d8e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 426 zcmV;b0agBqP)-G#$Otw& z-F>U-Uc~yL|NfVA==J#{VV+x@WWGKuV^$9gSsl`vfm8EPite6;MOXoPdj1TWg=w{F zwU(T`+BlBY(R=S6DzvUvl3cxiry^ozPhP&k|N8p&)h;Jygp>ime!o8sBoAO=Yt7vO zOw)ASSnD8S?;Wk)E=<#O46G{vE~QY)w+qKF4JCPi-6IQQL(5tZi}74LBy9nOV;nM{ z?eh08AGd%X-#+!$*lK@x?_>+OfAE;sWma0=(7Y2*gc>)ABtK|qokge2`Ww3LXrxcvG2>bEkglUh&@I?Yrobz4^* zlAEU;>H=@d5~*BXJn(8ahb0U2Y>>~t{;;Tc{d-t)E)fn869}-@lPVF&D@y|K4;NRv UNiGHKf&c&j07*qoM6N<$f+mo=^Z)<= diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png deleted file mode 100644 index ba62d067ea0a4d103678cb1113070259a52ab469..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<50VEjg9xVrP=6bp~hG?9>I>DFgu!4ZwbFO&{ zoj6>lXo`7?-8BE=)U@M+730jKbM!-R2VJfeuYGXd#*SU4;96WynAf>;s~&beNXly2 zRMW$;SX}mEgICi34udA|MaG_oEU#46Tk10g-&daNaNPMa=NCi6!?UUna<93q=H8#nHgYA4x+n7_a8`gE N?CI*~vd$@?2>`;CRA>MI diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png.mcmeta b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png.mcmeta deleted file mode 100644 index e962dcee6..000000000 --- a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_blink.png.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "animation": { - "frametime": 8, - "frames": [ 0, 1 ] - } -} diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_on.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_normal_front_on.png deleted file mode 100644 index d87bcac8f2d5ea0c0d6ed637486f7454f2ac314e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx*Bp9q_EZ7UA`aE46LnI`94?1!+JMgexsBfLK zu*pMGCP>FQcE|e*+?+<;G433ZPin$+r&jW3O2}>GUnqH5;Fh|wsHLuw(ey(v(pF9B zP}p)Y_2q1)hcq1UlA1dqE*XCNjtR0$!t}Gi`gm*<=6eY<(TfR w+c#_Ft5vzLd-`X}ow?&{nvm4DT%i0+{QvhZcWxZnCmdKI;Vst0JgzOs{jB1 diff --git a/projects/common/src/main/resources/assets/computercraft/textures/block/computer_on.png b/projects/common/src/main/resources/assets/computercraft/textures/block/computer_on.png new file mode 100644 index 0000000000000000000000000000000000000000..3ad187b997c2bc5f1b2d226d21b2645353fe0792 GIT binary patch literal 89 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`3Z5>GAr}702@-J+>;(eeD0lHJ l^e{f^CvTcy!lJ>+$gstm`|HdUjS`?*22WQ%mvv4FO#nRN6?*^x literal 0 HcmV?d00001 diff --git a/projects/fabric/build.gradle.kts b/projects/fabric/build.gradle.kts index f2aef9cb8..db8701486 100644 --- a/projects/fabric/build.gradle.kts +++ b/projects/fabric/build.gradle.kts @@ -165,7 +165,6 @@ tasks.processResources { filesMatching("fabric.mod.json") { expand(mapOf("version" to modVersion)) } - exclude(".cache") } tasks.jar { diff --git a/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java b/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java index 292d1ea9a..170034086 100644 --- a/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java +++ b/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java @@ -4,6 +4,7 @@ package dan200.computercraft.client; +import dan200.computercraft.client.model.EmissiveComputerModel; import dan200.computercraft.client.model.turtle.TurtleModelLoader; import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.network.client.ClientNetworkContext; @@ -35,9 +36,12 @@ public class ComputerCraftClient { ClientRegistry.registerItemColours(ColorProviderRegistry.ITEM::register); ClientRegistry.registerMainThread(); - ModelLoadingRegistry.INSTANCE.registerModelProvider((manager, out) -> ClientRegistry.registerExtraModels(out)); ModelLoadingRegistry.INSTANCE.registerResourceProvider(loader -> (path, ctx) -> TurtleModelLoader.load(loader, path)); + ModelLoadingRegistry.INSTANCE.registerResourceProvider(loader -> (path, ctx) -> EmissiveComputerModel.load(loader, path)); + BlockRenderLayerMap.INSTANCE.putBlock(ModRegistry.Blocks.COMPUTER_NORMAL.get(), RenderType.cutout()); + BlockRenderLayerMap.INSTANCE.putBlock(ModRegistry.Blocks.COMPUTER_COMMAND.get(), RenderType.cutout()); + BlockRenderLayerMap.INSTANCE.putBlock(ModRegistry.Blocks.COMPUTER_ADVANCED.get(), RenderType.cutout()); BlockRenderLayerMap.INSTANCE.putBlock(ModRegistry.Blocks.MONITOR_NORMAL.get(), RenderType.cutout()); BlockRenderLayerMap.INSTANCE.putBlock(ModRegistry.Blocks.MONITOR_ADVANCED.get(), RenderType.cutout()); diff --git a/projects/fabric/src/client/java/dan200/computercraft/client/model/EmissiveComputerModel.java b/projects/fabric/src/client/java/dan200/computercraft/client/model/EmissiveComputerModel.java new file mode 100644 index 000000000..27db7a75b --- /dev/null +++ b/projects/fabric/src/client/java/dan200/computercraft/client/model/EmissiveComputerModel.java @@ -0,0 +1,172 @@ +// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.client.model; + +import com.google.gson.JsonObject; +import com.mojang.datafixers.util.Either; +import dan200.computercraft.api.ComputerCraftAPI; +import net.fabricmc.fabric.api.client.model.ModelProviderException; +import net.fabricmc.fabric.api.client.model.ModelResourceProvider; +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; +import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; +import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; +import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.*; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.GsonHelper; +import net.minecraft.util.RandomSource; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.state.BlockState; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Wraps a computer's {@link BlockModel}/{@link BakedModel} to render the computer's cursor as an emissive quad. + *

+ * While Fabric has a quite advanced rendering extension API (including support for custom materials), but unlike Forge + * it doesn't expose this in the model JSON (though externals mods like JMX + * do handle this). + *

+ * Instead, we support emissive quads by injecting a custom {@linkplain ModelResourceProvider model loader/provider} + * which targets a hard-coded list of computer models, and wraps the returned model in a custom + * {@linkplain FabricBakedModel} implementation which renders specific quads as emissive. + *

+ * See also the assets/computercraft/models/block/computer_on.json model, which is the base for all + * emissive computer models. + */ +public final class EmissiveComputerModel { + private static final Set MODELS = Set.of( + "item/computer_advanced", + "block/computer_advanced_on", + "block/computer_advanced_blinking", + "item/computer_command", + "block/computer_command_on", + "block/computer_command_blinking", + "item/computer_normal", + "block/computer_normal_on", + "block/computer_normal_blinking" + ); + + private EmissiveComputerModel() { + } + + public static @Nullable UnbakedModel load(ResourceManager resources, ResourceLocation path) throws ModelProviderException { + if (!path.getNamespace().equals(ComputerCraftAPI.MOD_ID) || !MODELS.contains(path.getPath())) return null; + + JsonObject json; + try (var reader = resources.openAsReader(new ResourceLocation(path.getNamespace(), "models/" + path.getPath() + ".json"))) { + json = GsonHelper.parse(reader).getAsJsonObject(); + } catch (IOException e) { + throw new ModelProviderException("Failed loading model " + path, e); + } + + // Parse a subset of the model JSON + var parent = new ResourceLocation(GsonHelper.getAsString(json, "parent")); + + Map> textures = new HashMap<>(); + if (json.has("textures")) { + var jsonObject = GsonHelper.getAsJsonObject(json, "textures"); + + for (var entry : jsonObject.entrySet()) { + var texture = entry.getValue().getAsString(); + textures.put(entry.getKey(), texture.startsWith("#") + ? Either.right(texture.substring(1)) + : Either.left(new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(texture))) + ); + } + } + + return new Unbaked(parent, textures); + } + + /** + * An {@link UnbakedModel} which wraps the returned model using {@link Baked}. + *

+ * This subclasses {@link BlockModel} to allow using these models as a parent of other models. + */ + private static final class Unbaked extends BlockModel { + Unbaked(ResourceLocation parent, Map> materials) { + super(parent, List.of(), materials, null, null, ItemTransforms.NO_TRANSFORMS, List.of()); + } + + @Override + public BakedModel bake(ModelBaker baker, Function spriteGetter, ModelState state, ResourceLocation location) { + var baked = super.bake(baker, spriteGetter, state, location); + if (!hasTexture("cursor")) return baked; + + var render = RendererAccess.INSTANCE.getRenderer(); + if (render == null) return baked; + + return new Baked( + baked, + spriteGetter.apply(getMaterial("cursor")), + render.materialFinder().find(), + render.materialFinder().emissive(0, true).find() + ); + } + } + + /** + * A {@link FabricBakedModel} which renders quads using the {@code "cursor"} texture as emissive. + */ + private static final class Baked extends ForwardingBakedModel { + private final TextureAtlasSprite cursor; + private final RenderMaterial defaultMaterial; + private final RenderMaterial emissiveMaterial; + + Baked(BakedModel wrapped, TextureAtlasSprite cursor, RenderMaterial defaultMaterial, RenderMaterial emissiveMaterial) { + this.wrapped = wrapped; + this.cursor = cursor; + this.defaultMaterial = defaultMaterial; + this.emissiveMaterial = emissiveMaterial; + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + emitQuads(context, state, randomSupplier.get()); + } + + @Override + public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { + emitQuads(context, null, randomSupplier.get()); + } + + private void emitQuads(RenderContext context, @Nullable BlockState state, RandomSource random) { + var emitter = context.getEmitter(); + for (var faceIdx = 0; faceIdx <= ModelHelper.NULL_FACE_ID; faceIdx++) { + var cullFace = ModelHelper.faceFromIndex(faceIdx); + var quads = wrapped.getQuads(state, cullFace, random); + + var count = quads.size(); + for (var i = 0; i < count; i++) { + final var q = quads.get(i); + emitter.fromVanilla(q, q.getSprite() == cursor ? emissiveMaterial : defaultMaterial, cullFace); + emitter.emit(); + } + } + } + } +} diff --git a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json index e9fccca86..652f58ae1 100644 --- a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json +++ b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_advanced_front_blink", + "cursor": "computercraft:block/computer_blink", + "front": "computercraft:block/computer_advanced_front", "side": "computercraft:block/computer_advanced_side", "top": "computercraft:block/computer_advanced_top" } diff --git a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json index 497c1337d..fb7ab4898 100644 --- a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json +++ b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_advanced_front_on", + "cursor": "computercraft:block/computer_on", + "front": "computercraft:block/computer_advanced_front", "side": "computercraft:block/computer_advanced_side", "top": "computercraft:block/computer_advanced_top" } diff --git a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json index 62d746878..2177d9c7a 100644 --- a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json +++ b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_command_front_blink", + "cursor": "computercraft:block/computer_blink", + "front": "computercraft:block/computer_command_front", "side": "computercraft:block/computer_command_side", "top": "computercraft:block/computer_command_top" } diff --git a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_on.json b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_on.json index 36c6f0fa6..e4c5d608b 100644 --- a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_on.json +++ b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_command_on.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_command_front_on", + "cursor": "computercraft:block/computer_on", + "front": "computercraft:block/computer_command_front", "side": "computercraft:block/computer_command_side", "top": "computercraft:block/computer_command_top" } diff --git a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json index 7250268d7..a2f258290 100644 --- a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json +++ b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_normal_front_blink", + "cursor": "computercraft:block/computer_blink", + "front": "computercraft:block/computer_normal_front", "side": "computercraft:block/computer_normal_side", "top": "computercraft:block/computer_normal_top" } diff --git a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json index da2e671fe..e8dc8eb0c 100644 --- a/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json +++ b/projects/fabric/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_normal_front_on", + "cursor": "computercraft:block/computer_on", + "front": "computercraft:block/computer_normal_front", "side": "computercraft:block/computer_normal_side", "top": "computercraft:block/computer_normal_top" } diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 9291f2e4a..589e44f0d 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -206,7 +206,6 @@ tasks.processResources { filesMatching("META-INF/mods.toml") { expand(mapOf("forgeVersion" to libs.versions.forge.get(), "file" to mapOf("jarVersion" to modVersion))) } - exclude(".cache") } tasks.jar { diff --git a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json index e9fccca86..652f58ae1 100644 --- a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json +++ b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_blinking.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_advanced_front_blink", + "cursor": "computercraft:block/computer_blink", + "front": "computercraft:block/computer_advanced_front", "side": "computercraft:block/computer_advanced_side", "top": "computercraft:block/computer_advanced_top" } diff --git a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json index 497c1337d..fb7ab4898 100644 --- a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json +++ b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_advanced_on.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_advanced_front_on", + "cursor": "computercraft:block/computer_on", + "front": "computercraft:block/computer_advanced_front", "side": "computercraft:block/computer_advanced_side", "top": "computercraft:block/computer_advanced_top" } diff --git a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json index 62d746878..2177d9c7a 100644 --- a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json +++ b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_blinking.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_command_front_blink", + "cursor": "computercraft:block/computer_blink", + "front": "computercraft:block/computer_command_front", "side": "computercraft:block/computer_command_side", "top": "computercraft:block/computer_command_top" } diff --git a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_on.json b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_on.json index 36c6f0fa6..e4c5d608b 100644 --- a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_on.json +++ b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_command_on.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_command_front_on", + "cursor": "computercraft:block/computer_on", + "front": "computercraft:block/computer_command_front", "side": "computercraft:block/computer_command_side", "top": "computercraft:block/computer_command_top" } diff --git a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json index 7250268d7..a2f258290 100644 --- a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json +++ b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_blinking.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_normal_front_blink", + "cursor": "computercraft:block/computer_blink", + "front": "computercraft:block/computer_normal_front", "side": "computercraft:block/computer_normal_side", "top": "computercraft:block/computer_normal_top" } diff --git a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json index da2e671fe..e8dc8eb0c 100644 --- a/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json +++ b/projects/forge/src/generated/resources/assets/computercraft/models/block/computer_normal_on.json @@ -1,7 +1,8 @@ { - "parent": "minecraft:block/orientable", + "parent": "computercraft:block/computer_on", "textures": { - "front": "computercraft:block/computer_normal_front_on", + "cursor": "computercraft:block/computer_on", + "front": "computercraft:block/computer_normal_front", "side": "computercraft:block/computer_normal_side", "top": "computercraft:block/computer_normal_top" }