Add emissive textures module, Try to fix puzzle-splashscreen

This commit is contained in:
Motschen
2021-12-30 17:31:10 +01:00
parent 1a1335a659
commit da4f52561e
10 changed files with 167 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ public class PuzzleConfig extends MidnightConfigLite {
@Entry public static boolean checkUpdates = true; @Entry public static boolean checkUpdates = true;
@Entry public static boolean showPuzzleInfo = true; @Entry public static boolean showPuzzleInfo = true;
@Entry public static boolean resourcepackSplashScreen = true; @Entry public static boolean resourcepackSplashScreen = true;
@Entry public static boolean randomEntityTextures = true; @Entry public static boolean emissiveTextures = true;
@Entry public static boolean customRenderLayers = true; @Entry public static boolean customRenderLayers = true;
@Entry public static boolean unlimitedRotations = true; @Entry public static boolean unlimitedRotations = true;
@Entry public static boolean biggerModels = true; @Entry public static boolean biggerModels = true;

5
puzzle-emissives/build.gradle Executable file
View File

@@ -0,0 +1,5 @@
archivesBaseName = "puzzle-emissives"
dependencies {
api project(":puzzle-base")
}

View File

@@ -0,0 +1,60 @@
package net.puzzlemc.emissives;
import net.fabricmc.api.ClientModInitializer;
import net.puzzlemc.core.config.PuzzleConfig;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class PuzzleEmissiveTextures implements ClientModInitializer {
public static final Map<Identifier, Identifier> emissiveTextures = new HashMap<>();
public void onInitializeClient() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("puzzle", "emissive_textures");
}
@Override
public void reload(ResourceManager manager) {
if (PuzzleConfig.emissiveTextures) {
String suffix = "_e";
for (Identifier id : manager.findResources("optifine", path -> path.contains("emissive.properties"))) {
try (InputStream stream = manager.getResource(id).getInputStream()) {
Properties properties = new Properties();
properties.load(stream);
if (properties.get("suffix.emissive") != null) {
suffix = properties.get("suffix.emissive").toString();
}
} catch (Exception e) {
LogManager.getLogger("Puzzle").error("Error occurred while loading emissive.properties " + id.toString(), e);
}
String finalSuffix = suffix;
for (Identifier emissiveId : manager.findResources("textures", path -> path.endsWith(finalSuffix + ".png"))) {
try {
String normalTexture = emissiveId.toString();
normalTexture = normalTexture.substring(0, normalTexture.lastIndexOf(finalSuffix));
Identifier normalId = Identifier.tryParse(normalTexture + ".png");
emissiveTextures.put(normalId, emissiveId);
if (PuzzleConfig.debugMessages) LogManager.getLogger("Puzzle").info(normalId + " " + emissiveId);
} catch (Exception e) {
LogManager.getLogger("Puzzle").error("Error occurred while loading emissive texture " + emissiveId.toString(), e);
}
}
}
}
}
});
}
}

View File

@@ -0,0 +1,37 @@
package net.puzzlemc.emissives.mixin;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.*;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.puzzlemc.core.config.PuzzleConfig;
import net.puzzlemc.emissives.PuzzleEmissiveTextures;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = LivingEntityRenderer.class)
public abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends EntityModel<T>> extends EntityRenderer<T> implements FeatureRendererContext<T, M> {
@Shadow public abstract M getModel();
protected MixinLivingEntityRenderer(EntityRendererFactory.Context ctx) {
super(ctx);
}
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/EntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;IIFFFF)V", shift = At.Shift.AFTER), method = "render*")
private void onRender(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
if (PuzzleConfig.emissiveTextures && PuzzleEmissiveTextures.emissiveTextures.containsKey(this.getTexture(entity))) {
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getBeaconBeam(PuzzleEmissiveTextures.emissiveTextures.get(this.getTexture(entity)),true));
this.getModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,40 @@
{
"schemaVersion": 1,
"id": "puzzle-emissives",
"version": "${version}",
"name": "Puzzle Emissive Textures",
"description": "Displays emissive textures on blocks and entities",
"authors": [
"PuzzleMC",
"Motschen"
],
"contact": {
"homepage": "https://www.midnightdust.eu/",
"sources": "https://github.com/TeamMidnightDust/Puzzle",
"issues": "https://github.com/TeamMidnightDust/Puzzle/issues"
},
"license": "MIT",
"icon": "assets/puzzle/icon.png",
"environment": "client",
"entrypoints": {
"client": [
"net.puzzlemc.emissives.PuzzleEmissiveTextures"
]
},
"custom": {
"modmenu": {
"parent": "puzzle"
}
},
"mixins": [
"puzzle-emissives.mixins.json"
],
"depends": {
"fabric": "*"
}
}

View File

@@ -0,0 +1,11 @@
{
"required": true,
"package": "net.puzzlemc.emissives.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"MixinLivingEntityRenderer"
],
"injectors": {
"defaultRequire": 1
}
}

View File

@@ -53,10 +53,14 @@ public class PuzzleClient implements ClientModInitializer {
PuzzleSplashScreen.resetColors(); PuzzleSplashScreen.resetColors();
MinecraftClient.getInstance().getTextureManager().registerTexture(PuzzleSplashScreen.LOGO, new PuzzleSplashScreen.LogoTexture()); MinecraftClient.getInstance().getTextureManager().registerTexture(PuzzleSplashScreen.LOGO, new PuzzleSplashScreen.LogoTexture());
})); }));
PuzzleApi.addToResourceOptions(new PuzzleWidget(Text.of("Disable splash screen logo blending "), (button) -> button.setMessage(PuzzleConfig.disableSplashScreenBlend ? YES : NO), (button) -> {
PuzzleConfig.disableSplashScreenBlend = !PuzzleConfig.disableSplashScreenBlend;
PuzzleConfig.write(id);
}));
} }
if (FabricLoader.getInstance().isModLoaded("puzzle-randomentities")) { if (FabricLoader.getInstance().isModLoaded("puzzle-emissives")) {
PuzzleApi.addToResourceOptions(new PuzzleWidget(Text.of("Random Entity Textures"), (button) -> button.setMessage(PuzzleConfig.randomEntityTextures ? YES : NO), (button) -> { PuzzleApi.addToResourceOptions(new PuzzleWidget(Text.of("Emissive Textures"), (button) -> button.setMessage(PuzzleConfig.emissiveTextures ? YES : NO), (button) -> {
PuzzleConfig.randomEntityTextures = !PuzzleConfig.randomEntityTextures; PuzzleConfig.emissiveTextures = !PuzzleConfig.emissiveTextures;
PuzzleConfig.write(id); PuzzleConfig.write(id);
})); }));
} }

View File

@@ -1,6 +1,7 @@
package net.puzzlemc.splashscreen.mixin; package net.puzzlemc.splashscreen.mixin;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Overlay; import net.minecraft.client.gui.screen.Overlay;
import net.minecraft.client.gui.screen.SplashOverlay; import net.minecraft.client.gui.screen.SplashOverlay;
@@ -69,6 +70,10 @@ public abstract class MixinSplashScreen extends Overlay {
GlStateManager._clear(16384, MinecraftClient.IS_SYSTEM_MAC); GlStateManager._clear(16384, MinecraftClient.IS_SYSTEM_MAC);
} }
} }
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;enableBlend()V", shift = At.Shift.AFTER))
private void disableBlend(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (PuzzleConfig.disableSplashScreenBlend) RenderSystem.disableBlend();
}
@ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"), index = 5) @ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"), index = 5)
private int modifyProgressFrame(int color) { // Set the Progress Bar Frame Color to our configured value // private int modifyProgressFrame(int color) { // Set the Progress Bar Frame Color to our configured value //

View File

@@ -14,3 +14,4 @@ include 'puzzle-models'
include 'puzzle-blocks' include 'puzzle-blocks'
//include 'puzzle-randomentities' //include 'puzzle-randomentities'
include 'puzzle-gui' include 'puzzle-gui'
include 'puzzle-emissives'