generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
315 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ + "]"; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/main/java/com/notcasey/simple_f3/SimpleF3ConfigScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/main/java/com/notcasey/simple_f3/config/SimpleF3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
src/main/java/com/notcasey/simple_f3/mixin/InGameHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
src/main/java/com/notcasey/simple_f3/mixin/KeyboardMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
src/main/java/com/notcasey/simple_f3/mixin/TitleScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/main/java/net/fabricmc/example/mixin/ExampleMixin.java
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
|
||
} |
Oops, something went wrong.