-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
291 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/main/java/dev/dfonline/codeclient/action/impl/GoTo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/dev/dfonline/codeclient/hypercube/item/Location.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.