diff --git a/gradle.properties b/gradle.properties index 579bd59..9625efb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,13 +8,13 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.15.11 # Mod Properties - mod_version = 8.0-1.21-fabric + mod_version = 9.0-1.21-fabric maven_group=net.i_no_am.view_model archives_base_name=view-model # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.100.4+1.21 -# ImproperUI -# check latest release on https://github.com/ItziSpyder/ImproperUI/releases +# ImproperUI Properties + # check on https://github.com/ItziSpyder/ImproperUI/releases/latest improperui_version=1.21-0.0.6-BETA diff --git a/src/main/java/net/i_no_am/viewmodel/client/Global.java b/src/main/java/net/i_no_am/viewmodel/Global.java similarity index 65% rename from src/main/java/net/i_no_am/viewmodel/client/Global.java rename to src/main/java/net/i_no_am/viewmodel/Global.java index a27e770..9ce8639 100644 --- a/src/main/java/net/i_no_am/viewmodel/client/Global.java +++ b/src/main/java/net/i_no_am/viewmodel/Global.java @@ -1,10 +1,10 @@ -package net.i_no_am.viewmodel.client; +package net.i_no_am.viewmodel; -import net.i_no_am.viewmodel.utils.Utils; +import net.minecraft.client.MinecraftClient; public interface Global { + MinecraftClient mc = MinecraftClient.getInstance(); String PREFIX = "§7[§aViewModel§7]§r "; - String CURRENT_VERSION = Utils.getModVersion(); String modId = "viewmodel"; String[] screens = { "assets/viewmodel/improperui/screen.ui", diff --git a/src/main/java/net/i_no_am/viewmodel/ViewModel.java b/src/main/java/net/i_no_am/viewmodel/ViewModel.java index 35b3611..3ff7b8f 100644 --- a/src/main/java/net/i_no_am/viewmodel/ViewModel.java +++ b/src/main/java/net/i_no_am/viewmodel/ViewModel.java @@ -1,11 +1,11 @@ package net.i_no_am.viewmodel; -import net.i_no_am.viewmodel.client.Global; import io.github.itzispyder.improperui.ImproperUIAPI; 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.i_no_am.viewmodel.config.ConfigManager; +import net.i_no_am.viewmodel.version.Version; +import net.i_no_am.viewmodel.config.Config; import net.i_no_am.viewmodel.event.SecondMenuCallBack; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; @@ -13,20 +13,18 @@ public class ViewModel implements ModInitializer, Global { - public static final KeyBinding BIND = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "binds.viewmodel.menu", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_V, - "binds.viewmodel" - )); + public static boolean isOutdated = false; + public static final KeyBinding BIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("binds.viewmodel.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V, "binds.viewmodel")); + @Override public void onInitialize() { + Version.checkUpdates(); ImproperUIAPI.init(modId, ViewModel.class, screens); ClientTickEvents.END_CLIENT_TICK.register(client -> { + Config.loadConfig(); while (BIND.wasPressed()) { ImproperUIAPI.parseAndRunFile(modId, "screen.ui",new SecondMenuCallBack()); } - ConfigManager.loadConfigValues(); }); } } diff --git a/src/main/java/net/i_no_am/viewmodel/client/ModVersionChecker.java b/src/main/java/net/i_no_am/viewmodel/client/ModVersionChecker.java deleted file mode 100644 index eb21271..0000000 --- a/src/main/java/net/i_no_am/viewmodel/client/ModVersionChecker.java +++ /dev/null @@ -1,72 +0,0 @@ -package net.i_no_am.viewmodel.client; - -import io.github.itzispyder.improperui.util.ChatUtils; -import net.i_no_am.viewmodel.utils.Utils; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; - -public class ModVersionChecker implements Global { - - public static boolean checked = false; - private static final String REPO_URL = "https://api.github.com/repos/I-No-oNe/View-Model/releases/latest"; - - public static void updateChecker() { - if (!checked) { - try { - String latestVersion = getLatestVersion(); - if (latestVersion != null && Utils.isUpdateAvailable(latestVersion)) { - ChatUtils.sendMessage(PREFIX + "Download the new version of View Model from Modrinth!"); - Text literal = Text.literal( "§a https://modrinth.com/mod/no-ones-view-model"); - ClickEvent event = new ClickEvent(ClickEvent.Action.OPEN_URL, "https://modrinth.com/mod/no-ones-view-model"); - MutableText text = literal.copy(); - Utils.sendText(text.fillStyle(text.getStyle().withClickEvent(event))); - - - - } - checked = true; - } catch (Exception e) { - e.printStackTrace(); - } - } - } - private static String getLatestVersion() throws Exception { - URL url = new URL(REPO_URL); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - conn.setRequestProperty("Accept", "application/json"); - - if (conn.getResponseCode() != 200) { - throw new RuntimeException("Failed: HTTP error code: " + conn.getResponseCode()); - } - - BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); - StringBuilder sb = new StringBuilder(); - String output; - while ((output = br.readLine()) != null) { - sb.append(output); - } - - conn.disconnect(); - - String jsonString = sb.toString(); - - String versionTag = "\"tag_name\":\""; - int startIndex = jsonString.indexOf(versionTag); - if (startIndex != -1) { - int endIndex = jsonString.indexOf('"', startIndex + versionTag.length()); - if (endIndex != -1) { - return jsonString.substring(startIndex + versionTag.length(), endIndex); - } - } - - return null; - } - -} diff --git a/src/main/java/net/i_no_am/viewmodel/client/ViewModelClient.java b/src/main/java/net/i_no_am/viewmodel/client/ViewModelClient.java deleted file mode 100644 index b663213..0000000 --- a/src/main/java/net/i_no_am/viewmodel/client/ViewModelClient.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.i_no_am.viewmodel.client; - -import net.fabricmc.api.ClientModInitializer; - -public class ViewModelClient implements ClientModInitializer { - @Override - public void onInitializeClient() { - } -} diff --git a/src/main/java/net/i_no_am/viewmodel/config/Config.java b/src/main/java/net/i_no_am/viewmodel/config/Config.java new file mode 100644 index 0000000..f7d5c41 --- /dev/null +++ b/src/main/java/net/i_no_am/viewmodel/config/Config.java @@ -0,0 +1,65 @@ +package net.i_no_am.viewmodel.config; + +import io.github.itzispyder.improperui.ImproperUIAPI; +import io.github.itzispyder.improperui.config.ConfigReader; +import io.github.itzispyder.improperui.util.ChatUtils; +import net.i_no_am.viewmodel.Global; +import net.i_no_am.viewmodel.config.settings.ConfigSettings; +import net.minecraft.util.Formatting; + +public class Config implements Global { + + private static final ConfigReader VMConfig = ImproperUIAPI.getConfigReader(modId, "config.properties"); + + /*First Page Settings:*/ + public static ConfigSettings mainPositionX; + public static ConfigSettings mainRotationX; + public static ConfigSettings offPositionX; + public static ConfigSettings offRotationX; + public static ConfigSettings mainPositionY; + public static ConfigSettings mainRotationY; + public static ConfigSettings offPositionY; + public static ConfigSettings offRotationY; + public static ConfigSettings mainPositionZ; + public static ConfigSettings mainRotationZ; + public static ConfigSettings offPositionZ; + public static ConfigSettings offRotationZ; + /*Second Page Settings*/ + public static ConfigSettings handSpeedSwing; + public static ConfigSettings mainHandScale; + public static ConfigSettings offHandScale; + public static ConfigSettings noHandSwingV2; + public static ConfigSettings noHandSwingV1; + public static ConfigSettings noFoodSwing; + public static ConfigSettings noHandRender; + + public static void loadConfig() { + /*First Page Settings:*/ + mainPositionX = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-position-x", 0.0)); + mainRotationX = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-rotation-x", 0.0)); + offPositionX = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-position-x", 0.0)); + offRotationX = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-rotation-x", 0.0)); + mainPositionY = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-position-y", 0.0)); + mainRotationY = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-rotation-y", 0.0)); + offPositionY = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-position-y", 0.0)); + offRotationY = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-rotation-y", 0.0)); + mainPositionZ = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-position-z", 0.0)); + mainRotationZ = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-rotation-z", 0.0)); + offPositionZ = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-position-z", 0.0)); + offRotationZ = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-rotation-z", 0.0)); + /*Second Page Settings:*/ + handSpeedSwing = new ConfigSettings<>(Double.class, VMConfig.readDouble("hand-speed-swing", 4.0));///it was 1 - 7, from now its 0 - 5 (2 and below didnt work) + mainHandScale = new ConfigSettings<>(Double.class, VMConfig.readDouble("main-hand-scale", 1.0)); + offHandScale = new ConfigSettings<>(Double.class, VMConfig.readDouble("off-hand-scale", 1.0)); + noHandSwingV2 = new ConfigSettings<>(Boolean.class, VMConfig.readBool("no-hand-swing-v2", false)); + noHandSwingV1 = new ConfigSettings<>(Boolean.class, VMConfig.readBool("no-hand-swing-v1", false)); + noFoodSwing = new ConfigSettings<>(Boolean.class, VMConfig.readBool("no-food-swing", false)); + noHandRender = new ConfigSettings<>(Boolean.class, VMConfig.readBool("no-hand-render", false)); + /*No Swing Logic*/ + if (noHandSwingV2.getVal() && (noHandSwingV1.getVal())) { + VMConfig.write("no-hand-swing", false); + VMConfig.write("no-hand-swing-v2", false); + ChatUtils.sendMessage(PREFIX + Formatting.RED + "CHOOSE ONE OPTION!"); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/i_no_am/viewmodel/config/ConfigManager.java b/src/main/java/net/i_no_am/viewmodel/config/ConfigManager.java deleted file mode 100644 index c8e09c4..0000000 --- a/src/main/java/net/i_no_am/viewmodel/config/ConfigManager.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.i_no_am.viewmodel.config; - -import io.github.itzispyder.improperui.ImproperUIAPI; -import io.github.itzispyder.improperui.config.ConfigReader; -import net.i_no_am.viewmodel.client.Global; -import net.i_no_am.viewmodel.config.settings.ViewModelSettings; -import net.i_no_am.viewmodel.config.settings.SettingsManager; - -import java.util.HashMap; -import java.util.Map; - -public class ConfigManager implements Global, SettingsManager { - - private static final Map> system = new HashMap<>(); - - /** - * If you want to add more features, do it via using {@link SettingsManager} + {@link ViewModelSettings}. - */ - - - public static void loadConfigValues() { - ConfigReader VMconfig = ImproperUIAPI.getConfigReader(modId, "config.properties"); - - system.put(ViewModelSettings.MAIN_ROT_X, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.MAIN_ROT_X.getKey(), MAIN_ROTATION_X))); - system.put(ViewModelSettings.MAIN_POS_X, new FloatSettingStructure((float) (VMconfig.readFloat(ViewModelSettings.MAIN_POS_X.getKey(), MAIN_POSITION_X) / DIVISION))); - system.put(ViewModelSettings.MAIN_ROT_Z, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.MAIN_ROT_Z.getKey(), MAIN_ROTATION_Z))); - system.put(ViewModelSettings.MAIN_POS_Z, new FloatSettingStructure((float) (VMconfig.readFloat(ViewModelSettings.MAIN_POS_Z.getKey(), MAIN_POSITION_Z) / DIVISION))); - system.put(ViewModelSettings.MAIN_ROT_Y, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.MAIN_ROT_Y.getKey(), MAIN_ROTATION_Y))); - system.put(ViewModelSettings.MAIN_POS_Y, new FloatSettingStructure((float) (VMconfig.readFloat(ViewModelSettings.MAIN_POS_Y.getKey(), MAIN_POSITION_Y) / DIVISION))); - - system.put(ViewModelSettings.OFF_ROT_X, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.OFF_ROT_X.getKey(), OFF_ROTATION_X))); - system.put(ViewModelSettings.OFF_POS_X, new FloatSettingStructure((float) (VMconfig.readFloat(ViewModelSettings.OFF_POS_X.getKey(), OFF_POSITION_X) / DIVISION))); - system.put(ViewModelSettings.OFF_ROT_Z, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.OFF_ROT_Z.getKey(), OFF_ROTATION_Z))); - system.put(ViewModelSettings.OFF_POS_Z, new FloatSettingStructure((float) (VMconfig.readFloat(ViewModelSettings.OFF_POS_Z.getKey(), OFF_POSITION_Z) / DIVISION))); - system.put(ViewModelSettings.OFF_ROT_Y, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.OFF_ROT_Y.getKey(), OFF_ROTATION_Y))); - system.put(ViewModelSettings.OFF_POS_Y, new FloatSettingStructure((float) (VMconfig.readFloat(ViewModelSettings.OFF_POS_Y.getKey(), OFF_POSITION_Y) / DIVISION))); - - system.put(ViewModelSettings.NO_SWING_V2, new BooleanSetting(VMconfig.readBool(ViewModelSettings.NO_SWING_V2.getKey(), NO_SWING_V2))); - system.put(ViewModelSettings.NO_SWING, new BooleanSetting(VMconfig.readBool(ViewModelSettings.NO_SWING.getKey(), NO_SWING))); - system.put(ViewModelSettings.HAND_SWING_SPEED, new IntegerSettingStructure(2 * VMconfig.readInt(ViewModelSettings.HAND_SWING_SPEED.getKey(), HAND_SWING_SPEED))); - system.put(ViewModelSettings.NO_FOOD_SWING, new BooleanSetting(VMconfig.readBool(ViewModelSettings.NO_FOOD_SWING.getKey(), NO_FOOD_SWING))); - system.put(ViewModelSettings.MAIN_SCALE, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.MAIN_SCALE.getKey(), MAIN_SCALE))); - system.put(ViewModelSettings.OFF_SCALE, new FloatSettingStructure((float) VMconfig.readFloat(ViewModelSettings.OFF_SCALE.getKey(), OFF_SCALE))); - system.put(ViewModelSettings.NO_HAND, new BooleanSetting(VMconfig.readBool(ViewModelSettings.NO_HAND.getKey(), NO_HAND))); - } - - public static SettingStructure get(ViewModelSettings key) { - return system.get(key); - } -} diff --git a/src/main/java/net/i_no_am/viewmodel/config/SettingStructure.java b/src/main/java/net/i_no_am/viewmodel/config/SettingStructure.java deleted file mode 100644 index f2bb2c7..0000000 --- a/src/main/java/net/i_no_am/viewmodel/config/SettingStructure.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.i_no_am.viewmodel.config; - -public abstract class SettingStructure { - private final T value; - - public SettingStructure(T value) { - this.value = value; - } - - public T getVal() { - return value; - } -} - -class FloatSettingStructure extends SettingStructure { - public FloatSettingStructure(Float value) { - super(value); - } -} - -class BooleanSetting extends SettingStructure { - public BooleanSetting(Boolean value) { - super(value); - } -} - -class IntegerSettingStructure extends SettingStructure { - public IntegerSettingStructure(Integer value) { - super(value); - } -} diff --git a/src/main/java/net/i_no_am/viewmodel/config/settings/ConfigSettings.java b/src/main/java/net/i_no_am/viewmodel/config/settings/ConfigSettings.java new file mode 100644 index 0000000..aad13e5 --- /dev/null +++ b/src/main/java/net/i_no_am/viewmodel/config/settings/ConfigSettings.java @@ -0,0 +1,13 @@ +package net.i_no_am.viewmodel.config.settings; + +public class ConfigSettings { + private final T value; + + public ConfigSettings(Class type, T value) { + this.value = value; + } + + public T getVal() { + return value; + } +} diff --git a/src/main/java/net/i_no_am/viewmodel/config/settings/SettingsManager.java b/src/main/java/net/i_no_am/viewmodel/config/settings/SettingsManager.java deleted file mode 100644 index c5dc6e9..0000000 --- a/src/main/java/net/i_no_am/viewmodel/config/settings/SettingsManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.i_no_am.viewmodel.config.settings; - -import net.i_no_am.viewmodel.config.ConfigManager; - -public interface SettingsManager { -/** - * @Param Add here the default settings to every setting - * After that go to: - * {@link ConfigManager} - */ - boolean NO_HAND = false; - int HAND_SWING_SPEED = 6; - int DIVISION = 10; - boolean NO_SWING_V2 = false; - boolean NO_SWING = false; - boolean NO_FOOD_SWING = false; - float MAIN_SCALE = 1.0F; - float OFF_SCALE = 1.0F; - float MAIN_ROTATION_X = 0.0F; - float MAIN_POSITION_X = 0.0F; - float MAIN_ROTATION_Z = 0.0F; - float MAIN_POSITION_Z = 0.0F; - float MAIN_ROTATION_Y = 0.0F; - float MAIN_POSITION_Y = 0.0F; - float OFF_ROTATION_X = 0.0F; - float OFF_POSITION_X = 0.0F; - float OFF_ROTATION_Z = 0.0F; - float OFF_POSITION_Z = 0.0F; - float OFF_ROTATION_Y = 0.0F; - float OFF_POSITION_Y = 0.0F; -} diff --git a/src/main/java/net/i_no_am/viewmodel/config/settings/ViewModelSettings.java b/src/main/java/net/i_no_am/viewmodel/config/settings/ViewModelSettings.java deleted file mode 100644 index 321f4b0..0000000 --- a/src/main/java/net/i_no_am/viewmodel/config/settings/ViewModelSettings.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.i_no_am.viewmodel.config.settings; - -public enum ViewModelSettings { - MAIN_ROT_X("main-rotation-x"), - MAIN_POS_X("main-position-x"), - MAIN_ROT_Z("main-rotation-z"), - MAIN_POS_Z("main-position-z"), - MAIN_ROT_Y("main-rotation-y"), - MAIN_POS_Y("main-position-y"), - OFF_ROT_X("off-rotation-x"), - OFF_POS_X("off-position-x"), - OFF_ROT_Z("off-rotation-z"), - OFF_POS_Z("off-position-z"), - OFF_ROT_Y("off-rotation-y"), - OFF_POS_Y("off-position-y"), - NO_SWING("no-hand-swing"), - NO_SWING_V2("no-hand-swing-v2"), - HAND_SWING_SPEED("hand-speed-swing"), - NO_FOOD_SWING("no-food-swing"), - MAIN_SCALE("main-hand-scale"), - OFF_SCALE("off-hand-scale"), - NO_HAND("no-hand-render"); - - private final String key; - - ViewModelSettings(String setting) { - this.key = setting; - } - - public String getKey() { - return key; - } -} diff --git a/src/main/java/net/i_no_am/viewmodel/event/SecondMenuCallBack.java b/src/main/java/net/i_no_am/viewmodel/event/SecondMenuCallBack.java index bf7ce05..ffd2381 100644 --- a/src/main/java/net/i_no_am/viewmodel/event/SecondMenuCallBack.java +++ b/src/main/java/net/i_no_am/viewmodel/event/SecondMenuCallBack.java @@ -4,12 +4,11 @@ import io.github.itzispyder.improperui.script.CallbackHandler; import io.github.itzispyder.improperui.script.CallbackListener; import io.github.itzispyder.improperui.script.events.MouseEvent; -import net.i_no_am.viewmodel.client.Global; +import net.i_no_am.viewmodel.Global; public class SecondMenuCallBack implements CallbackListener, Global { - @CallbackHandler public void openHandsSettingScreen(MouseEvent e) { if (e.input.isDown()) diff --git a/src/main/java/net/i_no_am/viewmodel/mixin/MixinCamera.java b/src/main/java/net/i_no_am/viewmodel/mixin/MixinCamera.java new file mode 100644 index 0000000..0262eb8 --- /dev/null +++ b/src/main/java/net/i_no_am/viewmodel/mixin/MixinCamera.java @@ -0,0 +1,24 @@ +package net.i_no_am.viewmodel.mixin; + +import net.i_no_am.viewmodel.Global; +import net.i_no_am.viewmodel.config.Config; +import net.minecraft.block.enums.CameraSubmersionType; +import net.minecraft.client.render.Camera; +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.CallbackInfoReturnable; + +@Mixin(Camera.class) +public abstract class MixinCamera implements Global { + + @Inject(method = "getSubmersionType", at = @At("RETURN"), cancellable = true) + private void onGetSubmersionType(CallbackInfoReturnable cir) { + if (mc.player.getHandItems() != null && cir.getReturnValue() == CameraSubmersionType.WATER && (Config.mainHandScale.getVal() != 1 || Config.offHandScale.getVal() != 1 || + Config.mainPositionX.getVal() != 0 || Config.mainPositionY.getVal() != 0 || Config.mainPositionZ.getVal() != 0 || + Config.offPositionX.getVal() != 0 || Config.offPositionY.getVal() != 0 || Config.offPositionZ.getVal() != 0)) { + cir.setReturnValue(CameraSubmersionType.NONE); + cir.cancel(); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/i_no_am/viewmodel/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/net/i_no_am/viewmodel/mixin/MixinClientPlayNetworkHandler.java deleted file mode 100644 index 2b96372..0000000 --- a/src/main/java/net/i_no_am/viewmodel/mixin/MixinClientPlayNetworkHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.i_no_am.viewmodel.mixin; - -import net.i_no_am.viewmodel.client.ModVersionChecker; -import net.i_no_am.viewmodel.utils.Utils; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.ClientConnection; -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.CallbackInfoReturnable; - -@Mixin(ClientPlayNetworkHandler.class) -public class MixinClientPlayNetworkHandler { - - - @Inject(method = "getConnection", at = @At("RETURN")) - private void onWorldLoadMixin(CallbackInfoReturnable cir) { - try { - ModVersionChecker.updateChecker(); - } catch (Exception e) { - e.printStackTrace(); - Utils.setChecked(false); - } - } -} \ No newline at end of file diff --git a/src/main/java/net/i_no_am/viewmodel/mixin/MixinHeldItemRenderer.java b/src/main/java/net/i_no_am/viewmodel/mixin/MixinHeldItemRenderer.java index 9078a96..393830b 100644 --- a/src/main/java/net/i_no_am/viewmodel/mixin/MixinHeldItemRenderer.java +++ b/src/main/java/net/i_no_am/viewmodel/mixin/MixinHeldItemRenderer.java @@ -1,8 +1,7 @@ package net.i_no_am.viewmodel.mixin; -import net.i_no_am.viewmodel.client.Global; -import net.i_no_am.viewmodel.config.ConfigManager; -import net.i_no_am.viewmodel.config.settings.ViewModelSettings; +import net.i_no_am.viewmodel.Global; +import net.i_no_am.viewmodel.config.Config; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.HeldItemRenderer; @@ -26,24 +25,25 @@ public abstract class MixinHeldItemRenderer implements Global { public void viewmodel(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack m, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { m.push(); if (hand == Hand.MAIN_HAND) { - float mainRotX = (Float) ConfigManager.get(ViewModelSettings.MAIN_ROT_X).getVal(); - float mainPosX = (Float) ConfigManager.get(ViewModelSettings.MAIN_POS_X).getVal(); - float mainRotZ = (Float) ConfigManager.get(ViewModelSettings.MAIN_ROT_Z).getVal(); - float mainPosZ = (Float) ConfigManager.get(ViewModelSettings.MAIN_POS_Z).getVal(); - float mainRotY = (Float) ConfigManager.get(ViewModelSettings.MAIN_ROT_Y).getVal(); - float mainPosY = (Float) ConfigManager.get(ViewModelSettings.MAIN_POS_Y).getVal(); + float mainRotX = Config.mainRotationX.getVal().floatValue(); + float mainPosX = Config.mainPositionX.getVal().floatValue(); + float mainRotZ = Config.mainRotationZ.getVal().floatValue(); + float mainPosZ = Config.mainPositionZ.getVal().floatValue(); + float mainRotY = Config.mainRotationY.getVal().floatValue(); + float mainPosY = Config.mainPositionY.getVal().floatValue(); m.multiply(RotationAxis.POSITIVE_X.rotationDegrees(mainRotX)); m.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(mainRotY)); m.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(mainRotZ)); m.translate(mainPosX, mainPosY, mainPosZ); - } else { - float offRotX = (Float) ConfigManager.get(ViewModelSettings.OFF_ROT_X).getVal(); - float offPosX = (Float) ConfigManager.get(ViewModelSettings.OFF_POS_X).getVal(); - float offRotZ = (Float) ConfigManager.get(ViewModelSettings.OFF_ROT_Z).getVal(); - float offPosZ = (Float) ConfigManager.get(ViewModelSettings.OFF_POS_Z).getVal(); - float offRotY = (Float) ConfigManager.get(ViewModelSettings.OFF_ROT_Y).getVal(); - float offPosY = (Float) ConfigManager.get(ViewModelSettings.OFF_POS_Y).getVal(); + } + else { + float offRotX = Config.offRotationX.getVal().floatValue(); + float offPosX = Config.offPositionX.getVal().floatValue(); + float offRotZ = Config.offRotationZ.getVal().floatValue(); + float offPosZ = Config.offPositionZ.getVal().floatValue(); + float offRotY = Config.offRotationY.getVal().floatValue(); + float offPosY = Config.offPositionY.getVal().floatValue(); m.multiply(RotationAxis.POSITIVE_X.rotationDegrees(offRotX)); m.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(offRotY)); @@ -60,8 +60,8 @@ public void popMatrixAfterRenderFirstPersonItem(AbstractClientPlayerEntity playe @Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V")) private void scaleForItems(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack ms, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { - float mainScale = (Float) ConfigManager.get(ViewModelSettings.MAIN_SCALE).getVal(); - float offScale = (Float) ConfigManager.get(ViewModelSettings.OFF_SCALE).getVal(); + float mainScale = Config.mainHandScale.getVal().floatValue(); + float offScale = Config.offHandScale.getVal().floatValue(); if (hand == Hand.MAIN_HAND) { ms.scale(mainScale, mainScale, mainScale); } else { @@ -70,30 +70,22 @@ private void scaleForItems(AbstractClientPlayerEntity player, float tickDelta, f } @Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IFFLnet/minecraft/util/Arm;)V")) - private void scaleForHands(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack ms, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { - float mainScale = (Float) ConfigManager.get(ViewModelSettings.MAIN_SCALE).getVal(); - float offScale = (Float) ConfigManager.get(ViewModelSettings.OFF_SCALE).getVal(); - if (hand == Hand.MAIN_HAND) { - ms.scale(mainScale, mainScale, mainScale); - } else { - ms.scale(offScale, offScale, offScale); - } - if ((boolean) ConfigManager.get(ViewModelSettings.NO_HAND).getVal()) { + private void noHandsRender(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack ms, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { + if (Config.noHandRender.getVal()) { ms.scale(0, 0, 0); } } - @Inject(method = "applyEatOrDrinkTransformation", at = @At("HEAD"), cancellable = true) - public void OnApplyEatOrDrinkTransformation(MatrixStack matrices, float tickDelta, Arm arm, ItemStack stack, PlayerEntity player, CallbackInfo ci) { - if ((Boolean) ConfigManager.get(ViewModelSettings.NO_FOOD_SWING).getVal()) { + public void noEatingAnimations(MatrixStack matrices, float tickDelta, Arm arm, ItemStack stack, PlayerEntity player, CallbackInfo ci) { + if (Config.noFoodSwing.getVal()) { ci.cancel(); } } @ModifyArgs(method = "renderItem(FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/network/ClientPlayerEntity;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderFirstPersonItem(Lnet/minecraft/client/network/AbstractClientPlayerEntity;FFLnet/minecraft/util/Hand;FLnet/minecraft/item/ItemStack;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V")) private void renderItem(Args args) { - if ((Boolean) ConfigManager.get(ViewModelSettings.NO_SWING).getVal() && !(boolean) ConfigManager.get(ViewModelSettings.NO_SWING_V2).getVal()) { + if (Config.noHandSwingV1.getVal() && !Config.noHandSwingV2.getVal()) { args.set(6, 0.0F); } } diff --git a/src/main/java/net/i_no_am/viewmodel/mixin/MixinLivingEntity.java b/src/main/java/net/i_no_am/viewmodel/mixin/MixinLivingEntity.java index 3c07ab8..1f2f314 100644 --- a/src/main/java/net/i_no_am/viewmodel/mixin/MixinLivingEntity.java +++ b/src/main/java/net/i_no_am/viewmodel/mixin/MixinLivingEntity.java @@ -1,7 +1,6 @@ package net.i_no_am.viewmodel.mixin; -import net.i_no_am.viewmodel.config.ConfigManager; -import net.i_no_am.viewmodel.config.settings.ViewModelSettings; +import net.i_no_am.viewmodel.config.Config; import net.minecraft.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -9,16 +8,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LivingEntity.class) -public class MixinLivingEntity { +public abstract class MixinLivingEntity { + @Inject(method = "getHandSwingDuration", at = @At("HEAD"), cancellable = true) private void onGetHandSwingDuration(CallbackInfoReturnable cir) { - if ((boolean) ConfigManager.get(ViewModelSettings.NO_SWING).getVal() || (boolean) ConfigManager.get(ViewModelSettings.NO_SWING_V2).getVal()) { + if (Config.noHandSwingV1.getVal() || Config.noHandSwingV2.getVal()) { cir.setReturnValue(0); cir.cancel(); } - if (!(boolean) ConfigManager.get(ViewModelSettings.NO_SWING).getVal() && !(boolean) ConfigManager.get(ViewModelSettings.NO_SWING_V2).getVal()){ - cir.setReturnValue((int) ConfigManager.get(ViewModelSettings.HAND_SWING_SPEED).getVal()); + if (!Config.noHandSwingV1.getVal() && !Config.noHandSwingV2.getVal()) { + cir.setReturnValue(Config.handSpeedSwing.getVal().intValue() + 2); cir.cancel(); } } -} +} \ No newline at end of file diff --git a/src/main/java/net/i_no_am/viewmodel/mixin/MixinTitleScreen.java b/src/main/java/net/i_no_am/viewmodel/mixin/MixinTitleScreen.java new file mode 100644 index 0000000..475564b --- /dev/null +++ b/src/main/java/net/i_no_am/viewmodel/mixin/MixinTitleScreen.java @@ -0,0 +1,32 @@ +package net.i_no_am.viewmodel.mixin; + +import net.fabricmc.loader.api.FabricLoader; +import net.i_no_am.viewmodel.ViewModel; +import net.i_no_am.viewmodel.Global; +import net.minecraft.client.gui.screen.ConfirmScreen; +import net.minecraft.client.gui.screen.TitleScreen; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Util; +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.net.URI; + +@Mixin(TitleScreen.class) +public class MixinTitleScreen implements Global { + @Inject(method = "init", at = @At("RETURN")) + private void onInit(CallbackInfo ci) { + if (ViewModel.isOutdated && !FabricLoader.getInstance().isDevelopmentEnvironment()) { + mc.setScreen(new ConfirmScreen( + confirm -> { + if (confirm) + Util.getOperatingSystem().open(URI.create("https://modrinth.com/mod/no-ones-view-model/versions")); + else mc.stop(); + }, + Text.of(Formatting.RED + "You are using an outdated version of View Model"), Text.of("Please download the latest version from " + Formatting.GREEN + "modrinth"), Text.of("Download"), Text.of("Quit Game"))); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/i_no_am/viewmodel/utils/Utils.java b/src/main/java/net/i_no_am/viewmodel/utils/Utils.java deleted file mode 100644 index 455c951..0000000 --- a/src/main/java/net/i_no_am/viewmodel/utils/Utils.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.i_no_am.viewmodel.utils; - -import net.fabricmc.loader.api.FabricLoader; -import net.i_no_am.viewmodel.client.Global; -import net.i_no_am.viewmodel.client.ModVersionChecker; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.Text; - -import java.util.Objects; - -public class Utils implements Global { - private static final MinecraftClient mc = MinecraftClient.getInstance(); - - public static void sendText(Text text) { - Objects.requireNonNull(mc.player).sendMessage(Text.of(text), false); - } - - public static boolean isUpdateAvailable(String latestVersion) { - return !CURRENT_VERSION.equals(latestVersion); - } - - public static void setChecked(boolean bool) { - ModVersionChecker.checked = bool; - } - - public static String getModVersion() { - String fullVersionString = FabricLoader.getInstance().getModContainer(modId).get().getMetadata().getVersion().getFriendlyString(); - String[] parts = fullVersionString.split("-"); - for (String part : parts) { - if (part.matches("\\d+\\.\\d+")) { - return part; - } - } - return "Unknown"; - } -} diff --git a/src/main/java/net/i_no_am/viewmodel/version/Version.java b/src/main/java/net/i_no_am/viewmodel/version/Version.java new file mode 100644 index 0000000..3e231d2 --- /dev/null +++ b/src/main/java/net/i_no_am/viewmodel/version/Version.java @@ -0,0 +1,56 @@ +package net.i_no_am.viewmodel.version; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.fabricmc.loader.api.FabricLoader; +import net.i_no_am.viewmodel.Global; +import net.i_no_am.viewmodel.ViewModel; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class Version implements Global { + + private static final String REPO = "https://api.github.com/repos/I-No-oNe/View-Model/releases/latest"; + + public static void checkUpdates() { + try { + String latestVersion = getLatestVersionFromGitHub(); + if (!latestVersion.equals(getModVersion())) { + ViewModel.isOutdated = true; + } + } catch (Exception ignored) {} + } + + private static String getLatestVersionFromGitHub() throws Exception { + HttpURLConnection connection = (HttpURLConnection) new URL(Version.REPO).openConnection(); + + connection.setRequestMethod("GET"); + connection.setRequestProperty("Accept", "application/vnd.github.v3+json"); + + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringBuilder response = new StringBuilder(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + JsonObject jsonResponse = JsonParser.parseString(response.toString()).getAsJsonObject(); + return jsonResponse.get("tag_name").getAsString(); + } + + + public static String getModVersion() { + String fullVersionString = FabricLoader.getInstance().getModContainer(modId).get().getMetadata().getVersion().getFriendlyString(); + String[] parts = fullVersionString.split("-"); + for (String part : parts) { + if (part.matches("\\d+\\.\\d+")) { + return part; + } + } + return "Unknown"; + } +} diff --git a/src/main/resources/assets/viewmodel/improperui/secondScreen.ui b/src/main/resources/assets/viewmodel/improperui/secondScreen.ui index dcf6eee..71aa24d 100644 --- a/src/main/resources/assets/viewmodel/improperui/secondScreen.ui +++ b/src/main/resources/assets/viewmodel/improperui/secondScreen.ui @@ -69,8 +69,8 @@ div #main { } div { inner-text: "Hand Swing Speed"; } slider -viewmodel:config.properties:hand-speed-swing { - min: 1.0 - max: 7.0 + min: 0.0 + max: 20.0 val: 3.0 width: 75% } @@ -92,8 +92,8 @@ div #main { child-align: grid grid-columns: 1 height: 15 - radio -viewmodel:config.properties:no-hand-swing {margin-left: 27;} - radio -viewmodel:config.properties:no-hand-swing-v2 {margin-left: 27; margin-top: 5;} + checkbox -viewmodel:config.properties:no-hand-swing-v1 {margin-left: 27;} + checkbox -viewmodel:config.properties:no-hand-swing-v2 {margin-left: 27; margin-top: 5;} } div #text{ inner-text: "Mode 2" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 90d2c28..ee289ff 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -15,9 +15,7 @@ "icon": "assets/viewmodel/icon.png", "environment": "*", "entrypoints": { - "client": [ - "net.i_no_am.viewmodel.client.ViewModelClient" - ], + "client": [], "main": [ "net.i_no_am.viewmodel.ViewModel" ] diff --git a/src/main/resources/viewmodel.mixins.json b/src/main/resources/viewmodel.mixins.json index 82d205e..7c5964a 100644 --- a/src/main/resources/viewmodel.mixins.json +++ b/src/main/resources/viewmodel.mixins.json @@ -7,8 +7,9 @@ "MixinLivingEntity" ], "client": [ - "MixinClientPlayNetworkHandler", - "MixinHeldItemRenderer" + "MixinCamera", + "MixinHeldItemRenderer", + "MixinTitleScreen" ], "injectors": { "defaultRequire": 1