Skip to content

Commit

Permalink
Add features for 1.20.4, 1.19.4, 1.19.2, 1.17.1, 1.16.5, 1.15.2 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sour-o7 authored Mar 8, 2024
1 parent 16dd814 commit cc5d740
Show file tree
Hide file tree
Showing 126 changed files with 9,144 additions and 1,842 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
import java.util.List;
import java.util.Objects;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.Executors;

public class ToyController {
private static final Logger LOGGER = LogManager.getLogger();
private static final ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm");
private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm");
private static ButtplugClientDevice device = null;
private static boolean shutDownHookAdded = false;
public static String lastErrorMessage = "";
Expand All @@ -24,9 +30,28 @@ public static boolean connectDevice() {
try {
device = null;
client.disconnect();

LOGGER.info("URL: " + MinegasmConfig.serverUrl);

client.connect(new URI(MinegasmConfig.serverUrl));
ExecutorService executor = Executors.newSingleThreadExecutor();
Future future = executor.submit(new Callable<Void>() {
public Void call() throws Exception {
client.connect(new URI(MinegasmConfig.serverUrl));
return null;
}
});

try
{
future.get(3, TimeUnit.SECONDS);
} catch (TimeoutException e) {
future.cancel(true);
client = new ButtplugClientWSClient("Minegasm");
throw new TimeoutException("Could not find WebSocket");
} finally {
executor.shutdownNow();
}

client.startScanning();

Thread.sleep(5000);
Expand Down Expand Up @@ -73,7 +98,7 @@ public static boolean connectDevice() {
isConnected = true;
} catch (Exception e) {
lastErrorMessage = e.getMessage();
e.printStackTrace();
LOGGER.error(e.getMessage(), e);
}

return Objects.nonNull(device);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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;
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 * MinegasmConfig.ticksPerSecond;
}
} 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<String, Integer> 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<String, Integer> 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<String, Integer> 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<String, Integer> 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<String, Integer> 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);


int returnValue = -1;

switch (MinegasmConfig.mode)
{
case NORMAL: returnValue = normal.get(type);
case MASOCHIST: returnValue = masochist.get(type);
case HEDONIST: returnValue = hedonist.get(type);
case ACCUMULATION: returnValue = accumulation.get(type);
case CUSTOM: returnValue = custom.get(type);
};

return returnValue;
}

public abstract int getIntensity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.therainbowville.minegasm.common;

import net.minecraft.advancements.FrameType;
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()
{
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 = 0;

switch (type) {
case TASK:
duration = 5;
break;
case GOAL:
duration = 7;
break;
case CHALLENGE:
duration = 10;
break;
};

vibrationCountdown = duration * MinegasmConfig.ticksPerSecond;
vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond;
} 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.therainbowville.minegasm.common;

import com.therainbowville.minegasm.config.MinegasmConfig;

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 * MinegasmConfig.ticksPerSecond;
vibrationFeedbackCountdown = 1 * 0;
} else {
vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond;
vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond;
}
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.therainbowville.minegasm.common;

import com.therainbowville.minegasm.config.MinegasmConfig;

public class VibrationStateClient extends AbstractVibrationState
{
public VibrationStateClient()
{
super(0);
}

public void setVibration(int intensity, int durationSeconds)
{
intensity = intensity;
vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond;
}

public int getIntensity()
{
if (vibrationCountdown > 0)
return Math.toIntExact(Math.round(intensity));
else return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.therainbowville.minegasm.common;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.util.math.Vec3d;

import com.therainbowville.minegasm.config.MinegasmConfig;


public class VibrationStateFish extends AbstractVibrationState
{

public VibrationStateFish()
{
super(0);
}

public void onTick(ClientPlayerEntity player)
{
if (player == null) return;

if (player.fishing != null)
{
Vec3d vector = player.fishing.getDeltaMovement();
double x = vector.x();
double y = vector.y();
double z = vector.z();
if (y < -0.075 && player.fishing.isInWater() && x == 0 && z == 0)
{
vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond;
LOGGER.info("Fishing!");
}
}
}

public int getIntensity()
{
if (vibrationCountdown > 0)
return getIntensity("fishing");
else return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.therainbowville.minegasm.common;

import com.therainbowville.minegasm.config.MinegasmConfig;

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() + 20);
else
return getIntensity("harvest");
}
else return 0;
}
}
Loading

0 comments on commit cc5d740

Please sign in to comment.