Skip to content

Commit 38f80d2

Browse files
committed
Merge branch 'back'
2 parents 2de1a2f + 84fbb00 commit 38f80d2

File tree

10 files changed

+291
-24
lines changed

10 files changed

+291
-24
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.20.1+build.9
88
loader_version=0.14.21
99

1010
# Mod Properties
11-
mod_version=1.5.4
11+
mod_version=1.5.5
1212
maven_group=dev.dfonline
1313
archives_base_name=CodeClient
1414

src/main/java/dev/dfonline/codeclient/CodeClient.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
import dev.dfonline.codeclient.action.Action;
55
import dev.dfonline.codeclient.action.None;
66
import dev.dfonline.codeclient.config.Config;
7-
import dev.dfonline.codeclient.dev.BuildClip;
8-
import dev.dfonline.codeclient.dev.ChestPeeker;
7+
import dev.dfonline.codeclient.dev.*;
98
import dev.dfonline.codeclient.dev.Debug.Debug;
109
import dev.dfonline.codeclient.dev.DevInventory.DevInventoryScreen;
11-
import dev.dfonline.codeclient.dev.NoClip;
12-
import dev.dfonline.codeclient.dev.RecentChestInsert;
1310
import dev.dfonline.codeclient.location.Dev;
1411
import dev.dfonline.codeclient.location.Location;
1512
import dev.dfonline.codeclient.location.Spawn;
@@ -72,8 +69,9 @@ public static <T extends PacketListener> boolean handlePacket(Packet<T> packet)
7269
if(currentAction.onReceivePacket(packet)) return true;
7370
if(Debug.handlePacket(packet)) return true;
7471
if(BuildClip.handlePacket(packet)) return true;
75-
Event.handlePacket(packet);
7672
if(ChestPeeker.handlePacket(packet)) return true;
73+
Event.handlePacket(packet);
74+
LastPos.handlePacket(packet);
7775

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

84+
/**
85+
* This needs to be true for NoClip to work.
86+
* Whilst this should be the first source to check if NoClip is on, keep in mind there is NoClip#isIgnoringWalls
87+
* Useful for fallback checks and preventing noclip packet spam screwing you over.
88+
*/
89+
public static boolean noClipOn() {
90+
if(MC.player == null) return false;
91+
if(!Config.getConfig().NoClipEnabled) return false;
92+
if(!(location instanceof Dev)) return false;
93+
if(!(currentAction instanceof None)) return false;
94+
if(!MC.player.getAbilities().creativeMode) return false;
95+
return true;
96+
}
97+
8698
/**
8799
* All outgoing packet events and debugging.
88100
* @return If the packet shouldn't be sent. True to not send.

src/main/java/dev/dfonline/codeclient/Commands.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
import com.mojang.brigadier.CommandDispatcher;
44
import dev.dfonline.codeclient.action.None;
5-
import dev.dfonline.codeclient.action.impl.*;
5+
import dev.dfonline.codeclient.action.impl.GetActionDump;
6+
import dev.dfonline.codeclient.action.impl.GetPlotSize;
7+
import dev.dfonline.codeclient.action.impl.MoveToSpawn;
8+
import dev.dfonline.codeclient.config.Config;
69
import dev.dfonline.codeclient.dev.BuildClip;
10+
import dev.dfonline.codeclient.dev.LastPos;
711
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
8-
import dev.dfonline.codeclient.config.Config;
12+
import dev.dfonline.codeclient.location.Creator;
913
import dev.dfonline.codeclient.location.Dev;
1014
import dev.dfonline.codeclient.location.Plot;
1115
import dev.dfonline.codeclient.websocket.SocketHandler;
1216
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1317
import net.minecraft.client.font.TextRenderer;
1418
import net.minecraft.text.ClickEvent;
1519
import net.minecraft.text.Text;
16-
import net.minecraft.util.Formatting;
1720

1821
import java.nio.file.Path;
1922

@@ -102,7 +105,27 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
102105
return 0;
103106
}));
104107

105-
108+
dispatcher.register(literal("back").executes(context -> {
109+
if(CodeClient.location instanceof Creator plot) {
110+
if(plot.devPos == null) {
111+
Utility.sendMessage("There is no position to go back to!", ChatType.FAIL);
112+
return 1;
113+
}
114+
if(!(CodeClient.currentAction instanceof None)) {
115+
Utility.sendMessage("CodeClient is currently busy, try again in a moment.",ChatType.FAIL);
116+
return 1;
117+
}
118+
if(LastPos.tpBack()) return 0;
119+
else {
120+
Utility.sendMessage("An error occurred whilst trying to go back.",ChatType.FAIL);
121+
return 1;
122+
}
123+
}
124+
else {
125+
Utility.sendMessage("You must be in dev or build mode to do this!",ChatType.FAIL);
126+
return 1;
127+
}
128+
}));
106129

107130
dispatcher.register(literal("getspawn").executes(context -> {
108131
if(!(CodeClient.location instanceof Dev)) return 1;

src/main/java/dev/dfonline/codeclient/MoveToLocation.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ public void setPos(Vec3d pos) {
3232
setPos(pos.x, pos.y, pos.z);
3333
}
3434
public void setPos(double x, double y, double z) {
35+
if(CodeClient.MC.getNetworkHandler() == null) return;
36+
if(new Vec3d(x,y,x).distanceTo(player.getPos()) > 10) {
37+
// I've always done it like this, problems?
38+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
39+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
40+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
41+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
42+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
43+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
44+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
45+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
46+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
47+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
48+
}
3549
this.player.setPos(x, y, z);
3650
this.player.teleport(x, y, z);
3751
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(x, y, z, false));
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package dev.dfonline.codeclient.action.impl;
2+
3+
import dev.dfonline.codeclient.CodeClient;
4+
import dev.dfonline.codeclient.Utility;
5+
import dev.dfonline.codeclient.action.Action;
6+
import dev.dfonline.codeclient.location.Dev;
7+
import dev.dfonline.codeclient.hypercube.item.Location;
8+
import net.minecraft.client.network.ClientPlayNetworkHandler;
9+
import net.minecraft.client.network.ClientPlayerEntity;
10+
import net.minecraft.item.ItemStack;
11+
import net.minecraft.network.packet.Packet;
12+
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
13+
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
14+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
15+
import net.minecraft.network.packet.c2s.play.TeleportConfirmC2SPacket;
16+
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
17+
import net.minecraft.util.math.Direction;
18+
import net.minecraft.util.math.Vec3d;
19+
20+
public class GoTo extends Action {
21+
public final Vec3d target;
22+
/**
23+
* If not null, we are using a location item to teleport.
24+
*/
25+
private ItemStack locationItem;
26+
private boolean active;
27+
private int buffer = 0;
28+
29+
public GoTo(Vec3d target, Callback callback) {
30+
super(callback);
31+
this.target = target;
32+
}
33+
34+
@Override
35+
public void init() {
36+
active = true;
37+
if(CodeClient.MC.player == null) return;
38+
if(CodeClient.location instanceof Dev dev && dev.isInArea(target)) {
39+
locationItem = new Location(dev.getPos().relativize(target)).setRotation(CodeClient.MC.player.getPitch(), CodeClient.MC.player.getYaw()).toItemStack();
40+
locationItemTeleport();
41+
}
42+
}
43+
44+
@Override
45+
public boolean onReceivePacket(Packet<?> packet) {
46+
if(locationItem == null) return super.onReceivePacket(packet);
47+
if(packet instanceof PlayerPositionLookS2CPacket tp) {
48+
if(CodeClient.MC.getNetworkHandler() == null || CodeClient.MC.player == null) return false;
49+
CodeClient.MC.getNetworkHandler().sendPacket(new TeleportConfirmC2SPacket(tp.getTeleportId()));
50+
CodeClient.MC.player.setPosition(target);
51+
active = false;
52+
callback();
53+
return true;
54+
}
55+
return false;
56+
}
57+
58+
@Override
59+
public void onTick() {
60+
if(CodeClient.MC.player == null || CodeClient.MC.getNetworkHandler() == null) {
61+
callback();
62+
return;
63+
}
64+
65+
CodeClient.MC.player.setVelocity(0,0,0);
66+
if(CodeClient.MC.player.getPos().equals(target)) {
67+
active = false;
68+
callback();
69+
return;
70+
}
71+
if(locationItem != null) return;
72+
hackTowards();
73+
}
74+
75+
private void locationItemTeleport() {
76+
ClientPlayerEntity player = CodeClient.MC.player;
77+
ClientPlayNetworkHandler net = CodeClient.MC.getNetworkHandler();
78+
if(player == null || net == null) return;
79+
ItemStack handItem = player.getMainHandStack();
80+
Utility.sendHandItem(locationItem);
81+
boolean sneaky = !player.isSneaking();
82+
if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
83+
net.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, player.getBlockPos(), Direction.UP));
84+
net.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, player.getBlockPos(), Direction.UP));
85+
if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
86+
Utility.sendHandItem(handItem);
87+
}
88+
89+
/**
90+
* Use hacky movement packets.
91+
*/
92+
private void hackTowards() {
93+
if(CodeClient.MC.player == null || CodeClient.MC.getNetworkHandler() == null) return;
94+
95+
int bufferStop = 1;
96+
int bufferReset = 0;
97+
98+
buffer++;
99+
if(buffer > bufferStop) {
100+
if(buffer >= bufferReset) {
101+
buffer = 0;
102+
}
103+
return;
104+
}
105+
if(!active) return;
106+
if(CodeClient.MC.player == null) return;
107+
Vec3d pos = CodeClient.MC.player.getPos();
108+
109+
Vec3d offset = pos.relativize(target);
110+
double maxLength = 50;
111+
double distance = offset.length();
112+
Vec3d jump = distance > maxLength ? pos.add(offset.normalize().multiply(maxLength)) : target;
113+
if(distance > 10) {
114+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
115+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
116+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
117+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
118+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
119+
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false));
120+
}
121+
CodeClient.MC.player.setPos(jump.x, jump.y, jump.z);
122+
}
123+
}

src/main/java/dev/dfonline/codeclient/dev/BuildClip.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.dfonline.codeclient.ChatType;
44
import dev.dfonline.codeclient.CodeClient;
55
import dev.dfonline.codeclient.Utility;
6+
import dev.dfonline.codeclient.hypercube.item.Location;
67
import dev.dfonline.codeclient.location.Build;
78
import dev.dfonline.codeclient.location.Dev;
89
import net.minecraft.client.network.ClientPlayNetworkHandler;
@@ -107,14 +108,8 @@ private static void finishClipping() {
107108
abilities.flying = wasFlying;
108109
waitForTP = true;
109110

110-
ItemStack location = Items.PAPER.getDefaultStack();
111-
NbtCompound compound = new NbtCompound();
112-
NbtCompound publicBukkitValues = new NbtCompound();
113-
Vec3d plotPos = new Vec3d(plot.getX(), 0, plot.getZ());
114-
Vec3d pos = plotPos.relativize(player.getPos());
115-
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())));
116-
compound.put("PublicBukkitValues", publicBukkitValues);
117-
location.setNbt(compound);
111+
Vec3d pos = plot.getPos().relativize(player.getPos());
112+
ItemStack location = new Location(pos.x, pos.y, pos.z, player.getPitch(), player.getYaw()).toItemStack();
118113

119114
ItemStack lastItem = player.getStackInHand(Hand.MAIN_HAND);
120115
Utility.sendHandItem(location);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.dfonline.codeclient.dev;
2+
3+
import dev.dfonline.codeclient.CodeClient;
4+
import dev.dfonline.codeclient.action.None;
5+
import dev.dfonline.codeclient.action.impl.GoTo;
6+
import dev.dfonline.codeclient.location.Creator;
7+
import net.minecraft.network.packet.Packet;
8+
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
9+
import net.minecraft.sound.SoundCategory;
10+
import net.minecraft.sound.SoundEvent;
11+
import net.minecraft.util.Identifier;
12+
import net.minecraft.util.math.BlockPos;
13+
14+
public class LastPos {
15+
public static void handlePacket(Packet<?> packet) {
16+
if(CodeClient.MC.player == null) return;
17+
if(CodeClient.location instanceof Creator plot) {
18+
if(plot.getSize() != null && !plot.isInPlot(BlockPos.ofFloored(CodeClient.MC.player.getPos()))) return; // todo: make a player version for this
19+
if(!(packet instanceof PlayerPositionLookS2CPacket)) return;
20+
plot.devPos = CodeClient.MC.player.getPos();
21+
}
22+
}
23+
24+
public static boolean tpBack() {
25+
if(CodeClient.MC.player == null) return false;
26+
if(CodeClient.location instanceof Creator plot && CodeClient.currentAction instanceof None) {
27+
if(plot.devPos == null) return false;
28+
CodeClient.currentAction = new GoTo(plot.devPos,() -> {
29+
CodeClient.MC.player.playSound(SoundEvent.of(new Identifier("minecraft:entity.enderman.teleport")), SoundCategory.PLAYERS, 2, 1);
30+
CodeClient.currentAction = new None();
31+
});
32+
CodeClient.currentAction.init();
33+
return true;
34+
}
35+
return false;
36+
}
37+
}

src/main/java/dev/dfonline/codeclient/dev/NoClip.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.dfonline.codeclient.dev;
22

33
import dev.dfonline.codeclient.CodeClient;
4-
import dev.dfonline.codeclient.config.Config;
54
import dev.dfonline.codeclient.location.Dev;
65
import net.minecraft.block.BlockState;
76
import net.minecraft.block.Blocks;
@@ -17,7 +16,7 @@ public class NoClip {
1716
public static LineType display = null;
1817

1918
public static boolean isIgnoringWalls() {
20-
return Config.getConfig().NoClipEnabled && isInDevSpace();
19+
return CodeClient.noClipOn() && isInDevSpace();
2120
}
2221

2322
public static boolean isInDevSpace() {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package dev.dfonline.codeclient.hypercube.item;
2+
3+
import net.minecraft.item.ItemStack;
4+
import net.minecraft.item.Items;
5+
import net.minecraft.nbt.NbtCompound;
6+
import net.minecraft.nbt.NbtString;
7+
import net.minecraft.util.math.Vec3d;
8+
import org.apache.commons.lang3.NotImplementedException;
9+
10+
public class Location {
11+
public double x = 0;
12+
public double y = 0;
13+
public double z = 0;
14+
public double pitch = 0;
15+
public double yaw = 0;
16+
17+
public Location(double x, double y, double z, double pitch, double yaw) {
18+
this.x = x;
19+
this.y = y;
20+
this.z = z;
21+
this.pitch = pitch;
22+
this.yaw = yaw;
23+
}
24+
public Location(Vec3d pos) {
25+
this.x = pos.x;
26+
this.y = pos.y;
27+
this.z = pos.z;
28+
}
29+
public Location(ItemStack item) {
30+
throw new NotImplementedException("Unimplemented!");
31+
}
32+
33+
/**
34+
* Mutates the location.
35+
* @return The mutated location with the rotation.
36+
*/
37+
public Location setRotation(double pitch, double yaw) {
38+
this.pitch = pitch;
39+
this.yaw = yaw;
40+
return this;
41+
}
42+
43+
public ItemStack toItemStack() {
44+
ItemStack location = Items.PAPER.getDefaultStack();
45+
NbtCompound compound = new NbtCompound();
46+
NbtCompound publicBukkitValues = new NbtCompound();
47+
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)));
48+
compound.put("PublicBukkitValues", publicBukkitValues);
49+
location.setNbt(compound);
50+
51+
return location;
52+
}
53+
}

0 commit comments

Comments
 (0)