Skip to content

Commit 4ec689b

Browse files
committed
feature: shaders and some minor bugfix!
1 parent 87b2bec commit 4ec689b

9 files changed

Lines changed: 156 additions & 18 deletions

File tree

src/main/java/team/steelcode/awakenings/Awakenings.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package team.steelcode.awakenings;
22

3+
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.renderer.GameRenderer;
6+
import net.minecraft.client.renderer.ShaderDefines;
7+
import net.minecraft.client.renderer.ShaderProgram;
8+
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.server.packs.resources.ResourceManager;
10+
import net.minecraft.util.profiling.ProfilerFiller;
311
import net.neoforged.api.distmarker.Dist;
412
import net.neoforged.bus.api.IEventBus;
513
import net.neoforged.bus.api.SubscribeEvent;
@@ -13,6 +21,8 @@
1321
import team.steelcode.awakenings.modules.events.server_events.ModCreativeTabEvents;
1422
import team.steelcode.awakenings.setup.ModRegisters;
1523

24+
import java.io.IOException;
25+
1626

1727
@Mod(Awakenings.MODID)
1828
public class Awakenings {
@@ -27,7 +37,6 @@ public Awakenings(IEventBus modEventBus, ModContainer modContainer) {
2737
ModRegisters.register(modEventBus);
2838

2939
modEventBus.addListener(ModCreativeTabEvents::addCustomItemsToCustomCreativeTab);
30-
modEventBus.addListener(ModCreativeTabEvents::addCustomItemsToMinecraftCreativeTab);
3140

3241
}
3342

@@ -47,6 +56,16 @@ public static class ClientModEvents {
4756
@SubscribeEvent
4857
public static void onClientSetup(FMLClientSetupEvent event) {
4958

59+
60+
Minecraft minecraft = Minecraft.getInstance();
61+
ResourceManager resourceManager = minecraft.getResourceManager();
62+
63+
// Carga el archivo del shader desde los recursos
64+
ShaderProgram exampleShader = new ShaderProgram(
65+
ResourceLocation.fromNamespaceAndPath(MODID, "shader"),
66+
DefaultVertexFormat.NEW_ENTITY, // Nombre del shader (ubicado en `assets/modid/shaders/post/example.json`)
67+
ShaderDefines.EMPTY); // Usar el tipo de programa básico disponible
68+
5069
}
5170
}
5271
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package team.steelcode.awakenings.mixin;
2+
3+
import com.mojang.blaze3d.resource.CrossFrameResourcePool;
4+
import net.minecraft.client.DeltaTracker;
5+
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.renderer.GameRenderer;
7+
import net.minecraft.client.renderer.LevelTargetBundle;
8+
import net.minecraft.client.renderer.PostChain;
9+
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.world.entity.player.Player;
11+
import org.spongepowered.asm.mixin.Final;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Shadow;
14+
import org.spongepowered.asm.mixin.Unique;
15+
import org.spongepowered.asm.mixin.injection.At;
16+
import org.spongepowered.asm.mixin.injection.Inject;
17+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
18+
import team.steelcode.awakenings.Awakenings;
19+
import team.steelcode.awakenings.data.ModAttributes;
20+
21+
import java.util.Set;
22+
23+
//Credits to Startraveler on Discord!
24+
@Mixin(GameRenderer.class)
25+
public class GameRendererAddPostShadersMixin {
26+
27+
@Shadow
28+
@Final
29+
private static ResourceLocation BLUR_POST_CHAIN_ID;
30+
@Final
31+
@Shadow
32+
private Minecraft minecraft;
33+
@Final
34+
@Shadow
35+
private CrossFrameResourcePool resourcePool;
36+
37+
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;doEntityOutline()V", shift = At.Shift.AFTER))
38+
private void verdant$addColorblindFilter(DeltaTracker deltaTracker, boolean renderLevel, CallbackInfo ci) {
39+
Player player = this.minecraft.player;
40+
// Make sure there is actually a player. (This should never fail, but it's good to be safe I guess).
41+
if (player != null) {
42+
// Check if the player has the colorblind effect. Do other checks here as needed.
43+
44+
double breaths = player.getAttribute(ModAttributes.BREATHS).getBaseValue();
45+
46+
if (breaths <= 0) {
47+
ResourceLocation RL = ResourceLocation.fromNamespaceAndPath(
48+
Awakenings.MODID, "without_elevation");
49+
50+
// If the player has the colorblind effect, get the post shader.
51+
52+
PostChain postchain = this.minecraft.getShaderManager()
53+
.getPostChain(RL, LevelTargetBundle.MAIN_TARGETS);
54+
55+
if (postchain != null) {
56+
// If the post shader was found, then apply it. If not, we probably have bigger problems; don't bother doing anything.
57+
postchain.process(this.minecraft.getMainRenderTarget(), this.resourcePool);
58+
}
59+
} else if (breaths > 0 && breaths < 200) {
60+
ResourceLocation RL = ResourceLocation.fromNamespaceAndPath(
61+
Awakenings.MODID, "decolored_vision");
62+
PostChain postchain = this.minecraft.getShaderManager()
63+
.getPostChain(RL, LevelTargetBundle.MAIN_TARGETS);
64+
65+
if (postchain != null) {
66+
// If the post shader was found, then apply it. If not, we probably have bigger problems; don't bother doing anything.
67+
postchain.process(this.minecraft.getMainRenderTarget(), this.resourcePool);
68+
}
69+
}
70+
71+
72+
}
73+
}
74+
}

src/main/java/team/steelcode/awakenings/modules/events/client_events/ModRegisterGuiLayerEvent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import net.neoforged.bus.api.SubscribeEvent;
66
import net.neoforged.fml.common.EventBusSubscriber;
77
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
8+
import net.neoforged.neoforge.client.event.RenderFrameEvent;
9+
import net.neoforged.neoforge.client.event.RenderHighlightEvent;
10+
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
811
import team.steelcode.awakenings.Awakenings;
912
import team.steelcode.awakenings.modules.gui.ModGuiBreathsOverlay;
1013

@@ -15,5 +18,8 @@ public class ModRegisterGuiLayerEvent {
1518
public static void onRegisterGuiLayersEvent(RegisterGuiLayersEvent event) {
1619
event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(
1720
Awakenings.MODID, "breaths_overlay"), new ModGuiBreathsOverlay());
21+
22+
1823
}
24+
1925
}

src/main/java/team/steelcode/awakenings/modules/events/server_events/ModCreativeTabEvents.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,4 @@ public static void addCustomItemsToCustomCreativeTab(BuildCreativeModeTabContent
2323
event.accept(ModItems.SWORD_SHEATH.get());
2424
}
2525
}
26-
27-
public static void addCustomItemsToMinecraftCreativeTab(BuildCreativeModeTabContentsEvent event) {
28-
29-
if (event.getTabKey() == CreativeModeTabs.COLORED_BLOCKS) {
30-
event.accept(ModItems.ALUMINUM_NUGGET.get());
31-
event.accept(ModItems.ALUMINUM_INGOT.get());
32-
event.accept(ModItems.ALUMINUM_RAW.get());
33-
event.accept(ModBlocks.ALUMINUM_BLOCK.asItem());
34-
}
35-
}
3626
}

src/main/java/team/steelcode/awakenings/modules/events/server_events/ModTickEvent.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public static void onPlayerTickEvent(PlayerTickEvent.Post event) {
2626

2727

2828
if (breaths <= 0) {
29-
event.getEntity().addEffect(
30-
new MobEffectInstance(
31-
MobEffects.DARKNESS, 40, 0, true, true, true));
3229
event.getEntity().addEffect(
3330
new MobEffectInstance(
3431
MobEffects.DIG_SLOWDOWN, 40, 0, false, false, false));
@@ -39,7 +36,6 @@ public static void onPlayerTickEvent(PlayerTickEvent.Post event) {
3936
new MobEffectInstance(
4037
MobEffects.MOVEMENT_SLOWDOWN, 40, 0, true, true, true));
4138
} else {
42-
4339
if (breaths >= 50 && breaths < 200) {
4440
event.getEntity().addEffect(
4541
new MobEffectInstance(
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"targets": {
3+
"swap": {}
4+
},
5+
"passes": [
6+
{
7+
"program": "minecraft:post/color_convolve",
8+
"inputs": [
9+
{
10+
"sampler_name": "In",
11+
"target": "minecraft:main"
12+
}
13+
],
14+
"output": "swap",
15+
"uniforms": [
16+
{
17+
"name": "RedMatrix",
18+
"values": [ 0.6, 0.1, 0.1 ]
19+
},
20+
{
21+
"name": "GreenMatrix",
22+
"values": [ 0.1, 0.6, 0.1 ]
23+
},
24+
{
25+
"name": "BlueMatrix",
26+
"values": [ 0.1, 0.1, 0.6 ]
27+
},
28+
{
29+
"name": "Saturation",
30+
"values": [ 0.3 ]
31+
},
32+
{ "name": "Offset",
33+
"values": [ -0.1, -0.1, -0.1 ]
34+
}
35+
]
36+
},
37+
{
38+
"program": "minecraft:post/box_blur",
39+
"inputs": [
40+
{
41+
"sampler_name": "In",
42+
"target": "swap"
43+
}
44+
],
45+
"output": "minecraft:main",
46+
"uniforms": [
47+
{
48+
"name": "Radius",
49+
"values": [ 0.2 ]
50+
}
51+
]
52+
}
53+
]
54+
}
-1.65 KB
Binary file not shown.

src/main/resources/awakenings.mixins.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"compatibilityLevel": "JAVA_17",
66
"refmap": "mixins.awakenings.refmap.json",
77
"mixins": [
8-
"GameRendererAddPostShadersMixin"
98
],
109
"client": [
1110
"GameRendererAddPostShadersMixin"

src/main/templates/META-INF/neoforge.mods.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ authors = "${mod_authors}" #optional
3535
description = '''${mod_description}'''
3636

3737
# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
38-
#[[mixins]]
39-
#config="${mod_id}.mixins.json"
38+
[[mixins]]
39+
config="${mod_id}.mixins.json"
4040

4141
# The [[accessTransformers]] block allows you to declare where your AT file is.
4242
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg

0 commit comments

Comments
 (0)