From 04eef7010094f286e6038ab1f25c87bb00fff0e0 Mon Sep 17 00:00:00 2001 From: Sour3 <31393967+Sour-o7@users.noreply.github.com> Date: Thu, 29 Feb 2024 00:01:11 -0800 Subject: [PATCH 1/5] Added Features and Restructured Vibration States Restructured Vibration States (Inspired from https://github.com/Fyustorm/mInetiface) Added Instant Feedback to some events (Inspired from https://github.com/Fyustorm/mInetiface) Added Accumulation Mode (May need balancing) Code Cleanup --- .../minegasm/client/ClientEventHandler.java | 403 +++++------------- .../common/AbstractVibrationState.java | 128 ++++++ .../common/VibrationStateAdvancement.java | 45 ++ .../minegasm/common/VibrationStateAttack.java | 35 ++ .../minegasm/common/VibrationStateClient.java | 22 + .../minegasm/common/VibrationStateFish.java | 35 ++ .../common/VibrationStateHarvest.java | 30 ++ .../minegasm/common/VibrationStateHurt.java | 34 ++ .../minegasm/common/VibrationStateMine.java | 51 +++ .../minegasm/common/VibrationStatePlace.java | 33 ++ .../common/VibrationStateVitality.java | 62 +++ .../common/VibrationStateXpChange.java | 51 +++ .../minegasm/config/ClientConfig.java | 1 + .../minegasm/config/ConfigHelper.java | 24 +- .../minegasm/config/ConfigScreen.java | 8 +- .../minegasm/config/PauseMenuButton.java | 1 + 16 files changed, 645 insertions(+), 318 deletions(-) create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java create mode 100644 forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index ce91413..f635c4e 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,24 +1,22 @@ package com.therainbowville.minegasm.client; import com.therainbowville.minegasm.common.Minegasm; +import com.therainbowville.minegasm.common.*; import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; -import net.minecraft.advancements.FrameType; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.phys.Vec3; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraftforge.common.util.FakePlayer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.LevelAccessor; import net.minecraft.network.chat.TextComponent; import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.ToolAction; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.EntityLeaveWorldEvent; @@ -40,160 +38,103 @@ @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ClientEventHandler { private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); - private static final int TICKS_PER_SECOND = 20; + private static int tickCounter = -1; private static int clientTickCounter = -1; - private static final double[] state = new double[1200]; private static boolean paused = false; private static UUID playerId = null; + + private static Map vibrationStates = new HashMap(); + + static { + vibrationStates.put("advancement", new VibrationStateAdvancement()); + vibrationStates.put("attack", new VibrationStateAttack()); + vibrationStates.put("fish", new VibrationStateFish()); + vibrationStates.put("hurt", new VibrationStateHurt()); + vibrationStates.put("mine", new VibrationStateMine()); + vibrationStates.put("place", new VibrationStatePlace()); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("vitality", new VibrationStateVitality()); + vibrationStates.put("xpChange", new VibrationStateXpChange()); + vibrationStates.put("generic", new VibrationStateClient()); + } public static void afterConnect() { - setState(getStateCounter(), 5); + //setState(getStateCounter(), 5); + ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); } - private static void clearState() { - tickCounter = -1; - clientTickCounter = -1; - Arrays.fill(state, 0); - paused = false; - } - - private static int getStateCounter() { - return tickCounter / 20; - } - - private static void setState(int start, int duration, int intensity, boolean decay) { - if (duration <= 0) { - return; + private static double getIntensity() + { + double intensity = 0; + for (Map.Entry state : vibrationStates.entrySet()) + { + intensity = Math.max(intensity, state.getValue().getIntensity()); +// LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); + } - - if (decay) { - int safeDuration = Math.max(0, duration - 2); - for (int i = 0; i < safeDuration; i++) { - setState(start+i, intensity); - } - setState(start+safeDuration, intensity/2); - setState(start+safeDuration+1, intensity/4); - } else { - for (int i = 0; i < duration; i++) { - setState(start+i, intensity); - } + return intensity / 100; + } + + private static void tickAll() + { + for (AbstractVibrationState state : vibrationStates.values()) + { + state.onTick(); } } - - private static void setState(int counter, int intensity) { - boolean accumulate = false; //XXX reserved for future use - setState(counter, intensity, accumulate); + + private static void resetAll() + { + for (AbstractVibrationState state : vibrationStates.values()) + { + state.resetState(); + } } - private static void setState(int counter, int intensity, boolean accumulate) { - int safeCounter = counter % state.length; - if (accumulate) { - state[safeCounter] = Math.min(1.0, state[safeCounter] + (intensity / 100.0)); - } else { - state[safeCounter] = Math.min(1.0, Math.max(state[safeCounter], (intensity / 100.0))); + private static boolean isPlayer(Entity entity){ + try { + if (entity instanceof Player && !(entity instanceof FakePlayer)) { + Player player = (Player) entity;; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); } + } catch (Throwable e) { + LOGGER.throwing(e); + } + return false; } - private static int getIntensity(String type) { - Map normal = new HashMap<>(); - normal.put("attack", 60); - normal.put("hurt", 0); - normal.put("mine", 80); - normal.put("place", 20); - normal.put("xpChange", 100); - normal.put("harvest", 0); - normal.put("fishing", 50); - normal.put("vitality", 0); - normal.put("advancement", 100); - - - Map masochist = new HashMap<>(); - masochist.put("attack", 0); - masochist.put("hurt", 100); - masochist.put("mine", 0); - masochist.put("place", 0); - masochist.put("xpChange", 0); - masochist.put("fishing", 0); - masochist.put("harvest", 0); - masochist.put("vitality", 10); - masochist.put("advancement", 0); - - Map hedonist = new HashMap<>(); - hedonist.put("attack", 60); - hedonist.put("hurt", 10); - hedonist.put("mine", 80); - hedonist.put("place", 20); - hedonist.put("xpChange", 100); - hedonist.put("fishing", 50); - hedonist.put("harvest", 20); - hedonist.put("vitality", 10); - hedonist.put("advancement", 100); - - Map custom = new HashMap<>(); - custom.put("attack", MinegasmConfig.attackIntensity); - custom.put("hurt", MinegasmConfig.hurtIntensity); - custom.put("mine", MinegasmConfig.mineIntensity); - custom.put("place", MinegasmConfig.placeIntensity); - custom.put("xpChange", MinegasmConfig.xpChangeIntensity); - custom.put("fishing", MinegasmConfig.fishingIntensity); - custom.put("harvest", MinegasmConfig.harvestIntensity); - custom.put("vitality", MinegasmConfig.vitalityIntensity); - custom.put("advancement", MinegasmConfig.advancementIntensity); - - if (MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST)) { - return masochist.get(type); - } else if (MinegasmConfig.mode.equals(ClientConfig.GameplayMode.HEDONIST)) { - return hedonist.get(type); - } else if (MinegasmConfig.mode.equals(ClientConfig.GameplayMode.CUSTOM)) { - return custom.get(type); - } else { - return normal.get(type); - } + private static void clearState() { + tickCounter = -1; + clientTickCounter = -1; + paused = false; + resetAll(); } @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END ) { - Player player = event.player;; - UUID uuid = player.getGameProfile().getId(); - - float playerHealth = player.getHealth(); - float playerFoodLevel = player.getFoodData().getFoodLevel(); + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + Player player = event.player; - onPlayerTickFishing(event); - - tickCounter = (tickCounter + 1) % (20 * (60 * TICKS_PER_SECOND)); // 20 min day cycle - - if (tickCounter % TICKS_PER_SECOND == 0) { // every 1 sec - if (uuid.equals(playerId)) { - int stateCounter = getStateCounter(); - - if (MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST)) { - if (playerHealth > 0 && playerHealth <= 1) { - setState(stateCounter, getIntensity("vitality")); - } - } else if (playerHealth >= 20 && playerFoodLevel >= 20) { - setState(stateCounter, getIntensity("vitality")); - } - - double newVibrationLevel = state[stateCounter]; - state[stateCounter] = 0; - - LOGGER.trace("Tick " + stateCounter + ": " + newVibrationLevel); - - if (ToyController.currentVibrationLevel != newVibrationLevel) { - ToyController.setVibrationLevel(newVibrationLevel); - } - } + tickCounter = (tickCounter + 1) % (20 * (60 * 20)); + + + if (tickCounter % 1 == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); } - if (tickCounter % (5 * TICKS_PER_SECOND) == 0) { // 5 secs - LOGGER.debug("Health: " + playerHealth); - LOGGER.debug("Food: " + playerFoodLevel); - } } } catch (Throwable e) { LOGGER.throwing(e); @@ -225,19 +166,10 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { @SubscribeEvent public static void onAttack(AttackEntityEvent event) { - try { - Entity entity = event.getEntityLiving(); - if (entity instanceof Player) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - setState(getStateCounter(), 3, getIntensity("attack"), true); - } + if (isPlayer(event.getEntityLiving())) + { + ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); } - } catch (Throwable e) { - LOGGER.throwing(e); - } } @SubscribeEvent @@ -249,118 +181,36 @@ public static void onCriticalHit(CriticalHitEvent event) @SubscribeEvent public static void onHurt(LivingHurtEvent event) { - try { - Entity entity = event.getEntityLiving(); - if (entity instanceof Player) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - setState(getStateCounter(), 3, getIntensity("hurt"), true); - } - } - } catch (Throwable e) { - LOGGER.throwing(e); + if (isPlayer(event.getEntityLiving())) + { + ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onDeath(LivingDeathEvent event) + public static void onBreak(BlockEvent.BreakEvent event) { - try { - Entity entity = event.getEntityLiving(); - if (entity instanceof Player) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - ToyController.setVibrationLevel(0); - } + if (isPlayer(event.getPlayer())) + { + ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); } - } catch (Throwable e) { - LOGGER.throwing(e); } - } - + + // Triggers when player starts to break block @SubscribeEvent public static void onHarvest(PlayerEvent.HarvestCheck event) { - try { - Player player = event.getPlayer();; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - BlockState blockState = event.getTargetBlock(); - Block block = blockState.getBlock(); - - // ToolType. AXE, HOE, PICKAXE, SHOVEL - @SuppressWarnings("ConstantConditions") float blockHardness = block.defaultBlockState().getDestroySpeed(null, null); - LOGGER.debug("Harvest: tool: " + - "?" + - " can harvest? " + event.canHarvest() + " hardness: " + blockHardness); - - int intensity = Math.toIntExact(Math.round((getIntensity("harvest") / 100.0 * (blockHardness / 50.0)) * 100)); - - if (event.canHarvest()) { - setState(getStateCounter(), 1, intensity, false); - } - } - } catch (Throwable e) { - LOGGER.throwing(e); + if (isPlayer(event.getPlayer())) + { + ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); } } - - @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - try { - Player player = event.getPlayer();; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - BlockState blockState = event.getState(); - Block block = blockState.getBlock(); - @SuppressWarnings("ConstantConditions") float blockHardness = block.defaultBlockState().getDestroySpeed(null, null); - - LOGGER.info("Breaking: " + block.toString()); - - ItemStack mainhandItem = event.getPlayer().getMainHandItem(); - boolean usingAppropriateTool = mainhandItem.isCorrectToolForDrops(blockState); - List toolCan = ToolAction.getActions().stream().filter(a -> mainhandItem.canPerformAction(a)).collect(Collectors.toList()); - LOGGER.debug("mainhand: " + mainhandItem + " [" + toolCan + "]"); - LOGGER.debug("using pickaxe: " + mainhandItem.toString() + ", using appropriate tool: " + usingAppropriateTool); - - if (toolCan.contains(ToolAction.get("AXE")) && usingAppropriateTool) { - int duration = Math.max(1, Math.min(5, Math.toIntExact(Math.round(Math.ceil(Math.log(blockHardness + 0.5)))))); - int intensity = Math.toIntExact(Math.round((getIntensity("mine") / 100.0 * (blockHardness / 50.0)) * 100)); - setState(getStateCounter(), duration, intensity, true); - } - - LOGGER.info("XP to drop: " + event.getExpToDrop()); - } - } catch (Throwable e) { - LOGGER.throwing(e); - } - } - + @SubscribeEvent public static void onPlace(BlockEvent.EntityPlaceEvent event){ - try { - UUID uuid = event.getEntity().getUUID(); - - if (uuid.equals(playerId)) { - BlockState blockState = event.getState(); - Block block = blockState.getBlock(); - @SuppressWarnings("ConstantConditions") float blockHardness = block.defaultBlockState().getDestroySpeed(null, null); - - LOGGER.info("Placing: " + block.toString()); - - int duration = Math.max(1, Math.min(5, Math.toIntExact(Math.round(Math.ceil(Math.log(blockHardness + 0.5)))))); - int intensity = Math.toIntExact(Math.round((getIntensity("place") / 100.0 * (blockHardness / 50.0)) * 100)); - setState(getStateCounter(), duration, intensity, true); - } - } catch (Throwable e) { - LOGGER.throwing(e); + if (isPlayer(event.getEntity())) + { + ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); } } @@ -379,66 +229,19 @@ public static void onXpPickup(PlayerXpEvent.PickupXp event) @SubscribeEvent public static void onXpChange(PlayerXpEvent.XpChange event) { - try { - Player player = event.getPlayer();; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - int xpChange = event.getAmount(); - long duration = Math.round(Math.ceil(Math.log(xpChange + 0.5))); - - LOGGER.info("XP CHANGE: " + xpChange); - LOGGER.debug("duration: " + duration); - - setState(getStateCounter(), Math.toIntExact(duration), getIntensity("xpChange"), true); - } - } catch (Throwable e) { - LOGGER.throwing(e); - } - } - - public static void onPlayerTickFishing(TickEvent.PlayerTickEvent event) { - try { - Player player = event.player; - - // Vibrate on fish hook - if (player.fishing != null) - { - Vec3 vector = player.fishing.getDeltaMovement(); - double x = vector.x(); - double y = vector.y(); - double z = vector.z(); - if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { - setState(getStateCounter(), 1, getIntensity("fishing"), true); - LOGGER.info("Fishing!"); - } - } - } catch (Throwable e) { - LOGGER.throwing(e); + if (isPlayer(event.getEntityLiving())) + { + ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((Player)event.getEntityLiving()).totalExperience, event.getAmount()); } } + @SubscribeEvent public static void onAdvancementEvent(AdvancementEvent event) { - - try { - Player player = event.getPlayer();; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(playerId)) { - LOGGER.info("Advancement Event: " + event); - FrameType type = event.getAdvancement().getDisplay().getFrame(); - int duration = switch (type) { - case TASK -> 5; - case GOAL -> 7; - case CHALLENGE -> 10; - }; - setState(getStateCounter(), duration, getIntensity("advancement"), true); - } - } catch (Throwable e) { - LOGGER.throwing(e); + if (isPlayer(event.getEntityLiving())) + { + ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); } } @@ -470,7 +273,6 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) } - @SubscribeEvent public static void onWorldLoaded(WorldEvent.Load event) { @@ -478,12 +280,15 @@ public static void onWorldLoaded(WorldEvent.Load event) { LOGGER.info("World loaded: " + world.toString()); } + @SubscribeEvent public static void onWorldEntry(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); if( !entity.level.isClientSide() ) { return; } + + if (ToyController.isConnected) return; if (entity instanceof Player) { LOGGER.info("Player respawn world: " + entity.toString()); @@ -496,7 +301,7 @@ public static void onWorldEntry(EntityJoinWorldEvent event) { LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); LOGGER.info("Stealth: " + MinegasmConfig.stealth); if (ToyController.connectDevice()) { - setState(getStateCounter(), 5); + ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); if (!MinegasmConfig.stealth){ player.displayClientMessage(new TextComponent(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java new file mode 100644 index 0000000..8153357 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -0,0 +1,128 @@ +package com.therainbowville.minegasm.common; + +import java.util.Map; +import java.util.HashMap; + +import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +// Architecture inspired from https://github.com/Fyustorm/mInetiface +public abstract class AbstractVibrationState +{ + + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); + protected final float streakCountdownAmount; + protected float intensity; + + protected float vibrationCountdown; + protected float vibrationFeedbackCountdown; + + protected AbstractVibrationState(float streakSeconds) + { + streakCountdownAmount = streakSeconds * 20; + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + + public void onTick() + { + if (accumulationEnabled()) + { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() + { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + + protected static boolean accumulationEnabled() + { + return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); + } + + public static int getIntensity(String type) { + Map normal = new HashMap<>(); + normal.put("attack", 60); + normal.put("hurt", 0); + normal.put("mine", 80); + normal.put("place", 20); + normal.put("xpChange", 100); + normal.put("harvest", 10); + normal.put("fishing", 50); + normal.put("vitality", 0); + normal.put("advancement", 100); + + Map masochist = new HashMap<>(); + masochist.put("attack", 0); + masochist.put("hurt", 100); + masochist.put("mine", 0); + masochist.put("place", 0); + masochist.put("xpChange", 0); + masochist.put("fishing", 0); + masochist.put("harvest", 0); + masochist.put("vitality", 10); + masochist.put("advancement", 0); + + Map hedonist = new HashMap<>(); + hedonist.put("attack", 60); + hedonist.put("hurt", 10); + hedonist.put("mine", 80); + hedonist.put("place", 20); + hedonist.put("xpChange", 100); + hedonist.put("fishing", 50); + hedonist.put("harvest", 20); + hedonist.put("vitality", 10); + hedonist.put("advancement", 100); + + Map accumulation = new HashMap<>(); + accumulation.put("attack", 1); + accumulation.put("hurt", 1); + accumulation.put("mine", 1); + accumulation.put("place", 1); + accumulation.put("xpChange", 1); + accumulation.put("fishing", 50); + accumulation.put("harvest", 10); + accumulation.put("vitality", 0); + accumulation.put("advancement", 1); + + Map custom = new HashMap<>(); + custom.put("attack", MinegasmConfig.attackIntensity); + custom.put("hurt", MinegasmConfig.hurtIntensity); + custom.put("mine", MinegasmConfig.mineIntensity); + custom.put("place", MinegasmConfig.placeIntensity); + custom.put("xpChange", MinegasmConfig.xpChangeIntensity); + custom.put("fishing", MinegasmConfig.fishingIntensity); + custom.put("harvest", MinegasmConfig.harvestIntensity); + custom.put("vitality", MinegasmConfig.vitalityIntensity); + custom.put("advancement", MinegasmConfig.advancementIntensity); + + + return switch (MinegasmConfig.mode) + { + case NORMAL -> normal.get(type); + case MASOCHIST -> masochist.get(type); + case HEDONIST -> hedonist.get(type); + case ACCUMULATION -> accumulation.get(type); + case CUSTOM -> custom.get(type); + }; + } + + public abstract int getIntensity(); +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java new file mode 100644 index 0000000..921baa2 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -0,0 +1,45 @@ +package com.therainbowville.minegasm.common; + +import net.minecraft.advancements.FrameType; +import net.minecraft.advancements.Advancement; +import net.minecraftforge.event.entity.player.AdvancementEvent; + +public class VibrationStateAdvancement extends AbstractVibrationState +{ + public VibrationStateAdvancement() + { + super(0); + } + + public void onAdvancement(AdvancementEvent event) + { + if (getIntensity("advancement") == 0) return; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + if (advancement == null) return; + FrameType type = advancement.getDisplay().getFrame(); + int duration = switch (type) { + case TASK -> 5; + case GOAL -> 7; + case CHALLENGE -> 10; + }; + + vibrationCountdown = duration * 20; + vibrationFeedbackCountdown = 1.5f * 20; + } catch (Throwable e) { + LOGGER.throwing(e); + } + } + + public int getIntensity() + { + if (accumulationEnabled()) + return Math.toIntExact(Math.round(intensity)); + else if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("advancement") + 20); + else if (vibrationCountdown > 0) + return getIntensity("advancement"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java new file mode 100644 index 0000000..60b7cba --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -0,0 +1,35 @@ +package com.therainbowville.minegasm.common; + +public class VibrationStateAttack extends AbstractVibrationState +{ + public VibrationStateAttack() + { + super(3); + } + + public void onAttack() + { + if (getIntensity("attack") == 0) return; + + if (accumulationEnabled()) + { + intensity = Math.min(100, intensity + 5); + vibrationCountdown = streakCountdownAmount; + vibrationFeedbackCountdown = 1 * 0; + } else { + vibrationCountdown = 3 * 20; + vibrationFeedbackCountdown = 1 * 20; + } + } + + public int getIntensity() + { + if (accumulationEnabled()) + return Math.toIntExact(Math.round(intensity)); + else if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("attack") + 20); + else if (vibrationCountdown > 0) + return getIntensity("attack"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java new file mode 100644 index 0000000..2f427a7 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -0,0 +1,22 @@ +package com.therainbowville.minegasm.common; + +public class VibrationStateClient extends AbstractVibrationState +{ + public VibrationStateClient() + { + super(0); + } + + public void setVibration(int intensity, int durationSeconds) + { + intensity = intensity; + vibrationCountdown = durationSeconds * 20; + } + + public int getIntensity() + { + if (vibrationCountdown > 0) + return Math.toIntExact(Math.round(intensity)); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java new file mode 100644 index 0000000..48b8238 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -0,0 +1,35 @@ +package com.therainbowville.minegasm.common; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.Vec3; + +public class VibrationStateFish extends AbstractVibrationState +{ + public VibrationStateFish() + { + super(0); + } + + public void onTick(Player player) + { + if (player.fishing != null) + { + Vec3 vector = player.fishing.getDeltaMovement(); + double x = vector.x(); + double y = vector.y(); + double z = vector.z(); + if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) + { + vibrationCountdown = 1.5f * 20; + LOGGER.info("Fishing!"); + } + } + } + + public int getIntensity() + { + if (vibrationCountdown > 0) + return getIntensity("fishing"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java new file mode 100644 index 0000000..1b7f274 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -0,0 +1,30 @@ +package com.therainbowville.minegasm.common; + +import net.minecraft.world.level.block.state.BlockState; + +public class VibrationStateHarvest extends AbstractVibrationState +{ + private VibrationStateMine mineState; + + public VibrationStateHarvest(VibrationStateMine state) + { + super(0); + mineState = state; + } + + public void onHarvest() { + vibrationCountdown = 3; + mineState.onHarvest(); + } + + public int getIntensity() + { + if (vibrationCountdown > 0){ + if (accumulationEnabled()) + return Math.min(100, mineState.getIntensity() + 19); + else + return getIntensity("harvest"); + } + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java new file mode 100644 index 0000000..f6a7fff --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -0,0 +1,34 @@ +package com.therainbowville.minegasm.common; + +public class VibrationStateHurt extends AbstractVibrationState +{ + public VibrationStateHurt() + { + super(3); + } + + public void onHurt() { + if (getIntensity("hurt") == 0) return; + + if (accumulationEnabled()) + { + intensity = Math.min(100, intensity + 10); + vibrationCountdown = streakCountdownAmount; + vibrationFeedbackCountdown = 1 * 20; + } else { + vibrationCountdown = 3 * 20; + vibrationFeedbackCountdown = 1 * 20; + } + } + + public int getIntensity() + { + if (accumulationEnabled()) + return Math.toIntExact(Math.round(intensity)); + else if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("hurt") + 20); + else if (vibrationCountdown > 0) + return getIntensity("hurt"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java new file mode 100644 index 0000000..6c03329 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -0,0 +1,51 @@ +package com.therainbowville.minegasm.common; + +import net.minecraft.world.level.block.state.BlockState; + +public class VibrationStateMine extends AbstractVibrationState +{ + public VibrationStateMine() + { + super(5); + } + + public void onBreak(BlockState block) { + if (getIntensity("mine") == 0) return; + + String blockName = block.getBlock().getName().getString(); + if (accumulationEnabled()) + { + if (blockName.contains("Ore")) { + intensity = Math.min(100, intensity + 1); + vibrationCountdown = streakCountdownAmount; + vibrationFeedbackCountdown = 1 * 20; + } else { + intensity = Math.min(100, intensity + .25f); + vibrationCountdown = streakCountdownAmount; + } + } else { + if (blockName.contains("Ore")) { + vibrationCountdown = 3 * 20; + vibrationFeedbackCountdown = 1 * 20; + } else + vibrationCountdown = 3 * 20; + } + } + + public void onHarvest() { + if (accumulationEnabled()){ + vibrationCountdown = Math.max(3, vibrationCountdown); + } + } + + public int getIntensity() + { + if (accumulationEnabled()) + return Math.toIntExact(Math.round(intensity)); + else if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("mine") + 20); + else if (vibrationCountdown > 0) + return getIntensity("mine"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java new file mode 100644 index 0000000..fa2e009 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -0,0 +1,33 @@ +package com.therainbowville.minegasm.common; + +public class VibrationStatePlace extends AbstractVibrationState +{ + public VibrationStatePlace() + { + super(5); + } + + public void onPlace() { + if (getIntensity("place") == 0) return; + + if (accumulationEnabled()) + { + intensity = Math.min(100, intensity + .5f); + vibrationCountdown = streakCountdownAmount; + vibrationFeedbackCountdown = 1 * 20; + } else { + vibrationCountdown = 3 * 20; + } + } + + public int getIntensity() + { + if (accumulationEnabled()) + return Math.toIntExact(Math.round(intensity)); + else if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("place") + 20); + else if (vibrationCountdown > 0) + return getIntensity("place"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java new file mode 100644 index 0000000..c1a0ac4 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -0,0 +1,62 @@ +package com.therainbowville.minegasm.common; + +import net.minecraft.world.entity.player.Player; + +import com.therainbowville.minegasm.config.MinegasmConfig; +import com.therainbowville.minegasm.config.ClientConfig; + +public class VibrationStateVitality extends AbstractVibrationState +{ + private int intensityCooldown; + private boolean targetMet; + + public VibrationStateVitality() + { + super(1); + intensityCooldown = 0; + targetMet = false; + } + + public void onTick(Player player) + { + float playerHealth = player.getHealth(); + float playerFoodLevel = player.getFoodData().getFoodLevel(); + + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ + + if (targetMet == false){ + targetMet = true; + vibrationFeedbackCountdown = 3 * 20; + } + } else + targetMet = false; + +// if (accumulationEnabled() && targetMet) +// { +// if (intensityCooldown == 0) { +// intensity = Math.min(100, intensity + .1f); +// intensityCooldown = 10 * 20; +// } +// vibrationCountdown = streakCountdownAmount; +// intensityCooldown = Math.max(0, intensityCooldown - 1); +// } else + if (targetMet) { + vibrationCountdown = 1; + } + } + + public int getIntensity() + { + if (getIntensity("vitality") == 0) return 0; + + //if (accumulationEnabled()) + //return Math.toIntExact(Math.round(intensity)); + //else + if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("vitality") + 20); + else if (vibrationCountdown > 0) + return getIntensity("vitality"); + else return 0; + } +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java new file mode 100644 index 0000000..179ba80 --- /dev/null +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -0,0 +1,51 @@ +package com.therainbowville.minegasm.common; + +public class VibrationStateXpChange extends AbstractVibrationState +{ + private int lastLevel; + + public VibrationStateXpChange() + { + super(1); + lastLevel = -1; + } + + // Code adapted from https://github.com/Fyustorm/mInetiface + public void onXpChange(int level, int amount) { + if (amount == 0 || getIntensity("xpChange") == 0) + return; + + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } + + lastLevel = level; + + if (accumulationEnabled()) + { + intensity = Math.min(100, intensity + amount / 5); + vibrationCountdown = streakCountdownAmount; + vibrationFeedbackCountdown = 1 * 20; + } else { + int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + vibrationCountdown = duration * 20; + vibrationFeedbackCountdown = 1 * 20; + } + } + + public int getIntensity() + { + if (accumulationEnabled()) + return Math.toIntExact(Math.round(intensity)); + else if (vibrationFeedbackCountdown > 0) + return Math.min(100, getIntensity("xpChange") + 20); + else if (vibrationCountdown > 0) + return getIntensity("xpChange"); + else return 0; + } +} + diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index b8f4827..e603497 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -134,6 +134,7 @@ public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), HEDONIST("gui." + Minegasm.MOD_ID + ".config.mode.hedonist"), + ACCUMULATION("gui." + Minegasm.MOD_ID + ".config.mode.accumulation"), CUSTOM("gui." + Minegasm.MOD_ID + ".config.mode.custom"); private final String translateKey; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index 7e07612..0f04e49 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -14,6 +14,7 @@ public static void bakeClient() { MinegasmConfig.vibrate = ConfigHolder.CLIENT.vibrate.get(); MinegasmConfig.mode = ConfigHolder.CLIENT.mode.get(); MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -33,38 +34,27 @@ public static void saveClient() try{ MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - - // Needs to sleep inbetween, or it can get confused and reset the config - + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - Thread.sleep(5); ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - Thread.sleep(5); ConfigHolder.CLIENT.mode.set(buffer.mode); - Thread.sleep(5); ConfigHolder.CLIENT.stealth.set(buffer.stealth); - Thread.sleep(5); + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - Thread.sleep(5); ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); } catch (Throwable e) - {} + { + LOGGER.info(e); + } } - + public static ConfigGuiHandler.ConfigGuiFactory createConfigGuiFactory() { return new ConfigGuiHandler.ConfigGuiFactory((minecraft, screen) -> new ConfigScreen(screen)); } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index 0694b25..0d1d185 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -110,12 +110,15 @@ protected void init() { case NORMAL -> "Normal"; case MASOCHIST -> "Masochist"; case HEDONIST -> "Hedonist"; + case ACCUMULATION -> "Accumulation"; case CUSTOM -> "Custom"; })) - .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.CUSTOM) + .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) .withInitialValue(MinegasmConfig.mode) .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - new TextComponent("Mode"), (button, value) -> MinegasmConfig.mode = value) + new TextComponent("Mode"), (button, value) -> { + MinegasmConfig.mode = value; + }) ); this.addRenderableWidget(new Button( @@ -187,6 +190,7 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } + } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index 2f25404..23255ae 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -34,6 +34,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +// Adapted from https://github.com/Creators-of-Create/Create/ public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); From f47e3c60b88ff7d6c2eb6ffdd8eadc6746060b21 Mon Sep 17 00:00:00 2001 From: Sour3 Date: Sat, 2 Mar 2024 23:11:54 -0800 Subject: [PATCH 2/5] Added Tick Frequency Config Option Added Option to change how frequently Minegasm runs --- .../minegasm/client/ClientEventHandler.java | 4 +- .../common/AbstractVibrationState.java | 2 +- .../common/VibrationStateAdvancement.java | 6 ++- .../minegasm/common/VibrationStateAttack.java | 6 ++- .../minegasm/common/VibrationStateClient.java | 4 +- .../minegasm/common/VibrationStateFish.java | 4 +- .../common/VibrationStateHarvest.java | 4 +- .../minegasm/common/VibrationStateHurt.java | 8 ++-- .../minegasm/common/VibrationStateMine.java | 10 +++-- .../minegasm/common/VibrationStatePlace.java | 6 ++- .../common/VibrationStateVitality.java | 2 +- .../common/VibrationStateXpChange.java | 8 ++-- .../minegasm/config/ClientConfig.java | 40 ++++++++++++++++++- .../minegasm/config/ConfigHelper.java | 7 +++- .../minegasm/config/ConfigScreen.java | 26 ++++++++++-- .../minegasm/config/MinegasmConfig.java | 11 ++++- 16 files changed, 117 insertions(+), 31 deletions(-) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index f635c4e..c534548 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -119,10 +119,10 @@ public static void onPlayerTick(TickEvent.PlayerTickEvent event) { if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { Player player = event.player; - tickCounter = (tickCounter + 1) % (20 * (60 * 20)); + tickCounter = (tickCounter + 1) % 100; - if (tickCounter % 1 == 0) // TODO: Add ticks per second config option (Default: Every tick) + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) { tickAll(); diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 8153357..076fd57 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -22,7 +22,7 @@ public abstract class AbstractVibrationState protected AbstractVibrationState(float streakSeconds) { - streakCountdownAmount = streakSeconds * 20; + streakCountdownAmount = streakSeconds * MinegasmConfig.ticksPerSecond; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index 921baa2..e716f67 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -4,6 +4,8 @@ import net.minecraft.advancements.Advancement; import net.minecraftforge.event.entity.player.AdvancementEvent; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateAdvancement extends AbstractVibrationState { public VibrationStateAdvancement() @@ -25,8 +27,8 @@ public void onAdvancement(AdvancementEvent event) case CHALLENGE -> 10; }; - vibrationCountdown = duration * 20; - vibrationFeedbackCountdown = 1.5f * 20; + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; } catch (Throwable e) { LOGGER.throwing(e); } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index 60b7cba..3ddfb65 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -1,5 +1,7 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateAttack extends AbstractVibrationState { public VibrationStateAttack() @@ -17,8 +19,8 @@ public void onAttack() vibrationCountdown = streakCountdownAmount; vibrationFeedbackCountdown = 1 * 0; } else { - vibrationCountdown = 3 * 20; - vibrationFeedbackCountdown = 1 * 20; + vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index 2f427a7..c952b68 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -1,5 +1,7 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateClient extends AbstractVibrationState { public VibrationStateClient() @@ -10,7 +12,7 @@ public VibrationStateClient() public void setVibration(int intensity, int durationSeconds) { intensity = intensity; - vibrationCountdown = durationSeconds * 20; + vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } public int getIntensity() diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index 48b8238..a1ab209 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -3,6 +3,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateFish extends AbstractVibrationState { public VibrationStateFish() @@ -20,7 +22,7 @@ public void onTick(Player player) double z = vector.z(); if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { - vibrationCountdown = 1.5f * 20; + vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index 1b7f274..47bfe38 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -2,6 +2,8 @@ import net.minecraft.world.level.block.state.BlockState; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; @@ -21,7 +23,7 @@ public int getIntensity() { if (vibrationCountdown > 0){ if (accumulationEnabled()) - return Math.min(100, mineState.getIntensity() + 19); + return Math.min(100, mineState.getIntensity() + 20); else return getIntensity("harvest"); } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index f6a7fff..061b489 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -1,5 +1,7 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateHurt extends AbstractVibrationState { public VibrationStateHurt() @@ -14,10 +16,10 @@ public void onHurt() { { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount; - vibrationFeedbackCountdown = 1 * 20; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - vibrationCountdown = 3 * 20; - vibrationFeedbackCountdown = 1 * 20; + vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index 6c03329..354b9d8 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -2,6 +2,8 @@ import net.minecraft.world.level.block.state.BlockState; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateMine extends AbstractVibrationState { public VibrationStateMine() @@ -18,17 +20,17 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount; - vibrationFeedbackCountdown = 1 * 20; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { intensity = Math.min(100, intensity + .25f); vibrationCountdown = streakCountdownAmount; } } else { if (blockName.contains("Ore")) { - vibrationCountdown = 3 * 20; - vibrationFeedbackCountdown = 1 * 20; + vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else - vibrationCountdown = 3 * 20; + vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index fa2e009..577477e 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -1,5 +1,7 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStatePlace extends AbstractVibrationState { public VibrationStatePlace() @@ -14,9 +16,9 @@ public void onPlace() { { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount; - vibrationFeedbackCountdown = 1 * 20; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - vibrationCountdown = 3 * 20; + vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index c1a0ac4..e40998b 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -27,7 +27,7 @@ public void onTick(Player player) if (targetMet == false){ targetMet = true; - vibrationFeedbackCountdown = 3 * 20; + vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } } else targetMet = false; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 179ba80..3f8d37b 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -1,5 +1,7 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; + public class VibrationStateXpChange extends AbstractVibrationState { private int lastLevel; @@ -29,11 +31,11 @@ public void onXpChange(int level, int amount) { { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount; - vibrationFeedbackCountdown = 1 * 20; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); - vibrationCountdown = duration * 20; - vibrationFeedbackCountdown = 1 * 20; + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index e603497..c3ca8ff 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -15,6 +15,8 @@ public final class ClientConfig { final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; + final ForgeConfigSpec.EnumValue tickFrequency; + final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -39,6 +41,7 @@ public final class ClientConfig { static final int DEFAULT_HARVEST_INTENSITY = 0; static final int DEFAULT_VITALITY_INTENSITY = 0; static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -60,6 +63,10 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); + + tickFrequency = builder + .translation(Minegasm.MOD_ID + ".config.mode") + .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); builder.push("intensity"); @@ -149,5 +156,36 @@ public String getTranslateKey() { } } + public enum TickFrequencyOptions { + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), + EVERY_50_TICKS(50); + + private int value; + + TickFrequencyOptions(int value) { + this.value = value; + } + + public int getInt() + { + return value; + } + + public static TickFrequencyOptions fromInt(int value) + { + for (TickFrequencyOptions type : values()) { + if (type.getInt() == value) { + return type; + } + } + return null; + } + } -} +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index 0f04e49..c7ba222 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -14,6 +14,8 @@ public static void bakeClient() { MinegasmConfig.vibrate = ConfigHolder.CLIENT.vibrate.get(); MinegasmConfig.mode = ConfigHolder.CLIENT.mode.get(); MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); + MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); + MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); @@ -34,11 +36,12 @@ public static void saveClient() try{ MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); ConfigHolder.CLIENT.mode.set(buffer.mode); ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); @@ -59,4 +62,4 @@ public static ConfigGuiHandler.ConfigGuiFactory createConfigGuiFactory() { return new ConfigGuiHandler.ConfigGuiFactory((minecraft, screen) -> new ConfigScreen(screen)); } -} +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index 0d1d185..d4fb3a9 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -125,6 +125,27 @@ protected void init() { this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, new TextComponent("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); + this.addRenderableWidget( + CycleButton.builder((Integer tickFrequency) -> + new TextComponent(switch (tickFrequency) { + case 1 -> "Every Tick"; + case 2 -> "Every Other Tick"; + case 5 -> "Every 5 Ticks"; + case 10 -> "Every 10 Ticks"; + case 20 -> "Every Second"; + default -> "Every " + Float.toString(tickFrequency / 20f)+ " Seconds"; + })) + .withValues(1, 2, 5, 10, 20, 30, 40, 50) + .withInitialValue(MinegasmConfig.tickFrequency) + .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, + new TextComponent("Tick Frequency"), (button, value) -> { + MinegasmConfig.tickFrequency = value; + MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); + LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); + } + ) + ); + this.addRenderableWidget(new Button( this.width / 2 - 100, this.height - 27, 200, 20, CommonComponents.GUI_DONE, button -> this.onClose())); @@ -189,9 +210,8 @@ public void render(PoseStack poseStack, int i, int j, float f) { // Minecraft.getInstance().font.draw(poseStack, text.getString(), x, y, 0xFFFFFF); drawCenteredString(poseStack, Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } - - } + } class CustomModeConfigScreen extends Screen { @@ -325,4 +345,4 @@ private void refreshValue() } } -} +} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index 640b2d4..b1a115a 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -20,6 +20,9 @@ public class MinegasmConfig { public static boolean vibrate; public static ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public static boolean stealth; + public static int tickFrequency; + public static int ticksPerSecond; + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -50,7 +53,7 @@ public static void save() { ConfigHelper.saveClient(); } - + } class MinegasmConfigBuffer @@ -60,6 +63,8 @@ class MinegasmConfigBuffer public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; + public int tickFrequency; + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -76,6 +81,8 @@ class MinegasmConfigBuffer this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; + this.tickFrequency = MinegasmConfig.tickFrequency; + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; @@ -86,4 +93,4 @@ class MinegasmConfigBuffer this.vitalityIntensity = MinegasmConfig.vitalityIntensity; this.advancementIntensity = MinegasmConfig.advancementIntensity; } -} +} \ No newline at end of file From 40b3f972db2037344c36750854173345eff90290 Mon Sep 17 00:00:00 2001 From: Sour3 Date: Sun, 3 Mar 2024 00:01:32 -0800 Subject: [PATCH 3/5] Fixed bug with new tick frequency --- .../minegasm/common/AbstractVibrationState.java | 4 ++-- .../therainbowville/minegasm/common/VibrationStateAttack.java | 2 +- .../therainbowville/minegasm/common/VibrationStateHurt.java | 2 +- .../therainbowville/minegasm/common/VibrationStateMine.java | 4 ++-- .../therainbowville/minegasm/common/VibrationStatePlace.java | 2 +- .../minegasm/common/VibrationStateXpChange.java | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 076fd57..e88aad1 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -22,7 +22,7 @@ public abstract class AbstractVibrationState protected AbstractVibrationState(float streakSeconds) { - streakCountdownAmount = streakSeconds * MinegasmConfig.ticksPerSecond; + streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; @@ -36,7 +36,7 @@ public void onTick() vibrationCountdown--; else if (intensity > 0) { intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; } } else { vibrationCountdown = Math.max(0, vibrationCountdown - 1); diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index 3ddfb65..99f8e03 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -16,7 +16,7 @@ public void onAttack() if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 061b489..f2e1798 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -15,7 +15,7 @@ public void onHurt() { if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index 354b9d8..a69f846 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -19,11 +19,11 @@ public void onBreak(BlockState block) { { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { intensity = Math.min(100, intensity + .25f); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; } } else { if (blockName.contains("Ore")) { diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index 577477e..06ef6d8 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -15,7 +15,7 @@ public void onPlace() { if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 3f8d37b..f61d685 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -30,7 +30,7 @@ public void onXpChange(int level, int amount) { if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); - vibrationCountdown = streakCountdownAmount; + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); From 1f193811d78e7cf2c16115a4ee4bf8078be0df7e Mon Sep 17 00:00:00 2001 From: Sour3 Date: Sun, 3 Mar 2024 00:11:10 -0800 Subject: [PATCH 4/5] Fixed another bug Fixed another bug --- .../minegasm/common/AbstractVibrationState.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index e88aad1..f72e827 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -33,16 +33,16 @@ public void onTick() if (accumulationEnabled()) { if (vibrationCountdown > 0) - vibrationCountdown--; + vibrationCountdown =- Math.max(0, vibrationCountdown - MinegasmConfig.tickFrequency); else if (intensity > 0) { intensity = Math.max(0, intensity - 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; } } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); + vibrationCountdown = Math.max(0, vibrationCountdown - MinegasmConfig.tickFrequency); } - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - MinegasmConfig.tickFrequency); } public void resetState() From d97dcd8653a3947c27ce80e55e0b5b3a762f08b8 Mon Sep 17 00:00:00 2001 From: Sour3 Date: Sun, 3 Mar 2024 00:34:47 -0800 Subject: [PATCH 5/5] Revert "Fixed another bug" This reverts commit 1f193811d78e7cf2c16115a4ee4bf8078be0df7e. --- .../minegasm/common/AbstractVibrationState.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index f72e827..e88aad1 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -33,16 +33,16 @@ public void onTick() if (accumulationEnabled()) { if (vibrationCountdown > 0) - vibrationCountdown =- Math.max(0, vibrationCountdown - MinegasmConfig.tickFrequency); + vibrationCountdown--; else if (intensity > 0) { intensity = Math.max(0, intensity - 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; } } else { - vibrationCountdown = Math.max(0, vibrationCountdown - MinegasmConfig.tickFrequency); + vibrationCountdown = Math.max(0, vibrationCountdown - 1); } - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - MinegasmConfig.tickFrequency); + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); } public void resetState()