Browse Source

Initial commit

master
Martmists 3 months ago
commit
cdc9228e9f
20 changed files with 536 additions and 0 deletions
  1. +2
    -0
      .gitattributes
  2. +25
    -0
      .gitignore
  3. +14
    -0
      LICENSE
  4. +3
    -0
      README.md
  5. +55
    -0
      build.gradle
  6. +14
    -0
      gradle.properties
  7. +10
    -0
      settings.gradle
  8. +65
    -0
      src/main/java/com/martmists/buyinggf/BuyingGFMod.java
  9. +8
    -0
      src/main/java/com/martmists/buyinggf/colors/ColorProvider.java
  10. +24
    -0
      src/main/java/com/martmists/buyinggf/colors/FlashColorProvider.java
  11. +17
    -0
      src/main/java/com/martmists/buyinggf/colors/GenericColorProvider.java
  12. +37
    -0
      src/main/java/com/martmists/buyinggf/colors/GradientColorProvider.java
  13. +12
    -0
      src/main/java/com/martmists/buyinggf/effects/EffectRenderer.java
  14. +39
    -0
      src/main/java/com/martmists/buyinggf/effects/GenericEffectRenderer.java
  15. +42
    -0
      src/main/java/com/martmists/buyinggf/effects/ScrollEffectRenderer.java
  16. +65
    -0
      src/main/java/com/martmists/buyinggf/mixin/ClientPlayNetworkHandlerMixin.java
  17. +71
    -0
      src/main/java/com/martmists/buyinggf/mixin/EntityRendererMixin.java
  18. BIN
     
  19. +24
    -0
      src/main/resources/fabric.mod.json
  20. +9
    -0
      src/main/resources/mixins.buyinggf.json

+ 2
- 0
.gitattributes View File

@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

+ 25
- 0
.gitignore View File

@@ -0,0 +1,25 @@
# Compiled nonsense that does not belong in *source* control
/build
/bin
/.gradle
/minecraft
/out
/run
/classes

# IDE nonsense that could go in source control but really shouldn't
.classpath
.project
.metadata
.settings
*.launch
*.iml
.idea
*.ipr
*.iws

# Files from bad operating systems :^)
Thumbs.db
.DS_Store
local.properties
.directory

+ 14
- 0
LICENSE View File

@@ -0,0 +1,14 @@
Copyright 2020 Martmists

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 3
- 0
README.md View File

@@ -0,0 +1,3 @@
# Buying GF

Bringing Runescape-style text headers to Minecraft!

+ 55
- 0
build.gradle View File

@@ -0,0 +1,55 @@
plugins {
id "java"
id "idea"
id "fabric-loom" version "0.4.29"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

archivesBaseName = "${project.archives_base_name}"
group = "${project.maven_group}"
version = "${project.mod_version}+${project.minecraft_version}"

repositories {
mavenCentral()
maven { url "http://maven.fabricmc.net/" } // Fabric maven - home of Fabric API and ModMenu
maven { url "https://jitpack.io" }
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand version: project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}

jar {
from "LICENSE"
}

+ 14
- 0
gradle.properties View File

@@ -0,0 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.9.0+build.204
fabric_version=0.15.1+build.380-1.16.1

# Mod Properties
mod_version = 1.0.0
maven_group = com.martmists
archives_base_name = buying-gf

+ 10
- 0
settings.gradle View File

@@ -0,0 +1,10 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

+ 65
- 0
src/main/java/com/martmists/buyinggf/BuyingGFMod.java View File

@@ -0,0 +1,65 @@
package com.martmists.buyinggf;

import com.martmists.buyinggf.colors.*;
import com.martmists.buyinggf.effects.*;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.util.Pair;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class BuyingGFMod implements ClientModInitializer {
private static class Colors {
static int RED = 0xff0000;
static int GREEN = 0x00ff00;
static int BLUE = 0x0000ff;
static int CYAN = 0x00ffff;
static int PURPLE = 0xff00ff;
static int WHITE = 0xffffff;
static int YELLOW = 0xffff00;
static int ORANGE = 0xffa500;
static int DARK_RED = 0x8b0000;
static int DARK_GREEN = 0x006400;
}

public static Map<UUID, Pair<String, Long>> lastMessage = new HashMap<>();
public static Map<String, EffectRenderer> renderers = new HashMap<>();
public static Map<String, ColorProvider> colors = new HashMap<>();

// Colors
public static ColorProvider NO_COLOR = new GenericColorProvider(Colors.YELLOW);
public static ColorProvider YELLOW_COLOR = register("yellow", new GenericColorProvider(Colors.YELLOW));
public static ColorProvider RED_COLOR = register("red", new GenericColorProvider(Colors.RED));
public static ColorProvider GREEN_COLOR = register("green", new GenericColorProvider(Colors.GREEN));
public static ColorProvider CYAN_COLOR = register("cyan", new GenericColorProvider(Colors.CYAN));
public static ColorProvider PURPLE_COLOR = register("purple", new GenericColorProvider(Colors.PURPLE));
public static ColorProvider WHITE_COLOR = register("white", new GenericColorProvider(Colors.WHITE));

public static ColorProvider FLASH_1_COLOR = register("flash1", new FlashColorProvider(Colors.RED, Colors.YELLOW));
public static ColorProvider FLASH_2_COLOR = register("flash2", new FlashColorProvider(Colors.CYAN, Colors.BLUE));
public static ColorProvider FLASH_3_COLOR = register("flash3", new FlashColorProvider(Colors.GREEN, Colors.DARK_GREEN));

public static ColorProvider GLOW_1_COLOR = register("glow1", new GradientColorProvider(Colors.RED, Colors.ORANGE, Colors.YELLOW, Colors.GREEN, Colors.CYAN));
public static ColorProvider GLOW_2_COLOR = register("glow2", new GradientColorProvider(Colors.RED, Colors.PURPLE, Colors.BLUE, Colors.DARK_RED));
public static ColorProvider GLOW_3_COLOR = register("glow3", new GradientColorProvider(Colors.WHITE, Colors.GREEN, Colors.WHITE, Colors.CYAN));

// Effects
public static EffectRenderer NO_EFFECT = new GenericEffectRenderer();

// Register funcs
public static EffectRenderer register(String name, EffectRenderer e) {
renderers.put(name, e);
return e;
}

public static ColorProvider register(String name, ColorProvider e) {
colors.put(name, e);
return e;
}

@Override
public void onInitializeClient() {
System.out.println("Buying gf");
}
}

+ 8
- 0
src/main/java/com/martmists/buyinggf/colors/ColorProvider.java View File

@@ -0,0 +1,8 @@
package com.martmists.buyinggf.colors;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;

public interface ColorProvider {
int getColor(PlayerEntity player, Pair<String, Long> entry, long duration);
}

+ 24
- 0
src/main/java/com/martmists/buyinggf/colors/FlashColorProvider.java View File

@@ -0,0 +1,24 @@
package com.martmists.buyinggf.colors;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;

import java.util.Date;

public class FlashColorProvider implements ColorProvider {
private final int c1;
private final int c2;

public FlashColorProvider(int color1, int color2) {
c1 = color1;
c2 = color2;
}

@Override
public int getColor(PlayerEntity player, Pair<String, Long> entry, long duration) {
long time = new Date().getTime() - entry.getRight();
float max = (float)duration;
float progress = time / max;
return (Math.floor(progress * 4) % 2 == 1) ? c2 : c1;
}
}

+ 17
- 0
src/main/java/com/martmists/buyinggf/colors/GenericColorProvider.java View File

@@ -0,0 +1,17 @@
package com.martmists.buyinggf.colors;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;

public class GenericColorProvider implements ColorProvider {
private final int color;

public GenericColorProvider(int color) {
this.color = color;
}

@Override
public int getColor(PlayerEntity player, Pair<String, Long> entry, long duration) {
return color;
}
}

+ 37
- 0
src/main/java/com/martmists/buyinggf/colors/GradientColorProvider.java View File

@@ -0,0 +1,37 @@
package com.martmists.buyinggf.colors;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;

import java.util.Date;

public class GradientColorProvider implements ColorProvider {
int RED = 0xFF0000;
int GREEN = 0x00FF00;
int BLUE = 0x0000FF;

private final int[] colors;

public GradientColorProvider(int... colors) {
this.colors = colors;
}

@Override
public int getColor(PlayerEntity player, Pair<String, Long> entry, long duration) {
long time = new Date().getTime() - entry.getRight();
float max = (float)duration;
float progress = time / max;
float partial = (progress * (colors.length-1)) % 1;
int ct = colors[(int) Math.ceil(progress * (colors.length-1))];
int cs = colors[(int) Math.floor(progress * (colors.length-1))];
int mix = getNextColor(ct, cs, partial);
return mix;
}

public int getNextColor(int c1, int c2, float p) {
int r = Math.round((c1 & RED) * p + (c2 & RED) * (1-p));
int g = Math.round((c1 & GREEN) * p + (c2 & GREEN) * (1-p));
int b = Math.round((c1 & BLUE) * p + (c2 & BLUE) * (1-p));
return (r | g | b); // OR in case something really fucked happened
}
}

+ 12
- 0
src/main/java/com/martmists/buyinggf/effects/EffectRenderer.java View File

@@ -0,0 +1,12 @@
package com.martmists.buyinggf.effects;

import com.martmists.buyinggf.colors.ColorProvider;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;

public interface EffectRenderer {
void render(EntityRenderer renderer, PlayerEntity player, Pair<String, Long> entry, ColorProvider c, MatrixStack matrices, VertexConsumerProvider consumerProvider, int light, boolean sneaking);
}

+ 39
- 0
src/main/java/com/martmists/buyinggf/effects/GenericEffectRenderer.java View File

@@ -0,0 +1,39 @@
package com.martmists.buyinggf.effects;

import com.martmists.buyinggf.BuyingGFMod;
import com.martmists.buyinggf.colors.ColorProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;

import java.util.Date;

public class GenericEffectRenderer implements EffectRenderer {
private final int duration = 5000;

@Override
public void render(EntityRenderer renderer, PlayerEntity player, Pair<String, Long> entry, ColorProvider c, MatrixStack matrices, VertexConsumerProvider consumerProvider, int light, boolean sneaking) {
if (new Date().getTime() - entry.getRight() > duration) {
BuyingGFMod.lastMessage.put(player.getUuid(), null);
return;
}

matrices.push();
matrices.translate(0.0D, player.getHeight() + 0.8F, 0.0D);
matrices.multiply(MinecraftClient.getInstance().getEntityRenderManager().getRotation());
matrices.scale(-0.020F, -0.020F, 0.020F);
TextRenderer textRenderer = renderer.getFontRenderer();
float renderStart = (float) (-textRenderer.getWidth(entry.getLeft()) / 2);
if (!sneaking) {
textRenderer.draw(matrices, entry.getLeft(), renderStart, 0, 0);
matrices.peek().getModel().addToLastColumn(new Vector3f(-0.01f, 0.01f, 0.002f));
textRenderer.draw(matrices, entry.getLeft(), renderStart, 0, c.getColor(player, entry, duration));
}
matrices.pop();
}
}

+ 42
- 0
src/main/java/com/martmists/buyinggf/effects/ScrollEffectRenderer.java View File

@@ -0,0 +1,42 @@
package com.martmists.buyinggf.effects;

import com.martmists.buyinggf.BuyingGFMod;
import com.martmists.buyinggf.colors.ColorProvider;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Pair;
import org.lwjgl.opengl.GL11;

import java.util.Date;

public class ScrollEffectRenderer implements EffectRenderer {
private final int duration = 5000;

@Override
public void render(EntityRenderer renderer, PlayerEntity player, Pair<String, Long> entry, ColorProvider c, MatrixStack matrices, VertexConsumerProvider consumerProvider, int light, boolean sneaking) {
if (new Date().getTime() - entry.getRight() > duration) {
BuyingGFMod.lastMessage.put(player.getUuid(), null);
return;
}

matrices.push();
matrices.translate(0.0D, player.getHeight() + 0.8F, 0.0D);
matrices.multiply(MinecraftClient.getInstance().getEntityRenderManager().getRotation());
matrices.scale(-0.020F, -0.020F, 0.020F);
TextRenderer textRenderer = renderer.getFontRenderer();
float renderStart = (float) (-textRenderer.getWidth(entry.getLeft()) / 2);
if (!sneaking) {
// GL11.glScissor(); // Region around box
// GL11.glEnable(GL11.GL_SCISSOR_TEST);
// TODO: Scroll text from right to left, letting glScissors take care of the textbox
// GL11.glDisable(GL11.GL_SCISSOR_TEST);
}
matrices.pop();
}
}

+ 65
- 0
src/main/java/com/martmists/buyinggf/mixin/ClientPlayNetworkHandlerMixin.java View File

@@ -0,0 +1,65 @@
package com.martmists.buyinggf.mixin;

import com.martmists.buyinggf.BuyingGFMod;
import com.martmists.buyinggf.colors.ColorProvider;
import com.martmists.buyinggf.effects.EffectRenderer;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.MessageType;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Pair;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Date;
import java.util.UUID;

@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Inject(method = "onGameMessage", at = @At("HEAD"))
void playerMessage(GameMessageS2CPacket packet, CallbackInfo ci) {
if (packet.getLocation() == MessageType.CHAT) {
BuyingGFMod.lastMessage.put(packet.getSenderUuid(), new Pair<>(
(String) ((TranslatableText) packet.getMessage()).getArgs()[1],
new Date().getTime()));
}
}

@ModifyArg(method = "onGameMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;addChatMessage(Lnet/minecraft/network/MessageType;Lnet/minecraft/text/Text;Ljava/util/UUID;)V"), index = 1)
Text replace(MessageType t, Text o, UUID p) {
if (t == MessageType.CHAT) {
TranslatableText tr = (TranslatableText) o;
return new TranslatableText(tr.getKey(), tr.getArgs()[0], strip((String) tr.getArgs()[1]));
}
return o;
}

String strip(String s) {
String[] args = s.split(":", 2);
ColorProvider c = BuyingGFMod.NO_COLOR;
EffectRenderer e = BuyingGFMod.NO_EFFECT;

if (args.length >= 3) {
if (BuyingGFMod.renderers.containsKey(args[0])) {
if (BuyingGFMod.colors.containsKey(args[1])) {
s = args[2];
} else {
s = args[1] + ":" + args[2];
}
} else if (BuyingGFMod.colors.containsKey(args[0])) {
s = args[1];
}
} else if (args.length >= 2) {
if (BuyingGFMod.renderers.containsKey(args[0])) {
s = args[1];
} else if (BuyingGFMod.colors.containsKey(args[0])) {
s = args[1];
}
}
return s;
}
}

+ 71
- 0
src/main/java/com/martmists/buyinggf/mixin/EntityRendererMixin.java View File

@@ -0,0 +1,71 @@
package com.martmists.buyinggf.mixin;

import com.martmists.buyinggf.BuyingGFMod;
import com.martmists.buyinggf.colors.ColorProvider;
import com.martmists.buyinggf.effects.EffectRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Pair;
import org.spongepowered.asm.mixin.Final;
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(EntityRenderer.class)
public abstract class EntityRendererMixin {
@Shadow
@Final
protected EntityRenderDispatcher dispatcher;

/**
* @author Martmists
* @reason I'm too lazy to do local capture
*/
@Inject(method = "renderLabelIfPresent", at = @At("RETURN"))
public void renderLabelIfPresent(Entity entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
double distanceToCamera = this.dispatcher.getSquaredDistanceToCamera(entity);
if (distanceToCamera <= 4096.0D) {
if (entity instanceof PlayerEntity) {
Pair<String, Long> entry = BuyingGFMod.lastMessage.getOrDefault(entity.getUuid(), null);
if (entry == null) return;
String renderText = entry.getLeft();
String[] args = renderText.split(":", 2);
ColorProvider c = BuyingGFMod.NO_COLOR;
EffectRenderer e = BuyingGFMod.NO_EFFECT;

if (args.length >= 3) {
if (BuyingGFMod.renderers.containsKey(args[0])) {
e = BuyingGFMod.renderers.get(args[0]);
if (BuyingGFMod.colors.containsKey(args[1])) {
c = BuyingGFMod.colors.get(args[1]);
renderText = args[2];
} else {
renderText = args[1] + ":" + args[2];
}
} else if (BuyingGFMod.colors.containsKey(args[0])) {
c = BuyingGFMod.colors.get(args[0]);
renderText = args[1];
}
} else if (args.length >= 2) {
if (BuyingGFMod.renderers.containsKey(args[0])) {
e = BuyingGFMod.renderers.get(args[0]);
renderText = args[1];
} else if (BuyingGFMod.colors.containsKey(args[0])) {
c = BuyingGFMod.colors.get(args[0]);
renderText = args[1];
}
}
entry = new Pair<>(renderText, entry.getRight());

e.render((EntityRenderer) (Object) this, (PlayerEntity) entity, entry, c, matrices, vertexConsumers, light, entity.isSneaky());
}
}
}
}

BIN
View File


+ 24
- 0
src/main/resources/fabric.mod.json View File

@@ -0,0 +1,24 @@
{
"schemaVersion": 1,
"id": "buying-gf",
"version": "${version}",
"name": "Buying GF",
"icon": "assets/buygf/icon.png",
"description": "Runescape chat headers",
"license": "MIT",
"contact": {
"sources": "https://pion.martmists.com/martmists/buying-gf"
},
"environment": "client",
"entrypoints": {
"client": [
"com.martmists.buyinggf.BuyingGFMod"
]
},
"mixins": [
"mixins.buyinggf.json"
],
"depends": {
"fabricloader": ">=0.4.0"
}
}

+ 9
- 0
src/main/resources/mixins.buyinggf.json View File

@@ -0,0 +1,9 @@
{
"required": true,
"package": "com.martmists.buyinggf.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ClientPlayNetworkHandlerMixin",
"EntityRendererMixin"
]
}

Loading…
Cancel
Save