Added teleporting up and down
This commit is contained in:
parent
f046b5c458
commit
682aeedc7e
@ -6,7 +6,7 @@ minecraft_version=1.19.3
|
||||
yarn_mappings=1.19.3+build.2
|
||||
loader_version=0.14.13
|
||||
# Mod Properties
|
||||
mod_version=2.0.1
|
||||
mod_version=2.1.0
|
||||
maven_group=cmods
|
||||
archives_base_name=haxxor
|
||||
# Dependencies
|
||||
|
@ -7,6 +7,7 @@ import cmods.cmods.client.ui.Line;
|
||||
import cmods.cmods.client.ui.ToggleButton;
|
||||
import cmods.haxxor.client.AutoFarmer;
|
||||
import cmods.haxxor.client.options.HaxxorOptions;
|
||||
import cmods.haxxor.client.ui.ElevatorOptionsScreen;
|
||||
import cmods.haxxor.client.ui.FarmerOptionsScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
@ -35,6 +36,9 @@ public class HaxxorModule extends Module {
|
||||
optionButtons.add((screen, client) -> ButtonWidget.builder(Text.translatable("haxxor.options.farmer"),
|
||||
button -> client.setScreen(new FarmerOptionsScreen(screen))).build());
|
||||
|
||||
optionButtons.add(((screen, client) -> ButtonWidget.builder(Text.translatable("haxxor.options.elevator"),
|
||||
button -> client.setScreen(new ElevatorOptionsScreen(screen))).build()));
|
||||
|
||||
optionButtons.add((screen, client) -> new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||
Text.translatable("haxxor.options.fall_damage"), options.cancelFallDamage));
|
||||
|
||||
|
118
src/main/java/cmods/haxxor/client/Elevator.java
Normal file
118
src/main/java/cmods/haxxor/client/Elevator.java
Normal file
@ -0,0 +1,118 @@
|
||||
package cmods.haxxor.client;
|
||||
|
||||
import cmods.haxxor.client.options.HaxxorOptions;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Elevator {
|
||||
private static KeyBinding teleport_up_key;
|
||||
private static KeyBinding teleport_down_key;
|
||||
private static boolean up_was_pressed = false;
|
||||
private static boolean down_was_pressed = false;
|
||||
private static final HaxxorOptions.ElevatorOptions options = HaxxorOptions.getInstance().elevatorOptions;
|
||||
|
||||
|
||||
public static void init() {
|
||||
teleport_up_key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.haxxor.elevator.up",
|
||||
GLFW.GLFW_KEY_UP,
|
||||
"category.haxxor.options"
|
||||
));
|
||||
|
||||
teleport_down_key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.haxxor.elevator.down",
|
||||
GLFW.GLFW_KEY_DOWN,
|
||||
"category.haxxor.options"
|
||||
));
|
||||
}
|
||||
|
||||
public static void tick(MinecraftClient client) {
|
||||
if (teleport_up_key.isPressed() && !up_was_pressed)
|
||||
tp_up(client);
|
||||
|
||||
if (teleport_down_key.isPressed() && !down_was_pressed)
|
||||
tp_down(client);
|
||||
|
||||
up_was_pressed = teleport_up_key.isPressed();
|
||||
down_was_pressed = teleport_down_key.isPressed();
|
||||
}
|
||||
|
||||
private static void tp_up(MinecraftClient client) {
|
||||
if (client == null || client.player == null || client.world == null)
|
||||
return;
|
||||
|
||||
BlockPos blockPos = client.player.getBlockPos();
|
||||
|
||||
Vec3d pos = null;
|
||||
for (int i = 1; i <= options.max_tp_up.get(); i++) {
|
||||
if (can_tp_to_block(client, blockPos.up(i))) {
|
||||
pos = blockPos.up(i).toCenterPos();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos == null) {
|
||||
if (options.send_too_far_message.get())
|
||||
client.player.sendMessage(Text.translatable("haxxor.message.elevator.too_far"));
|
||||
return;
|
||||
}
|
||||
|
||||
teleport(client, pos.getX(), Math.floor(pos.getY()), pos.getZ());
|
||||
}
|
||||
|
||||
private static void tp_down(MinecraftClient client) {
|
||||
if (client == null || client.player == null || client.world == null)
|
||||
return;
|
||||
|
||||
BlockPos blockPos = client.player.getBlockPos();
|
||||
|
||||
Vec3d pos = null;
|
||||
for (int i = 1; i <= options.max_tp_down.get(); i++) {
|
||||
if (can_tp_to_block(client, blockPos.down(i))) {
|
||||
pos = blockPos.down(i).toCenterPos();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos == null) {
|
||||
if (options.send_too_far_message.get())
|
||||
client.player.sendMessage(Text.translatable("haxxor.message.elevator.too_far"));
|
||||
return;
|
||||
}
|
||||
|
||||
teleport(client, pos.getX(), Math.floor(pos.getY()), pos.getZ());
|
||||
}
|
||||
|
||||
private static boolean can_tp_to_block(MinecraftClient client, BlockPos pos) {
|
||||
if (client.player == null || client.world == null)
|
||||
return false;
|
||||
|
||||
return client.world.getBlockState(pos.down()).hasSolidTopSurface(client.world, pos, client.player) &&
|
||||
client.world.getBlockState(pos).isAir() &&
|
||||
client.world.getBlockState(pos.up()).isAir();
|
||||
}
|
||||
|
||||
private static void teleport(MinecraftClient client, double x, double y, double z) {
|
||||
if (client.player == null)
|
||||
return;
|
||||
|
||||
Vec3d position = new Vec3d(x, y, z);
|
||||
|
||||
if (options.send_tp_message.get())
|
||||
client.player.sendMessage(Text.translatable("haxxor.message.elevator", position.getX(), position.getY(), position.getZ()));
|
||||
|
||||
client.player.setPosition(position);
|
||||
|
||||
PlayerMoveC2SPacket packet = new PlayerMoveC2SPacket.PositionAndOnGround(position.getX(), position.getY(),
|
||||
position.getZ(), client.player.isOnGround());
|
||||
Objects.requireNonNull(client.getNetworkHandler()).sendPacket(packet);
|
||||
}
|
||||
}
|
@ -47,6 +47,7 @@ public class HaxxorClient implements ClientModInitializer {
|
||||
));
|
||||
|
||||
AutoFarmer.init();
|
||||
Elevator.init();
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(this::tick);
|
||||
}
|
||||
@ -63,6 +64,7 @@ public class HaxxorClient implements ClientModInitializer {
|
||||
options.flyHackEnabled.set(fly_hack_key.isPressed());
|
||||
|
||||
AutoFarmer.tick(client);
|
||||
Elevator.tick(client);
|
||||
FlyHack.tick(client);
|
||||
FallDamageCancel.tick(client);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public final class HaxxorOptions extends ModuleOptions {
|
||||
|
||||
public final AutoFarmerOptions autoFarmer;
|
||||
public final UIOptions uiOptions;
|
||||
public final ElevatorOptions elevatorOptions;
|
||||
|
||||
public final BooleanOption flyHackEnabled = new BooleanOption(false);
|
||||
public final BooleanOption cancelFallDamage = new BooleanOption(true);
|
||||
@ -34,12 +35,14 @@ public final class HaxxorOptions extends ModuleOptions {
|
||||
private HaxxorOptions() {
|
||||
autoFarmer = new AutoFarmerOptions();
|
||||
uiOptions = new UIOptions();
|
||||
elevatorOptions = new ElevatorOptions();
|
||||
}
|
||||
|
||||
public void load(@Nullable Properties properties) {
|
||||
// Sub category properties
|
||||
autoFarmer.load(properties);
|
||||
uiOptions.load(properties);
|
||||
elevatorOptions.load(properties);
|
||||
|
||||
// Top level properties
|
||||
cancelFallDamage.value = getBooleanProperty(properties, "cancel_fall_damage", cancelFallDamage.value);
|
||||
@ -49,6 +52,7 @@ public final class HaxxorOptions extends ModuleOptions {
|
||||
// Sub category properties
|
||||
autoFarmer.save(properties);
|
||||
uiOptions.save(properties);
|
||||
elevatorOptions.save(properties);
|
||||
|
||||
// Top level properties
|
||||
properties.setProperty("cancel_fall_damage", cancelFallDamage.value.toString());
|
||||
@ -140,4 +144,32 @@ public final class HaxxorOptions extends ModuleOptions {
|
||||
properties.setProperty(PREFIX + "show_fly_hack", show_fly_hack.value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ElevatorOptions {
|
||||
private final String PREFIX = MODULE_PREFIX + "elevator.";
|
||||
|
||||
public final BooleanOption send_too_far_message = new BooleanOption(true);
|
||||
public final BooleanOption send_tp_message = new BooleanOption(true);
|
||||
|
||||
public final IntegerOption max_tp_up = new IntegerOption(10);
|
||||
public final IntegerOption max_tp_down = new IntegerOption(10);
|
||||
|
||||
ElevatorOptions() { }
|
||||
|
||||
private void load(@Nullable Properties properties) {
|
||||
send_too_far_message.value = getBooleanProperty(properties, PREFIX + "send_too_far_message", send_too_far_message.value);
|
||||
send_tp_message.value = getBooleanProperty(properties, PREFIX + "send_tp_message", send_tp_message.value);
|
||||
|
||||
max_tp_up.value = getIntegerProperty(properties, PREFIX + "max_tp_up", max_tp_up.value);
|
||||
max_tp_down.value = getIntegerProperty(properties, PREFIX + "max_tp_down", max_tp_down.value);
|
||||
}
|
||||
|
||||
private void save(Properties properties) {
|
||||
properties.setProperty(PREFIX + "send_too_far_message", send_too_far_message.value.toString());
|
||||
properties.setProperty(PREFIX + "send_tp_message", send_tp_message.value.toString());
|
||||
|
||||
properties.setProperty(PREFIX + "max_tp_up", max_tp_up.value.toString());
|
||||
properties.setProperty(PREFIX + "max_tp_down", max_tp_down.value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package cmods.haxxor.client.ui;
|
||||
|
||||
import cmods.cmods.client.options.CmodsOptions;
|
||||
import cmods.cmods.client.ui.IntegerAdjustWidget;
|
||||
import cmods.cmods.client.ui.ToggleButton;
|
||||
import cmods.haxxor.client.options.HaxxorOptions;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
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.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static cmods.cmods.client.ui.Constants.*;
|
||||
|
||||
public class ElevatorOptionsScreen extends Screen {
|
||||
private final Screen parent;
|
||||
private final CmodsOptions global_options = CmodsOptions.getInstance();
|
||||
private final HaxxorOptions.ElevatorOptions options = HaxxorOptions.getInstance().elevatorOptions;
|
||||
|
||||
public ElevatorOptionsScreen(Screen parent) {
|
||||
super(Text.translatable("haxxor.options.elevator.title"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
if (client == null)
|
||||
return;
|
||||
|
||||
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
||||
|
||||
GridWidget grid = new GridWidget();
|
||||
grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter();
|
||||
GridWidget.Adder adder = grid.createAdder(2);
|
||||
|
||||
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||
Text.translatable("haxxor.options.elevator.too_far"), options.send_too_far_message));
|
||||
|
||||
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||
Text.translatable("haxxor.options.elevator.tp_message"), options.send_tp_message));
|
||||
|
||||
adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.elevator.max_tp_up"), options.max_tp_up));
|
||||
|
||||
adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.elevator.max_tp_down"), options.max_tp_down));
|
||||
|
||||
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) {
|
||||
this.renderBackground(matrices);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 0xffffff);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
public void removed() {
|
||||
global_options.save();
|
||||
}
|
||||
}
|
@ -40,6 +40,9 @@ public class HaxxorOptionsScreen extends Screen {
|
||||
adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.farmer"),
|
||||
button -> this.client.setScreen(new FarmerOptionsScreen(this))).build());
|
||||
|
||||
adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.elevator"),
|
||||
button -> this.client.setScreen(new ElevatorOptionsScreen(this))).build());
|
||||
|
||||
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||
Text.translatable("haxxor.options.fall_damage"), options.cancelFallDamage));
|
||||
|
||||
|
@ -10,6 +10,9 @@
|
||||
"haxxor.actions.available": "Actions available",
|
||||
"haxxor.actions.unavailable": "Actions unavailable",
|
||||
|
||||
"haxxor.message.elevator": "Teleporting to: [%.2f, %.2f, %.2f]",
|
||||
"haxxor.message.elevator.too_far": "Too far!",
|
||||
|
||||
"haxxor.options": "Haxxor",
|
||||
"haxxor.options.title": "Haxxor Options",
|
||||
|
||||
@ -34,7 +37,16 @@
|
||||
"haxxor.options.farmer.crop_select.seeds": "Seeds to Plant",
|
||||
"haxxor.options.farmer.crop_select.blocks": "Crops to Break",
|
||||
|
||||
"haxxor.options.elevator": "Elevator",
|
||||
"haxxor.options.elevator.title": "Elevator Options",
|
||||
"haxxor.options.elevator.too_far": "Too Far Message",
|
||||
"haxxor.options.elevator.tp_message": "Teleport Message",
|
||||
"haxxor.options.elevator.max_tp_up": "Max Tp Up",
|
||||
"haxxor.options.elevator.max_tp_down": "Max Tp Down",
|
||||
|
||||
"category.haxxor.options": "Haxxor",
|
||||
"key.haxxor.auto_farm": "Auto Farm Toggle",
|
||||
"key.haxxor.fly": "Fly Hack Toggle"
|
||||
"key.haxxor.fly": "Fly Hack Toggle",
|
||||
"key.haxxor.elevator.up": "Teleport Up",
|
||||
"key.haxxor.elevator.down": "Teleport Down"
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
"haxxor.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.11",
|
||||
"fabricloader": ">=0.14.10",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.19.3",
|
||||
"cmods": "1.0.1"
|
||||
|
Loading…
Reference in New Issue
Block a user