Skip to content

Commit

Permalink
Merge branch 'back'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Oct 27, 2023
2 parents 2de1a2f + 84fbb00 commit 38f80d2
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.20.1+build.9
loader_version=0.14.21

# Mod Properties
mod_version=1.5.4
mod_version=1.5.5
maven_group=dev.dfonline
archives_base_name=CodeClient

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import dev.dfonline.codeclient.action.Action;
import dev.dfonline.codeclient.action.None;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.dev.BuildClip;
import dev.dfonline.codeclient.dev.ChestPeeker;
import dev.dfonline.codeclient.dev.*;
import dev.dfonline.codeclient.dev.Debug.Debug;
import dev.dfonline.codeclient.dev.DevInventory.DevInventoryScreen;
import dev.dfonline.codeclient.dev.NoClip;
import dev.dfonline.codeclient.dev.RecentChestInsert;
import dev.dfonline.codeclient.location.Dev;
import dev.dfonline.codeclient.location.Location;
import dev.dfonline.codeclient.location.Spawn;
Expand Down Expand Up @@ -72,8 +69,9 @@ public static <T extends PacketListener> boolean handlePacket(Packet<T> packet)
if(currentAction.onReceivePacket(packet)) return true;
if(Debug.handlePacket(packet)) return true;
if(BuildClip.handlePacket(packet)) return true;
Event.handlePacket(packet);
if(ChestPeeker.handlePacket(packet)) return true;
Event.handlePacket(packet);
LastPos.handlePacket(packet);

String name = packet.getClass().getName().replace("net.minecraft.network.packet.s2c.play.","");
// if(!List.of("PlayerListS2CPacket","WorldTimeUpdateS2CPacket","GameMessageS2CPacket","KeepAliveS2CPacket", "ChunkDataS2CPacket", "UnloadChunkS2CPacket","TeamS2CPacket", "ChunkRenderDistanceCenterS2CPacket", "MessageHeaderS2CPacket", "LightUpdateS2CPacket", "OverlayMessageS2CPacket").contains(name)) LOGGER.info(name);
Expand All @@ -83,6 +81,20 @@ public static <T extends PacketListener> boolean handlePacket(Packet<T> packet)
return false;
}

/**
* This needs to be true for NoClip to work.
* Whilst this should be the first source to check if NoClip is on, keep in mind there is NoClip#isIgnoringWalls
* Useful for fallback checks and preventing noclip packet spam screwing you over.
*/
public static boolean noClipOn() {
if(MC.player == null) return false;
if(!Config.getConfig().NoClipEnabled) return false;
if(!(location instanceof Dev)) return false;
if(!(currentAction instanceof None)) return false;
if(!MC.player.getAbilities().creativeMode) return false;
return true;
}

/**
* All outgoing packet events and debugging.
* @return If the packet shouldn't be sent. True to not send.
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/dev/dfonline/codeclient/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import com.mojang.brigadier.CommandDispatcher;
import dev.dfonline.codeclient.action.None;
import dev.dfonline.codeclient.action.impl.*;
import dev.dfonline.codeclient.action.impl.GetActionDump;
import dev.dfonline.codeclient.action.impl.GetPlotSize;
import dev.dfonline.codeclient.action.impl.MoveToSpawn;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.dev.BuildClip;
import dev.dfonline.codeclient.dev.LastPos;
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.location.Creator;
import dev.dfonline.codeclient.location.Dev;
import dev.dfonline.codeclient.location.Plot;
import dev.dfonline.codeclient.websocket.SocketHandler;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.nio.file.Path;

Expand Down Expand Up @@ -102,7 +105,27 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
return 0;
}));


dispatcher.register(literal("back").executes(context -> {
if(CodeClient.location instanceof Creator plot) {
if(plot.devPos == null) {
Utility.sendMessage("There is no position to go back to!", ChatType.FAIL);
return 1;
}
if(!(CodeClient.currentAction instanceof None)) {
Utility.sendMessage("CodeClient is currently busy, try again in a moment.",ChatType.FAIL);
return 1;
}
if(LastPos.tpBack()) return 0;
else {
Utility.sendMessage("An error occurred whilst trying to go back.",ChatType.FAIL);
return 1;
}
}
else {
Utility.sendMessage("You must be in dev or build mode to do this!",ChatType.FAIL);
return 1;
}
}));

dispatcher.register(literal("getspawn").executes(context -> {
if(!(CodeClient.location instanceof Dev)) return 1;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/dev/dfonline/codeclient/MoveToLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public void setPos(Vec3d pos) {
setPos(pos.x, pos.y, pos.z);
}
public void setPos(double x, double y, double z) {
if(CodeClient.MC.getNetworkHandler() == null) return;
if(new Vec3d(x,y,x).distanceTo(player.getPos()) > 10) {
// I've always done it like this, problems?
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
}
this.player.setPos(x, y, z);
this.player.teleport(x, y, z);
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(x, y, z, false));
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/dev/dfonline/codeclient/action/impl/GoTo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package dev.dfonline.codeclient.action.impl;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.action.Action;
import dev.dfonline.codeclient.location.Dev;
import dev.dfonline.codeclient.hypercube.item.Location;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.network.packet.c2s.play.TeleportConfirmC2SPacket;
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

public class GoTo extends Action {
public final Vec3d target;
/**
* If not null, we are using a location item to teleport.
*/
private ItemStack locationItem;
private boolean active;
private int buffer = 0;

public GoTo(Vec3d target, Callback callback) {
super(callback);
this.target = target;
}

@Override
public void init() {
active = true;
if(CodeClient.MC.player == null) return;
if(CodeClient.location instanceof Dev dev && dev.isInArea(target)) {
locationItem = new Location(dev.getPos().relativize(target)).setRotation(CodeClient.MC.player.getPitch(), CodeClient.MC.player.getYaw()).toItemStack();
locationItemTeleport();
}
}

@Override
public boolean onReceivePacket(Packet<?> packet) {
if(locationItem == null) return super.onReceivePacket(packet);
if(packet instanceof PlayerPositionLookS2CPacket tp) {
if(CodeClient.MC.getNetworkHandler() == null || CodeClient.MC.player == null) return false;
CodeClient.MC.getNetworkHandler().sendPacket(new TeleportConfirmC2SPacket(tp.getTeleportId()));
CodeClient.MC.player.setPosition(target);
active = false;
callback();
return true;
}
return false;
}

@Override
public void onTick() {
if(CodeClient.MC.player == null || CodeClient.MC.getNetworkHandler() == null) {
callback();
return;
}

CodeClient.MC.player.setVelocity(0,0,0);
if(CodeClient.MC.player.getPos().equals(target)) {
active = false;
callback();
return;
}
if(locationItem != null) return;
hackTowards();
}

private void locationItemTeleport() {
ClientPlayerEntity player = CodeClient.MC.player;
ClientPlayNetworkHandler net = CodeClient.MC.getNetworkHandler();
if(player == null || net == null) return;
ItemStack handItem = player.getMainHandStack();
Utility.sendHandItem(locationItem);
boolean sneaky = !player.isSneaking();
if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
net.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, player.getBlockPos(), Direction.UP));
net.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, player.getBlockPos(), Direction.UP));
if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
Utility.sendHandItem(handItem);
}

/**
* Use hacky movement packets.
*/
private void hackTowards() {
if(CodeClient.MC.player == null || CodeClient.MC.getNetworkHandler() == null) return;

int bufferStop = 1;
int bufferReset = 0;

buffer++;
if(buffer > bufferStop) {
if(buffer >= bufferReset) {
buffer = 0;
}
return;
}
if(!active) return;
if(CodeClient.MC.player == null) return;
Vec3d pos = CodeClient.MC.player.getPos();

Vec3d offset = pos.relativize(target);
double maxLength = 50;
double distance = offset.length();
Vec3d jump = distance > maxLength ? pos.add(offset.normalize().multiply(maxLength)) : target;
if(distance > 10) {
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
}
CodeClient.MC.player.setPos(jump.x, jump.y, jump.z);
}
}
11 changes: 3 additions & 8 deletions src/main/java/dev/dfonline/codeclient/dev/BuildClip.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.dfonline.codeclient.ChatType;
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.hypercube.item.Location;
import dev.dfonline.codeclient.location.Build;
import dev.dfonline.codeclient.location.Dev;
import net.minecraft.client.network.ClientPlayNetworkHandler;
Expand Down Expand Up @@ -107,14 +108,8 @@ private static void finishClipping() {
abilities.flying = wasFlying;
waitForTP = true;

ItemStack location = Items.PAPER.getDefaultStack();
NbtCompound compound = new NbtCompound();
NbtCompound publicBukkitValues = new NbtCompound();
Vec3d plotPos = new Vec3d(plot.getX(), 0, plot.getZ());
Vec3d pos = plotPos.relativize(player.getPos());
publicBukkitValues.put("hypercube:varitem", NbtString.of("{\"id\":\"loc\",\"data\":{\"isBlock\":false,\"loc\":{\"x\":%.1f,\"y\":%.1f,\"z\":%.1f,\"pitch\":%.1f,\"yaw\":%.1f}}}".formatted(pos.x, pos.y, pos.z, player.getPitch(), player.getYaw())));
compound.put("PublicBukkitValues", publicBukkitValues);
location.setNbt(compound);
Vec3d pos = plot.getPos().relativize(player.getPos());
ItemStack location = new Location(pos.x, pos.y, pos.z, player.getPitch(), player.getYaw()).toItemStack();

ItemStack lastItem = player.getStackInHand(Hand.MAIN_HAND);
Utility.sendHandItem(location);
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/dev/dfonline/codeclient/dev/LastPos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.dfonline.codeclient.dev;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.action.None;
import dev.dfonline.codeclient.action.impl.GoTo;
import dev.dfonline.codeclient.location.Creator;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

public class LastPos {
public static void handlePacket(Packet<?> packet) {
if(CodeClient.MC.player == null) return;
if(CodeClient.location instanceof Creator plot) {
if(plot.getSize() != null && !plot.isInPlot(BlockPos.ofFloored(CodeClient.MC.player.getPos()))) return; // todo: make a player version for this
if(!(packet instanceof PlayerPositionLookS2CPacket)) return;
plot.devPos = CodeClient.MC.player.getPos();
}
}

public static boolean tpBack() {
if(CodeClient.MC.player == null) return false;
if(CodeClient.location instanceof Creator plot && CodeClient.currentAction instanceof None) {
if(plot.devPos == null) return false;
CodeClient.currentAction = new GoTo(plot.devPos,() -> {
CodeClient.MC.player.playSound(SoundEvent.of(new Identifier("minecraft:entity.enderman.teleport")), SoundCategory.PLAYERS, 2, 1);
CodeClient.currentAction = new None();
});
CodeClient.currentAction.init();
return true;
}
return false;
}
}
3 changes: 1 addition & 2 deletions src/main/java/dev/dfonline/codeclient/dev/NoClip.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.dfonline.codeclient.dev;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.location.Dev;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -17,7 +16,7 @@ public class NoClip {
public static LineType display = null;

public static boolean isIgnoringWalls() {
return Config.getConfig().NoClipEnabled && isInDevSpace();
return CodeClient.noClipOn() && isInDevSpace();
}

public static boolean isInDevSpace() {
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/dev/dfonline/codeclient/hypercube/item/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dev.dfonline.codeclient.hypercube.item;

import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtString;
import net.minecraft.util.math.Vec3d;
import org.apache.commons.lang3.NotImplementedException;

public class Location {
public double x = 0;
public double y = 0;
public double z = 0;
public double pitch = 0;
public double yaw = 0;

public Location(double x, double y, double z, double pitch, double yaw) {
this.x = x;
this.y = y;
this.z = z;
this.pitch = pitch;
this.yaw = yaw;
}
public Location(Vec3d pos) {
this.x = pos.x;
this.y = pos.y;
this.z = pos.z;
}
public Location(ItemStack item) {
throw new NotImplementedException("Unimplemented!");
}

/**
* Mutates the location.
* @return The mutated location with the rotation.
*/
public Location setRotation(double pitch, double yaw) {
this.pitch = pitch;
this.yaw = yaw;
return this;
}

public ItemStack toItemStack() {
ItemStack location = Items.PAPER.getDefaultStack();
NbtCompound compound = new NbtCompound();
NbtCompound publicBukkitValues = new NbtCompound();
publicBukkitValues.put("hypercube:varitem", NbtString.of("{\"id\":\"loc\",\"data\":{\"isBlock\":false,\"loc\":{\"x\":%.1f,\"y\":%.1f,\"z\":%.1f,\"pitch\":%.1f,\"yaw\":%.1f}}}".formatted(x, y, z, pitch, yaw)));
compound.put("PublicBukkitValues", publicBukkitValues);
location.setNbt(compound);

return location;
}
}
Loading

0 comments on commit 38f80d2

Please sign in to comment.