Skip to content

Commit

Permalink
Fix and improve grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
ojaha065 committed Jun 25, 2023
1 parent 9a256e2 commit 5d42c65
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
# PiShock Shock Collar Integration for Minecraft
This simple Forge mod allows players to connect their [PiShock](https://pishock.com) device to the game for some added stakes. Whenever the player takes damage, they will get a corresponding shock, the intensity of which can be configured and will scale up based on the amount of damage taken.

## Supported Minecraft/Forge versions
1.19.x (Forge 45.x)
This is a client-side mod, so it can be used in any multiplayer server.

## Supported Minecraft/Minecraft Forge versions
* 1.19.x (Minecraft Forge 45.x)

## Needed hardware
* A PiShock
* A shocker; needs to paired to the PiShock (multiple shockers might be supported in a future release)
* A shocker — needs to be paired to the PiShock
* Multiple shockers might be supported in a future release.

## Setup instructions (tl;dr - I've done this before and I know what I'm doing)
## Setup instructions (tl;dr I've done this before, and I know what I'm doing)
1. Download the latest release and drop the jar into Forge `mods` folder.
2. Launch the game once and then see the Mod configuration section below.
3. Launch the game again. If everything is set corrently the shocker will vibrate for one second during Minecraft startup process.
2. Launch the game once and then see the _Mod configuration_ section below.
3. Launch the game again. If everything is set currently, the shocker will vibrate once for one second during the Minecraft startup process.

## Setup instructions
0. Have a working Minecraft and Forge installation. See [How to install Forge](https://www.wikihow.com/Install-Minecraft-Forge) if you're unsure.
* Make sure you've launched the game at least once with Forge installed so required folder structure is generated.
* Make sure you've launched the game at least once with Forge installed so the required folder structure is generated.
1. Download the latest release jar from [here](https://github.com/ojaha065/PiShockForMC/releases).
2. Drop the downloaded .jar file into `mods` folder inside Minecraft game directory. See [Where are Minecraft files stored?](https://help.minecraft.net/hc/en-us/articles/4409159214605-Managing-Data-and-Game-Storage-in-Minecraft-Java-Edition-#h_01FGA90Z06DE00GT8E81SWX9SE) if you're unsure how to find the correct game directory.
3. Run the game once so a configuration file gets generated.
4. See the Mod configuration section below. The config file can be found inside `config` folder inside Minecraft game directory.
5. Launch the game again. If everything is set corrently the shocker will vibrate for one second during Minecraft startup process.
3. Run the game once so a configuration file for the mod gets generated.
4. See the _Mod configuration_ section below. The configuration file can be found inside `config` folder inside Minecraft game directory.
5. Launch the game again. If everything is set correctly, the shocker will vibrate once for one second during the Minecraft startup process.

## 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 @@ -35,7 +38,7 @@ mode = "Shock"
intensity_range = "NORMAL"
#If enabled, sends 5 second shock/vibrate/beep at the maximum* intensity when the player dies
#(*the maximum is based on the configured intensity range)
death_punishment = false
punishment_for_death = false
[pishock]
#Username you use to log into PiShock.com. Can be found in the Account section of the website.
Expand All @@ -48,10 +51,13 @@ death_punishment = false
```

`username`, `apikey` and `code` are all mandatory and you can get all of them from 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` has the best balance between feeling kinda nasty but not being too overwhelming. But it's all very dependant on each persons pain tolerance and location of the shocker so feel free to experiment.
`username`, `apikey` and `code` are all mandatory, and you must get all of them from 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` has 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.

### :warning: Important notice
The mod uses duration of 600 milliseconds for most shocks. Using milliseconds insteads of seconds is currently undocumented feature in PiShock API and it seems that `Max Duration` setting for share codes does not work corectly with it. When creating a share code you need to set `Max Duration` to value of at least 6 (seconds).
The mod uses duration of 600 milliseconds for most shocks.
Using milliseconds instead of seconds is currently undocumented feature in PiShock API,
and it seems that `Max Duration` setting for share codes does not work correctly with it.
When creating a share code, you need to set `Max Duration` to value of at least 6 (seconds).

### Intensity ranges
| intensity_range | Shock intensity % range |
Expand All @@ -63,4 +69,9 @@ The mod uses duration of 600 milliseconds for most shocks. Using milliseconds in
| ULTRA_HARDCORE | 81% - 100% |

## The boring stuff
Authors of this mod are not responsible for any injuries caused by use of the shock collar. It's not recommended to put any kind of electrical device near the heart or use any kind of shock collar if you have a heart condition. Shock collars are not meant for use on humans and can cause serious injury, even cardiac events. We kindly urge you to prioritize safety, understand your personal and others limitations, and exercise caution at all times.
Authors of this mod are not responsible for any injuries caused by use of the shock collar.
It's not recommended to put any kind of electrical device near the heart
or use any kind of shock collar if you have a heart condition.
Shock collars are not meant for use on humans and can cause serious injury, even cardiac events.
We kindly urge you to prioritize safety,
understand your personal and other's limitations, and exercise caution at all times.
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 @@ -11,7 +11,7 @@ public class Config {

public static ForgeConfigSpec.EnumValue<INTENSITY_SETTING_VALUE> intensity;
public static ForgeConfigSpec.EnumValue<PiShockAPI.OP_CODE> mode;
public static ForgeConfigSpec.BooleanValue deathPunishment;
public static ForgeConfigSpec.BooleanValue punishmentForDeath;

static {
INSTANCE = build(new ForgeConfigSpec.Builder()).build();
Expand All @@ -38,10 +38,10 @@ private static ForgeConfigSpec.Builder build(final ForgeConfigSpec.Builder build
.comment("Set the shock/vibration/beep intensity range", "Ranges from lowest to highest are: 1 - 20, 21 - 40, 41 - 60, 61 - 80, 80 - 100")
.defineEnum("intensity_range", INTENSITY_SETTING_VALUE.MINIMAL, INTENSITY_SETTING_VALUE.values());

// TODO: Make death punishment (duration, intensity etc.) configurable
deathPunishment = builder
// TODO: Make the punishment (duration, intensity etc.) configurable
punishmentForDeath = builder
.comment("If enabled, sends 5 second shock/vibrate/beep at the maximum* intensity when the player dies", "(*the maximum is based on the configured intensity range)")
.define("death_punishment", false);
.define("punishment_for_death", false);

return builder;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/kissakala/pishockmc/PiShockAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void sendRequest(final OP_CODE operation, final int intensity, final int
Map.entry("Username", Config.username.get()),
Map.entry("Apikey", Config.apikey.get()),
Map.entry("Code", Config.code.get()),
Map.entry("Name", "PiShock for Minecraft"),
Map.entry("Name", "PiShock integration for Minecraft"),
Map.entry("Op", operation.getValue()),
Map.entry("Duration", duration >= 100 ? Utils.clamp(duration, 100, 15_000) : Utils.clamp(duration, 1, 15)),
Map.entry("Intensity", Utils.clamp(intensity, 1, 100))
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/fi/kissakala/pishockmc/PiShockForMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PiShockForMC {
@Nullable private static Integer cooldownTimer = null;
@Nullable private static Integer gracePeriodTimer = null;
private static float damageBacklog = 0f;
private static DEATH_PUNISHMENT_STATE deathPunishmentState = DEATH_PUNISHMENT_STATE.INACTIVE;
private static PUNISHMENT_FOR_DEATH_STATE punishmentForDeathState = PUNISHMENT_FOR_DEATH_STATE.INACTIVE;

public PiShockForMC() {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
Expand All @@ -48,7 +48,7 @@ private void onClientSetup(final FMLClientSetupEvent _event) {
LOGGER.info(Utils.log("PiShock for Minecraft initialized"));
}

// As far as I know there isn't a client-side event to easily watch player health in Forge.
// As far as I know, there isn't a client-side event to easily watch player health in Forge.
// So need to do this manually.
private void onClientTick(final TickEvent.ClientTickEvent event) {
// Skip tick start event
Expand All @@ -58,11 +58,12 @@ private void onClientTick(final TickEvent.ClientTickEvent event) {

KeyMappingsHandler.onClientTick(API);

// Check for a waiting death punishment early in the flow so the player cannot escape it by pausing or exiting the world once it's activated
if (DEATH_PUNISHMENT_STATE.WAITING.equals(deathPunishmentState)) {
// Check for a waiting punishment for death early in the flow
// so the player cannot escape it by pausing or exiting the world once it's activated
if (PUNISHMENT_FOR_DEATH_STATE.WAITING.equals(punishmentForDeathState)) {
if (cooldownTimer == null || --cooldownTimer <= 0) {
cooldownTimer = null;
deathPunishmentState = DEATH_PUNISHMENT_STATE.DONE;
punishmentForDeathState = PUNISHMENT_FOR_DEATH_STATE.DONE;
API.sendRequest(
Config.mode.get(),
(int) (20f * Config.intensity.get().getMultiplier()),
Expand All @@ -87,7 +88,8 @@ private void onClientTick(final TickEvent.ClientTickEvent event) {
}

// Skip if the player is in creative or spectator mode
// Player usually cannot take damage while in those game modes and even if they somehow do we don't want to shock them for it
// Player usually cannot take damage while in those game modes,
// and even if they somehow do, we don't want to shock them for it
if (player.isCreative() || player.isSpectator()) {
resetState();
return;
Expand All @@ -96,7 +98,7 @@ private void onClientTick(final TickEvent.ClientTickEvent event) {
final float currentHealth = player.getHealth();

if (gracePeriodTimer != null) {
// If the grace period is still active just update the current health and short circuit
// If the grace period is still active, just update the current health and short circuit
// Also, do not advance the grace period while the player is dead
// --> Fixes an edge case issue where punishment for death would be unfairly activated if the player joins a world where they are currently dead
if (currentHealth <= 0 || --gracePeriodTimer > 0) {
Expand All @@ -108,32 +110,33 @@ private void onClientTick(final TickEvent.ClientTickEvent event) {
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("PiShock enabled. You'll be punished for any damage you take..."));
}

// If we don't know the health from the previous tick it most likely means that the player just joined the world.
// If we don't know the health from the previous tick,
// it most likely means that the player just joined the world.
// Just start the grace period (to avoid unfairly shocking the player immediately after the world has been loaded) for 100 ticks and skip the rest
if (previousTickHealth == null) {
previousTickHealth = currentHealth;
gracePeriodTimer = 100;
return;
}

// Main business logic
// First check if the player is dead and if the punishment for death is enabled...
if (currentHealth <= 0 && Config.deathPunishment.get()) {
if (DEATH_PUNISHMENT_STATE.DONE.equals(deathPunishmentState)) {
// The main business logic
// First checks if the player is dead and if the punishment for death is enabled...
if (currentHealth <= 0 && Config.punishmentForDeath.get()) {
if (PUNISHMENT_FOR_DEATH_STATE.DONE.equals(punishmentForDeathState)) {
LOGGER.trace(Utils.log("Player is dead but has been already punished for this death --> Do nothing"));
return;
}

LOGGER.debug(Utils.log("Player has died and the punishment for death is enabled --> Get ready..."));
deathPunishmentState = DEATH_PUNISHMENT_STATE.WAITING;
punishmentForDeathState = PUNISHMENT_FOR_DEATH_STATE.WAITING;
damageBacklog = 0f; // Cancel any other pending damage
}

// ..If not, then check if the player has taken any damage since the last tick...
else if (currentHealth < previousTickHealth) {
final float lostHealth = previousTickHealth - currentHealth;
LOGGER.debug(Utils.log("Player has taken %s damage since the last tick".formatted(lostHealth)));
deathPunishmentState = DEATH_PUNISHMENT_STATE.INACTIVE;
punishmentForDeathState = PUNISHMENT_FOR_DEATH_STATE.INACTIVE;

if (currentHealth < player.getMaxHealth()) { // Ignore this "damage" if the player somehow already is at their maximum health
if (cooldownTimer == null) {
Expand Down Expand Up @@ -183,10 +186,10 @@ private static void resetState() {
cooldownTimer = null;
gracePeriodTimer = null;
damageBacklog = 0f;
deathPunishmentState = DEATH_PUNISHMENT_STATE.INACTIVE;
punishmentForDeathState = PUNISHMENT_FOR_DEATH_STATE.INACTIVE;
}

private enum DEATH_PUNISHMENT_STATE {
private enum PUNISHMENT_FOR_DEATH_STATE {
INACTIVE,
WAITING,
DONE
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/kissakala/pishockmc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static int clamp(final int integer, final int min, final int max) {
}

/**
* Simple helper for logging that prepends "[PiShock]" to String
* Simple helper for logging. Prepends "[PiShock]" to String
* @param message The input
* @return "[PiShock] " + the given input
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
modLoader="javafml"
loaderVersion="[45,)"
license="MIT"
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" # TODO
issueTrackerURL="https://github.com/ojaha065/PiShockForMC/issues"

[[mods]]
modId="pishockmc"
version="1.19-1.0.0.0"
displayName="PiShock for Minecraft"

#updateJSONURL="https://change.me.example.invalid/updates.json" # TODO
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" # TODO
displayURL="https://github.com/ojaha065/PiShockForMC"
logoFile="logo.png" # TODO: An actual proper logo. This is just 5-minutes-in-photoshop placeholder...

credits="Special thanks to PiShock and its main developer Fedack/Lethos (https://twitter.com/Lethos_OTStorm) for making this mod possible :)"
authors="JHaiko"
description='''
PiShock Shock Collar Integration for Minecraft
This simple mod allows players to connect their PiShock device to the game for some added stakes. Whenever the player takes damage, they will get a corresponding shock, the intensity of which can be configured and will scale up based on the amount of damage taken.
This simple client-only mod allows players to connect their PiShock device to the game for some added stakes. Whenever the player takes damage, they will get a corresponding shock, the intensity of which can be configured and will scale up based on the amount of damage taken.
For detailed setup instructions and configuration, please refer to the GitHub page.
---
Authors of this mod or PiShock are not responsible for any injuries caused by use of the shock collar. It's not recommended to put any kind of electrical device near the heart or use any kind of shock collar if you have a heart condition. Shock collars are not meant for use on humans and can cause serious injury, even cardiac events. We kindly urge you to prioritize safety, understand your personal and others limitations, and exercise caution at all times.
Authors of this mod or PiShock are not responsible for any injuries caused by use of the shock collar. It's not recommended to put any kind of electrical device near the heart or use any kind of shock collar if you have a heart condition. Shock collars are not meant for use on humans and can cause serious injury, even cardiac events. We kindly urge you to prioritize safety, understand your personal and other's limitations, and exercise caution at all times.
'''

# Display Test controls the display of the mod in the server connection screen
Expand Down

0 comments on commit 5d42c65

Please sign in to comment.