mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-17 12:25:10 +01:00
Add emissive textures module, Try to fix puzzle-splashscreen
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user