Added Nightvision Key
Version 0.0.2
This commit is contained in:
@@ -9,7 +9,7 @@ yarn_mappings=1.19.3+build.5
|
||||
loader_version=0.14.14
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.0.0
|
||||
mod_version=0.0.2
|
||||
maven_group=finnmod.survivaltools
|
||||
archives_base_name=finnmod
|
||||
|
||||
|
||||
@@ -1,20 +1,144 @@
|
||||
package finnmod.survivaltools;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SurvivalTools implements ModInitializer {
|
||||
public static final String MOD_ID = "survivaltools";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("finnmod");
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class SurvivalTools implements ModInitializer {
|
||||
|
||||
private static final MinecraftClient client = MinecraftClient.getInstance();
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("finnmod");
|
||||
boolean ChatWelcomeMessage = false;
|
||||
private static boolean nightVisionEnabled = false;
|
||||
private boolean isKeyPressed = false;
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (SurvivalTools.client != null && SurvivalTools.client.world != null) {
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
if (myKeyBinding.isPressed()) {
|
||||
// Key is pressed
|
||||
if (!isKeyPressed) {
|
||||
// Key was not previously pressed, so execute the function
|
||||
toggleNightVision();
|
||||
isKeyPressed = true;
|
||||
}
|
||||
} else {
|
||||
// Key is not pressed
|
||||
isKeyPressed = false;
|
||||
}
|
||||
if(nightVisionEnabled)
|
||||
{
|
||||
StatusEffectInstance nightVisionEffect = new StatusEffectInstance(StatusEffects.NIGHT_VISION, 5200,0,false,false);
|
||||
client.player.addStatusEffect(nightVisionEffect);
|
||||
}
|
||||
InGameHud hud = SurvivalTools.client.inGameHud;
|
||||
Text fpsText = Text.literal("FPS: " + GetFPS() + GetLocation()); // + " " +GetBlock()
|
||||
hud.setOverlayMessage(fpsText, false);
|
||||
WelcomeMessage();
|
||||
//GetPing();
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatWelcomeMessage = false;
|
||||
}
|
||||
});
|
||||
LOGGER.info("SurvivalTools Started!");
|
||||
}
|
||||
public void WelcomeMessage() {
|
||||
if (!ChatWelcomeMessage) {
|
||||
Text Message = Text.literal("SurvivalTools Loaded").formatted(Formatting.DARK_AQUA);
|
||||
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Message);
|
||||
|
||||
Text Message2 = Text.literal("Made by Finn_#9999").formatted(Formatting.AQUA);
|
||||
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Message2);
|
||||
//enableGamma();
|
||||
ChatWelcomeMessage = true;
|
||||
}
|
||||
}
|
||||
public int GetFPS() {
|
||||
return client.getCurrentFps();
|
||||
}
|
||||
public String GetBlock() {
|
||||
Entity player = client.player;
|
||||
BlockHitResult hitResult = (BlockHitResult) player.raycast(10, 0, false);
|
||||
BlockPos blockPos = hitResult.getBlockPos();
|
||||
BlockState blockState = client.world.getBlockState(blockPos);
|
||||
return blockState.getBlock().getName().getString();
|
||||
}
|
||||
public String GetLocation() {
|
||||
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||
Entity player = minecraft.player;
|
||||
|
||||
float yaw = player.getHeadYaw();
|
||||
float pitch = player.getPitch();
|
||||
float yawRadians = (float) degreesToRadians(yaw);
|
||||
float pitchRadians = (float) degreesToRadians(pitch);
|
||||
double x = -Math.sin(yawRadians) * Math.cos(pitchRadians);
|
||||
double y = -Math.sin(pitchRadians);
|
||||
double z = Math.cos(yawRadians) * Math.cos(pitchRadians);
|
||||
Vec3d facing = new Vec3d(x, y, z).normalize();
|
||||
String cardinalDirection;
|
||||
if (Math.abs(facing.getX()) > Math.abs(facing.getZ())) {
|
||||
if (facing.getX() > 0) {
|
||||
cardinalDirection = "East";
|
||||
} else {
|
||||
cardinalDirection = "West";
|
||||
}
|
||||
} else {
|
||||
if (facing.getZ() > 0) {
|
||||
cardinalDirection = "South";
|
||||
} else {
|
||||
cardinalDirection = "North";
|
||||
}
|
||||
}
|
||||
//Location
|
||||
double X = minecraft.player.getX();
|
||||
int coordinatesX = (int)X;
|
||||
double Y = minecraft.player.getY();
|
||||
int coordinatesY = (int)Y;
|
||||
double Z = minecraft.player.getZ();
|
||||
int coordinatesZ = (int)Z;
|
||||
String Coordinates = " X: " + coordinatesX + " Y: " + coordinatesY + " Z: " + coordinatesZ;
|
||||
return Coordinates + " " + cardinalDirection;
|
||||
}
|
||||
public static double degreesToRadians(double degrees) {
|
||||
return degrees * Math.PI / 180.0;
|
||||
}
|
||||
public void enableGamma() {
|
||||
client.options.getGamma().setValue(1.0);
|
||||
client.worldRenderer.reload();
|
||||
}
|
||||
KeyBinding myKeyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"Nightvision Key", // The translation key used to display the key binding in the options menu
|
||||
InputUtil.Type.KEYSYM, // The input type (key or mouse button)
|
||||
GLFW.GLFW_KEY_N, // The GLFW keycode for the N key
|
||||
"Survival Tools" // The translation key used to group this key binding with other key bindings in the options menu
|
||||
));
|
||||
public static void toggleNightVision() {
|
||||
if (nightVisionEnabled) {
|
||||
client.player.removeStatusEffect(StatusEffects.NIGHT_VISION);
|
||||
nightVisionEnabled = false;
|
||||
} else {
|
||||
nightVisionEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
"id": "finnmod",
|
||||
"version": "${version}",
|
||||
"name": "SurvivalTools",
|
||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||
"description": "Simple Vanilla Minecraft Mod that enables Nightvision and displays additional information above your Inventory.",
|
||||
"authors": [
|
||||
"Finn_#9999"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
"homepage": "https://github.com/Finnn-glitch",
|
||||
"sources": "https://github.com/Finnn-glitch/survivaltools-1.19.3"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/finnmod/icon.png",
|
||||
@@ -29,8 +29,8 @@
|
||||
"finnmod.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.14",
|
||||
"minecraft": "~1.19.3",
|
||||
"fabricloader": ">=0.14.0",
|
||||
"minecraft": ">=1.17.0",
|
||||
"java": ">=17",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user