Начинающий
- Статус
- Оффлайн
- Регистрация
- 27 Май 2024
- Сообщения
- 31
- Реакции
- 0
- Выберите загрузчик игры
- Fabric
хз спайдер срилиона под все серваки
java:
package releon.module.movement;
import java.util.Comparator;
import java.util.stream.Stream;
import releon.event.EventHandler;
import releon.event.MotionUpdateEvent;
import releon.event.TickEvent;
import releon.module.ModuleBase;
import releon.module.ModuleCategory;
import releon.setting.ModeSetting;
import releon.util.GameTimer;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.CarpetBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket;
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.RaycastContext;
public class Spider extends ModuleBase {
private final GameTimer jumpDelay = new GameTimer();
private final GameTimer carpetDelay = new GameTimer();
private final GameTimer iceDelay = new GameTimer();
private final ModeSetting modeSetting = createModeSetting();
private int slimeJumpCooldown;
private long lastWaterBucketUse;
private boolean touchingWall;
public Spider() {
super("Spider", ModuleCategory.MOVEMENT);
this.registerSettings(this.modeSetting);
}
@Override
public void bk() {
Spider.mc.options.jumpKey.setPressed(false);
Spider.mc.options.sneakKey.setPressed(false);
this.lastWaterBucketUse = 0L;
this.touchingWall = false;
}
@EventHandler
public void onMovementUpdate(MotionUpdateEvent event) {
if (Spider.mc.player == null || Spider.mc.world == null) {
return;
}
if (this.isMode("SpookyTime")) {
this.handleSpookyTimeWaterBucketClimb();
return;
}
if (!this.isMode("FunSky")) {
return;
}
this.touchingWall = Spider.mc.player.horizontalCollision;
this.handleFunSkyWaterBucketClimb();
if (!this.touchingWall) {
Spider.mc.options.sneakKey.setPressed(false);
}
}
@EventHandler
public void onTick(TickEvent event) {
if (Spider.mc.player == null || Spider.mc.world == null) {
return;
}
if (this.isMode("FunTime")) {
this.handleFunTime();
}
if (this.isMode("Slime Block")) {
this.handleSlimeBlock();
}
if (this.isMode("Ice Walk")) {
this.handleIceWalk();
}
if (this.isMode("FunTime Fly")) {
this.handleFunTimeFly();
}
if (this.isMode("Grief Carpet")) {
this.handleGriefCarpet();
}
}
private boolean isMode(String modeName) {
return this.isSelectedMode(this.modeSetting, modeName);
}
private void handleFunTime() {
Spider.mc.options.jumpKey.setPressed(Spider.mc.options.forwardKey.isPressed());
Spider.mc.player.setPitch(75.0f);
if (!Spider.mc.player.horizontalCollision) {
return;
}
if (!this.hasElapsed(this.jumpDelay, 300.0)) {
return;
}
Spider.mc.player.setOnGround(true);
Spider.mc.player.jump();
int wheatSlot = this.findHotbarSlot(Items.WHEAT);
if (wheatSlot != -1) {
this.useWheatOnCrosshairBlock(wheatSlot);
Spider.mc.player.fallDistance = 0.0f;
this.resetTimer(this.jumpDelay);
return;
}
this.notifyUser("Нужна Пшеница ", 3000L);
this.disableModule();
}
private void handleSlimeBlock() {
BlockPos playerPos = Spider.mc.player.getBlockPos();
BlockPos[] adjacentBlocks = new BlockPos[]{
playerPos.east(),
playerPos.west(),
playerPos.north(),
playerPos.south()
};
boolean slimeNearby = false;
for (BlockPos adjacentPos : adjacentBlocks) {
if (Spider.mc.world.getBlockState(adjacentPos).getBlock() != Blocks.SLIME_BLOCK) {
continue;
}
slimeNearby = true;
break;
}
if (!slimeNearby || !Spider.mc.player.horizontalCollision || Spider.mc.player.getVelocity().y <= -1.0) {
return;
}
HitResult hitResult = Spider.mc.crosshairTarget;
if (!(hitResult instanceof BlockHitResult)) {
return;
}
BlockHitResult blockHitResult = (BlockHitResult)hitResult;
BlockPos targetPos = blockHitResult.getBlockPos();
if (Spider.mc.world.getBlockState(targetPos).getBlock() == Blocks.AIR) {
return;
}
int slimeSlot = this.findHotbarSlot(Items.SLIME_BLOCK);
if (slimeSlot == -1) {
return;
}
Spider.mc.player.getInventory().selectedSlot = slimeSlot;
Spider.mc.player.setPitch(54.0f);
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, blockHitResult);
Spider.mc.player.swingHand(Hand.MAIN_HAND);
if (this.slimeJumpCooldown >= 1) {
Spider.mc.player.setVelocity(Spider.mc.player.getVelocity().x, 0.63, Spider.mc.player.getVelocity().z);
this.slimeJumpCooldown = 0;
} else {
++this.slimeJumpCooldown;
}
}
private void handleIceWalk() {
Spider.mc.player.setPitch(90.0f);
int blockSlot = this.findIceOrSoulSandSlot();
if (blockSlot == -1) {
return;
}
this.placeBlockBelowPlayer(blockSlot);
}
private void handleFunTimeFly() {
if (!Spider.mc.player.horizontalCollision) {
return;
}
if (!this.hasElapsed(this.jumpDelay, 1.0)) {
return;
}
Spider.mc.player.setOnGround(true);
Spider.mc.player.jump();
int lightningRodSlot = this.ensureHotbarSlot(Items.LIGHTNING_ROD);
if (lightningRodSlot != -1) {
this.placeLightningRodsAbovePlayer(lightningRodSlot);
Spider.mc.player.fallDistance = 0.0f;
this.resetTimer(this.jumpDelay);
return;
}
this.notifyUser("Нужен громоотвод", 3000L);
}
private void handleFunSkyWaterBucketClimb() {
int waterBucketSlot = this.findHotbarSlot(Items.WATER_BUCKET);
if (waterBucketSlot == -1) {
return;
}
if (Spider.mc.player.isTouchingWater()) {
Spider.mc.player.setVelocity(Spider.mc.player.getVelocity().x, 0.46, Spider.mc.player.getVelocity().z);
return;
}
if (Spider.mc.player.isOnGround()) {
this.lastWaterBucketUse = 0L;
this.resetTimer(this.jumpDelay);
return;
}
if (!this.hasElapsed(this.jumpDelay, 120.0)) {
return;
}
if (!this.touchingWall) {
Spider.mc.options.jumpKey.setPressed(false);
Spider.mc.options.sneakKey.setPressed(false);
return;
}
long now = System.currentTimeMillis();
if (now - this.lastWaterBucketUse < this.getWaterBucketReuseDelayMs()) {
return;
}
Spider.mc.options.jumpKey.setPressed(true);
this.useWaterBucketLookingDown(waterBucketSlot);
Spider.mc.options.sneakKey.setPressed(true);
this.lastWaterBucketUse = now;
}
private void handleSpookyTimeWaterBucketClimb() {
int waterBucketSlot = this.findHotbarSlot(Items.WATER_BUCKET);
if (waterBucketSlot == -1) {
return;
}
if (!Spider.mc.player.horizontalCollision) {
return;
}
this.sendUseItemPacketForHotbarSlot(waterBucketSlot);
Spider.mc.player.setVelocity(Spider.mc.player.getVelocity().x, 0.29, Spider.mc.player.getVelocity().z);
}
private void useWheatOnCrosshairBlock(int wheatSlot) {
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
Spider.mc.player.getInventory().selectedSlot = wheatSlot;
Spider.mc.player.setPitch(75.0f);
BlockHitResult hitResult = this.raycastFromRotation(Spider.mc.player.getYaw(), 75.0f, 4.5);
if (hitResult.getType() == HitResult.Type.BLOCK) {
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
}
Spider.mc.player.getInventory().selectedSlot = previousSlot;
}
private void useWaterBucketLookingDown(int waterBucketSlot) {
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
float previousPitch = Spider.mc.player.getPitch();
Spider.mc.player.getInventory().selectedSlot = waterBucketSlot;
Spider.mc.player.setPitch(-90.0f);
Spider.mc.player.networkHandler.sendPacket((Packet)new PlayerInteractItemC2SPacket(
Hand.MAIN_HAND,
0,
Spider.mc.player.getYaw(),
Spider.mc.player.getPitch()
));
Spider.mc.player.setVelocity(Spider.mc.player.getVelocity().x, 0.45, Spider.mc.player.getVelocity().z);
Spider.mc.player.setPitch(previousPitch);
Spider.mc.player.getInventory().selectedSlot = previousSlot;
}
private long getWaterBucketReuseDelayMs() {
double distanceToGround = this.getDistanceToGround();
if (distanceToGround < 5.0) {
return 450L;
}
if (distanceToGround < 20.0) {
return 550L;
}
return 650L;
}
private double getDistanceToGround() {
double playerY = Spider.mc.player.getY();
for (double scanY = playerY; scanY > (double)Spider.mc.world.getBottomY(); scanY -= 0.1) {
BlockPos scanPos = BlockPos.ofFloored(Spider.mc.player.getX(), scanY, Spider.mc.player.getZ());
if (Spider.mc.world.getBlockState(scanPos).isAir()) {
continue;
}
return Math.max(playerY - (scanY + 1.0), 0.0);
}
return 0.0;
}
private void useSlotTemporarilyOnCrosshair(Slot slot) {
this.swapSlotToMainHand(slot, true);
this.syncSelectedSlot();
Spider.mc.player.setPitch(75.0f);
BlockHitResult hitResult = this.raycastFromRotation(Spider.mc.player.getYaw(), 75.0f, 4.5);
if (hitResult.getType() == HitResult.Type.BLOCK) {
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
}
this.swapSlotToMainHand(slot, true);
}
private Slot findLilyPadSlot() {
return this.streamInventorySlots()
.sorted(Comparator.comparing(slot -> slot.equals(this.getSelectedInventorySlot())))
.filter(slot -> slot.getStack().getItem() == Items.LILY_PAD)
.findFirst()
.orElse(null);
}
private int findIceOrSoulSandSlot() {
for (int slot = 0; slot < 9; ++slot) {
Item item = Spider.mc.player.getInventory().getStack(slot).getItem();
if (item == Items.ICE || item == Items.PACKED_ICE || item == Items.BLUE_ICE || item == Items.SOUL_SAND) {
return slot;
}
}
return -1;
}
private void placeReplaceableBlockBelow(int blockSlot) {
BlockPos placePos = Spider.mc.player.getBlockPos().down();
if (!Spider.mc.world.getBlockState(placePos).isReplaceable()) {
return;
}
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
Spider.mc.player.getInventory().selectedSlot = blockSlot;
Spider.mc.player.setPitch(80.0f);
BlockHitResult hitResult = this.raycastFromRotation(Spider.mc.player.getYaw(), 80.0f, 4.5);
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
Spider.mc.player.swingHand(Hand.MAIN_HAND);
Spider.mc.player.getInventory().selectedSlot = previousSlot;
}
private void placeAgainstFacingDirection(int blockSlot) {
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
Spider.mc.player.getInventory().selectedSlot = blockSlot;
Spider.mc.player.setPitch(80.0f);
Direction facing = Spider.mc.player.getHorizontalFacing();
float yaw = switch (facing) {
case NORTH -> 180.0f;
case SOUTH -> 0.0f;
case WEST -> 90.0f;
case EAST -> 270.0f;
default -> Spider.mc.player.getYaw();
};
Spider.mc.player.setYaw(yaw);
BlockHitResult hitResult = this.raycastFromRotation(yaw, 80.0f, 4.5);
if (hitResult.getType() == HitResult.Type.BLOCK) {
Spider.mc.player.swingHand(Hand.MAIN_HAND);
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
}
Spider.mc.player.getInventory().selectedSlot = previousSlot;
}
private void placeLightningRodsAbovePlayer(int lightningRodSlot) {
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
Spider.mc.player.getInventory().selectedSlot = lightningRodSlot;
BlockPos playerPos = Spider.mc.player.getBlockPos();
for (int offset = 1; offset <= 2; ++offset) {
BlockPos placePos = playerPos.up(offset);
if (!Spider.mc.world.getBlockState(placePos).isAir()) {
continue;
}
this.placeBlockAt(placePos);
}
Spider.mc.player.getInventory().selectedSlot = previousSlot;
}
private void placeBlockAt(BlockPos placePos) {
if (!Spider.mc.world.getBlockState(placePos).isAir()) {
return;
}
Vec3d hitPos = new Vec3d(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5);
BlockHitResult hitResult = new BlockHitResult(hitPos, Direction.UP, placePos.down(), false);
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
Spider.mc.player.swingHand(Hand.MAIN_HAND);
}
private int findHotbarSlot(Item item) {
for (int slot = 0; slot < 9; ++slot) {
if (Spider.mc.player.getInventory().getStack(slot).getItem() == item) {
return slot;
}
}
return -1;
}
private int findInventorySlot(Item item) {
for (int slot = 9; slot < 36; ++slot) {
if (Spider.mc.player.getInventory().getStack(slot).getItem() == item) {
return slot;
}
}
return -1;
}
private int ensureHotbarSlot(Item item) {
int hotbarSlot = this.findHotbarSlot(item);
if (hotbarSlot != -1) {
return hotbarSlot;
}
int inventorySlot = this.findInventorySlot(item);
if (inventorySlot == -1) {
return -1;
}
int selectedSlot = Spider.mc.player.getInventory().selectedSlot;
Spider.mc.interactionManager.clickSlot(
Spider.mc.player.playerScreenHandler.syncId,
inventorySlot,
selectedSlot,
SlotActionType.SWAP,
(PlayerEntity)Spider.mc.player
);
return selectedSlot;
}
private void handleGriefCarpet() {
int carpetSlot = this.findHotbarCarpetSlot();
if (carpetSlot == -1) {
return;
}
BlockPos playerPos = Spider.mc.player.getBlockPos();
BlockPos belowPos = playerPos.down();
if (!Spider.mc.player.isOnGround()
&& Spider.mc.world.getBlockState(playerPos).isAir()
&& !Spider.mc.world.getBlockState(belowPos).isAir()
&& this.hasElapsed(this.carpetDelay, 1.0)) {
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
float previousYaw = Spider.mc.player.getYaw();
float previousPitch = Spider.mc.player.getPitch();
Spider.mc.player.getInventory().selectedSlot = carpetSlot;
this.interactWithBlockFace(belowPos, Direction.UP);
Spider.mc.player.setYaw(previousYaw);
Spider.mc.player.setPitch(previousPitch);
Spider.mc.player.getInventory().selectedSlot = previousSlot;
this.resetTimer(this.carpetDelay);
}
BlockPos carpetPos = Spider.mc.player.getBlockPos().down();
if (Spider.mc.player.isOnGround() && Spider.mc.world.getBlockState(carpetPos).getBlock() instanceof CarpetBlock) {
Spider.mc.player.networkHandler.sendPacket((Packet)new PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK,
carpetPos,
Direction.UP
));
Spider.mc.player.jump();
Vec3d velocity = Spider.mc.player.getVelocity();
Spider.mc.player.setVelocity(velocity.x, 0.4, velocity.z);
}
}
private void placeBlockBelowPlayer(int blockSlot) {
BlockPos replacePos = Spider.mc.player.getBlockPos().down();
BlockPos supportPos = replacePos.down();
if (!Spider.mc.world.getBlockState(replacePos).isReplaceable()) {
return;
}
if (Spider.mc.world.getBlockState(supportPos).isAir()) {
return;
}
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
Spider.mc.player.getInventory().selectedSlot = blockSlot;
Spider.mc.player.setPitch(90.0f);
Vec3d hitPos = new Vec3d(supportPos.getX() + 0.5, supportPos.getY() + 1.0, supportPos.getZ() + 0.5);
BlockHitResult hitResult = new BlockHitResult(hitPos, Direction.UP, supportPos, false);
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
Spider.mc.player.getInventory().selectedSlot = previousSlot;
}
private void rotateToward(BlockPos blockPos) {
Vec3d eyes = Spider.mc.player.getEyePos();
Vec3d center = Vec3d.ofCenter((Vec3i)blockPos);
double deltaX = center.x - eyes.x;
double deltaY = center.y - eyes.y;
double deltaZ = center.z - eyes.z;
double horizontalLength = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
float yaw = (float)Math.toDegrees(Math.atan2(deltaZ, deltaX)) - 90.0f;
float pitch = (float)(-Math.toDegrees(Math.atan2(deltaY, horizontalLength)));
Spider.mc.player.setYaw(yaw);
Spider.mc.player.setPitch(pitch);
}
private void interactWithBlockFace(BlockPos blockPos, Direction side) {
this.rotateToward(blockPos);
Vec3d hitPos = Vec3d.ofCenter((Vec3i)blockPos);
BlockHitResult hitResult = new BlockHitResult(hitPos, side, blockPos, false);
Spider.mc.interactionManager.interactBlock(Spider.mc.player, Hand.MAIN_HAND, hitResult);
Spider.mc.player.swingHand(Hand.MAIN_HAND);
}
private BlockHitResult raycastFromRotation(float yaw, float pitch, double range) {
Vec3d eyes = Spider.mc.player.getEyePos();
Vec3d direction = Vec3d.fromPolar(pitch, yaw).normalize();
Vec3d end = eyes.add(direction.multiply(range));
RaycastContext raycast = new RaycastContext(
eyes,
end,
RaycastContext.ShapeType.OUTLINE,
RaycastContext.FluidHandling.NONE,
(Entity)Spider.mc.player
);
return Spider.mc.world.raycast(raycast);
}
private void sendUseItemPacketForHotbarSlot(int slot) {
int previousSlot = Spider.mc.player.getInventory().selectedSlot;
if (slot != previousSlot) {
Spider.mc.player.networkHandler.sendPacket((Packet)new UpdateSelectedSlotC2SPacket(slot));
}
Spider.mc.player.networkHandler.sendPacket((Packet)new PlayerInteractItemC2SPacket(
Hand.MAIN_HAND,
0,
Spider.mc.player.getYaw(),
Spider.mc.player.getPitch()
));
if (slot != previousSlot) {
Spider.mc.player.networkHandler.sendPacket((Packet)new UpdateSelectedSlotC2SPacket(previousSlot));
}
}
private static ModeSetting createModeSetting() {
return SpiderClientBridge.createModeSetting(
"Mode",
"Select mode",
"FunTime",
"FunTime",
"FunSky",
"FunTime Fly",
"Slime Block",
"SpookyTime"
);
}
private void registerSettings(ModeSetting... settings) {
SpiderClientBridge.registerSettings(this, settings);
}
private boolean isSelectedMode(ModeSetting setting, String modeName) {
return SpiderClientBridge.isSelectedMode(setting, modeName);
}
private boolean hasElapsed(GameTimer timer, double milliseconds) {
return SpiderClientBridge.hasElapsed(timer, milliseconds);
}
private void resetTimer(GameTimer timer) {
SpiderClientBridge.resetTimer(timer);
}
private void notifyUser(String message, long durationMs) {
SpiderClientBridge.notifyUser(message, durationMs);
}
private void disableModule() {
SpiderClientBridge.disableModule(this);
}
private Stream<Slot> streamInventorySlots() {
return SpiderClientBridge.streamInventorySlots();
}
private Slot getSelectedInventorySlot() {
return SpiderClientBridge.getSelectedInventorySlot();
}
private void swapSlotToMainHand(Slot slot, boolean swapBack) {
SpiderClientBridge.swapSlotToMainHand(slot, swapBack);
}
private void syncSelectedSlot() {
SpiderClientBridge.syncSelectedSlot();
}
private int findHotbarCarpetSlot() {
for (int slot = 0; slot < 9; ++slot) {
ItemStack stack = Spider.mc.player.getInventory().getStack(slot);
if (stack.isEmpty()) {
continue;
}
Item item = stack.getItem();
if (!(item instanceof BlockItem)) {
continue;
}
Block block = ((BlockItem)item).getBlock();
if (block instanceof CarpetBlock) {
return slot;
}
}
return -1;
}
}