Skip to content

Commit

Permalink
Support for PiShock V3 firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
ojaha065 committed Nov 4, 2023
1 parent 4b58795 commit 8f02060
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ to connect their [PiShock](https://pishock.com) device to the game for added rea
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 is a client-side mod, it should only be installed client-side, and it works in multiplayer too.**
**This is a client-side mod. It works in multiplayer too but should be installed and configured client-side only.**

## :information_source: Important info for PiShock firmware V3 users
If you have updated your PiShock firmware to V3 (beta) you must use version 1.1.2.0 or later of the mod.

## Supported Minecraft/Minecraft Forge versions
* 1.19.x (Minecraft Forge 44.x, 45.x)
* 1.20.x (Minecraft Forge 46.x, 47.x)
* 1.20.x (Minecraft Forge 46.x, 47.x, 48.x)

## Needed hardware
* A PiShock
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ plugins {
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
}

version = '1.20-1.1.1.0'
version = '1.20-1.1.2.0'
group = 'fi.kissakala'
base.archivesName = 'pishockmc'

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
mappings channel: 'official', version: '1.20.1'
mappings channel: 'official', version: '1.20.2'
copyIdeResources = true

runs {
client {
Expand All @@ -37,7 +38,7 @@ repositories {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.20.1-47.1.0'
minecraft 'net.minecraftforge:forge:1.20.2-48.0.34'
}

jar {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 12 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
13 changes: 3 additions & 10 deletions src/main/java/fi/kissakala/pishockmc/PiShockAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.mojang.logging.LogUtils;
import net.minecraftforge.common.ForgeConfigSpec;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

import java.io.Closeable;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void sendRequest(final OP_CODE operation, final int intensity, final int
responseString = new String(is.readAllBytes());
}

if (!"Operation Succeeded.".equals(responseString)) {
if (!StringUtils.equalsAny(responseString, "Operation Attempted.", "Operation Succeeded.")) {
throw new RuntimeException("PiShock API request failed: " + responseString);
}
} catch (final Exception error) {
Expand Down Expand Up @@ -141,13 +142,6 @@ public CompletableFuture<CONNECTION_STATE> connect() {
return this.connectionState;
}

if (!shockerInfo.online) {
LOGGER.warn(Utils.log("The configured PiShock device is not online!"));

this.connectionState = CONNECTION_STATE.CONNECTED_WITH_WARNING;
return this.connectionState;
}

LOGGER.info(Utils.log("Shocker \"{}\" found! Sending vibrate..."));
sendRequest(OP_CODE.Vibrate, 25, 1);

Expand Down Expand Up @@ -239,7 +233,6 @@ private record GetShockerInfoResponse(
String name,
Boolean paused,
Integer maxIntensity,
Integer maxDuration,
Boolean online
Integer maxDuration
){}
}
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.1.0"
version="1.20-1.1.2.0"
displayName="PiShock for Minecraft"

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

0 comments on commit 8f02060

Please sign in to comment.