Skip to content

Commit

Permalink
Initial Fabric work
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Dec 6, 2023
1 parent 6a0deed commit 44472b5
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 150

uniform sampler2D Sampler0;
uniform vec4 ColorModulator;

in vec2 texCoord0;
in vec4 vertexColor;

out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor;
if (color.a < 0.1) {
discard;
}
fragColor = color * ColorModulator;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"blend": {
"func": "add",
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "ping_rendertype_ping",
"fragment": "ping_rendertype_ping",
"attributes": [
"Position",
"UV0",
"Color",
"Normal"
],
"samplers": [
{ "name": "Sampler0" }
],
"uniforms": [
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#version 150

uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform vec2 ScreenSize;

in vec3 Position;
in vec2 UV0;
in vec4 Color;

out vec2 texCoord0;
out vec4 vertexColor;

const float VIEW_SHRINK = 1.0 - (1.0 / 256.0);
const mat4 VIEW_SCALE = mat4(
VIEW_SHRINK, 0.0, 0.0, 0.0,
0.0, VIEW_SHRINK, 0.0, 0.0,
0.0, 0.0, VIEW_SHRINK, 0.0,
0.0, 0.0, 0.0, 1.0
);

void main() {
vec4 linePosStart = ProjMat * VIEW_SCALE * ModelViewMat * vec4(Position, 1.0);
vec4 linePosEnd = ProjMat * VIEW_SCALE * ModelViewMat * vec4(Position, 1.0);

vec3 ndc1 = linePosStart.xyz / linePosStart.w;
vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;

vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * ScreenSize);
vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) / ScreenSize;

if (lineOffset.x < 0.0) {
lineOffset *= -1.0;
}

gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
texCoord0 = UV0;
vertexColor = Color;
}
8 changes: 1 addition & 7 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ dependencies {
include "mysticdrew:common-networking-fabric:${common_networking}-${minecraft_version}"
}

remapJar {
archiveClassifier.set("fabric")
}

loom {
if (project(":common").file("src/main/resources/${mod_id}.accesswidener").exists()) {
accessWidenerPath.set(project(":common").file("src/main/resources/${mod_id}.accesswidener"))
}
accessWidenerPath = file("src/main/resources/${mod_id}.accesswidener")
mixin {
defaultRefmapName.set("${mod_id}.refmap.json")
}
Expand Down
31 changes: 30 additions & 1 deletion fabric/src/main/java/com/girafi/ping/Ping.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
package com.girafi.ping;

import com.girafi.ping.client.KeyHelper;
import com.girafi.ping.client.PingHandlerHelper;
import com.girafi.ping.client.PingKeybinds;
import com.girafi.ping.client.gui.PingSelectGui;
import commonnetwork.CommonNetworkMod;
import commonnetwork.networking.FabricNetworkHandler;
import commonnetwork.networking.data.Side;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;

public class Ping implements ModInitializer {

@Override
public void onInitialize() {
//ForgeConfigRegistry.INSTANCE.register(Constants.MOD_ID, ModConfig.Type.COMMON, ConfigurationHandler.spec);
PingCommon.loadCommon(FabricLoader.getInstance().getConfigDir());

//Register keybinds
KeyBindingHelper.registerKeyBinding(PingKeybinds.KEY_BINDING);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_ALERT);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_MINE);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_LOOK);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_GOTO);

//TODO Register Shader Instance (Probably not here, but somehow somewhere)

ClientTickEvents.END_CLIENT_TICK.register((mc) -> {
PingHandlerHelper.pingTimer();
KeyHelper.onTick();

if ((mc.level == null || mc.isPaused()) && PingSelectGui.active) {
PingSelectGui.deactivate();
}
});
}
}
22 changes: 22 additions & 0 deletions fabric/src/main/java/com/girafi/ping/mixin/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.girafi.ping.mixin;

import com.girafi.ping.client.PingHandlerHelper;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LevelRenderer.class)
public class MixinLevelRenderer {

@Inject(at = @At("TAIL"), method = "renderLevel(Lcom/mojang/blaze3d/vertex/PoseStack;FJZLnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/GameRenderer;Lnet/minecraft/client/renderer/LightTexture;Lorg/joml/Matrix4f;)V")
private void renderLevel(PoseStack poseStack, float f, long l, boolean b, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo info) {
PingHandlerHelper.translateWorldPing(poseStack, projectionMatrix);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.girafi.ping.mixin;

import com.girafi.ping.Constants;
import com.girafi.ping.client.ClientHandlerBase;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.server.packs.resources.ResourceProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.IOException;
import java.util.List;
import java.util.function.Consumer;

@Mixin(GameRenderer.class)
public class MixinShaderInstance {

@Inject(at = @At("HEAD"), method = "reloadShaders(Lnet/minecraft/server/packs/resources/ResourceProvider;)V")
private void renderLevel(ResourceProvider resourceProvider, CallbackInfo info) {

}
}
3 changes: 2 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "${version}",
"name": "${mod_name}",
"description": "${description}",
"accessWidener" : "${mod_id}.accesswidener",
"authors": [
"${mod_author}"
],
Expand All @@ -27,7 +28,7 @@
"fabric-api": "*",
"minecraft": "1.20.2",
"java": ">=17",
"forgeconfigapiport": ">=9.1.2"
"fabric-key-binding-api-v1": "*"
},
"suggests": {
"another-mod": "*"
Expand Down
2 changes: 2 additions & 0 deletions fabric/src/main/resources/ping.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accessWidener v2 named
accessible field net/minecraft/client/renderer/GameRenderer shaders Ljava/util/Map;
3 changes: 2 additions & 1 deletion fabric/src/main/resources/ping.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
"MixinServerPlayerGamemode",
"MixinLevelRenderer",
"MixinShaderInstance"
],
"client": [
],
Expand Down
4 changes: 0 additions & 4 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ tasks.named("sourcesJar", Jar) {
from(project(":common").sourceSets.main.allSource)
}

tasks.jarJar.configure {
archiveClassifier.set('forge')
}

processResources {
from project(":common").sourceSets.main.resources
}
Expand Down
4 changes: 0 additions & 4 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ tasks.withType(ProcessResources).matching(notNeoTask).configureEach {
from project(":common").sourceSets.main.resources
}

tasks.jarJar.configure {
archiveClassifier.set('neoforge')
}

tasks.named("build").configure {
dependsOn("jarJar")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static void registerKeybinds(RegisterKeyMappingsEvent event) {

@SubscribeEvent
public static void registerShaders(RegisterShadersEvent event) throws IOException {
event.registerShader(new ShaderInstance(event.getResourceProvider(), new ResourceLocation(Constants.MOD_ID, "rendertype_ping"), DefaultVertexFormat.POSITION_TEX_COLOR), (p_172645_) -> {
rendertypePing = p_172645_;
event.registerShader(new ShaderInstance(event.getResourceProvider(), new ResourceLocation(Constants.MOD_ID, "rendertype_ping"), DefaultVertexFormat.POSITION_TEX_COLOR), (renderShaderInstance) -> {
rendertypePing = renderShaderInstance;
});
}
}

0 comments on commit 44472b5

Please sign in to comment.