Files
bucket/redstoneclient.java

92 lines
3.5 KiB
Java

/*
* The MIT License (MIT)
*
* Copyright (c) 2025 iloveredston0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.iloveredston0.redstoneclient.client;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class RedstoneclientClient implements ClientModInitializer {
private static KeyBinding killAuraKey;
private boolean killAuraActive = false;
@Override
public void onInitializeClient() {
killAuraKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.redstoneclient.killaura",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_V,
"category.redstoneclient.combat"
));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (killAuraKey.wasPressed()) {
killAuraActive = !killAuraActive;
ClientPlayerEntity player = client.player;
if (player != null) {
player.sendMessage(Text.of("Killaura " + (killAuraActive ? "aktiviert" : "deaktiviert")), true);
}
}
if (killAuraActive) {
attackNearestEntity(client);
}
});
}
private void attackNearestEntity(MinecraftClient client) {
ClientPlayerEntity player = client.player;
if (player == null || client.world == null) return;
List<Entity> nearbyEntities = client.world.getEntitiesByClass(
Entity.class,
player.getBoundingBox().expand(6.0),
entity -> entity != player && !entity.isSpectator() && entity.isAlive()
);
if (!nearbyEntities.isEmpty()) {
nearbyEntities.sort(Comparator.comparingDouble(entity ->
entity.squaredDistanceTo(player)));
Entity target = nearbyEntities.get(0);
client.interactionManager.attackEntity(player, target);
player.swingHand(player.getActiveHand());
}
}
}