Replace repository content with Codeberg version

This commit is contained in:
nitrogenoliquido committed 2026-11-08 10:50:20 -05:00
1 parent 9c1430df6e
commit fd9c5922da
621 files changed
+197975 -130605

No files matched your search

+168
View File
@@ -0,0 +1,168 @@
// Auto Tool - switch to the best tool for the block you are mining.
//
// While you hold the attack key on a block, the hotbar slot that mines it fastest is
// selected. With "switch_back" on, your old slot is selected again when you stop.
//
// Callbacks (descriptor slots +0x1d8 / +0x1e8):
// auto_tool_on_inventory_tick every tick
// auto_tool_on_shutdown module unloaded: free the allowed-block list
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
// ---- settings ----
extern "C" float auto_tool_activation_time_value; // "activation_time": ticks to wait before switching
extern "C" unsigned char auto_tool_allow_using_fists_value; // "allow_using_fists": may switch away from an empty hand
extern "C" unsigned char auto_tool_allow_using_sword_value; // "allow_using_sword": may switch away from a sword
extern "C" unsigned char auto_tool_allow_using_tools_value; // "allow_using_tools": may switch away from a tool
extern "C" unsigned char auto_tool_allow_using_other_value; // "allow_using_other": may switch away from anything else
extern "C" unsigned char auto_tool_require_sneak_value; // "require_sneak"
extern "C" unsigned char auto_tool_restrict_allowed_blocks; // "restrict_allowed_blocks": only for blocks in the list
extern "C" unsigned char auto_tool_switch_back_value; // "switch_back"
extern "C" void *auto_tool_allowed_block_set[2]; // the block list (start, end of a vector of ids)
// ---- module state ----
extern "C" char auto_tool_module_descriptor[];
extern "C" int auto_tool_slot_switch_back; // slot to go back to afterwards, -1 = none
extern "C" int auto_tool_slot_we_switched; // slot we selected
extern "C" int auto_tool_activation_countdown; // ticks left before we may switch
// ---- game / engine functions ----
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(int, java_get_inventory_player_current_item, (void *jvm, void *inventory_player)); // selected hotbar slot
FN(void, java_set_inventory_player_current_item, (void *jvm, void *inventory_player, int slot));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void *, java_get_game_settings_attack_key, (void *jvm, void *game_settings));
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(void *, java_get_game_settings_sneak_key, (void *jvm, void *game_settings));
FN(unsigned char, is_key_down, (void *jvm, void *k));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft)); // what the crosshair points at
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 1 = a block
FN(Vec3, java_get_moving_object_position_block_x, (void *jvm, void *moving_object_position));
FN(void *, java_call_variant, (void *jvm, void *world, int x, int y, int z)); // block at x, y, z
FN(int, get_block_id, (void *jvm, void *blk));
FN(unsigned char, id_vector_contains, (void *set, int id));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *object, int slot));
FN(float, java_call_item_stack_get_str_vs_block, (void *jvm, void *item_stack, void *blk)); // mining speed of the item on the block
FN(unsigned char, claim_release_hotbar_module, (void *timer)); // ask for control of the hotbar (one module at a time)
FN(void, release_owner, (void *timer)); // give control of the hotbar back
FN(void, libc_free, (void *ptr));
// Is the module allowed to switch away from the item in your hand?
static bool may_switch_from_held_item(Ctx *ctx) {
void *held = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (!held)
return auto_tool_allow_using_fists_value == 1;
switch (java_call_static_item_get_id_from_item(ctx->jvm, held)) {
// shovels, pickaxes, axes (iron, wood, stone, diamond, gold) and shears
case 256: case 257: case 258:
case 269: case 270: case 271:
case 273: case 274: case 275:
case 277: case 278: case 279:
case 284: case 285: case 286:
case 359:
return auto_tool_allow_using_tools_value == 1;
// swords (iron, wood, stone, diamond, gold)
case 267: case 268: case 272: case 276: case 283:
return auto_tool_allow_using_sword_value == 1;
default:
return auto_tool_allow_using_other_value == 1;
}
}
// Give the hotbar back, and select the old slot again if we remembered one.
static void stop_and_switch_back(Ctx *ctx, void *inventory) {
release_owner(auto_tool_module_descriptor);
if (auto_tool_slot_switch_back != -1) {
java_set_inventory_player_current_item(ctx->jvm, inventory, auto_tool_slot_switch_back);
auto_tool_slot_switch_back = -1;
}
}
extern "C" void auto_tool_on_inventory_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
int current_slot = java_get_inventory_player_current_item(ctx->jvm, inventory);
// The player picked another slot themselves: forget the slot to switch back to.
if (auto_tool_slot_switch_back != -1 && auto_tool_slot_we_switched != current_slot) {
auto_tool_slot_switch_back = -1;
stop_and_switch_back(ctx, inventory);
return;
}
// Check that we should be active. If not, restart the wait and switch back.
bool active = true;
void *block = nullptr;
if (auto_tool_slot_switch_back == -1 && !may_switch_from_held_item(ctx))
active = false;
if (active) {
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
if (java_call_entity_player_is_using_item(ctx->jvm, ctx->player)) {
active = false;
} else if (!java_get_key_binding_key_code(ctx->jvm, java_get_game_settings_attack_key(ctx->jvm, settings))) {
active = false; // not mining
} else if (auto_tool_require_sneak_value == 1 && !is_key_down(ctx->jvm, java_get_game_settings_sneak_key(ctx->jvm, settings))) {
active = false;
} else {
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 1) {
active = false; // not looking at a block
} else {
Vec3 pos = java_get_moving_object_position_block_x(ctx->jvm, hit);
block = java_call_variant(ctx->jvm, ctx->world, (int)pos.x, (int)pos.y, (int)pos.z);
if (!block)
active = false;
else if (auto_tool_restrict_allowed_blocks == 1 && !id_vector_contains(auto_tool_allowed_block_set, get_block_id(ctx->jvm, block)))
active = false;
}
}
}
if (!active) {
auto_tool_activation_countdown = (int)auto_tool_activation_time_value;
stop_and_switch_back(ctx, inventory);
return;
}
// Still waiting for "activation_time".
if (auto_tool_activation_countdown > 0) {
auto_tool_activation_countdown = auto_tool_activation_countdown - 1;
stop_and_switch_back(ctx, inventory);
return;
}
// Find the hotbar slot that mines this block fastest (starting from the current slot,
// so on a tie the current one wins). Speed 1.0 is the bare hand.
int best_slot = current_slot;
float best_speed = 1.0f;
for (int i = 0; i < 9; i++) {
int slot = (current_slot + i) % 9;
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, slot);
if (!stack)
continue;
float speed = java_call_item_stack_get_str_vs_block(ctx->jvm, stack, block);
if (speed > best_speed)
best_slot = slot;
best_speed = speed > best_speed ? speed : best_speed;
}
if (best_slot == current_slot)
return;
// Switch, if no other module is using the hotbar right now.
if (claim_release_hotbar_module(auto_tool_module_descriptor)) {
java_set_inventory_player_current_item(ctx->jvm, inventory, best_slot);
auto_tool_slot_we_switched = best_slot;
if (auto_tool_slot_switch_back == -1 && auto_tool_switch_back_value)
auto_tool_slot_switch_back = current_slot;
}
}
extern "C" void auto_tool_on_shutdown(Hook *hook) {
libc_free(auto_tool_allowed_block_set[0]);
auto_tool_allowed_block_set[0] = auto_tool_allowed_block_set[1] = nullptr;
}
+61
View File
@@ -0,0 +1,61 @@
// Auto Tool — Selects the best tool when digging.
// category: block descriptor: 0x2ee158 settings block: 0x2ee350
// functions: gui auto_tool_gui, register auto_tool_register
// implementation: src/logic/block/auto_tool.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_auto_tool); // "Main"
S(str_allow_while_using); // "Allow while using"
S(str_conditions_in_auto_tool); // "Conditions"
S(str_activation_time_in_auto_tool); // "activation_time"
S(str_switch_back); // "switch_back"
S(str_allow_using_sword); // "allow_using_sword"
S(str_allow_using_tools); // "allow_using_tools"
S(str_allow_using_fists); // "allow_using_fists"
S(str_allow_using_other); // "allow_using_other"
S(str_require_sneak_in_auto_tool); // "require_sneak"
S(str_restrict_allowed_blocks_in_auto_tool); // "restrict_allowed_blocks"
S(str_allowed_blocks_in_auto_tool); // "allowed_blocks"
D(auto_tool_activation_time_setting); // setting num "activation_time"
D(auto_tool_allow_using_fists_setting); // setting bool "allow_using_fists"
D(auto_tool_allow_using_sword_setting); // setting bool "allow_using_sword"
D(auto_tool_allow_using_tools_setting); // setting bool "allow_using_tools"
D(auto_tool_allow_using_other_setting); // setting bool "allow_using_other"
D(auto_tool_require_sneak_setting); // setting bool "require_sneak"
D(auto_tool_restrict_allowed_blocks_setting); // setting bool "restrict_allowed_blocks"
D(auto_tool_restrict_allowed_blocks); // current value of setting "restrict_allowed_blocks" (+0x18)
D(auto_tool_switch_back_setting); // setting bool "switch_back"
D(auto_tool_allowed_blocks_setting); // setting kind2 "allowed_blocks"
extern "C" void auto_tool_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_auto_tool);
W_slider(window, gui, auto_tool_activation_time_setting);
W_bool(window, gui, auto_tool_switch_back_setting);
W_label(gui, window, str_allow_while_using);
W_bool(window, gui, auto_tool_allow_using_sword_setting);
W_bool(window, gui, auto_tool_allow_using_tools_setting);
W_bool(window, gui, auto_tool_allow_using_fists_setting);
W_bool(window, gui, auto_tool_allow_using_other_setting);
W_label(gui, window, str_conditions_in_auto_tool);
W_bool(window, gui, auto_tool_require_sneak_setting);
W_bool(window, gui, auto_tool_restrict_allowed_blocks_setting);
if (*(unsigned char *)auto_tool_restrict_allowed_blocks == 1) {
W_items(window, gui, auto_tool_allowed_blocks_setting);
} else {
EPILOG_NOP();
}
}
extern "C" void auto_tool_register(void *module) {
R_num(module, str_activation_time_in_auto_tool, auto_tool_activation_time_setting);
R_bool(module, str_switch_back, auto_tool_switch_back_setting);
R_bool(module, str_allow_using_sword, auto_tool_allow_using_sword_setting);
R_bool(module, str_allow_using_tools, auto_tool_allow_using_tools_setting);
R_bool(module, str_allow_using_fists, auto_tool_allow_using_fists_setting);
R_bool(module, str_allow_using_other, auto_tool_allow_using_other_setting);
R_bool(module, str_require_sneak_in_auto_tool, auto_tool_require_sneak_setting);
R_bool(module, str_restrict_allowed_blocks_in_auto_tool, auto_tool_restrict_allowed_blocks_setting);
R_kind2(module, str_allowed_blocks_in_auto_tool, auto_tool_allowed_blocks_setting);
}
+361
View File
@@ -0,0 +1,361 @@
// Block In - build a box of blocks around yourself (roof first, then the walls).
//
// Every tick the module looks for the next free spot around the player, aims at it with
// smooth, slightly random head movement, and presses "use item" once the aim is on it.
// When nothing is left to place and you stand in the middle of your block, it turns itself off.
//
// Callbacks:
// block_in_on_tick (unused, empty)
// block_in_rotation_override_placement the rotation sent to the server when placing
// block_in_tick_while_placing every tick: walk to the middle of the block / stand still
// block_in_enable_remember_facing module switched on/off
// block_in_tick every tick: pick the next spot, aim, place
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
struct Pair { float x, y; }; // yaw, pitch difference
struct Offset3 { signed char dx, dy, dz; };
struct Offset2 { signed char dx, dz; };
struct Rot { float yaw, pitch; };
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
struct RotHook {
char padding_00[8];
unsigned char override_yaw, override_pitch; // +0x08 / +0x09 set to 1 to replace the rotation
char padding_0a[2];
Rot rot; // +0x0c rotation to send
};
// ---- settings ----
extern "C" unsigned char block_in_require_ground; // only while standing on the ground
extern "C" float block_in_aim_speed; // how fast to turn the head
// ---- module state ----
extern "C" char block_in_module_descriptor[];
extern "C" unsigned char block_in_active; // 1 while aiming/placing this tick
// 0 = not placing, 1 = walk to the middle of the block first, 2 = in the middle, stand still
extern "C" int block_in_rotation_mode;
extern "C" Rot block_in_placement_rotation; // where to look while walking to the middle
// Spots already placed (a 64-bit mask): bits 0..11 the walls (3 heights x 4 sides), bits 32..41 the roof.
extern "C" void *block_in_placed_count;
extern "C" int block_in_facing_quadrant; // which side to start the walls on (0..3, from the yaw)
extern "C" double block_in_last_y; // player height last tick (moving up or down resets the mask)
// States of the random walks that make the aim look human.
extern "C" char block_in_rng_states[], block_in_rng_states_second[], block_in_rng_states_third[], block_in_rng_states_fourth[], block_in_rng_states_fifth[], block_in_rng_states_in_block_in_d[];
// The 10 roof spots, relative to the block below the feet, and the 4 wall directions.
extern "C" const Offset3 block_in_roof_spots_relative_block_below[10];
extern "C" const Offset2 block_in_side_directions[4];
// Bounds of the random ranges used for aim points (the name says the value: 3_6 = 3.6, neg_0_25 = -0.25).
extern "C" const float random_range_bound_neg_0_25, random_range_bound_neg_0_4, random_range_bound_0_25_in_block_in, random_range_bound_0_4_in_block_in,
random_range_bound_0_6_in_block_in, random_range_bound_neg_0_1_in_block_in, random_range_bound_neg_0_2, random_range_bound_3_6,
random_range_bound_3_8, random_range_bound_1_1_in_block_in, random_range_bound_1_2_in_block_in, random_range_bound_0_8_in_block_in;
// ---- game / engine functions ----
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(float, libc_roundf, (float v));
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_forward_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, vec3_add_eye_height_sneak, (Vec3 v));
FN(double, libc_floor, (double x));
FN(double, libc_fmod, (double x, double y));
FN(void *, java_block_pos_init, (void *jvm, void *object, int y, int z));
FN(void *, java_call_world_get_block_state, (void *jvm, void *world, void *pos, int x, int y, int z));
FN(int, get_block_id, (void *jvm, void *block));
FN(void *, java_get_entity_bounding_box, (void *jvm, void *entity));
FN(Box, java_get_axis_aligned_bb_min_x, (void *jvm, void *bounding_box));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Box, aabb_make, (Vec3 lo, Vec3 hi));
FN(unsigned char, aabb_intersects, (Box a, Box b));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, walk_update, (void *state, Range r, double d)); // next value of a random walk inside the range
FN(unsigned char, update_rotation_priority_peak, (int ms)); // may this module control the rotation?
FN(void, switch_best_hotbar_slot, (Ctx *ctx, void *mod, unsigned char on, void (*cb)(void *)));
FN(void, key_category, (void *));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(Rot, get_silent_rotation_offset, ());
FN(Rot, rot_add, (Rot a, Rot b));
FN(void *, java_call_entity_living_base_get_position, (void *jvm, void *entity_living_base)); // eye position
FN(Vec3, java_get_vec3_x_coord, (void *jvm, void *bp));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(Pair, rot_sub, (Rot a, Rot b));
FN(float, wrap_angle, (float deg)); // to -180..180
FN(Pair, rot_scale, (Pair p, float k));
FN(float, limit_rotation_delta, (float lo, float hi, float v)); // clamp
FN(Pair, rot_lerp, (Pair a, Pair b, float k));
FN(void, apply_silent_rotation, (Pair r));
FN(void *, java_get_game_settings_use_item_key, (void *jvm, void *game_settings));
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(void, queue_module_toggle, (void *module_manager, void *module, unsigned char enabled));
static unsigned long long &placed_mask() { return *(unsigned long long *)&block_in_placed_count; }
extern "C" void block_in_on_tick(void *) {
}
// When placing: send our aim to the server, and in "walk to the middle" mode the walking direction.
extern "C" void block_in_rotation_override_placement(RotHook *hook) {
if (block_in_active != 1)
return;
hook->override_yaw = 1;
hook->override_pitch = 1;
if (block_in_rotation_mode == 1)
hook->rot = block_in_placement_rotation;
}
// While placing: hold forward to walk to the middle of the block (mode 1), never walk otherwise.
extern "C" void block_in_tick_while_placing(Hook *hook) {
if (block_in_rotation_mode == 0)
return;
Ctx *ctx = hook->ctx;
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
java_set_key_binding_pressed(ctx->jvm, forward_key, block_in_rotation_mode == 1);
java_set_key_binding_pressed(ctx->jvm, back_key, 0);
java_set_key_binding_pressed(ctx->jvm, left_key, 0);
java_set_key_binding_pressed(ctx->jvm, right_key, 0);
}
// On enable: start fresh and remember which way we face. On disable: give the movement keys back.
extern "C" void block_in_enable_remember_facing(EvHook *hook) {
if (hook->ev != block_in_module_descriptor)
return;
Ctx *ctx = hook->ctx;
if (hook->on == 1) {
block_in_placed_count = nullptr;
int quadrant = (int)libc_roundf(get_entity_rotation(ctx->jvm, ctx->player).yaw / 90.0f);
block_in_facing_quadrant = quadrant % 4;
return;
}
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
java_set_key_binding_pressed(ctx->jvm, forward_key, java_get_key_binding_key_code(ctx->jvm, forward_key));
java_set_key_binding_pressed(ctx->jvm, back_key, java_get_key_binding_key_code(ctx->jvm, back_key));
java_set_key_binding_pressed(ctx->jvm, left_key, java_get_key_binding_key_code(ctx->jvm, left_key));
java_set_key_binding_pressed(ctx->jvm, right_key, java_get_key_binding_key_code(ctx->jvm, right_key));
}
// Can a block be placed here? True for air, water and tall grass.
static bool is_open(Ctx *ctx, void *pos, int x, int y, int z) {
unsigned block_id = get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, x, y, z));
return block_id <= 31 && (0x80000301u >> block_id & 1); // ids 0 (air), 8, 9 (water), 31 (tall grass)
}
static double abs_d(double x) { return __builtin_fabs(x); }
static float abs_f(float x) { return __builtin_fabsf(x); }
// Is the position in the middle part of its block (0.31 .. 0.69 on both x and z)?
static bool in_block_middle(double frac_x, double frac_z) {
return 0.69 >= frac_x && frac_x >= 0.31 && frac_z >= 0.31 && 0.69 >= frac_z;
}
// Roof: look for the next roof spot. Returns false when the walls should be done first
// (or the roof is complete). bx/by/bz is the block below the feet.
static bool find_roof_spot(Ctx *ctx, void *pos, int bx, int by, int bz, Vec3 *target, unsigned char *bit) {
unsigned long long placed = placed_mask();
for (int i = 0; i < 10; i++) {
const Offset3 &spot = block_in_roof_spots_relative_block_below[i];
// Skip spots that are still open (and not placed by us yet).
if (!(placed >> 32 >> i & 1) && is_open(ctx, pos, bx + spot.dx, by + spot.dy, bz + spot.dz))
continue;
if (i == 0)
return false; // already standing under a roof: do the walls
*bit = (unsigned char)(32 + i);
// Aim at a random point on the side of the block that is there.
float fx = (float)bx, fy = (float)by, fz = (float)bz;
Range height = rot_make_floats(random_range_bound_3_6, random_range_bound_3_8);
switch (i == 9 ? 4 : (i - 1) & 3) {
case 0:
target->x = bx;
target->y = fy + walk_update(block_in_rng_states, height, 0.5);
target->z = fz + walk_update(block_in_rng_states_second, rot_make_floats(random_range_bound_neg_0_1_in_block_in, random_range_bound_neg_0_2), 0.5);
break;
case 1:
target->x = fx + walk_update(block_in_rng_states, rot_make_floats(random_range_bound_1_1_in_block_in, random_range_bound_1_2_in_block_in), 0.5);
target->y = fy + walk_update(block_in_rng_states_second, height, 0.5);
target->z = bz;
break;
case 2:
target->x = bx + 1;
target->y = fy + walk_update(block_in_rng_states, height, 0.5);
target->z = fz + walk_update(block_in_rng_states_second, rot_make_floats(random_range_bound_1_1_in_block_in, random_range_bound_1_2_in_block_in), 0.5);
break;
case 3:
target->x = fx + walk_update(block_in_rng_states, rot_make_floats(random_range_bound_neg_0_1_in_block_in, random_range_bound_neg_0_2), 0.5);
target->y = fy + walk_update(block_in_rng_states_second, height, 0.5);
target->z = bz + 1;
break;
default: // the last spot: aim at the underside, straight above
target->x = fx + walk_update(block_in_rng_states, rot_make_floats(random_range_bound_0_4_in_block_in, random_range_bound_0_6_in_block_in), 0.5);
target->y = by + 4;
target->z = fz + walk_update(block_in_rng_states_second, rot_make_floats(random_range_bound_0_4_in_block_in, random_range_bound_0_6_in_block_in), 0.5);
break;
}
return true;
}
return false;
}
// Walls: one column on each of the 4 sides, filled from the bottom (feet, head, above head).
static bool find_wall_spot(Ctx *ctx, void *pos, int bx, int by, int bz, Vec3 *target, unsigned char *bit) {
unsigned long long placed = placed_mask();
for (int d = 0; d < 4; d++) {
int dir = (block_in_facing_quadrant + d) & 3;
int dx = block_in_side_directions[dir].dx, dz = block_in_side_directions[dir].dz;
int nx = bx + dx, nz = bz + dz;
// Skip a side the player is standing in.
Box player_box = java_get_axis_aligned_bb_min_x(ctx->jvm, java_get_entity_bounding_box(ctx->jvm, ctx->player));
Vec3 lo = {(double)nx, (double)by, (double)nz};
Box column = aabb_make(lo, vec3_add(lo, Vec3{1.0, 3.0, 1.0}));
if (aabb_intersects(player_box, column))
continue;
// The lowest open spot that has a block under it to place against.
int base = dir * 3;
int level;
Range r;
if (!(placed >> base & 1) && is_open(ctx, pos, nx, by, nz) && !is_open(ctx, pos, nx, by - 1, nz)) {
level = 0;
r = rot_make_floats(random_range_bound_neg_0_25, random_range_bound_neg_0_4);
} else if (!(placed >> (base + 1) & 1) && is_open(ctx, pos, nx, by + 1, nz) && !is_open(ctx, pos, nx, by, nz)) {
level = 1;
r = rot_make_floats(random_range_bound_0_25_in_block_in, random_range_bound_0_4_in_block_in);
} else if (!(placed >> (base + 2) & 1) && is_open(ctx, pos, nx, by + 2, nz) && !is_open(ctx, pos, nx, by + 1, nz)) {
level = 2;
r = rot_make_floats(random_range_bound_0_25_in_block_in, random_range_bound_0_4_in_block_in);
} else {
continue;
}
// Aim at a random point on the top of the block below that spot.
target->x = (0.5 - (double)(walk_update(block_in_rng_states_third, r, 0.5) * (float)dx)) + nx;
target->z = (0.5 - (double)(walk_update(block_in_rng_states_fourth, r, 0.5) * (float)dz)) + nz;
target->y = by + level;
*bit = (unsigned char)(base + level);
return true;
}
return false;
}
// Turn the head a step towards the target, and place when the aim is on it.
// Returns false if the module should turn itself off.
static bool aim_and_place(Ctx *ctx, Vec3 me, Vec3 target, unsigned char bit) {
if (!update_rotation_priority_peak(500))
return false;
switch_best_hotbar_slot(ctx, block_in_module_descriptor, 1, key_category);
if (!block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player)))
return false; // no blocks in the hotbar
// How far the head still has to turn.
Rot current = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Vec3 eye = java_get_vec3_x_coord(ctx->jvm, java_call_entity_living_base_get_position(ctx->jvm, ctx->player));
Pair diff = rot_sub(rot_look_at(eye, target), current);
float diff_yaw = wrap_angle(diff.x);
float diff_pitch = diff.y;
// Turn part of the way (by aim speed), limited to a random maximum per tick.
Pair step = rot_scale(Pair{diff_yaw, diff_pitch}, (float)((double)block_in_aim_speed * 0.5 + 0.5));
float jitter_yaw = walk_update(block_in_rng_states_fifth, rot_make_floats(random_range_bound_0_8_in_block_in, random_range_bound_1_2_in_block_in), 0.2);
float jitter_pitch = walk_update(block_in_rng_states_in_block_in_d, rot_make_floats(random_range_bound_0_8_in_block_in, random_range_bound_1_2_in_block_in), 0.2);
float max_yaw = jitter_yaw * 180.0f * block_in_aim_speed;
float max_pitch = 180.0f * jitter_pitch * block_in_aim_speed;
Pair limited = {limit_rotation_delta(-max_yaw, max_yaw, diff_yaw), limit_rotation_delta(-max_pitch, max_pitch, diff_pitch)};
Pair turn = rot_lerp(step, limited, 0.5f);
apply_silent_rotation(turn);
// Within 1 degree after this step: right click.
float error_yaw = abs_f(diff_yaw - turn.x);
float error_pitch = abs_f(diff_pitch - turn.y);
if (1.0f > error_pitch + error_yaw) {
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
placed_mask() |= 1ull << (bit & 63);
}
block_in_active = 1;
// Not in the middle of the block yet: walk there first.
double frac_x = abs_d(libc_fmod(me.x, 1.0));
double frac_z = libc_fmod(me.z, 1.0);
if (in_block_middle(frac_x, abs_d(frac_z))) {
block_in_rotation_mode = 2;
return true;
}
block_in_rotation_mode = 1;
Vec3 middle = {libc_floor(me.x) + 0.5, me.y, libc_floor(me.z) + 0.5};
block_in_placement_rotation = rot_look_at(me, middle);
return true;
}
extern "C" void block_in_tick(Hook *hook) {
block_in_active = 0;
block_in_rotation_mode = 0;
Ctx *ctx = hook->ctx;
bool turn_off = false;
if (ctx->in_game != 1) {
turn_off = true;
} else {
unsigned char on_ground = java_get_entity_on_ground(ctx->jvm, ctx->player);
if (block_in_require_ground && !on_ground) {
turn_off = true;
} else {
Vec3 me = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
me = vec3_add_eye_height_sneak(me);
// The block below the feet.
int bx = (int)libc_floor(me.x);
int by = (int)(libc_floor(me.y) + -1.0);
int bz = (int)libc_floor(me.z);
// Moved up or down: start over.
if (abs_d(me.y - block_in_last_y) > 0.01)
placed_mask() = 0;
block_in_last_y = me.y;
// A BlockPos object reused for the block lookups (only once the JVM handle is ready).
void *pos = **(int **)ctx->jvm ? java_block_pos_init(ctx->jvm, nullptr, 0, 0) : nullptr;
Vec3 target;
unsigned char bit;
if (find_roof_spot(ctx, pos, bx, by, bz, &target, &bit) || find_wall_spot(ctx, pos, bx, by, bz, &target, &bit)) {
turn_off = !aim_and_place(ctx, me, target, bit);
} else {
// Nothing left to place: done once we stand in the middle of the block.
if (!on_ground)
return;
double frac_x = abs_d(libc_fmod(me.x, 1.0));
double frac_z = abs_d(libc_fmod(me.z, 1.0));
turn_off = in_block_middle(frac_x, frac_z);
}
}
}
if (turn_off)
queue_module_toggle(ctx->module_manager, block_in_module_descriptor, 0);
}
+26
View File
@@ -0,0 +1,26 @@
// Block In — Places blocks around you.
// category: block descriptor: 0x2f6108 settings block: 0x2f6300
// functions: gui block_in_gui, register block_in_register
// implementation: src/logic/block/block_in.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_block_in); // "Main"
S(str_conditions_in_block_in); // "Conditions"
S(str_speed_in_block_in); // "speed"
S(str_require_ground); // "require_ground"
D(block_in_require_ground_setting); // setting bool "require_ground"
D(block_in_speed_setting); // setting num "speed"
extern "C" void block_in_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_block_in);
W_slider(window, gui, block_in_speed_setting);
W_label(gui, window, str_conditions_in_block_in);
W_bool(window, gui, block_in_require_ground_setting);
}
extern "C" void block_in_register(void *module) {
R_num(module, str_speed_in_block_in, block_in_speed_setting);
R_bool(module, str_require_ground, block_in_require_ground_setting);
}
+323
View File
@@ -0,0 +1,323 @@
// Bridge Assist - sneak automatically at block edges while bridging backwards.
//
// While you walk backwards placing blocks, this module holds sneak just before you would
// step off the edge, and lets go again a moment later. It can also restrict placing to
// clicks that hit the edge of the block below you.
//
// Callbacks:
// bridge_assist_disable module switched off: give the sneak key back
// bridge_assist_on_late_tick every tick: keep the module's keybind state in sync
// bridge_assist_tick every tick: hold / release sneak
// bridge_assist_place right click: decide if placing is allowed
// bridge_assist_edge_check helper: is the ground under our next position air?
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct Range { float lo, hi; };
struct Box { double x0, y0, z0, x1, y1, z1; };
struct PlaceEvt {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char cancelled; // +0x10 placing already cancelled
unsigned char allow; // +0x11 set to 1 to allow placing
};
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
// ---- settings ----
extern "C" int bridge_assist_activation_mode; // 0 = off, 1 = on, 2 = toggle with the keybind
extern "C" unsigned char bridge_assist_only_while_sneak_held; // only while you hold sneak yourself
extern "C" unsigned char bridge_assist_only_when_looking_down; // only with pitch >= 65
extern "C" unsigned char bridge_assist_only_while_not_rising; // not while walking forwards
extern "C" unsigned char bridge_assist_only_few_ticks_after_landing; // only shortly after holding blocks
extern "C" unsigned char bridge_assist_also_air_while_falling; // also in the air while not falling
extern "C" unsigned char bridge_assist_randomise; // randomise margin and release delay
extern "C" unsigned char bridge_assist_edge_only_placing; // only allow placing on the edge
extern "C" float bridge_assist_edge_margin; // how close to the edge before sneaking (blocks)
extern "C" float bridge_assist_release_delay; // ticks to keep sneaking after the edge is safe
// ---- module state ----
extern "C" char bridge_assist_module_descriptor[];
extern "C" unsigned char bridge_assist_sneak_held_by_us; // we are controlling the sneak key
extern "C" unsigned char bridge_assist_placing; // active this tick
extern "C" unsigned char bridge_assist_restrict_placing_edge; // placing is restricted to the edge this tick
extern "C" int bridge_assist_cooldown_after_sneaking_ticks; // 20 after placing a block, counts down
extern "C" int bridge_assist_ticks_left_hold; // "only_few_ticks_after_landing" countdown
extern "C" float bridge_assist_release_timer; // ticks left before sneak is released
extern "C" char bridge_assist_rng_states[], bridge_assist_rng_states_second[], bridge_assist_rng_states_third[]; // random walk states
// Bounds of random ranges (the name says the value: neg_0_5 = -0.5, 0_04 = 0.04).
extern "C" const float random_range_bound_neg_0_5, random_range_bound_0_5_in_bridge_assist, random_range_bound_0_04_in_bridge_assist,
random_range_bound_0_08_in_bridge_assist, random_range_bound_3_in_bridge_assist, random_range_bound_0_15_in_bridge_assist;
// ---- game / engine functions ----
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_sneak_key, (void *jvm, void *game_settings));
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(void, track_owner, (void *ctx, void *mod, unsigned char toggle));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *hit)); // 1 = a block
FN(unsigned, java_get_variant, (void *jvm, void *hit)); // side of the block that was hit (>= 2: a vertical side)
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(void *, java_get_game_settings_forward_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(unsigned char, is_key_down, (void *jvm, void *k));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(double, libc_fmod, (double x, double y));
FN(double, libc_floor, (double x));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, vec3_add_eye_height_sneak, (Vec3 v));
FN(void *, java_get_moving_object_position_hit_vec, (void *jvm, void *hit));
FN(Vec3, java_get_vec3_x_coord, (void *jvm, void *bp));
FN(Vec3, java_get_adjacent_block_position, (void *jvm, void *hit));
FN(float, java_get_entity_living_base_move_forward, (void *jvm, void *entity_living_base));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(void *, java_get_entity_bounding_box, (void *jvm, void *entity));
FN(Box, java_get_axis_aligned_bb_min_x, (void *jvm, void *bounding_box));
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(float, java_get_entity_living_base_land_movement_factor, (void *jvm, void *entity_living_base));
FN(Vec3, horizontal_motion, (Rot rotation, float fwd, float strafe, float speed));
FN(void *, java_call_variant, (void *jvm, void *world, int x, int y, int z)); // block at x, y, z
FN(int, get_block_id, (void *jvm, void *block));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, walk_update, (void *state, Range r, double d)); // next value of a random walk inside the range
FN(unsigned char, walk_should_change, (void *state, Range r, double d));
FN(float, random_rotation, (Range r)); // random value in the range
static double abs_d(double x) { return __builtin_fabs(x); }
static float abs_f(float x) { return __builtin_fabsf(x); }
// On disable: give the sneak key back to the player.
extern "C" void bridge_assist_disable(EvHook *hook) {
if (hook->ev != bridge_assist_module_descriptor || hook->on || !(bridge_assist_sneak_held_by_us & 1))
return;
Ctx *ctx = hook->ctx;
void *sneak_key = java_get_game_settings_sneak_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
java_set_key_binding_pressed(ctx->jvm, sneak_key, java_get_key_binding_key_code(ctx->jvm, sneak_key));
bridge_assist_sneak_held_by_us = 0;
}
extern "C" void bridge_assist_on_late_tick(Hook *hook) {
if (bridge_assist_placing == 1)
track_owner(hook->ctx, bridge_assist_module_descriptor, bridge_assist_activation_mode == 2);
}
// Where will the player be next tick, and is there no block under any corner of that spot
// (shrunk by the edge margin)? Returns 1 when we would walk off an edge.
extern "C" unsigned char bridge_assist_edge_check(void *jvm, void *game_settings, void *world, void *player) {
// Middle of the feet, just below them.
Box box = java_get_axis_aligned_bb_min_x(jvm, java_get_entity_bounding_box(jvm, player));
Vec3 feet = vec3_make((box.x0 + box.x1) * 0.5, box.y0 + -0.01, (box.z0 + box.z1) * 0.5);
Vec3 motion = java_get_entity_motion_x(jvm, player);
double margin = bridge_assist_edge_margin;
if (bridge_assist_randomise == 1) {
margin -= walk_update(bridge_assist_rng_states, rot_make_floats(0.0f, random_range_bound_0_15_in_bridge_assist), 5.0);
if (0.0 > margin)
margin = 0.0;
}
// The movement keys held, as input values.
void *forward_key = java_get_game_settings_forward_key(jvm, game_settings);
void *back_key = java_get_game_settings_back_key(jvm, game_settings);
void *left_key = java_get_game_settings_left_key(jvm, game_settings);
void *right_key = java_get_game_settings_right_key(jvm, game_settings);
float forward = is_key_down(jvm, forward_key) ? 1.0f : 0.0f;
if (is_key_down(jvm, back_key))
forward += -1.0f;
float strafe = is_key_down(jvm, left_key) ? 1.0f : 0.0f;
if (is_key_down(jvm, right_key))
strafe += -1.0f;
// Next position = feet + motion + what the keys add.
Rot rotation = get_entity_rotation(jvm, player);
Vec3 push = horizontal_motion(rotation, forward, strafe, java_get_entity_living_base_land_movement_factor(jvm, player));
Vec3 next = vec3_add(feet, vec3_add(motion, push));
// The (up to 4) blocks under the spot, shrunk by the margin. Any solid one = safe.
int x0 = (int)libc_floor(next.x - margin);
int z0 = (int)libc_floor(next.z - margin);
int y = (int)libc_floor(next.y);
double x1_floor = libc_floor(next.x + margin);
double z1_floor = libc_floor(margin + next.z);
if (get_block_id(jvm, java_call_variant(jvm, world, x0, y, z0)))
return 0;
int z1 = (int)z1_floor;
if (z0 != z1 && get_block_id(jvm, java_call_variant(jvm, world, x0, y, z1)))
return 0;
int x1 = (int)x1_floor;
if (x0 == x1)
return 1;
if (get_block_id(jvm, java_call_variant(jvm, world, x1, y, z0)))
return 0;
if (z0 == z1)
return 1;
return !get_block_id(jvm, java_call_variant(jvm, world, x1, y, z1));
}
extern "C" void bridge_assist_tick(Hook *hook) {
bridge_assist_restrict_placing_edge = 0;
bridge_assist_placing = 0;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
void *game_settings = get_game_settings(ctx->jvm, ctx->minecraft);
if (bridge_assist_cooldown_after_sneaking_ticks > 0)
bridge_assist_cooldown_after_sneaking_ticks -= 1;
void *sneak_key = java_get_game_settings_sneak_key(ctx->jvm, game_settings);
unsigned char sneak_held = java_get_key_binding_key_code(ctx->jvm, sneak_key);
// Conditions. If one fails, give the sneak key back.
bool conditions_ok = true;
if (bridge_assist_only_while_sneak_held != sneak_held)
conditions_ok = false;
else if (bridge_assist_only_when_looking_down == 1 && 65.0f > get_entity_rotation(ctx->jvm, ctx->player).pitch)
conditions_ok = false;
else if (bridge_assist_only_while_not_rising == 1 && java_get_entity_living_base_move_forward(ctx->jvm, ctx->player) > 0.0f)
conditions_ok = false;
if (conditions_ok) {
bridge_assist_placing = bridge_assist_activation_mode != 0;
if (bridge_assist_only_few_ticks_after_landing == 1) {
// Holding blocks keeps the countdown at 2; otherwise it runs out.
int ticks_left;
if (block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player))) {
ticks_left = 2;
} else {
ticks_left = bridge_assist_ticks_left_hold;
if (ticks_left <= 0)
conditions_ok = false;
ticks_left -= 1;
}
if (conditions_ok)
bridge_assist_ticks_left_hold = ticks_left;
}
}
if (!conditions_ok) {
if (bridge_assist_sneak_held_by_us == 1)
java_set_key_binding_pressed(ctx->jvm, sneak_key, sneak_held);
bridge_assist_sneak_held_by_us = 0;
return;
}
bridge_assist_sneak_held_by_us = 1;
// What to do with the sneak key this tick.
enum { KEEP, CHECK_EDGE, COUNT_DOWN } action;
if (is_key_down(ctx->jvm, sneak_key)) {
// Sneaking now: release once the edge is safe (after the release delay).
if (bridge_assist_only_while_sneak_held == 1) {
if (java_get_entity_living_base_move_forward(ctx->jvm, ctx->player) >= 0.0f || bridge_assist_cooldown_after_sneaking_ticks <= 0)
action = KEEP;
else
action = CHECK_EDGE;
} else if (java_get_entity_on_ground(ctx->jvm, ctx->player)) {
action = CHECK_EDGE;
} else if (bridge_assist_also_air_while_falling == 1 && !(0.0 > java_get_entity_motion_x(ctx->jvm, ctx->player).y)) {
action = CHECK_EDGE;
} else {
action = COUNT_DOWN;
}
} else {
// Not sneaking: press sneak if we are about to walk off the edge.
if (!java_get_entity_on_ground(ctx->jvm, ctx->player)) {
if (bridge_assist_also_air_while_falling != 1 || 0.0 > java_get_entity_motion_x(ctx->jvm, ctx->player).y)
return;
}
if (!bridge_assist_edge_check(ctx->jvm, game_settings, ctx->world, ctx->player))
return;
java_set_key_binding_pressed(ctx->jvm, sneak_key, 1);
action = KEEP;
}
// Still at the edge: keep sneaking.
if (action == CHECK_EDGE && bridge_assist_edge_check(ctx->jvm, game_settings, ctx->world, ctx->player))
action = KEEP;
if (action != KEEP) {
// Count the release timer down; at 0 release sneak and start a new (random) delay.
bridge_assist_release_timer += -1.0f;
if (!(bridge_assist_release_timer > 0.0f)) {
java_set_key_binding_pressed(ctx->jvm, sneak_key, 0);
float delay = bridge_assist_release_delay;
if (bridge_assist_randomise == 1) {
delay += walk_update(bridge_assist_rng_states_second, rot_make_floats(random_range_bound_neg_0_5, random_range_bound_0_5_in_bridge_assist), 30.0);
if (walk_should_change(bridge_assist_rng_states_third, rot_make_floats(random_range_bound_0_04_in_bridge_assist, random_range_bound_0_08_in_bridge_assist), 60.0))
delay += random_rotation(rot_make_floats(0.0f, random_range_bound_3_in_bridge_assist));
}
bridge_assist_release_timer = delay + bridge_assist_release_timer;
return;
}
}
bridge_assist_restrict_placing_edge = bridge_assist_edge_only_placing;
}
// Is the crosshair on the outer edge of the side of the block we are standing on,
// while walking straight backwards at a diagonal angle?
static bool aimed_at_edge_below(Ctx *ctx) {
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 1 || java_get_variant(ctx->jvm, hit) < 2 ||
!java_get_entity_on_ground(ctx->jvm, ctx->player))
return false;
// Only back held (no left/right).
void *game_settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *back_key = java_get_game_settings_back_key(ctx->jvm, game_settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, game_settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, game_settings);
if (!is_key_down(ctx->jvm, back_key) || is_key_down(ctx->jvm, left_key) || is_key_down(ctx->jvm, right_key))
return false;
// Facing diagonally (30..60 degrees within each quarter turn).
float yaw = abs_f((float)libc_fmod(get_entity_rotation(ctx->jvm, ctx->player).yaw, 90.0));
if (30.0f > yaw || yaw > 60.0f)
return false;
// The point hit must be within 1 block sideways and up to 1 block below the feet.
Vec3 pos = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
pos = vec3_add_eye_height_sneak(pos);
Vec3 hit_pos = java_get_vec3_x_coord(ctx->jvm, java_get_moving_object_position_hit_vec(ctx->jvm, hit));
double dy = hit_pos.y - pos.y;
if (abs_d(hit_pos.x - pos.x) > 1.0 || -1.0 > dy || dy > 0.0 || abs_d(hit_pos.z - pos.z) > 1.0)
return false;
// The point hit must not be near a corner of the face. Standing right on the new block
// the band is wider (0.25) than otherwise (0.15).
Vec3 new_block = java_get_adjacent_block_position(ctx->jvm, hit);
bool inside_z = new_block.z < pos.z && pos.z < new_block.z + 1.0;
bool inside_x = new_block.x < pos.x && pos.x < new_block.x + 1.0;
double frac_x = abs_d(libc_fmod(hit_pos.x, 1.0));
double frac_z = libc_fmod(hit_pos.z, 1.0);
double edge = inside_x && inside_z ? 0.25 : 0.15;
double far = 1.0 - edge;
if (!(far < frac_x) && !(frac_x < edge))
return true;
frac_z = abs_d(frac_z);
return !(far < frac_z) && !(frac_z < edge);
}
// Right click: with "edge_only_placing", only allow clicks on the edge below us.
extern "C" void bridge_assist_place(PlaceEvt *h) {
if (h->cancelled || bridge_assist_cooldown_after_sneaking_ticks == 20)
return;
Ctx *ctx = h->ctx;
if (bridge_assist_restrict_placing_edge == 1 && aimed_at_edge_below(ctx)) {
h->allow = 1;
return;
}
if (block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player)))
bridge_assist_cooldown_after_sneaking_ticks = 20;
}
+58
View File
@@ -0,0 +1,58 @@
// Bridge Assist — Sneaks and unsneaks for you while bridging.
// category: block descriptor: 0x2e9ac0 settings block: 0x2e9cb8
// functions: gui bridge_assist_gui, register bridge_assist_register
// implementation: src/logic/block/bridge_assist.cpp
#pragma once
#include "slinky/api.h"
S(str_main); // "Main"
S(str_conditions_in_bridge_assist); // "Conditions"
S(str_edge_offset_in_bridge_assist); // "edge_offset"
S(str_unsneak_delay_in_bridge_assist); // "unsneak_delay"
S(str_select_blocks_in_bridge_assist); // "select_blocks"
S(str_randomize_in_bridge_assist); // "randomize"
S(str_sneak_on_jump_in_bridge_assist); // "sneak_on_jump"
S(str_avoid_double_sneak); // "avoid_double_sneak"
S(str_require_sneak); // "require_sneak"
S(str_require_holding_blocks); // "require_holding_blocks"
S(str_require_looking_down); // "require_looking_down"
S(str_require_not_forward); // "require_not_forward"
D(bridge_assist_require_sneak_setting); // setting bool "require_sneak"
D(bridge_assist_require_looking_down_setting); // setting bool "require_looking_down"
D(bridge_assist_require_not_forward_setting); // setting bool "require_not_forward"
D(bridge_assist_select_blocks_setting); // setting enum "select_blocks"
D(bridge_assist_require_holding_blocks_setting); // setting bool "require_holding_blocks"
D(bridge_assist_sneak_on_jump_setting); // setting bool "sneak_on_jump"
D(bridge_assist_edge_offset_setting); // setting num "edge_offset"
D(bridge_assist_randomize_setting); // setting bool "randomize"
D(bridge_assist_avoid_double_sneak_setting); // setting bool "avoid_double_sneak"
D(bridge_assist_unsneak_delay_setting); // setting num "unsneak_delay"
extern "C" void bridge_assist_gui(void *gui, void *window) {
W_label(gui, window, str_main);
W_slider(window, gui, bridge_assist_edge_offset_setting);
W_slider(window, gui, bridge_assist_unsneak_delay_setting);
W_enumw(window, gui, bridge_assist_select_blocks_setting);
W_bool(window, gui, bridge_assist_randomize_setting);
W_bool(window, gui, bridge_assist_sneak_on_jump_setting);
W_bool(window, gui, bridge_assist_avoid_double_sneak_setting);
W_label(gui, window, str_conditions_in_bridge_assist);
W_bool(window, gui, bridge_assist_require_sneak_setting);
W_bool(window, gui, bridge_assist_require_holding_blocks_setting);
W_bool(window, gui, bridge_assist_require_looking_down_setting);
W_bool(window, gui, bridge_assist_require_not_forward_setting);
}
extern "C" void bridge_assist_register(void *module) {
R_num(module, str_edge_offset_in_bridge_assist, bridge_assist_edge_offset_setting);
R_num(module, str_unsneak_delay_in_bridge_assist, bridge_assist_unsneak_delay_setting);
R_enum(module, str_select_blocks_in_bridge_assist, bridge_assist_select_blocks_setting);
R_bool(module, str_randomize_in_bridge_assist, bridge_assist_randomize_setting);
R_bool(module, str_sneak_on_jump_in_bridge_assist, bridge_assist_sneak_on_jump_setting);
R_bool(module, str_avoid_double_sneak, bridge_assist_avoid_double_sneak_setting);
R_bool(module, str_require_sneak, bridge_assist_require_sneak_setting);
R_bool(module, str_require_holding_blocks, bridge_assist_require_holding_blocks_setting);
R_bool(module, str_require_looking_down, bridge_assist_require_looking_down_setting);
R_bool(module, str_require_not_forward, bridge_assist_require_not_forward_setting);
}
+462
View File
@@ -0,0 +1,462 @@
// Clutch - save yourself from falling by placing a block.
//
// When you are about to fall (knocked off an edge, walking backwards into the void, ...),
// the module picks the best nearby block to place against, turns your head to it with
// smooth, slightly random movement, and right clicks once the crosshair is on it.
// Afterwards it turns your head back to where you were really looking ("snap back").
//
// Callbacks:
// clutch_tick every tick: right click when the crosshair is on the planned block
// clutch_rotation_override_flag tells the engine we control the rotation this tick
// clutch_on_late_tick every tick: pick a block, aim at it, snap back afterwards
// clutch_pick_aim_target helper: aim point on one candidate block and how far we must turn
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct BlockPos { int x, y, z; };
struct Rot { float yaw, pitch; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
// ---- settings ----
extern "C" float clutch_clicks_per_second;
extern "C" float clutch_snapback_duration; // ticks to turn back to the real rotation
extern "C" float clutch_snapback_delay; // ticks to wait before turning back
extern "C" float clutch_randomisation; // 0 = no randomness, 1 = full
extern "C" float clutch_aim_speed; // max degrees per tick
extern "C" float clutch_aim_multiplier; // fraction of the remaining angle to turn per tick
extern "C" float clutch_aim_multiplier_strength; // how much the multiplier is used vs. the max speed
extern "C" unsigned char clutch_snapback_instantly_on_jump;
extern "C" unsigned char clutch_require_air; // only while in the air
extern "C" unsigned char clutch_require_damage; // only within 10 ticks of being hit
extern "C" unsigned char clutch_require_moving_backwards;
extern "C" float clutch_min_height; // only when the ground is at least this far below
extern "C" float clutch_range; // how far away a block may be (index into the candidate table)
extern "C" float clutch_max_aim_distance; // give up when the head would have to turn more than this
extern "C" unsigned char clutch_sideways_only; // never place on the block straight below
extern "C" unsigned char clutch_multipoint_aim;
extern "C" int clutch_select_blocks_1_switch_2; // 1 = switch to blocks, 2 = switch to blocks and back
extern "C" unsigned char clutch_disable_after; // turn the module off after one clutch
// ---- module state ----
extern "C" char clutch_module_descriptor[];
extern "C" float clutch_click_cooldown; // ticks until the next right click
extern "C" unsigned char clutch_planned; // a block is planned and we hold blocks
extern "C" BlockPos clutch_planned_block; // block to place against
extern "C" unsigned char clutch_planned_face_up; // place on its top (1) or on a side (0)
extern "C" unsigned char clutch_rotating; // we control the rotation this tick
extern "C" Vec3 clutch_aim_point; // point on the block we aim at
extern "C" int clutch_ticks_since_last_hurt;
extern "C" int clutch_ticks_left_jump_snapback; // window after a clutch in which jumping snaps back at once
extern "C" int clutch_snapback_delay_second; // ticks left before the snap back starts
extern "C" int clutch_snapback_ticks_left; // ticks left of the snap back
extern "C" unsigned char clutch_disable_module_after_snapback;
extern "C" double clutch_jump_wiggle_direction; // sum of the random yaw wiggles on jump
extern "C" char clutch_random_walk_1[], clutch_random_walk_2[], clutch_random_walk_3[], clutch_random_walk_4[],
clutch_random_walk_5[], clutch_random_walk_6[], clutch_random_walk_7[], clutch_random_walk_8[]; // random walk states
// Candidate blocks around the player, nearest first. Each entry packs an offset as three
// 4-bit numbers (x, y, z, each + 8). The first table says how many entries are within a distance.
extern "C" const unsigned short clutch_candidates_within_distance_n[8];
extern "C" const unsigned short clutch_candidate_offsets_4_bits_each[];
// Bounds of random ranges (the name says the value: neg_0_1 = -0.1, 0_05 = 0.05).
extern "C" const float random_range_bound_0_05_in_clutch, random_range_bound_neg_0_1_in_clutch, random_range_bound_0_1_in_clutch, random_range_bound_neg_20_in_clutch,
random_range_bound_20_in_clutch_a, random_range_bound_neg_0_05_in_clutch, random_range_bound_5_in_clutch, random_range_bound_15_in_clutch,
random_range_bound_0_05_in_clutch_a, random_range_bound_neg_0_01, random_range_bound_0_01_in_clutch;
// ---- game / engine functions ----
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 1 = a block
FN(BlockPos, java_get_moving_object_position_block_pos, (void *jvm, void *hit));
FN(int, java_get_variant, (void *jvm, void *hit)); // face hit, 1 = top
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_use_item_key, (void *jvm, void *game_settings));
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(Vec3, java_get_adjacent_block_position, (void *jvm, void *hit)); // where the new block goes
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(unsigned char, is_silent_rotation_active, ());
FN(void *, get_held_item, (void *jvm, void *game_settings)); // here: the jump key
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(Rot, get_silent_rotation_offset, ());
FN(Rot, get_render_rotation, ()); // where the player really looks
FN(Rot, rot_add, (Rot a, Rot b));
FN(Rot, rot_sub, (Rot a, Rot b));
FN(Rot, rot_scale, (Rot rotation, float k));
FN(float, wrap_angle, (float deg)); // to -180..180
FN(void, apply_silent_rotation, (Rot rotation));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, random_rotation, (Range r)); // random value in the range
FN(float, walk_update, (void *state, Range r, double d)); // next value of a random walk
FN(float, walk_update_timed, (void *state, Range r, double a, double b));
FN(float, limit_rotation_delta, (float lo, float hi, float v)); // clamp
FN(float, lerp_unclamped_float, (float a, float b, float t));
FN(void *, java_get_entity_bounding_box, (void *jvm, void *entity));
FN(Box, java_get_axis_aligned_bb_min_x, (void *jvm, void *bounding_box));
FN(void *, java_call_entity_living_base_get_position, (void *jvm, void *entity_living_base)); // eye position
FN(Vec3, java_get_vec3_x_coord, (void *jvm, void *vec3));
FN(void *, java_get_entity_riding_entity, (void *jvm, void *entity));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(double, libc_hypot, (double x, double y));
FN(double, libc_acos, (double x));
FN(float, libc_sinf, (float x));
FN(float, libc_cosf, (float x));
FN(double, libc_floor, (double x));
FN(double, libc_fmod, (double x, double y));
FN(void *, java_block_pos_init, (void *jvm, void *object, int y, int z));
FN(void *, java_call_world_get_block_state, (void *jvm, void *world, void *pos, int x, int y, int z));
FN(int, get_block_id, (void *jvm, void *block));
FN(double, vec3_distance_sq, (Vec3 a, Vec3 b));
FN(void *, java_new_vec3_init, (void *jvm, Vec3 v));
FN(void *, java_world_ray_trace_blocks, (void *jvm, void *world, void *from, void *to, unsigned char liquids, unsigned char ignore_no_box, unsigned char last));
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(void, track_owner, (Ctx *ctx, void *mod, unsigned char back));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(void, queue_module_toggle, (void *module_manager, void *module, unsigned char enabled));
FN(unsigned char, update_rotation_priority_peak, (int ms)); // may this module control the rotation?
FN(Vec3, java_get_entity_rotation_pitch, (void *jvm, void *entity)); // look direction (unit vector)
FN(Vec3, vec3_scale, (Vec3 v, double k));
FN(unsigned char, aabb_ray_hit, (Box b, Vec3 origin, Vec3 dir, Vec3 *hit));
static const float BIGGEST_FLOAT = 3.40282347e+38f;
static const double MAX_REACH_SQUARED = 4.49 * 4.49;
static int abs_i(int v) { return v < 0 ? -v : v; }
static double abs_d(double x) { return __builtin_fabs(x); }
static float abs_f(float x) { return __builtin_fabsf(x); }
static bool same_block(BlockPos a, BlockPos b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
// Every tick: right click when the crosshair is on the planned block, at "clicks_per_second".
extern "C" void clutch_tick(Hook *hook) {
float cooldown = clutch_click_cooldown;
if (cooldown > 0.0f) {
cooldown += -1.0f;
clutch_click_cooldown = cooldown;
if (cooldown > 0.0f)
return;
}
clutch_click_cooldown = 20.0f / clutch_clicks_per_second + cooldown;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1 || !clutch_planned)
return;
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 1)
return;
if (!same_block(java_get_moving_object_position_block_pos(ctx->jvm, hit), clutch_planned_block))
return;
// Must be the planned face: the top, or a side.
bool hit_top = java_get_variant(ctx->jvm, hit) == 1;
if (hit_top != (clutch_planned_face_up != 0))
return;
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
// Next time, place against the block we just placed.
Vec3 placed = java_get_adjacent_block_position(ctx->jvm, hit);
clutch_planned_block.x = (int)placed.x;
clutch_planned_block.y = (int)placed.y;
clutch_planned_block.z = (int)placed.z;
}
extern "C" void clutch_rotation_override_flag(char *h) {
if (clutch_rotating == 1) {
h[8] = 1; // override yaw
h[9] = 1; // override pitch
}
}
// Pick a point on the side of a candidate block (at base + rel) that faces the player.
// Writes it to *out and returns how many degrees the head has to turn to look at it.
extern "C" float clutch_pick_aim_target(Vec3 *eye, Rot cur, Vec3 *center, BlockPos *base, BlockPos *rel, Vec3 *out) {
int rx = rel->x, ry = rel->y, rz = rel->z;
float jitter_inset = walk_update(clutch_random_walk_1, rot_make_floats(0.0f, random_range_bound_0_05_in_clutch_a), 1.0);
float randomness = clutch_randomisation;
float jitter_x = walk_update(clutch_random_walk_2, rot_make_floats(random_range_bound_neg_0_01, random_range_bound_0_01_in_clutch), 0.5);
float jitter_z = walk_update(clutch_random_walk_3, rot_make_floats(random_range_bound_neg_0_01, random_range_bound_0_01_in_clutch), 0.5);
double shift_x = (double)(jitter_x * randomness), shift_z = (double)(jitter_z * randomness);
if (!clutch_multipoint_aim) {
// Lean towards the side of the block the previous aim point was on.
double frac_x = abs_d(libc_fmod(center->x, 1.0));
double frac_z = abs_d(libc_fmod(center->z, 1.0));
frac_x = 0.5 < frac_x ? abs_d(frac_x + -1.0) : frac_x;
frac_z = 0.5 < frac_z ? abs_d(frac_z + -1.0) : frac_z;
shift_z += frac_x * (clutch_aim_point.z < center->z ? -1.0 : 1.0);
shift_x += frac_z * (clutch_aim_point.x < center->x ? -1.0 : 1.0);
}
// The face pointing at us: on the x side if the block is further away in x, else on the z side.
// Stay a little away from the face's edges.
double inset = (double)(randomness * jitter_inset) + 0.1;
double far = 1.0 - inset;
double x_lo, x_hi, z_lo, z_hi;
if ((unsigned)abs_i(rx) > (unsigned)abs_i(rz)) {
x_lo = x_hi = (double)((unsigned)rx >> 31); // 1 if the block is at -x (aim at its +x face), else 0
z_lo = inset;
z_hi = far;
} else {
x_lo = inset;
x_hi = far;
z_lo = z_hi = (double)((unsigned)rz >> 31);
}
// Aim point: as close to our position as the face allows; higher for blocks further away.
int bx = rx + base->x, by = ry + base->y, bz = rz + base->z;
double distance = (double)(abs_i(rel->x) + abs_i(rel->z));
double aim_x = limit_rotation_delta((float)(x_lo + bx), (float)(x_hi + bx), (float)(shift_x + center->x));
double aim_y = (double)limit_rotation_delta(0.0f, 0.65f, (float)(distance * 0.25)) + ((double)by + 0.25);
double aim_z = limit_rotation_delta((float)(z_lo + bz), (float)(z_hi + bz), (float)(shift_z + center->z));
Vec3 aim = vec3_make(aim_x, aim_y, aim_z);
Rot diff = rot_sub(rot_look_at(*eye, aim), cur);
*out = aim;
return abs_f(wrap_angle(diff.yaw)) + abs_f(diff.pitch);
}
// Should we try to clutch right now?
static bool should_clutch(Ctx *ctx, unsigned char on_ground) {
if (clutch_require_air & on_ground)
return false;
if (clutch_ticks_since_last_hurt >= 11 && clutch_require_damage)
return false;
if (java_get_entity_riding_entity(ctx->jvm, ctx->player))
return false;
if (clutch_require_moving_backwards == 1) {
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double speed = libc_hypot(motion.x, motion.z);
if (speed == 0.0)
return false;
// Angle between the facing direction and the motion: under 90 degrees = moving forwards.
float facing = (float)((double)get_entity_rotation(ctx->jvm, ctx->player).yaw * -3.141592653589793 / 180.0 + -3.141592653589793);
float sin_facing = libc_sinf(facing), cos_facing = libc_cosf(facing);
if (1.5707963267948966 > libc_acos(((double)sin_facing * motion.x + (double)cos_facing * motion.z) / speed))
return false;
}
return true;
}
// Find the best block to place against. Sets clutch_aim_point / clutch_planned_block.
// Returns false when there is nothing to do.
static bool plan_block(Ctx *ctx, Box player_box, Vec3 eye, Rot cur) {
// Middle of the feet, just inside the block below.
Vec3 center = {(player_box.lo.x + player_box.hi.x) * 0.5, player_box.lo.y + -0.99, (player_box.lo.z + player_box.hi.z) * 0.5};
clutch_planned_face_up = 0;
void *pos = **(int **)ctx->jvm ? java_block_pos_init(ctx->jvm, nullptr, 0, 0) : nullptr;
BlockPos base = {(int)libc_floor(center.x), (int)libc_floor(center.y), (int)libc_floor(center.z)};
// Ground closer than "min_height": nothing to do.
if (clutch_min_height > 0.0f) {
int y = base.y;
for (int depth = 1;; depth++, y--) {
if (get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, base.x, y, base.z)))
return false;
if (!(clutch_min_height > (float)depth))
break;
}
}
unsigned long long candidates = clutch_candidates_within_distance_n[(int)clutch_range];
long long best_rank = -3;
float best_cost = BIGGEST_FLOAT;
Vec3 best_aim = {};
BlockPos best_block = {};
Vec3 aim;
// Keep the previously planned block while it is still there, reachable and visible.
if (!((double)clutch_planned_block.y > center.y) &&
get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, clutch_planned_block.x, clutch_planned_block.y, clutch_planned_block.z))) {
BlockPos rel = {clutch_planned_block.x - base.x, clutch_planned_block.y - base.y, clutch_planned_block.z - base.z};
float cost = clutch_pick_aim_target(&eye, cur, &center, &base, &rel, &aim);
if (!(cost > clutch_max_aim_distance) && MAX_REACH_SQUARED > vec3_distance_sq(eye, aim)) {
void *hit = java_world_ray_trace_blocks(ctx->jvm, ctx->world, java_new_vec3_init(ctx->jvm, eye), java_new_vec3_init(ctx->jvm, aim), 0, 1, 0);
BlockPos hit_block = clutch_planned_block;
if (hit)
hit_block = java_get_moving_object_position_block_pos(ctx->jvm, hit);
if (same_block(hit_block, clutch_planned_block)) {
best_aim = aim;
best_block = hit_block;
best_cost = BIGGEST_FLOAT;
if (cost != BIGGEST_FLOAT) {
best_rank = abs_i(hit_block.x - base.x) + abs_i(hit_block.y - base.y) + abs_i(hit_block.z - base.z) - 2;
best_cost = cost;
}
}
}
}
// Try the candidate blocks, nearest first.
for (unsigned long long i = 0; i < candidates; i++) {
unsigned packed = clutch_candidate_offsets_4_bits_each[i];
int ox = (packed & 0xf) - 8, oy = (packed >> 4 & 0xf) - 8, oz = (packed >> 8 & 0xf) - 8;
int x = base.x + ox, y = base.y + oy, z = base.z + oz;
if (!get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, x, y, z)))
continue; // air, nothing to place against
if (!ox && !oz) {
// A block straight below: aim at a random point on its top. That always wins.
if (clutch_sideways_only)
return false;
double inset = (double)(walk_update(clutch_random_walk_1, rot_make_floats(0.0f, random_range_bound_0_05_in_clutch), 1.0) * clutch_randomisation) + 0.1;
double shift_x = walk_update(clutch_random_walk_4, rot_make_floats(random_range_bound_neg_0_1_in_clutch, random_range_bound_0_1_in_clutch), 1.0) * clutch_randomisation;
double shift_z = walk_update(clutch_random_walk_5, rot_make_floats(random_range_bound_neg_0_1_in_clutch, random_range_bound_0_1_in_clutch), 1.0) * clutch_randomisation;
double aim_x = limit_rotation_delta((float)((double)x + inset), (float)((double)(x + 1) - inset), (float)(center.x + shift_x));
double aim_z = limit_rotation_delta((float)((double)z + inset), (float)((double)(z + 1) - inset), (float)(center.z + shift_z));
clutch_aim_point = vec3_make(aim_x, (double)y + 1.0, aim_z);
clutch_planned_block = BlockPos{x, y, z};
clutch_planned_face_up = 1;
return true;
}
// Once a block is found, only blocks at the same distance are still worth checking.
long long rank = abs_i(ox) + abs_i(oy) + abs_i(oz);
candidates = clutch_candidates_within_distance_n[rank];
BlockPos rel = {ox, oy, oz};
float cost = clutch_pick_aim_target(&eye, cur, &center, &base, &rel, &aim);
if (cost > best_cost && best_rank <= rank)
continue;
if (!(MAX_REACH_SQUARED > vec3_distance_sq(eye, aim)))
continue;
best_aim = aim;
best_block = BlockPos{x, y, z};
best_cost = cost;
}
if (best_cost > clutch_max_aim_distance)
return false;
clutch_aim_point = best_aim;
clutch_planned_block = best_block;
return true;
}
// Turn the head a step towards the aim point.
static void aim_at_planned_block(Ctx *ctx, Vec3 eye, Rot cur) {
// Already looking at the top of the planned block: nothing to do.
int bx = clutch_planned_block.x, by = clutch_planned_block.y, bz = clutch_planned_block.z;
Vec3 look = vec3_scale(java_get_entity_rotation_pitch(ctx->jvm, ctx->player), 4.4);
Box top = {{bx + 0.02, by + 0.02, bz + 0.02}, {bx + 0.98, (double)(by + 1), 0.98 + bz}};
Vec3 hit;
if (aabb_ray_hit(top, eye, look, &hit) && (double)by + 0.99 > hit.y)
return;
Rot want = rot_look_at(eye, clutch_aim_point);
Rot diff = rot_sub(want, cur);
float yaw_diff;
if ((double)want.pitch > 89.999)
yaw_diff = walk_update(clutch_random_walk_6, rot_make_floats(random_range_bound_neg_20_in_clutch, random_range_bound_20_in_clutch_a), 0.5) * clutch_randomisation; // straight down: yaw does not matter, wiggle it
else
yaw_diff = wrap_angle(diff.yaw);
// Turn at most "aim_speed" (randomly a bit less) per tick...
float speed = clutch_aim_speed;
Range speed_range = rot_make_floats((float)((double)clutch_randomisation * -0.25 + 1.0), 1.0f);
float max_yaw = walk_update_timed(clutch_random_walk_7, speed_range, 10.0, 1.0) * speed;
speed_range = rot_make_floats((float)((double)clutch_randomisation * -0.25 + 1.0), 1.0f);
float max_pitch = speed * walk_update_timed(clutch_random_walk_8, speed_range, 10.0, 1.0);
float capped_yaw = limit_rotation_delta(-max_yaw, max_yaw, yaw_diff);
float capped_pitch = limit_rotation_delta(-max_pitch, max_pitch, diff.pitch);
// ...mixed with turning a fraction ("aim_multiplier") of the remaining angle.
float mult_yaw = clutch_aim_multiplier + walk_update_timed(clutch_random_walk_7, rot_make_floats(random_range_bound_neg_0_05_in_clutch, random_range_bound_0_05_in_clutch), 10.0, 1.0);
float mult_pitch = clutch_aim_multiplier + walk_update_timed(clutch_random_walk_8, rot_make_floats(random_range_bound_neg_0_05_in_clutch, random_range_bound_0_05_in_clutch), 10.0, 1.0);
float turn_yaw = lerp_unclamped_float(capped_yaw, mult_yaw * yaw_diff, clutch_aim_multiplier_strength);
float turn_pitch = lerp_unclamped_float(capped_pitch, mult_pitch * diff.pitch, clutch_aim_multiplier_strength);
apply_silent_rotation(Rot{turn_yaw, turn_pitch});
}
// Turn back to the real rotation, evenly over the remaining snap-back ticks.
static void snap_back(Ctx *ctx) {
if (clutch_snapback_delay_second > 0)
return;
int ticks_left = clutch_snapback_ticks_left;
if (ticks_left <= 0 || !is_silent_rotation_active())
return;
Rot now = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Rot diff = rot_sub(get_render_rotation(), now);
diff.yaw = wrap_angle(diff.yaw);
apply_silent_rotation(rot_scale(diff, 1.0f / (float)ticks_left));
}
extern "C" void clutch_on_late_tick(Hook *hook) {
clutch_planned = 0;
clutch_rotating = 0;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
unsigned char on_ground = java_get_entity_on_ground(ctx->jvm, ctx->player);
clutch_ticks_since_last_hurt = java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) == 0 ? clutch_ticks_since_last_hurt + 1 : 0;
// Shortly after a clutch, jumping turns the head back at once (with a small random wiggle).
if (clutch_ticks_left_jump_snapback > 0) {
clutch_ticks_left_jump_snapback -= 1;
if (on_ground && is_silent_rotation_active() && clutch_snapback_instantly_on_jump &&
java_get_key_binding_key_code(ctx->jvm, get_held_item(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)))) {
Rot cur = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Rot real = get_render_rotation();
double sign = 0.0 > clutch_jump_wiggle_direction ? 1.0 : -1.0; // wiggle the other way than last time
float wiggle_yaw = (float)((double)random_rotation(rot_make_floats(random_range_bound_5_in_clutch, random_range_bound_15_in_clutch)) * sign);
float wiggle_pitch = (float)((double)random_rotation(rot_make_floats(random_range_bound_5_in_clutch, random_range_bound_15_in_clutch)) * sign);
clutch_jump_wiggle_direction += wiggle_yaw;
Rot diff = rot_sub(rot_add(real, rot_scale(Rot{wiggle_yaw, wiggle_pitch}, clutch_randomisation)), cur);
diff.yaw = wrap_angle(diff.yaw);
apply_silent_rotation(diff);
clutch_rotating = 1;
clutch_snapback_delay_second = (int)clutch_snapback_duration;
return;
}
}
Box player_box = java_get_axis_aligned_bb_min_x(ctx->jvm, java_get_entity_bounding_box(ctx->jvm, ctx->player));
Vec3 eye = java_get_vec3_x_coord(ctx->jvm, java_call_entity_living_base_get_position(ctx->jvm, ctx->player));
Rot cur = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
bool start_aiming = false;
if (should_clutch(ctx, on_ground) && plan_block(ctx, player_box, eye, cur)) {
if (clutch_select_blocks_1_switch_2 == 1)
track_owner(ctx, clutch_module_descriptor, 0);
else if (clutch_select_blocks_1_switch_2 == 2)
track_owner(ctx, clutch_module_descriptor, 1);
clutch_planned = block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player));
if (clutch_planned) {
// Plan the snap back for after the clutch.
float delay_scale = random_rotation(rot_make_floats(1.0f, (float)((double)clutch_randomisation * 0.5 + 1.0)));
clutch_snapback_delay_second = (int)(delay_scale * clutch_snapback_delay);
clutch_ticks_left_jump_snapback = 10;
clutch_disable_module_after_snapback = clutch_disable_after;
start_aiming = true;
}
} else {
clutch_planned = 0;
}
if (!start_aiming) {
// Not clutching: run the snap-back timers.
if (clutch_snapback_delay_second > 0) {
clutch_snapback_delay_second -= 1;
clutch_snapback_ticks_left = (int)clutch_snapback_duration;
} else if (clutch_snapback_ticks_left > 0) {
clutch_snapback_ticks_left -= 1;
clutch_planned = 0;
} else {
// Snap back finished.
if (clutch_disable_module_after_snapback == 1) {
queue_module_toggle(ctx->module_manager, clutch_module_descriptor, 0);
clutch_disable_module_after_snapback = 0;
}
return;
}
}
if (!update_rotation_priority_peak(1000))
return;
clutch_rotating = 1;
if (clutch_planned)
aim_at_planned_block(ctx, eye, cur);
else
snap_back(ctx);
}
+94
View File
@@ -0,0 +1,94 @@
// Clutch — Clutches for you when falling.
// category: block descriptor: 0x2f5580 settings block: 0x2f5778
// functions: gui clutch_gui, register clutch_register
// implementation: src/logic/block/clutch.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_clutch); // "Main"
S(str_aim_in_clutch); // "Aim"
S(str_snap_back); // "Snap-back"
S(str_conditions_in_clutch); // "Conditions"
S(str_range_in_clutch); // "range"
S(str_max_aim_dist); // "max_aim_dist"
S(str_min_height); // "min_height"
S(str_click_speed_in_clutch); // "click_speed"
S(str_randomization_in_clutch); // "randomization"
S(str_select_blocks_in_clutch); // "select_blocks"
S(str_sideways_only); // "sideways_only"
S(str_aim_speed); // "aim_speed"
S(str_aim_mult); // "aim_mult"
S(str_aim_mult_strength); // "aim_mult_strength"
S(str_aim_multipoint); // "aim_multipoint"
S(str_snapback_delay); // "snapback_delay"
S(str_snapback_duration); // "snapback_duration"
S(str_snapback_instant_on_jump); // "snapback_instant_on_jump"
S(str_snapback_disable_after); // "snapback_disable_after"
S(str_require_air_in_clutch); // "require_air"
S(str_require_damage_in_clutch); // "require_damage"
S(str_require_backwards); // "require_backwards"
D(clutch_click_speed_setting); // setting num "click_speed"
D(clutch_snapback_duration_setting); // setting num "snapback_duration"
D(clutch_snapback_delay_setting); // setting num "snapback_delay"
D(clutch_randomization_setting); // setting num "randomization"
D(clutch_aim_speed_setting); // setting num "aim_speed"
D(clutch_aim_mult_setting); // setting num "aim_mult"
D(clutch_aim_mult_strength_setting); // setting num "aim_mult_strength"
D(clutch_snapback_instant_on_jump_setting); // setting bool "snapback_instant_on_jump"
D(clutch_require_air_setting); // setting bool "require_air"
D(clutch_require_damage_setting); // setting bool "require_damage"
D(clutch_require_backwards_setting); // setting bool "require_backwards"
D(clutch_min_height_setting); // setting num "min_height"
D(clutch_range_setting); // setting num "range"
D(clutch_max_aim_dist_setting); // setting num "max_aim_dist"
D(clutch_sideways_only_setting); // setting bool "sideways_only"
D(clutch_aim_multipoint_setting); // setting bool "aim_multipoint"
D(clutch_select_blocks_setting); // setting enum "select_blocks"
D(clutch_snapback_disable_after_setting); // setting bool "snapback_disable_after"
extern "C" void clutch_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_clutch);
W_slider(window, gui, clutch_range_setting);
W_slider(window, gui, clutch_max_aim_dist_setting);
W_slider(window, gui, clutch_min_height_setting);
W_slider(window, gui, clutch_click_speed_setting);
W_slider(window, gui, clutch_randomization_setting);
W_enumw(window, gui, clutch_select_blocks_setting);
W_bool(window, gui, clutch_sideways_only_setting);
W_label(gui, window, str_aim_in_clutch);
W_slider(window, gui, clutch_aim_speed_setting);
W_slider(window, gui, clutch_aim_mult_setting);
W_slider(window, gui, clutch_aim_mult_strength_setting);
W_bool(window, gui, clutch_aim_multipoint_setting);
W_label(gui, window, str_snap_back);
W_slider(window, gui, clutch_snapback_delay_setting);
W_slider(window, gui, clutch_snapback_duration_setting);
W_bool(window, gui, clutch_snapback_instant_on_jump_setting);
W_bool(window, gui, clutch_snapback_disable_after_setting);
W_label(gui, window, str_conditions_in_clutch);
W_bool(window, gui, clutch_require_air_setting);
W_bool(window, gui, clutch_require_damage_setting);
W_bool(window, gui, clutch_require_backwards_setting);
}
extern "C" void clutch_register(void *module) {
R_num(module, str_range_in_clutch, clutch_range_setting);
R_num(module, str_max_aim_dist, clutch_max_aim_dist_setting);
R_num(module, str_min_height, clutch_min_height_setting);
R_num(module, str_click_speed_in_clutch, clutch_click_speed_setting);
R_num(module, str_randomization_in_clutch, clutch_randomization_setting);
R_enum(module, str_select_blocks_in_clutch, clutch_select_blocks_setting);
R_bool(module, str_sideways_only, clutch_sideways_only_setting);
R_num(module, str_aim_speed, clutch_aim_speed_setting);
R_num(module, str_aim_mult, clutch_aim_mult_setting);
R_num(module, str_aim_mult_strength, clutch_aim_mult_strength_setting);
R_bool(module, str_aim_multipoint, clutch_aim_multipoint_setting);
R_num(module, str_snapback_delay, clutch_snapback_delay_setting);
R_num(module, str_snapback_duration, clutch_snapback_duration_setting);
R_bool(module, str_snapback_instant_on_jump, clutch_snapback_instant_on_jump_setting);
R_bool(module, str_snapback_disable_after, clutch_snapback_disable_after_setting);
R_bool(module, str_require_air_in_clutch, clutch_require_air_setting);
R_bool(module, str_require_damage_in_clutch, clutch_require_damage_setting);
R_bool(module, str_require_backwards, clutch_require_backwards_setting);
}
+68
View File
@@ -0,0 +1,68 @@
// Fast Mine - break blocks faster.
//
// Two tricks:
// - the pause between breaking one block and starting the next ("block hit delay") is
// capped at "break_delay", and can count down faster;
// - on the first tick of mining a block, the progress is jumped ahead so the block
// breaks in 1/"speed" of the normal number of ticks.
//
// Callbacks (descriptor slots +0x48 / +0x168):
// fast_mine_on_tick every tick: shorten the block hit delay
// fast_mine_on_late_tick every tick, after mining progress was updated: skip ahead
#include "slinky/engine.h"
// ---- settings ----
extern "C" float fast_mine_break_delay_value; // "break_delay": longest delay allowed (ticks)
extern "C" unsigned char fast_mine_decr_block_hit_delay_value; // "decr_block_hit_delay": count the delay down twice as fast
extern "C" float fast_mine_speed; // "speed": 2 = blocks break in half the ticks
// ---- module state ----
extern "C" int fast_mine_last_block_hit_delay; // block hit delay seen last tick
extern "C" float fast_mine_last_progress_value; // mining progress seen last tick (0 = not mining)
// ---- game / engine functions ----
FN(void *, java_get_minecraft_player_controller, (void *jvm, void *minecraft));
FN(float, java_get_player_controller_mp_cur_block_damage_mp, (void *jvm, void *blk)); // mining progress, 0..1
FN(void, java_set_player_controller_mp_cur_block_damage_mp, (void *jvm, void *blk, float value));
FN(int, java_get_player_controller_mp_block_hit_delay, (void *jvm, void *blk));
FN(void, java_set_player_controller_mp_block_hit_delay, (void *jvm, void *blk, int value));
FN(float, libc_ceilf, (float v));
extern "C" void fast_mine_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
int delay = 0;
void *controller = java_get_minecraft_player_controller(ctx->jvm, ctx->minecraft);
if (controller) {
fast_mine_last_progress_value = java_get_player_controller_mp_cur_block_damage_mp(ctx->jvm, controller);
delay = java_get_player_controller_mp_block_hit_delay(ctx->jvm, controller);
if ((float)delay > fast_mine_break_delay_value) {
// Longer than allowed: cap it.
java_set_player_controller_mp_block_hit_delay(ctx->jvm, controller, (int)fast_mine_break_delay_value);
} else if (delay > 0 && fast_mine_decr_block_hit_delay_value && delay == fast_mine_last_block_hit_delay) {
// The game did not count it down this tick yet: take one off ourselves.
java_set_player_controller_mp_block_hit_delay(ctx->jvm, controller, delay - 1);
}
}
fast_mine_last_block_hit_delay = delay;
}
extern "C" void fast_mine_on_late_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
void *controller = java_get_minecraft_player_controller(ctx->jvm, ctx->minecraft);
if (!controller)
return;
// Only on the first tick of mining a block (progress went from 0 to something).
float progress_per_tick = java_get_player_controller_mp_cur_block_damage_mp(ctx->jvm, controller);
if (progress_per_tick == 0.0f || fast_mine_last_progress_value != 0.0f)
return;
// Ticks the block normally takes, and ticks we want it to take.
long long normal_ticks = (long long)libc_ceilf(1.0f / progress_per_tick);
double wanted = 1.0 / (double)fast_mine_speed / (double)progress_per_tick;
long long wanted_ticks = (long long)libc_ceilf((float)wanted);
// Jump ahead by the difference.
unsigned int ticks_done = (unsigned int)((int)normal_ticks - (int)wanted_ticks + 1);
java_set_player_controller_mp_cur_block_damage_mp(ctx->jvm, controller, (float)(long long)ticks_done * progress_per_tick);
}
+35
View File
@@ -0,0 +1,35 @@
// Fast Mine — Increases block mining speed.
// category: block descriptor: 0x2f1d90 settings block: 0x2f1f88
// functions: gui fast_mine_gui, register fast_mine_register, status fast_mine_status
// implementation: src/logic/block/fast_mine.cpp
#pragma once
#include "slinky/api.h"
S(str_2fx_in_fast_mine); // "%.2fx"
S(str_main_in_fast_mine); // "Main"
S(str_speed_in_fast_mine); // "speed"
S(str_break_delay_in_fast_mine); // "break_delay"
S(str_decr_block_hit_delay); // "decr_block_hit_delay"
D(fast_mine_break_delay_setting); // setting num "break_delay"
D(fast_mine_decr_block_hit_delay_setting); // setting bool "decr_block_hit_delay"
D(fast_mine_speed_setting); // setting num "speed"
extern "C" float fast_mine_speed; // current value of setting "speed" (+0x30)
extern "C" void fast_mine_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_fast_mine);
W_slider(window, gui, fast_mine_speed_setting);
W_slider(window, gui, fast_mine_break_delay_setting);
W_bool(window, gui, fast_mine_decr_block_hit_delay_setting);
}
extern "C" void fast_mine_register(void *module) {
R_num(module, str_speed_in_fast_mine, fast_mine_speed_setting);
R_num(module, str_break_delay_in_fast_mine, fast_mine_break_delay_setting);
R_bool(module, str_decr_block_hit_delay, fast_mine_decr_block_hit_delay_setting);
}
extern "C" void fast_mine_status(void *self) {
log_fmt(self, 0x20, str_2fx_in_fast_mine, (double)fast_mine_speed);
}
+120
View File
@@ -0,0 +1,120 @@
// Fast Place - place blocks quickly while holding right click.
//
// Minecraft repeats right click only every 4 ticks. While you hold the use key, this
// module clicks at "max_cps" clicks per second instead (after "activation_delay" ticks).
// It skips clicks that would put a block inside yourself, except now and then at random.
//
// Callback:
// fast_place_tick every tick
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
// ---- settings ----
extern "C" float fast_place_max_cps; // clicks per second
extern "C" float fast_place_activation_delay; // ticks to hold before clicking starts
// ---- module state ----
extern "C" float fast_place_click_timer; // ticks until the next click
extern "C" unsigned char fast_place_use_key_held_last_tick;
extern "C" int fast_place_activation_delay_left;
extern "C" char fast_place_random_walk_1[]; // random walk state
// Bounds of the random range used to sometimes click anyway (0.02 .. 0.08).
extern "C" const float random_range_bound_0_02, random_range_bound_0_08_in_fast_place;
// ---- game / engine functions ----
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_use_item_key, (void *jvm, void *game_settings));
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(int, java_get_key_binding_press_time, (void *jvm, void *key_binding)); // clicks waiting to be handled
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *hit)); // 1 = a block
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(Vec3, java_get_adjacent_block_position, (void *jvm, void *hit)); // where the new block would go
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Box, aabb_make, (Vec3 lo, Vec3 hi));
FN(void *, java_get_entity_bounding_box, (void *jvm, void *entity));
FN(Box, java_get_axis_aligned_bb_min_x, (void *jvm, void *bounding_box));
FN(unsigned char, aabb_intersects, (Box a, Box b));
FN(Range, rot_make_floats, (float lo, float hi));
FN(unsigned char, walk_should_change, (void *state, Range r, double d)); // random yes/no
enum { ITEM_LADDER = 65 };
// Would a click right now be useful?
static bool should_click(Ctx *ctx) {
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 1)
return walk_should_change(fast_place_random_walk_1, rot_make_floats(random_range_bound_0_02, random_range_bound_0_08_in_fast_place), 20.0);
// Ladders can always be placed.
void *stack = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (stack && java_call_static_item_get_id_from_item(ctx->jvm, stack) == ITEM_LADDER)
return true;
// Only when the new block would not overlap the player (or now and then at random).
Vec3 cell_pos = java_get_adjacent_block_position(ctx->jvm, hit);
Box cell = aabb_make(cell_pos, vec3_add(cell_pos, vec3_make(1.0, 1.0, 1.0)));
Box player_box = java_get_axis_aligned_bb_min_x(ctx->jvm, java_get_entity_bounding_box(ctx->jvm, ctx->player));
return !aabb_intersects(cell, player_box) ||
walk_should_change(fast_place_random_walk_1, rot_make_floats(random_range_bound_0_02, random_range_bound_0_08_in_fast_place), 20.0);
}
extern "C" void fast_place_tick(Hook *hook) {
// Count the click timer down.
float timer = fast_place_click_timer;
if (timer > 0.0f) {
timer += -1.0f;
fast_place_click_timer = timer;
if (timer > 0.0f)
return;
}
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
void *use_key = java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
unsigned char was_held = fast_place_use_key_held_last_tick;
unsigned char held = java_get_key_binding_key_code(ctx->jvm, use_key);
fast_place_use_key_held_last_tick = held;
// Not holding right click: reset the activation delay.
if (!held) {
fast_place_activation_delay_left = (int)fast_place_activation_delay;
return;
}
if (fast_place_activation_delay_left > 0) {
fast_place_activation_delay_left -= 1;
return;
}
// A click is already waiting.
if (java_get_key_binding_press_time(ctx->jvm, use_key) > 0)
return;
timer = fast_place_click_timer;
if (!(0.0f >= timer))
return;
// Click as many times as fit in this tick (more than one at a high cps).
// The very first press clicks by itself, so that one is not repeated.
bool first_press = !was_held;
for (;;) {
timer = (float)((double)timer + 20.0 / (double)fast_place_max_cps); // 20 ticks per second
fast_place_click_timer = timer;
if (!first_press && block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player))) {
if (should_click(ctx))
java_increment_key_binding_press_time(ctx->jvm, use_key);
timer = fast_place_click_timer;
}
first_press = false;
if (!(0.0f >= timer))
return;
}
}
+31
View File
@@ -0,0 +1,31 @@
// Fast Place — Allows placing blocks faster.
// category: block descriptor: 0x2ea2d0 settings block: 0x2ea4c8
// functions: gui fast_place_gui, register fast_place_register, status fast_place_status
// implementation: src/logic/block/fast_place.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_fast_place); // "Main"
S(str_max_cps); // "max_cps"
S(str_activate_delay_in_fast_place); // "activate_delay"
S(str_1f_in_fast_place); // "%.1f"
D(fast_place_max_cps_setting); // setting num "max_cps"
extern "C" float fast_place_max_cps; // current value of setting "max_cps" (+0x30)
D(fast_place_activate_delay_setting); // setting num "activate_delay"
extern "C" void fast_place_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_fast_place);
W_slider(window, gui, fast_place_max_cps_setting);
W_slider(window, gui, fast_place_activate_delay_setting);
}
extern "C" void fast_place_register(void *module) {
R_num(module, str_max_cps, fast_place_max_cps_setting);
R_num(module, str_activate_delay_in_fast_place, fast_place_activate_delay_setting);
}
extern "C" void fast_place_status(void *self) {
log_fmt(self, 0x20, str_1f_in_fast_place, (double)fast_place_max_cps);
}
+89
View File
@@ -0,0 +1,89 @@
// Ghost Hand - click through entities (hit/use the block behind them).
//
// When the crosshair is on an entity, the engine asks ghost_hand_should_ignore_entity.
// If it returns 1, the entity is ignored and the click goes to whatever is behind it.
// The settings choose which held items and which kinds of entities this applies to.
//
// Callbacks:
// ghost_hand_should_ignore_entity engine query for one entity
// ghost_hand_on_reach_query descriptor slot +0xc8: mark the module as active
#include "slinky/engine.h"
// A boolean setting stored as a full setting record; the value is at +0x18.
struct Setting { char padding_00[0x18]; unsigned char on; };
// ---- settings ----
extern "C" unsigned char ghost_hand_module_enabled;
extern "C" unsigned char ghost_hand_require_mouse_setting; // "require_mouse_pressed"
extern "C" unsigned char ghost_hand_allow_with_fists; // "allow_using_fists"
extern "C" unsigned char ghost_hand_swords; // "allow_using_sword"
extern "C" unsigned char ghost_hand_tools; // "allow_using_tools"
extern "C" unsigned char ghost_hand_bows; // "allow_using_buckets"
extern "C" unsigned char ghost_hand_flint_steel; // "allow_using_fns" (flint and steel)
extern "C" unsigned char ghost_hand_cobweb; // "allow_using_cobweb"
extern "C" unsigned char ghost_hand_other_items; // "allow_using_other"
extern "C" unsigned char ghost_hand_non_living_entities; // "non_players": ignore entities that are not players
extern "C" Setting ghost_hand_bots_setting; // "bots": ignore players marked as bots
extern "C" Setting ghost_hand_friendlies_setting; // "friendlies": ignore friends and teammates
extern "C" Setting ghost_hand_enemies_setting; // "enemies": ignore everyone else
// ---- game / engine functions ----
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(void *, java_jni_is_instance_of_entity_other_player_mp, (void *jvm, void *candidate)); // the entity as a player, or null
FN(unsigned, entity_flags_get, (void *jvm, void *t)); // bit 1/4: friend/teammate, bit 2: bot
// Is the item in your hand allowed by the settings?
static bool held_item_allowed(Ctx *ctx) {
void *held = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (!held)
return ghost_hand_allow_with_fists == 1;
switch (java_call_static_item_get_id_from_item(ctx->jvm, held)) {
// shovels, pickaxes, axes (iron, wood, stone, diamond, gold) and shears
case 256: case 257: case 258:
case 269: case 270: case 271:
case 273: case 274: case 275:
case 277: case 278: case 279:
case 284: case 285: case 286:
case 359:
return ghost_hand_tools == 1;
// swords (iron, wood, stone, diamond, gold)
case 267: case 268: case 272: case 276: case 283:
return ghost_hand_swords == 1;
// bucket, water bucket, lava bucket
case 325: case 326: case 327:
return ghost_hand_bows == 1;
case 259: // flint and steel
return ghost_hand_flint_steel == 1;
case 30: // cobweb
return ghost_hand_cobweb == 1;
default:
return ghost_hand_other_items == 1;
}
}
extern "C" unsigned char ghost_hand_should_ignore_entity(Ctx *ctx, void *entity) {
if (ghost_hand_module_enabled != 1)
return 0;
if (ghost_hand_require_mouse_setting == 1 && !vertex_pointer_current(ctx))
return 0;
if (!held_item_allowed(ctx))
return 0;
void *player = java_jni_is_instance_of_entity_other_player_mp(ctx->jvm, entity);
if (!player)
return ghost_hand_non_living_entities;
// Bots first, then friends/teammates, then everyone else.
unsigned flags = entity_flags_get(ctx->jvm, player);
if (flags & 2)
return ghost_hand_bots_setting.on;
if (flags & 5)
return ghost_hand_friendlies_setting.on;
return ghost_hand_enemies_setting.on;
}
extern "C" void ghost_hand_on_reach_query(char *s) {
s[0x10] = 1;
}
+68
View File
@@ -0,0 +1,68 @@
// Ghost Hand — Allows interacting with blocks through entities.
// category: block descriptor: 0x2f48b0 settings block: 0x2f4aa8
// functions: gui ghost_hand_gui, register ghost_hand_register
// implementation: src/logic/block/ghost_hand.cpp
#pragma once
#include "slinky/api.h"
S(str_interact_through); // "Interact through"
S(str_allow_while_using_in_ghost_hand); // "Allow while using"
S(str_conditions_in_ghost_hand); // "Conditions"
S(str_non_players_in_ghost_hand); // "non_players"
S(str_friendlies_in_ghost_hand); // "friendlies"
S(str_bots_in_ghost_hand); // "bots"
S(str_enemies_in_ghost_hand); // "enemies"
S(str_allow_using_sword_in_ghost_hand); // "allow_using_sword"
S(str_allow_using_tools_in_ghost_hand); // "allow_using_tools"
S(str_allow_using_fists_in_ghost_hand); // "allow_using_fists"
S(str_allow_using_buckets); // "allow_using_buckets"
S(str_allow_using_fns); // "allow_using_fns"
S(str_allow_using_cobweb); // "allow_using_cobweb"
S(str_allow_using_other_in_ghost_hand); // "allow_using_other"
S(str_require_mouse_pressed_in_ghost_hand); // "require_mouse_pressed"
D(ghost_hand_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
D(ghost_hand_allow_using_fists_setting); // setting bool "allow_using_fists"
D(ghost_hand_allow_using_sword_setting); // setting bool "allow_using_sword"
D(ghost_hand_allow_using_tools_setting); // setting bool "allow_using_tools"
D(ghost_hand_allow_using_buckets_setting); // setting bool "allow_using_buckets"
D(ghost_hand_allow_using_fns_setting); // setting bool "allow_using_fns"
D(ghost_hand_allow_using_cobweb_setting); // setting bool "allow_using_cobweb"
D(ghost_hand_allow_using_other_setting); // setting bool "allow_using_other"
D(ghost_hand_non_players_setting); // setting bool "non_players"
D(ghost_hand_bots_setting); // setting bool "bots"
D(ghost_hand_friendlies_setting); // setting bool "friendlies"
D(ghost_hand_enemies_setting); // setting bool "enemies"
extern "C" void ghost_hand_gui(void *gui, void *window) {
W_label(gui, window, str_interact_through);
W_bool(window, gui, ghost_hand_non_players_setting);
W_bool(window, gui, ghost_hand_friendlies_setting);
W_bool(window, gui, ghost_hand_bots_setting);
W_bool(window, gui, ghost_hand_enemies_setting);
W_label(gui, window, str_allow_while_using_in_ghost_hand);
W_bool(window, gui, ghost_hand_allow_using_sword_setting);
W_bool(window, gui, ghost_hand_allow_using_tools_setting);
W_bool(window, gui, ghost_hand_allow_using_fists_setting);
W_bool(window, gui, ghost_hand_allow_using_buckets_setting);
W_bool(window, gui, ghost_hand_allow_using_fns_setting);
W_bool(window, gui, ghost_hand_allow_using_cobweb_setting);
W_bool(window, gui, ghost_hand_allow_using_other_setting);
W_label(gui, window, str_conditions_in_ghost_hand);
W_bool(window, gui, ghost_hand_require_mouse_pressed_setting);
}
extern "C" void ghost_hand_register(void *module) {
R_bool(module, str_non_players_in_ghost_hand, ghost_hand_non_players_setting);
R_bool(module, str_friendlies_in_ghost_hand, ghost_hand_friendlies_setting);
R_bool(module, str_bots_in_ghost_hand, ghost_hand_bots_setting);
R_bool(module, str_enemies_in_ghost_hand, ghost_hand_enemies_setting);
R_bool(module, str_allow_using_sword_in_ghost_hand, ghost_hand_allow_using_sword_setting);
R_bool(module, str_allow_using_tools_in_ghost_hand, ghost_hand_allow_using_tools_setting);
R_bool(module, str_allow_using_fists_in_ghost_hand, ghost_hand_allow_using_fists_setting);
R_bool(module, str_allow_using_buckets, ghost_hand_allow_using_buckets_setting);
R_bool(module, str_allow_using_fns, ghost_hand_allow_using_fns_setting);
R_bool(module, str_allow_using_cobweb, ghost_hand_allow_using_cobweb_setting);
R_bool(module, str_allow_using_other_in_ghost_hand, ghost_hand_allow_using_other_setting);
R_bool(module, str_require_mouse_pressed_in_ghost_hand, ghost_hand_require_mouse_pressed_setting);
}