Skip to content

Commit

Permalink
Update readme, code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ojaha065 committed Feb 26, 2024
1 parent 1faab0a commit 0858626
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Jani Haiko
Copyright (c) 2023 - 2024 Jani Haiko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
53 changes: 38 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PiShock Shock Collar Integration for Minecraft
# PiShock Shock Collar Integration for Minecraft: Java Edition
This Forge mod allows players
to connect their [PiShock](https://pishock.com) device to the game for added realism and _...fun..._:smiling_imp:.
Whenever the player takes damage, they will get a corresponding shock,
Expand Down Expand Up @@ -39,7 +39,8 @@ The mod is licensed under a MIT license, so feel free to include it in any modpa
This mod should be compatible with almost everything.
If you're using other mods that alter the player health (e.g., changes the maxium health),
please note that the shock intensity scaling might not work as expected.
However, even in that case the player will never be shocked with higher intensity than the configured `intensity_range` allows.
However,
even in that case the player will never be shocked with a higher intensity than the configured `intensity_range` allows.

## Mod configuration
The mod configuration file is named `pishockmc-client.toml` and it can be edited with any text editor. In-game settings GUI might be added in a later release to make configuring easier. The configuration file will look like this:
Expand All @@ -59,11 +60,16 @@ intensity_range = "NORMAL"
code = ""
```

`username`, `apikey` and `code` are all mandatory, and you must get all of them from [pishock.com](https://pishock.com).
`username`, `apikey` and `code` are all mandatory, and you can get all of them from [pishock.com](https://pishock.com).
It's also important to set the desired intensity level (`intensity_range`).
The default value is `MINIMAL`, but personally I feel that `NORMAL`or `INTENSE` have the best balance between feeling kinda nasty but not being too overwhelming.
But it's all very dependent on each person's pain tolerance and location of the shocker, so feel free to experiment.
Also, please be aware that for most people getting shocked at the same spot multiple times heightens the sensation and each consecutive shock will be more painful.
The default value is `MINIMAL`,
but for me personally `NORMAL`or `INTENSE` have the best balance
between feeling kinda nasty but not being too overwhelming.
But it's all very dependent on each person's pain tolerance and location of the shocker,
so you need to experiment what works for each person.
Also,
please be aware that for most people getting shocked at the same spot multiple times drastically heightens the sensation
and each consecutive shock will be more painful.

### Punishment for death
Setting `punishment_for_death` --> `enabled` option to `true` will send a shock with the configured intensity and duration when the player dies in-game.
Expand All @@ -76,14 +82,29 @@ When creating a share code,
the `Max Duration` value needs to be set to at least 6 (seconds)
or the value of `punishment_for_death` --> `duration` if it's higher than 6.

### Intensity ranges
| intensity_range | Maxium intensity % |
|-----------------|--------------------|
| MINIMAL | 20% |
| NORMAL | 40% |
| INTENSE | 60% |
| HARDCORE | 80% |
| ULTRA_HARDCORE | 100% |
The mod will warn about a misconfiguration if this is not set correctly.

### Shock intensity calculation
The intensity of the shock is calculated using the following formula:
[The amount of damage taken] * [intensity range multiplayer (see the table below)].
The maximum amount of damage taken into account is 20 (10 hearts).
This won't be exceeded even if other mods raise the player's maximum health.
If [absorption](https://minecraft.fandom.com/wiki/Absorption) cancels the incoming damage, no shock will be triggered.

After a shock is triggered,
there's a cooldown of 25 ticks (just bit over a second) before another shock can be triggered.
The damage taken during that time will be backlogged,
and another shock with the intensity calculated using the accumulated damage will be triggered after the cooldown ends.


### Intensity ranges and multipliers
| intensity_range | Maxium intensity % | Damage Multiplier |
|-----------------|--------------------|-------------------|
| MINIMAL | 20% | 1 |
| NORMAL | 40% | 2 |
| INTENSE | 60% | 3 |
| HARDCORE | 80% | 4 |
| ULTRA_HARDCORE | 100% | 5 |

## Common issues and FAQ
### Sometimes the shocker isn't activated when it should
Expand All @@ -108,7 +129,9 @@ Please open [an issue](https://github.com/ojaha065/PiShockForMC/issues) here on
* **Support for multiple shockers**
* I currently only own one, so testing and debugging would be kinda hard.
* In-game configuration GUI
* More configuration options
* **More configuration options**
* Configurable shock duration
* Configurable cooldown time

## The boring stuff

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
}

version = '1.20-1.1.2.1'
version = '1.20-1.1.2.2'
group = 'fi.kissakala'
base.archivesName = 'pishockmc'

Expand Down Expand Up @@ -32,7 +32,7 @@ repositories {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.20.4-49.0.14'
minecraft 'net.minecraftforge:forge:1.20.4-49.0.30'
}

jar {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fi/kissakala/pishockmc/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ private static ForgeConfigSpec.Builder build(final ForgeConfigSpec.Builder build

public enum INTENSITY_SETTING_VALUE {
MINIMAL(1f), // 1 - 20
NORMAL(2f), // 21 - 40
INTENSE(3f), // 41 - 60
HARDCORE(4f), // 61 - 80
ULTRA_HARDCORE(5f); // 81 - 100
NORMAL(2f), // 2 - 40
INTENSE(3f), // 3 - 60
HARDCORE(4f), // 4 - 80
ULTRA_HARDCORE(5f); // 5 - 100

private final float multiplier;
INTENSITY_SETTING_VALUE(final float multiplier) {
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/fi/kissakala/pishockmc/PiShockForMC.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fi.kissakala.pishockmc;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -108,22 +107,22 @@ private void onClientTick(final TickEvent.ClientTickEvent event) {

// FIXME: Messy
if (API.getConnectionState().equals(PiShockAPI.CONNECTION_STATE.OK)) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("PiShock enabled. You'll be punished for any damage you take..."));
Utils.logToChat("PiShock enabled. You'll be punished for any damage you take...");
gracePeriodTimer = null;
} else if (API.getConnectionState().equals(PiShockAPI.CONNECTION_STATE.CONNECTED_WITH_WARNING)) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("PiShock enabled. You'll be punished for any damage you take..."));
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("[WARNING] There seems to be some kind of misconfiguration or issue with PiShock configuration. Please check the Minecraft Output logs and mod documentation for more details."));
Utils.logToChat("PiShock enabled. You'll be punished for any damage you take...");
Utils.logToChat("[WARNING] There seems to be some kind of misconfiguration or issue with PiShock configuration. Please check the Minecraft Output logs and mod documentation for more details.");
gracePeriodTimer = null;
} else {
gracePeriodTimer = 20 * 10;
API.connect().thenAccept(connectionState -> {
if (connectionState.equals(PiShockAPI.CONNECTION_STATE.OK)) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("PiShock enabled. You'll be punished for any damage you take..."));
Utils.logToChat("PiShock enabled. You'll be punished for any damage you take...");
} else if (connectionState.equals(PiShockAPI.CONNECTION_STATE.CONNECTED_WITH_WARNING)) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("PiShock enabled. You'll be punished for any damage you take..."));
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("[WARNING] There seems to be some kind of misconfiguration or issue with PiShock configuration. Please check the Minecraft Output logs and mod documentation for more details."));
Utils.logToChat("PiShock enabled. You'll be punished for any damage you take...");
Utils.logToChat("[WARNING] There seems to be some kind of misconfiguration or issue with PiShock configuration. Please check the Minecraft Output logs and mod documentation for more details.");
} else {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("It seems that Minecraft cannot connect to your PiShock device. Please check the Minecraft Output logs and mod documentation for more help."));
Utils.logToChat("It seems that Minecraft cannot connect to your PiShock device. Please check the Minecraft Output logs and mod documentation for more help.");
}

gracePeriodTimer = null;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/fi/kissakala/pishockmc/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fi.kissakala.pishockmc;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;

import javax.annotation.Nonnull;

public class Utils {
Expand All @@ -22,4 +25,12 @@ public static int clamp(final int integer, final int min, final int max) {
public static String log(@Nonnull final String message) {
return "[PiShock] " + message;
}

/**
* Adds a message to the chat
* @param message The message
*/
public static void logToChat(@Nonnull final String message) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal(message));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/ojaha065/PiShockForMC/issues"

[[mods]]
modId="pishockmc"
version="1.20-1.1.2.1"
version="1.20-1.1.2.2"
displayName="PiShock for Minecraft"

#updateJSONURL="https://change.me.example.invalid/updates.json" # TODO
Expand Down

0 comments on commit 0858626

Please sign in to comment.