Skip to content

Commit

Permalink
Commit all.
Browse files Browse the repository at this point in the history
  • Loading branch information
I8aDOG committed Apr 4, 2023
1 parent 026f0e6 commit c5ad682
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 58 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Fabric Example Mod
# Simple F3

## Setup

For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using.

## License

This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.
Adds an extra, simplified, and customizable F3 screen. Accessed by pressing F3 twice in-game.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url "https://maven.terraformersmc.com/releases/" }
maven { url = "https://api.modrinth.com/maven" }
}

dependencies {
Expand All @@ -27,6 +29,11 @@ dependencies {
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"

modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
include "maven.modrinth:midnightlib:${project.midnightlib_version}"

modApi "com.terraformersmc:modmenu:6.1.0-rc.4"
}

base {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ org.gradle.parallel=true

# Mod Properties
mod_version = 1.0.0
maven_group = com.example
archives_base_name = fabric-example-mod
maven_group = com.notcasey
archives_base_name = more-f3

# Dependencies
fabric_version=0.75.3+1.19.4
midnightlib_version=1.3.0-fabric
90 changes: 90 additions & 0 deletions src/main/java/com/notcasey/simple_f3/SimpleDebugHud.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.notcasey.simple_f3;

import com.google.common.base.Strings;
import com.notcasey.simple_f3.config.SimpleF3Config;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

@Environment(EnvType.CLIENT)
public class SimpleDebugHud extends DrawableHelper {
private static final int TEXT_COLOR = 14737632;
private final MinecraftClient client;
private final TextRenderer textRenderer;

public SimpleDebugHud(MinecraftClient client) {
this.client = client;
this.textRenderer = client.textRenderer;
}

public void render(MatrixStack matrices) {
if (SimpleF3Config.IsDisabled()) {
SimpleF3.simpleDebugEnabled = false;
return;
}

BlockPos blockPos = this.client.getCameraEntity().getBlockPos();

List<String> list = new ArrayList<String>();
if (SimpleF3Config.show_game_version)
list.add("Minecraft ".concat(SharedConstants.getGameVersion().getName()));
if (SimpleF3Config.show_fps)
list.add(Integer.toString(this.client.getCurrentFps()).concat(" fps"));

if (SimpleF3Config.show_game_version || SimpleF3Config.show_fps)
list.add("");

if (SimpleF3Config.show_coords)
list.add(String.format(Locale.ROOT, "XYZ: %.3f / %.5f / %.3f", this.client.getCameraEntity().getX(), this.client.getCameraEntity().getY(), this.client.getCameraEntity().getZ()));
if (SimpleF3Config.show_biome && blockPos.getY() >= this.client.world.getBottomY() && blockPos.getY() < this.client.world.getTopY()) {
RegistryEntry biome = this.client.world.getBiome(blockPos);
list.add("Biome: " + getBiomeString(biome));
}

for(int i = 0; i < list.size(); ++i) {
String string = (String)list.get(i);
if (!Strings.isNullOrEmpty(string)) {
Objects.requireNonNull(this.textRenderer);
int j = 9;
int k = this.textRenderer.getWidth(string);
int l = 2;
int m = 2 + j * i;

if (SimpleF3Config.right_text)
l = this.client.getWindow().getScaledWidth() - 2 - k;

int textColor = 14737632;
if (SimpleF3Config.rainbow_text)
textColor = Color.HSBtoRGB((float) SimpleF3.rainbowHue/255f, 1f, 1f);

if (SimpleF3Config.classic_style)
this.textRenderer.drawWithShadow(matrices, string, (float)l, (float)m, textColor);
else {
fill(matrices, l - 1, m - 1, l + k + 1, m + j - 1, -1873784752);
this.textRenderer.draw(matrices, string, (float) l, (float) m, textColor);
}
}
}
}

private static String getBiomeString(RegistryEntry<Biome> biome) {
return (String)biome.getKeyOrValue().map((biomeKey) -> {
return biomeKey.getValue().toString();
}, (biome_) -> {
return "[unregistered " + biome_ + "]";
});
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/notcasey/simple_f3/SimpleF3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.notcasey.simple_f3;

import com.notcasey.simple_f3.config.SimpleF3Config;
import eu.midnightdust.lib.config.MidnightConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleF3 implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("simple_f3");

public static boolean simpleDebugEnabled = false;

public static int rainbowHue;

@Override
public void onInitializeClient() {
ClientTickEvents.START_CLIENT_TICK.register((tick) -> {
if (!simpleDebugEnabled)
return;

rainbowHue += 1;
if (rainbowHue > 255)
rainbowHue = 0;
});

MidnightConfig.init("simple_f3", SimpleF3Config.class);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/notcasey/simple_f3/SimpleF3ConfigScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.notcasey.simple_f3;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import eu.midnightdust.lib.config.MidnightConfig;

import java.util.Map;

public class SimpleF3ConfigScreen implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> MidnightConfig.getScreen(parent, "simple_f3");
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/notcasey/simple_f3/config/SimpleF3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.notcasey.simple_f3.config;

import eu.midnightdust.lib.config.MidnightConfig;

public class SimpleF3Config extends MidnightConfig {
@Comment(centered = true) public static Comment general_comment;
@Entry public static boolean auto_enable = false;
@Comment(centered = true) public static Comment display_comment;
@Entry public static boolean show_game_version = false;
@Entry public static boolean show_fps = true;
@Entry public static boolean show_coords = false;
@Entry public static boolean show_biome = false;
@Comment(centered = true) public static Comment rendering_comment;
@Entry public static boolean right_text = false;
@Entry public static boolean classic_style = false;
@Entry public static boolean rainbow_text = false;

public static boolean IsDisabled() {
return !show_game_version && !show_fps && !show_coords && !show_biome;
}

}
34 changes: 34 additions & 0 deletions src/main/java/com/notcasey/simple_f3/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.notcasey.simple_f3.mixin;

import com.notcasey.simple_f3.SimpleDebugHud;
import com.notcasey.simple_f3.SimpleF3;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
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(InGameHud.class)
public class InGameHudMixin extends DrawableHelper {
@Shadow @Final private MinecraftClient client;

private static SimpleDebugHud simpleDebugHud;

@Inject(at = @At("TAIL"), method = "<init>(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/render/item/ItemRenderer;)V")
private void ConstructorInject(MinecraftClient client, ItemRenderer itemRenderer, CallbackInfo info) {
this.simpleDebugHud = new SimpleDebugHud(client);
}

@Inject(at = @At("TAIL"), method = "render(Lnet/minecraft/client/util/math/MatrixStack;F)V")
private void render(MatrixStack matrices, float tickDelta, CallbackInfo info) {
if (SimpleF3.simpleDebugEnabled) {
simpleDebugHud.render(matrices);
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/notcasey/simple_f3/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.notcasey.simple_f3.mixin;

import com.notcasey.simple_f3.SimpleF3;
import com.notcasey.simple_f3.config.SimpleF3Config;
import net.minecraft.client.Keyboard;
import net.minecraft.client.MinecraftClient;
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(Keyboard.class)
public class KeyboardMixin {
@Shadow
private MinecraftClient client;

@Shadow
private boolean switchF3State;

// This is a really weird way of adding the second menu, but I don't feel like losing sanity over the other ways to mixin.
@Inject(method = "onKey(JIIII)V", at = @At("TAIL"))
private void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
if (SimpleF3Config.IsDisabled())
return;

if (this.client.currentScreen == null || this.client.currentScreen.passEvents) {
if (action == 0 && key == 292 && !this.switchF3State) {
if (!this.client.options.debugEnabled && !SimpleF3.simpleDebugEnabled) {
SimpleF3.simpleDebugEnabled = true;
}
else if (this.client.options.debugEnabled && SimpleF3.simpleDebugEnabled) {
SimpleF3.simpleDebugEnabled = false;

this.client.options.debugEnabled = false;
this.client.options.debugProfilerEnabled = false;
this.client.options.debugTpsEnabled = false;
}
}
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/notcasey/simple_f3/mixin/TitleScreenMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.notcasey.simple_f3.mixin;

import com.notcasey.simple_f3.SimpleF3;
import com.notcasey.simple_f3.config.SimpleF3Config;
import net.minecraft.client.gui.screen.TitleScreen;
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(TitleScreen.class)
public class TitleScreenMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
SimpleF3.simpleDebugEnabled = SimpleF3Config.auto_enable;
}
}
21 changes: 0 additions & 21 deletions src/main/java/net/fabricmc/example/ExampleMod.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/net/fabricmc/example/mixin/ExampleMixin.java

This file was deleted.

Binary file removed src/main/resources/assets/modid/icon.png
Binary file not shown.
Binary file added src/main/resources/assets/simple_f3/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/main/resources/assets/simple_f3/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"simple_f3.midnightconfig.title": "Simple F3 Config",

"simple_f3.midnightconfig.general_comment": "General",
"simple_f3.midnightconfig.display_comment": "Display",
"simple_f3.midnightconfig.rendering_comment": "Rendering",

"simple_f3.midnightconfig.auto_enable": "Auto-Enable Simple F3",
"simple_f3.midnightconfig.auto_enable.tooltip": "Automatically enables the Simple F3 screen when entering a world.",

"simple_f3.midnightconfig.show_game_version": "Show Game Version",

"simple_f3.midnightconfig.show_fps": "Show FPS",

"simple_f3.midnightconfig.show_coords": "Show Coordinates",

"simple_f3.midnightconfig.show_biome": "Show Biome",

"simple_f3.midnightconfig.right_text": "Move Text Right",

"simple_f3.midnightconfig.classic_style": "Classic Style",
"simple_f3.midnightconfig.classic_style.tooltip": "Renders the Simple F3 screen similar to older versions of Minecraft.",

"simple_f3.midnightconfig.rainbow_text": "Rainbow Text",
"simple_f3.midnightconfig.rainbow_text.tooltip": "Adds rainbow colors to the Simple F3 screen."

}
Loading

0 comments on commit c5ad682

Please sign in to comment.