Compare commits
2 Commits
7f6b4e3520
...
3e75601832
Author | SHA1 | Date | |
---|---|---|---|
3e75601832 | |||
5c5e86d1d8 |
@ -2,13 +2,13 @@
|
|||||||
org.gradle.jvmargs=-Xmx2G
|
org.gradle.jvmargs=-Xmx2G
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.19.2
|
minecraft_version=1.19.3
|
||||||
yarn_mappings=1.19.2+build.28
|
yarn_mappings=1.19.3+build.2
|
||||||
loader_version=0.14.10
|
loader_version=0.14.11
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.1.0
|
mod_version=1.2.0
|
||||||
maven_group=cmods
|
maven_group=cmods
|
||||||
archives_base_name=haxxor
|
archives_base_name=haxxor
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# check this on https://modmuss50.me/fabric.html
|
# check this on https://modmuss50.me/fabric.html
|
||||||
fabric_version=0.67.1+1.19.2
|
fabric_version=0.68.1+1.19.3
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cmods.haxxor.client;
|
package cmods.haxxor.client;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
@ -71,11 +72,11 @@ public class AutoFarmer { // Really just a namespace and needed to separate thin
|
|||||||
sendStopPackets(client);
|
sendStopPackets(client);
|
||||||
|
|
||||||
scanBlocks(client);
|
scanBlocks(client);
|
||||||
if (options.move_seeds && options.enabled)
|
if (options.move_seeds.get() && options.enabled.get())
|
||||||
adjustInventory(client);
|
adjustInventory(client);
|
||||||
findActions(client);
|
findActions(client);
|
||||||
|
|
||||||
if (options.enabled)
|
if (options.enabled.get())
|
||||||
run(client);
|
run(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ public class AutoFarmer { // Really just a namespace and needed to separate thin
|
|||||||
for (int i = 0; i < crops.length; i++) {
|
for (int i = 0; i < crops.length; i++) {
|
||||||
int slot = inventory.getSlotWithStack(new ItemStack(crops[i].seed_type));
|
int slot = inventory.getSlotWithStack(new ItemStack(crops[i].seed_type));
|
||||||
if (crops[i].seed_type != null && crops[i].planted_on != null && block.isOf(crops[i].planted_on) &&
|
if (crops[i].seed_type != null && crops[i].planted_on != null && block.isOf(crops[i].planted_on) &&
|
||||||
options.crops_enabled[i] && slot != -1) {
|
options.crops_enabled[i].get() && slot != -1) {
|
||||||
if (!item_in_main) {
|
if (!item_in_main) {
|
||||||
if (PlayerInventory.isValidHotbarIndex(slot)) {
|
if (PlayerInventory.isValidHotbarIndex(slot)) {
|
||||||
selectSlot(client, slot);
|
selectSlot(client, slot);
|
||||||
@ -168,9 +169,9 @@ public class AutoFarmer { // Really just a namespace and needed to separate thin
|
|||||||
potentialActions.clear();
|
potentialActions.clear();
|
||||||
BlockPos playerPos = client.player.getBlockPos();
|
BlockPos playerPos = client.player.getBlockPos();
|
||||||
|
|
||||||
for (int y = options.min_y; y <= options.max_y; y++) {
|
for (int y = options.min_y.get(); y <= options.max_y.get(); y++) {
|
||||||
for (int x = -options.horizontal_reach; x <= options.horizontal_reach; x++) {
|
for (int x = -options.horizontal_reach.get(); x <= options.horizontal_reach.get(); x++) {
|
||||||
for (int z = -options.horizontal_reach; z <= options.horizontal_reach; z++) {
|
for (int z = -options.horizontal_reach.get(); z <= options.horizontal_reach.get(); z++) {
|
||||||
BlockPos pos = playerPos.add(x, y, z);
|
BlockPos pos = playerPos.add(x, y, z);
|
||||||
|
|
||||||
ACTION_TYPE action = checkBlock(client, pos);
|
ACTION_TYPE action = checkBlock(client, pos);
|
||||||
@ -192,17 +193,17 @@ public class AutoFarmer { // Really just a namespace and needed to separate thin
|
|||||||
AutoFarmerCropType cropType = crops[i];
|
AutoFarmerCropType cropType = crops[i];
|
||||||
|
|
||||||
if (cropType.growth_pattern == GROWTH_PATTERN.BASIC && block.isOf(cropType.crop_type) &&
|
if (cropType.growth_pattern == GROWTH_PATTERN.BASIC && block.isOf(cropType.crop_type) &&
|
||||||
options.crops_enabled[i]) {
|
options.crops_enabled[i].get()) {
|
||||||
return isMature(block, cropType.crop_type.getClass()) ? ACTION_TYPE.BREAK : ACTION_TYPE.NONE;
|
return isMature(block, cropType.crop_type.getClass()) ? ACTION_TYPE.BREAK : ACTION_TYPE.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cropType.growth_pattern == GROWTH_PATTERN.LEAVE_BASE && block.isOf(cropType.crop_type) &&
|
if (cropType.growth_pattern == GROWTH_PATTERN.LEAVE_BASE && block.isOf(cropType.crop_type) &&
|
||||||
options.crops_enabled[i]) {
|
options.crops_enabled[i].get()) {
|
||||||
return isSecondBlock(client.world, pos, cropType.crop_type) ? ACTION_TYPE.BREAK : ACTION_TYPE.NONE;
|
return isSecondBlock(client.world, pos, cropType.crop_type) ? ACTION_TYPE.BREAK : ACTION_TYPE.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cropType.seed_type != null && cropType.planted_on != null && block.isOf(cropType.planted_on) &&
|
if (cropType.seed_type != null && cropType.planted_on != null && block.isOf(cropType.planted_on) &&
|
||||||
client.world.getBlockState(pos.up()).isAir() && options.seeds_enabled[i]) {
|
client.world.getBlockState(pos.up()).isAir() && options.seeds_enabled[i].get()) {
|
||||||
return ACTION_TYPE.PLACE;
|
return ACTION_TYPE.PLACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,7 +227,7 @@ public class AutoFarmer { // Really just a namespace and needed to separate thin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queuedActions.size() >= options.max_actions_per_tick)
|
if (queuedActions.size() >= options.max_actions_per_tick.get())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +245,7 @@ public class AutoFarmer { // Really just a namespace and needed to separate thin
|
|||||||
AutoFarmerCropType cropType = crops[i];
|
AutoFarmerCropType cropType = crops[i];
|
||||||
|
|
||||||
if (cropType.seed_type != null && cropType.planted_on != null && block.isOf(cropType.planted_on) &&
|
if (cropType.seed_type != null && cropType.planted_on != null && block.isOf(cropType.planted_on) &&
|
||||||
client.world.getBlockState(pos.up()).isAir() && options.seeds_enabled[i]) {
|
client.world.getBlockState(pos.up()).isAir() && options.seeds_enabled[i].get()) {
|
||||||
if (mainHandItem.isOf(cropType.seed_type)) {
|
if (mainHandItem.isOf(cropType.seed_type)) {
|
||||||
return ACTION_TYPE.PLACE_MAIN_HAND;
|
return ACTION_TYPE.PLACE_MAIN_HAND;
|
||||||
} else if (offHandItem.isOf(cropType.seed_type)) {
|
} else if (offHandItem.isOf(cropType.seed_type)) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cmods.haxxor.client;
|
package cmods.haxxor.client;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -9,21 +10,29 @@ import java.util.Objects;
|
|||||||
public class FallDamageCancel {
|
public class FallDamageCancel {
|
||||||
private static final HaxxorOptions options = HaxxorOptions.getInstance();
|
private static final HaxxorOptions options = HaxxorOptions.getInstance();
|
||||||
|
|
||||||
private static final int triggerHeight = 4;
|
private static final int triggerHeight = 6;
|
||||||
private static final float heightAdjust = 0.5f;
|
private static final float heightAdjust = 0.5f;
|
||||||
|
|
||||||
public static void tick(MinecraftClient client) {
|
public static void tick(MinecraftClient client) {
|
||||||
if (!options.cancel_fall_damage || client.world == null || client.player == null || client.player.isOnGround())
|
if (!options.cancel_fall_damage.get() || client.world == null || client.player == null ||
|
||||||
|
client.player.isCreative() || client.player.isOnGround() || client.player.getVelocity().getY() >= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BlockPos playerPos = client.player.getBlockPos();
|
BlockPos playerPos = client.player.getBlockPos();
|
||||||
|
|
||||||
|
if (!client.world.getBlockState(playerPos.up()).isAir() ||
|
||||||
|
!client.world.getBlockState(playerPos.up(2)).isAir()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < triggerHeight; i++) {
|
for (int i = 0; i < triggerHeight; i++) {
|
||||||
if (!client.world.getBlockState(playerPos.down(i)).isAir()) {
|
if (!client.world.getBlockState(playerPos.down(i)).isAir()) {
|
||||||
float totalFallDist = client.player.fallDistance + i;
|
float totalFallDist = client.player.fallDistance + i;
|
||||||
if (totalFallDist >= client.player.getSafeFallDistance()) {
|
if (totalFallDist >= client.player.getSafeFallDistance()) {
|
||||||
sendPacket(client);
|
sendPacket(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cmods.haxxor.client;
|
package cmods.haxxor.client;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ public class FlyHack {
|
|||||||
|
|
||||||
private static final HaxxorOptions.FlyHackOptions options = HaxxorOptions.getInstance().flyHack;
|
private static final HaxxorOptions.FlyHackOptions options = HaxxorOptions.getInstance().flyHack;
|
||||||
private static final int ticksToFirst = 40;
|
private static final int ticksToFirst = 40;
|
||||||
private static final int waitTicks = 8;
|
private static final int waitTicks = 5;
|
||||||
private static final float fallDist = 0.5f;
|
private static final float fallDist = 0.5f;
|
||||||
|
|
||||||
private static int tickCounter = ticksToFirst;
|
private static int tickCounter = ticksToFirst;
|
||||||
@ -18,9 +19,9 @@ public class FlyHack {
|
|||||||
if (client.player == null || client.world == null || client.player.isCreative())
|
if (client.player == null || client.world == null || client.player.isCreative())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
client.player.getAbilities().allowFlying = options.enabled;
|
client.player.getAbilities().allowFlying = options.enabled.get();
|
||||||
|
|
||||||
if (!options.enabled && client.player.getAbilities().flying) {
|
if (!options.enabled.get() && client.player.getAbilities().flying) {
|
||||||
client.player.getAbilities().flying = false;
|
client.player.getAbilities().flying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cmods.haxxor.client;
|
package cmods.haxxor.client;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
@ -49,13 +50,14 @@ public class HaxxorClient implements ClientModInitializer {
|
|||||||
|
|
||||||
public static boolean toggleAutoFarmer() {
|
public static boolean toggleAutoFarmer() {
|
||||||
auto_farm_key.setPressed(true);
|
auto_farm_key.setPressed(true);
|
||||||
|
options.autoFarmer.enabled.set(auto_farm_key.isPressed());
|
||||||
|
|
||||||
return options.autoFarmer.enabled = auto_farm_key.isPressed();
|
return options.autoFarmer.enabled.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tick(MinecraftClient client) {
|
private void tick(MinecraftClient client) {
|
||||||
options.autoFarmer.enabled = auto_farm_key.isPressed();
|
options.autoFarmer.enabled.set(auto_farm_key.isPressed());
|
||||||
options.flyHack.enabled = fly_hack_key.isPressed();
|
options.flyHack.enabled.set(fly_hack_key.isPressed());
|
||||||
|
|
||||||
AutoFarmer.tick(client);
|
AutoFarmer.tick(client);
|
||||||
FlyHack.tick(client);
|
FlyHack.tick(client);
|
||||||
|
@ -1,98 +0,0 @@
|
|||||||
package cmods.haxxor.client;
|
|
||||||
|
|
||||||
import java.util.prefs.Preferences;
|
|
||||||
|
|
||||||
public final class HaxxorOptions {
|
|
||||||
private static HaxxorOptions instance = null;
|
|
||||||
|
|
||||||
public final AutoFarmerOptions autoFarmer;
|
|
||||||
public final FlyHackOptions flyHack;
|
|
||||||
|
|
||||||
public boolean cancel_fall_damage = true;
|
|
||||||
|
|
||||||
|
|
||||||
public static HaxxorOptions getInstance() {
|
|
||||||
if (instance == null)
|
|
||||||
instance = new HaxxorOptions();
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private HaxxorOptions() {
|
|
||||||
autoFarmer = new AutoFarmerOptions();
|
|
||||||
flyHack = new FlyHackOptions();
|
|
||||||
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
autoFarmer.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
autoFarmer.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static class AutoFarmerOptions {
|
|
||||||
private final Preferences prefs = Preferences.userNodeForPackage(AutoFarmerOptions.class);
|
|
||||||
|
|
||||||
public boolean enabled;
|
|
||||||
public boolean move_seeds;
|
|
||||||
|
|
||||||
public int min_y = -2;
|
|
||||||
public int max_y = 1;
|
|
||||||
|
|
||||||
public int horizontal_reach = 4;
|
|
||||||
public int max_actions_per_tick = 30;
|
|
||||||
|
|
||||||
public final boolean[] seeds_enabled = new boolean[AutoFarmer.crops.length];
|
|
||||||
public final boolean[] crops_enabled = new boolean[AutoFarmer.crops.length];
|
|
||||||
|
|
||||||
public AutoFarmerOptions() { }
|
|
||||||
|
|
||||||
|
|
||||||
private void load() {
|
|
||||||
move_seeds = prefs.getBoolean("move_seeds", move_seeds);
|
|
||||||
min_y = prefs.getInt("min_y", min_y);
|
|
||||||
max_y = prefs.getInt("max_y", max_y);
|
|
||||||
horizontal_reach = prefs.getInt("horizontal_reach", horizontal_reach);
|
|
||||||
max_actions_per_tick = prefs.getInt("max_actions_per_tick", max_actions_per_tick);
|
|
||||||
|
|
||||||
for (int i = 0; i < AutoFarmer.crops.length; i++) {
|
|
||||||
if (AutoFarmer.crops[i].seed_type != null) {
|
|
||||||
seeds_enabled[i] = prefs.getBoolean("seed_" + AutoFarmer.crops[i].seed_type.getName().getString(),
|
|
||||||
seeds_enabled[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoFarmer.crops[i].crop_type != null) {
|
|
||||||
crops_enabled[i] = prefs.getBoolean("crop_" + AutoFarmer.crops[i].crop_type.getName().getString(),
|
|
||||||
crops_enabled[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void save() {
|
|
||||||
prefs.putBoolean("move_seeds", move_seeds);
|
|
||||||
prefs.putInt("min_y", min_y);
|
|
||||||
prefs.putInt("max_y", max_y);
|
|
||||||
prefs.putInt("horizontal_reach", horizontal_reach);
|
|
||||||
prefs.putInt("max_actions_per_tick", max_actions_per_tick);
|
|
||||||
|
|
||||||
for (int i = 0; i < AutoFarmer.crops.length; i++) {
|
|
||||||
if (AutoFarmer.crops[i].seed_type != null) {
|
|
||||||
prefs.putBoolean("seed_" + AutoFarmer.crops[i].seed_type.getName().getString(), seeds_enabled[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoFarmer.crops[i].crop_type != null) {
|
|
||||||
prefs.putBoolean("crop_" + AutoFarmer.crops[i].crop_type.getName().getString(), crops_enabled[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FlyHackOptions {
|
|
||||||
public boolean enabled;
|
|
||||||
}
|
|
||||||
}
|
|
11
src/main/java/cmods/haxxor/client/options/BooleanOption.java
Normal file
11
src/main/java/cmods/haxxor/client/options/BooleanOption.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package cmods.haxxor.client.options;
|
||||||
|
|
||||||
|
public class BooleanOption extends Option<Boolean> {
|
||||||
|
BooleanOption(Boolean default_value) {
|
||||||
|
super(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggle() {
|
||||||
|
value = !value;
|
||||||
|
}
|
||||||
|
}
|
105
src/main/java/cmods/haxxor/client/options/HaxxorOptions.java
Normal file
105
src/main/java/cmods/haxxor/client/options/HaxxorOptions.java
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
package cmods.haxxor.client.options;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.AutoFarmer;
|
||||||
|
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
public final class HaxxorOptions {
|
||||||
|
private static HaxxorOptions instance = null;
|
||||||
|
|
||||||
|
public final AutoFarmerOptions autoFarmer;
|
||||||
|
public final FlyHackOptions flyHack;
|
||||||
|
|
||||||
|
public BooleanOption cancel_fall_damage = new BooleanOption(true);
|
||||||
|
|
||||||
|
|
||||||
|
public static HaxxorOptions getInstance() {
|
||||||
|
if (instance == null)
|
||||||
|
instance = new HaxxorOptions();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HaxxorOptions() {
|
||||||
|
autoFarmer = new AutoFarmerOptions();
|
||||||
|
flyHack = new FlyHackOptions();
|
||||||
|
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
autoFarmer.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
autoFarmer.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class AutoFarmerOptions {
|
||||||
|
private final Preferences prefs = Preferences.userNodeForPackage(AutoFarmerOptions.class);
|
||||||
|
|
||||||
|
public BooleanOption enabled = new BooleanOption(false);
|
||||||
|
public BooleanOption move_seeds = new BooleanOption(true);
|
||||||
|
|
||||||
|
public IntegerOption min_y = new IntegerOption(-2);
|
||||||
|
public IntegerOption max_y = new IntegerOption(1);
|
||||||
|
|
||||||
|
public IntegerOption horizontal_reach = new IntegerOption(4);
|
||||||
|
public IntegerOption max_actions_per_tick = new IntegerOption(30);
|
||||||
|
|
||||||
|
public final BooleanOption[] seeds_enabled = new BooleanOption[AutoFarmer.crops.length];
|
||||||
|
public final BooleanOption[] crops_enabled = new BooleanOption[AutoFarmer.crops.length];
|
||||||
|
|
||||||
|
public AutoFarmerOptions() { }
|
||||||
|
|
||||||
|
|
||||||
|
private void load() {
|
||||||
|
move_seeds.value = prefs.getBoolean("move_seeds", move_seeds.value);
|
||||||
|
min_y.value = prefs.getInt("min_y", min_y.value);
|
||||||
|
max_y.value = prefs.getInt("max_y", max_y.value);
|
||||||
|
horizontal_reach.value = prefs.getInt("horizontal_reach", horizontal_reach.value);
|
||||||
|
max_actions_per_tick.value = prefs.getInt("max_actions_per_tick", max_actions_per_tick.value);
|
||||||
|
|
||||||
|
for (int i = 0; i < AutoFarmer.crops.length; i++) {
|
||||||
|
seeds_enabled[i] = new BooleanOption(true);
|
||||||
|
crops_enabled[i] = new BooleanOption(true);
|
||||||
|
|
||||||
|
if (AutoFarmer.crops[i].seed_type != null) {
|
||||||
|
seeds_enabled[i].value = prefs.getBoolean("seed_" + AutoFarmer.crops[i].seed_type.getName().getString(),
|
||||||
|
seeds_enabled[i].value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AutoFarmer.crops[i].crop_type != null) {
|
||||||
|
crops_enabled[i].value = prefs.getBoolean("crop_" + AutoFarmer.crops[i].crop_type.getName().getString(),
|
||||||
|
crops_enabled[i].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save() {
|
||||||
|
prefs.putBoolean("move_seeds", move_seeds.value);
|
||||||
|
prefs.putInt("min_y", min_y.value);
|
||||||
|
prefs.putInt("max_y", max_y.value);
|
||||||
|
prefs.putInt("horizontal_reach", horizontal_reach.value);
|
||||||
|
prefs.putInt("max_actions_per_tick", max_actions_per_tick.value);
|
||||||
|
|
||||||
|
for (int i = 0; i < AutoFarmer.crops.length; i++) {
|
||||||
|
if (AutoFarmer.crops[i].seed_type != null) {
|
||||||
|
prefs.putBoolean("seed_" + AutoFarmer.crops[i].seed_type.getName().getString(),
|
||||||
|
seeds_enabled[i].value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AutoFarmer.crops[i].crop_type != null) {
|
||||||
|
prefs.putBoolean("crop_" + AutoFarmer.crops[i].crop_type.getName().getString(),
|
||||||
|
crops_enabled[i].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FlyHackOptions {
|
||||||
|
public BooleanOption enabled = new BooleanOption(false);
|
||||||
|
}
|
||||||
|
}
|
23
src/main/java/cmods/haxxor/client/options/IntegerOption.java
Normal file
23
src/main/java/cmods/haxxor/client/options/IntegerOption.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package cmods.haxxor.client.options;
|
||||||
|
|
||||||
|
public class IntegerOption extends Option<Integer> {
|
||||||
|
IntegerOption(Integer default_value) {
|
||||||
|
super(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer inc() {
|
||||||
|
return inc(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer inc(int amount) {
|
||||||
|
return value += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer dec() {
|
||||||
|
return dec(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer dec(int amount) {
|
||||||
|
return value -= amount;
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/cmods/haxxor/client/options/Option.java
Normal file
17
src/main/java/cmods/haxxor/client/options/Option.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package cmods.haxxor.client.options;
|
||||||
|
|
||||||
|
public class Option<T> {
|
||||||
|
T value;
|
||||||
|
|
||||||
|
Option(T default_value) {
|
||||||
|
value = default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(T new_value) {
|
||||||
|
value = new_value;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
package cmods.haxxor.client.ui;
|
package cmods.haxxor.client.ui;
|
||||||
|
|
||||||
import cmods.haxxor.client.AutoFarmer;
|
import cmods.haxxor.client.AutoFarmer;
|
||||||
import cmods.haxxor.client.HaxxorOptions;
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.EmptyWidget;
|
||||||
|
import net.minecraft.client.gui.widget.GridWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.screen.ScreenTexts;
|
import net.minecraft.screen.ScreenTexts;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
@ -26,36 +29,34 @@ public class CropSelectScreen extends Screen {
|
|||||||
if (client == null)
|
if (client == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final int column1 = this.width / 2 + column1_offset;
|
|
||||||
final int column2 = this.width / 2 + column2_offset;
|
|
||||||
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier) + heightOffset;
|
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier) + heightOffset;
|
||||||
final int doneButtonX = this.width / 2 + doneButtonX_offset;
|
|
||||||
|
|
||||||
int y = startHeight;
|
GridWidget grid = new GridWidget();
|
||||||
|
grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter();
|
||||||
|
GridWidget.Adder adder = grid.createAdder(2);
|
||||||
|
|
||||||
for (int i = 0; i < AutoFarmer.crops.length; i++) {
|
for (int i = 0; i < AutoFarmer.crops.length; i++) {
|
||||||
int finalI = i;
|
|
||||||
|
|
||||||
if (AutoFarmer.crops[i].seed_type != null) {
|
if (AutoFarmer.crops[i].seed_type != null) {
|
||||||
addDrawableChild(new ToggleEnableButtonWidget(column1, y, buttonWidth, buttonHeight,
|
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||||
AutoFarmer.crops[i].seed_type.getName(), options.autoFarmer.seeds_enabled[i],
|
AutoFarmer.crops[i].seed_type.getName(), options.autoFarmer.seeds_enabled[i]));
|
||||||
(button, enable) -> options.autoFarmer.seeds_enabled[finalI] = enable));
|
} else {
|
||||||
|
adder.add(new EmptyWidget(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AutoFarmer.crops[i].crop_type != null) {
|
if (AutoFarmer.crops[i].crop_type != null) {
|
||||||
addDrawableChild(new ToggleEnableButtonWidget(column2, y, buttonWidth, buttonHeight,
|
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||||
AutoFarmer.crops[i].crop_type.getName(), options.autoFarmer.crops_enabled[i],
|
AutoFarmer.crops[i].crop_type.getName(), options.autoFarmer.crops_enabled[i]));
|
||||||
(button, enable) -> options.autoFarmer.crops_enabled[finalI] = enable));
|
} else {
|
||||||
|
adder.add(new EmptyWidget(0, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y += rowIncrement;
|
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> { options.save(); client.setScreen(parent); })
|
||||||
}
|
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
|
||||||
|
|
||||||
addDrawableChild(new ButtonWidget(doneButtonX, y + doneButtonRowIncrement, doneButtonWidth, buttonHeight,
|
grid.recalculateDimensions();
|
||||||
ScreenTexts.DONE, button -> {
|
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
|
||||||
options.save();
|
addDrawableChild(grid);
|
||||||
client.setScreen(parent);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
@ -10,11 +10,12 @@ public class CycleButtonWidget extends ButtonWidget {
|
|||||||
|
|
||||||
|
|
||||||
public CycleButtonWidget(int x, int y, int width, int height, Text[] options, int startIndex, CycleAction onCycle) {
|
public CycleButtonWidget(int x, int y, int width, int height, Text[] options, int startIndex, CycleAction onCycle) {
|
||||||
this(x, y, width, height, options, startIndex, onCycle, EMPTY);
|
this(x, y, width, height, options, startIndex, onCycle, ButtonWidget.DEFAULT_NARRATION_SUPPLIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CycleButtonWidget(int x, int y, int width, int height, Text[] options, int startIndex, CycleAction onCycle, TooltipSupplier tooltipSupplier) {
|
public CycleButtonWidget(int x, int y, int width, int height, Text[] options, int startIndex, CycleAction onCycle,
|
||||||
super(x, y, width, height, options[startIndex], onCycle, tooltipSupplier);
|
NarrationSupplier narrationSupplier) {
|
||||||
|
super(x, y, width, height, options[startIndex], onCycle, narrationSupplier);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.onCycle = onCycle;
|
this.onCycle = onCycle;
|
||||||
this.selectedIndex = startIndex;
|
this.selectedIndex = startIndex;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package cmods.haxxor.client.ui;
|
package cmods.haxxor.client.ui;
|
||||||
|
|
||||||
import cmods.haxxor.client.HaxxorClient;
|
import cmods.haxxor.client.HaxxorClient;
|
||||||
import cmods.haxxor.client.HaxxorOptions;
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.Environment;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.EmptyWidget;
|
||||||
|
import net.minecraft.client.gui.widget.GridWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.screen.ScreenTexts;
|
import net.minecraft.screen.ScreenTexts;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import static cmods.haxxor.client.ui.Constants.*;
|
import static cmods.haxxor.client.ui.Constants.*;
|
||||||
|
|
||||||
@ -32,69 +32,42 @@ public class FarmerOptionsScreen extends Screen {
|
|||||||
final int column1 = this.width / 2 + column1_offset;
|
final int column1 = this.width / 2 + column1_offset;
|
||||||
final int column2 = this.width / 2 + column2_offset;
|
final int column2 = this.width / 2 + column2_offset;
|
||||||
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
||||||
final int doneButtonX = this.width / 2 + doneButtonX_offset;
|
|
||||||
|
|
||||||
int row = 0;
|
GridWidget grid = new GridWidget();
|
||||||
|
grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter();
|
||||||
|
GridWidget.Adder adder = grid.createAdder(2);
|
||||||
|
|
||||||
addDrawableChild(new ButtonWidget(column1, startHeight, buttonWidth, buttonHeight,
|
adder.add(ButtonWidget.builder(options.autoFarmer.enabled.get() ? enabledText : disabledText,
|
||||||
options.autoFarmer.enabled ? enabledText : disabledText,
|
button -> button.setMessage(HaxxorClient.toggleAutoFarmer() ? enabledText : disabledText))
|
||||||
button -> button.setMessage(HaxxorClient.toggleAutoFarmer() ? enabledText : disabledText)));
|
.position(column1, startHeight).build());
|
||||||
|
|
||||||
addDrawableChild(new ButtonWidget(column2, startHeight, buttonWidth, buttonHeight,
|
adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.farmer.edit_actions"),
|
||||||
Text.translatable("haxxor.options.farmer.edit_actions"),
|
button -> client.setScreen(new CropSelectScreen(this)))
|
||||||
button -> client.setScreen(new CropSelectScreen(this))));
|
.position(column2, startHeight).build());
|
||||||
|
|
||||||
row++;
|
adder.add(new ToggleButton(0, 0, buttonWidth,
|
||||||
|
buttonHeight, Text.literal("Move Seeds"), options.autoFarmer.move_seeds));
|
||||||
|
|
||||||
addDrawableChild(new ToggleEnableButtonWidget(column1, startHeight + (rowIncrement * row), buttonWidth,
|
adder.add(new EmptyWidget(0, 0));
|
||||||
buttonHeight, Text.literal("Move Seeds"), options.autoFarmer.move_seeds,
|
|
||||||
(button, isEnabled) -> options.autoFarmer.move_seeds = isEnabled));
|
|
||||||
|
|
||||||
row++;
|
adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.farmer.min_y"),
|
||||||
|
options.autoFarmer.min_y));
|
||||||
|
|
||||||
addVariableAdjust(column1, startHeight + (rowIncrement * row), buttonWidth, buttonHeight, options.autoFarmer.min_y,
|
adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.farmer.max_y"),
|
||||||
Text.translatable("haxxor.options.farmer.min_y"),
|
options.autoFarmer.max_y));
|
||||||
() -> --options.autoFarmer.min_y,
|
|
||||||
() -> ++options.autoFarmer.min_y);
|
|
||||||
|
|
||||||
addVariableAdjust(column2, startHeight + (rowIncrement * row), buttonWidth, buttonHeight, options.autoFarmer.max_y,
|
adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.farmer.reach"),
|
||||||
Text.translatable("haxxor.options.farmer.max_y"),
|
options.autoFarmer.horizontal_reach));
|
||||||
() -> --options.autoFarmer.max_y,
|
|
||||||
() -> ++options.autoFarmer.max_y);
|
|
||||||
|
|
||||||
row++;
|
adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.farmer.actions_per_tick"),
|
||||||
|
options.autoFarmer.max_actions_per_tick, 5));
|
||||||
|
|
||||||
addVariableAdjust(column1, startHeight + (rowIncrement * row), buttonWidth, buttonHeight, options.autoFarmer.horizontal_reach,
|
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent))
|
||||||
Text.translatable("haxxor.options.farmer.reach"),
|
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
|
||||||
() -> --options.autoFarmer.horizontal_reach,
|
|
||||||
() -> ++options.autoFarmer.horizontal_reach);
|
|
||||||
|
|
||||||
addVariableAdjust(column2, startHeight + (rowIncrement * row), buttonWidth, buttonHeight, options.autoFarmer.max_actions_per_tick,
|
grid.recalculateDimensions();
|
||||||
Text.translatable("haxxor.options.farmer.actions_per_tick"),
|
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
|
||||||
() -> options.autoFarmer.max_actions_per_tick -= 5,
|
addDrawableChild(grid);
|
||||||
() -> options.autoFarmer.max_actions_per_tick += 5);
|
|
||||||
|
|
||||||
row++;
|
|
||||||
|
|
||||||
this.addDrawableChild(new ButtonWidget(doneButtonX,
|
|
||||||
startHeight + (rowIncrement * row) + doneButtonRowIncrement, doneButtonWidth, buttonHeight,
|
|
||||||
ScreenTexts.DONE, button -> client.setScreen(parent)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("SameParameterValue")
|
|
||||||
private void addVariableAdjust(int x, int y, int width, int height, int initialValue, @NotNull Text label,
|
|
||||||
UpdateTextAction minus, UpdateTextAction add) {
|
|
||||||
final int button_width = height + height / 4;
|
|
||||||
final String labelStr = label.getString() + ": ";
|
|
||||||
|
|
||||||
ButtonWidget middle = new ButtonWidget(x + button_width - 1, y, width - (button_width * 2) + 2, height,
|
|
||||||
Text.literal(labelStr + initialValue), button -> {});
|
|
||||||
this.addDrawableChild(middle);
|
|
||||||
|
|
||||||
this.addDrawableChild(new ButtonWidget(x, y, button_width, height, Text.literal("-"),
|
|
||||||
button -> middle.setMessage(Text.literal(labelStr + minus.onUpdate()))));
|
|
||||||
this.addDrawableChild(new ButtonWidget(x + width - button_width + 1, y, button_width, height, Text.literal("+"),
|
|
||||||
button -> middle.setMessage(Text.literal(labelStr + add.onUpdate()))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
@ -106,10 +79,4 @@ public class FarmerOptionsScreen extends Screen {
|
|||||||
public void removed() {
|
public void removed() {
|
||||||
options.save();
|
options.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
private interface UpdateTextAction {
|
|
||||||
int onUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package cmods.haxxor.client.ui;
|
package cmods.haxxor.client.ui;
|
||||||
|
|
||||||
import cmods.haxxor.client.HaxxorClient;
|
import cmods.haxxor.client.HaxxorClient;
|
||||||
import cmods.haxxor.client.HaxxorOptions;
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.GridWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.screen.ScreenTexts;
|
import net.minecraft.screen.ScreenTexts;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
@ -23,21 +25,24 @@ public class HaxxorOptionsScreen extends Screen {
|
|||||||
if (client == null)
|
if (client == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final int column1 = this.width / 2 + column1_offset;
|
|
||||||
final int column2 = this.width / 2 + column2_offset;
|
|
||||||
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
||||||
final int doneButtonX = this.width / 2 + doneButtonX_offset;
|
|
||||||
|
|
||||||
this.addDrawableChild(new ButtonWidget(column1, startHeight, buttonWidth, buttonHeight,
|
GridWidget grid = new GridWidget();
|
||||||
Text.translatable("haxxor.options.farmer"),
|
grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter();
|
||||||
button -> this.client.setScreen(new FarmerOptionsScreen(this))));
|
GridWidget.Adder adder = grid.createAdder(2);
|
||||||
|
|
||||||
this.addDrawableChild(new ToggleEnableButtonWidget(column2, startHeight, buttonWidth, buttonHeight,
|
adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.farmer"),
|
||||||
Text.translatable("haxxor.options.fall_damage"), options.cancel_fall_damage,
|
button -> this.client.setScreen(new FarmerOptionsScreen(this))).build());
|
||||||
(button, isEnabled) -> options.cancel_fall_damage = isEnabled));
|
|
||||||
|
|
||||||
this.addDrawableChild(new ButtonWidget(doneButtonX, startHeight + rowIncrement + doneButtonRowIncrement,
|
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||||
doneButtonWidth, buttonHeight, ScreenTexts.DONE, button -> this.client.setScreen(this.parent)));
|
Text.translatable("haxxor.options.fall_damage"), options.cancel_fall_damage));
|
||||||
|
|
||||||
|
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent))
|
||||||
|
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
|
||||||
|
|
||||||
|
grid.recalculateDimensions();
|
||||||
|
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
|
||||||
|
addDrawableChild(grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package cmods.haxxor.client.ui;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.IntegerOption;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
|
import net.minecraft.client.gui.widget.WrapperWidget;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class IntegerAdjustWidget extends WrapperWidget {
|
||||||
|
private final ArrayList<ButtonWidget> children;
|
||||||
|
private final IntegerOption option;
|
||||||
|
private final int delta;
|
||||||
|
|
||||||
|
public IntegerAdjustWidget(Text text, IntegerOption option) {
|
||||||
|
this(text, option, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerAdjustWidget(Text text, IntegerOption option, int delta) {
|
||||||
|
super(0, 0, 150, 20, text);
|
||||||
|
this.option = option;
|
||||||
|
this.delta = delta;
|
||||||
|
children = new ArrayList<>(3);
|
||||||
|
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<? extends ClickableWidget> wrappedWidgets() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWidth(int width) {
|
||||||
|
super.setWidth(width);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setX(int x) {
|
||||||
|
super.setX(x);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setY(int y) {
|
||||||
|
super.setY(y);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPos(int x, int y) {
|
||||||
|
super.setPos(x, y);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshDimensions() {
|
||||||
|
final int button_width = 25;
|
||||||
|
final String labelStr = getMessage().getString() + ": ";
|
||||||
|
|
||||||
|
children.clear();
|
||||||
|
|
||||||
|
ButtonWidget middle = ButtonWidget.builder(Text.literal(labelStr + option.get()), button -> {})
|
||||||
|
.dimensions(getX() + button_width - 1, getY(),width - (button_width * 2) + 2, height).build();
|
||||||
|
|
||||||
|
ButtonWidget sub = ButtonWidget.builder(Text.literal("-"),
|
||||||
|
button -> middle.setMessage(Text.literal(labelStr + option.dec(delta))))
|
||||||
|
.dimensions(getX(), getY(), button_width, height).build();
|
||||||
|
|
||||||
|
ButtonWidget add = ButtonWidget.builder(Text.literal("+"),
|
||||||
|
button -> middle.setMessage(Text.literal(labelStr + option.inc(delta))))
|
||||||
|
.dimensions(getX() + width - button_width + 1, getY(), button_width, height).build();
|
||||||
|
|
||||||
|
children.add(sub);
|
||||||
|
children.add(middle);
|
||||||
|
children.add(add);
|
||||||
|
}
|
||||||
|
}
|
39
src/main/java/cmods/haxxor/client/ui/OptionsSlideWidget.java
Normal file
39
src/main/java/cmods/haxxor/client/ui/OptionsSlideWidget.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package cmods.haxxor.client.ui;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.IntegerOption;
|
||||||
|
import net.minecraft.client.gui.widget.SliderWidget;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class OptionsSlideWidget extends SliderWidget {
|
||||||
|
private final IntegerOption option;
|
||||||
|
private final String messagePrefix;
|
||||||
|
|
||||||
|
private final int min;
|
||||||
|
private final int max;
|
||||||
|
private final int step;
|
||||||
|
|
||||||
|
public OptionsSlideWidget(int x, int y, int min, int max, Text text, IntegerOption option) {
|
||||||
|
this(x, y, min, max, 1, text, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionsSlideWidget(int x, int y, int min, int max, int step, Text text, IntegerOption option) {
|
||||||
|
super(x, y, 150, 20, text, ((double) option.get() - min) / (max - min));
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
this.step = step;
|
||||||
|
this.option = option;
|
||||||
|
messagePrefix = text.getString() + ": ";
|
||||||
|
|
||||||
|
updateMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateMessage() {
|
||||||
|
setMessage(Text.literal(messagePrefix + option.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyValue() {
|
||||||
|
option.set((int) (((value * ((max - min) / step))) + (min / step)) * step);
|
||||||
|
}
|
||||||
|
}
|
42
src/main/java/cmods/haxxor/client/ui/ToggleButton.java
Normal file
42
src/main/java/cmods/haxxor/client/ui/ToggleButton.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package cmods.haxxor.client.ui;
|
||||||
|
|
||||||
|
import cmods.haxxor.client.options.BooleanOption;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class ToggleButton extends ButtonWidget {
|
||||||
|
private final String name;
|
||||||
|
private final BooleanOption option;
|
||||||
|
|
||||||
|
private final String enabledText = Text.translatable("haxxor.state.enabled").getString();
|
||||||
|
private final String disabledText = Text.translatable("haxxor.state.disabled").getString();
|
||||||
|
|
||||||
|
|
||||||
|
public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option) {
|
||||||
|
this(x, y, width, height, name, option, ButtonWidget.DEFAULT_NARRATION_SUPPLIER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option,
|
||||||
|
NarrationSupplier narrationSupplier) {
|
||||||
|
super(x, y, width, height, name, b -> {}, narrationSupplier);
|
||||||
|
this.name = name.getString() + ": ";
|
||||||
|
this.option = option;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateText() {
|
||||||
|
setMessage(Text.literal(name + (option.get() ? enabledText : disabledText)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPress() {
|
||||||
|
option.toggle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
updateText();
|
||||||
|
super.renderButton(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
package cmods.haxxor.client.ui;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public class ToggleEnableButtonWidget extends ButtonWidget {
|
|
||||||
private final String name;
|
|
||||||
private boolean enabled;
|
|
||||||
private final ToggleAction onToggle;
|
|
||||||
|
|
||||||
private final String enabledText = Text.translatable("haxxor.state.enabled").getString();
|
|
||||||
private final String disabledText = Text.translatable("haxxor.state.disabled").getString();
|
|
||||||
|
|
||||||
|
|
||||||
public ToggleEnableButtonWidget(int x, int y, int width, int height, Text name, boolean startEnabled,
|
|
||||||
ToggleAction onToggle) {
|
|
||||||
this(x, y, width, height, name, startEnabled, onToggle, EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ToggleEnableButtonWidget(int x, int y, int width, int height, Text name, boolean startEnabled,
|
|
||||||
ToggleAction onToggle, TooltipSupplier tooltipSupplier) {
|
|
||||||
super(x, y, width, height, name, onToggle, tooltipSupplier);
|
|
||||||
this.name = name.getString() + ": ";
|
|
||||||
this.enabled = startEnabled;
|
|
||||||
this.onToggle = onToggle;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateText() {
|
|
||||||
setMessage(Text.literal(name + (enabled ? enabledText : disabledText)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPress() {
|
|
||||||
onToggle.onToggle(this, enabled = !enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
|
||||||
updateText();
|
|
||||||
super.renderButton(matrices, mouseX, mouseY, delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ToggleAction extends PressAction {
|
|
||||||
void onToggle(ButtonWidget button, boolean isEnabled);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default void onPress(ButtonWidget button) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package cmods.haxxor.mixin;
|
package cmods.haxxor.mixin;
|
||||||
|
|
||||||
import cmods.haxxor.client.AutoFarmer;
|
import cmods.haxxor.client.AutoFarmer;
|
||||||
import cmods.haxxor.client.HaxxorOptions;
|
import cmods.haxxor.client.options.HaxxorOptions;
|
||||||
import cmods.haxxor.client.ui.Line;
|
import cmods.haxxor.client.ui.Line;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
@ -27,7 +27,7 @@ public abstract class HudMixin extends DrawableHelper {
|
|||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "render")
|
@Inject(at = @At("TAIL"), method = "render")
|
||||||
private void render(MatrixStack matrices, float tickDelta, CallbackInfo callback) {
|
private void render(MatrixStack matrices, float tickDelta, CallbackInfo callback) {
|
||||||
if (this.client.options.debugEnabled || client.player == null)
|
if (this.client.options.debugEnabled || this.client.isPaused() || client.player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HaxxorOptions options = HaxxorOptions.getInstance();
|
HaxxorOptions options = HaxxorOptions.getInstance();
|
||||||
@ -41,7 +41,7 @@ public abstract class HudMixin extends DrawableHelper {
|
|||||||
int green = 0x00ff00;
|
int green = 0x00ff00;
|
||||||
|
|
||||||
|
|
||||||
if (options.autoFarmer.enabled) {
|
if (options.autoFarmer.enabled.get()) {
|
||||||
lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled")
|
lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled")
|
||||||
.append(Text.translatable("haxxor.state.on")), green, 0));
|
.append(Text.translatable("haxxor.state.on")), green, 0));
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +53,7 @@ public abstract class HudMixin extends DrawableHelper {
|
|||||||
lines.add(new Line(Text.translatable("haxxor.actions.available"), green, 1));
|
lines.add(new Line(Text.translatable("haxxor.actions.available"), green, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.flyHack.enabled) {
|
if (options.flyHack.enabled.get()) {
|
||||||
lines.add(new Line(Text.translatable("haxxor.hud.fly_hack_enabled")
|
lines.add(new Line(Text.translatable("haxxor.hud.fly_hack_enabled")
|
||||||
.append(Text.translatable("haxxor.state.on")), green, 0));
|
.append(Text.translatable("haxxor.state.on")), green, 0));
|
||||||
} else {
|
} else {
|
||||||
@ -62,10 +62,18 @@ public abstract class HudMixin extends DrawableHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (Line line: lines) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
|
Line line = lines.get(i);
|
||||||
|
|
||||||
|
if (i > 0 && lines.get(i - 1).indent() > line.indent()) {
|
||||||
|
y += 3;
|
||||||
|
} else if (i > 0 && lines.get(i - 1).indent() < line.indent()) {
|
||||||
|
y += 2;
|
||||||
|
}
|
||||||
|
|
||||||
DrawableHelper.drawTextWithShadow(matrices, textRenderer, line.text(), x + (5 * line.indent()), y,
|
DrawableHelper.drawTextWithShadow(matrices, textRenderer, line.text(), x + (5 * line.indent()), y,
|
||||||
line.color());
|
line.color());
|
||||||
y += 10;
|
y += textRenderer.fontHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,8 +22,8 @@ public class OptionsMixin extends Screen {
|
|||||||
if (client == null)
|
if (client == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.addDrawableChild(new ButtonWidget(20, 20, 100, 20,
|
addDrawableChild(ButtonWidget.builder(Text.translatable("haxxor.options"),
|
||||||
Text.translatable("haxxor.options"), (button) ->
|
button -> client.setScreen(new HaxxorOptionsScreen(this)))
|
||||||
client.setScreen(new HaxxorOptionsScreen(this))));
|
.position(20, 20).width(100).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ public class PauseMixin extends Screen {
|
|||||||
if (client == null)
|
if (client == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.addDrawableChild(new ButtonWidget(20, 20, 100, 20,
|
addDrawableChild(ButtonWidget.builder(Text.translatable("haxxor.options"),
|
||||||
Text.translatable("haxxor.options"), (button) ->
|
button -> client.setScreen(new HaxxorOptionsScreen(this)))
|
||||||
client.setScreen(new HaxxorOptionsScreen(this))));
|
.position(20, 20).width(100).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,17 +14,15 @@
|
|||||||
"icon": "assets/haxxor/icon.png",
|
"icon": "assets/haxxor/icon.png",
|
||||||
"environment": "client",
|
"environment": "client",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"client": [
|
"client": ["cmods.haxxor.client.HaxxorClient"],
|
||||||
"cmods.haxxor.client.HaxxorClient"
|
|
||||||
],
|
|
||||||
"modmenu": ["cmods.haxxor.client.ModMenuConfig"]
|
"modmenu": ["cmods.haxxor.client.ModMenuConfig"]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"haxxor.mixins.json"
|
"haxxor.mixins.json"
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.14.10",
|
"fabricloader": ">=0.14.11",
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
"minecraft": "1.19.2"
|
"minecraft": "1.19.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user