send position packet every second + some core stuff which still doesn't work
This commit is contained in:
parent
2d123256e2
commit
2fd4fda4ed
2 changed files with 23 additions and 4 deletions
|
@ -52,6 +52,8 @@ public class CorePlugin extends PositionPlugin.Listener {
|
||||||
private int nextTransactionId = 0;
|
private int nextTransactionId = 0;
|
||||||
private final Map<Integer, CompletableFuture<CompoundTag>> transactions = new HashMap<>();
|
private final Map<Integer, CompletableFuture<CompoundTag>> transactions = new HashMap<>();
|
||||||
|
|
||||||
|
private final List<Runnable> afterTicks = new ArrayList<>();
|
||||||
|
|
||||||
private final boolean kaboom;
|
private final boolean kaboom;
|
||||||
|
|
||||||
private int commandsPerSecond = 0;
|
private int commandsPerSecond = 0;
|
||||||
|
@ -163,9 +165,7 @@ public class CorePlugin extends PositionPlugin.Listener {
|
||||||
final CompletableFuture<CompoundTag> future = new CompletableFuture<>();
|
final CompletableFuture<CompoundTag> future = new CompletableFuture<>();
|
||||||
transactions.put(transactionId, future);
|
transactions.put(transactionId, future);
|
||||||
|
|
||||||
final Runnable afterTick = () -> bot.session.send(new ServerboundBlockEntityTagQuery(transactionId, beforeBlock));
|
afterTicks.add(() -> bot.session.send(new ServerboundBlockEntityTagQuery(transactionId, beforeBlock)));
|
||||||
|
|
||||||
bot.executor.schedule(afterTick, 50, TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,15 @@ public class CorePlugin extends PositionPlugin.Listener {
|
||||||
public void packetReceived (ClientboundBlockUpdatePacket packet) {
|
public void packetReceived (ClientboundBlockUpdatePacket packet) {
|
||||||
final BlockChangeEntry entry = packet.getEntry();
|
final BlockChangeEntry entry = packet.getEntry();
|
||||||
|
|
||||||
if (isCommandBlockUpdate(entry.getBlock())) return;
|
if (isCommandBlockUpdate(entry.getBlock())) {
|
||||||
|
for (Runnable runnable : afterTicks) {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
afterTicks.clear();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Vector3i position = entry.getPosition();
|
final Vector3i position = entry.getPosition();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.Client
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
|
@ -19,6 +20,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
// some part of the code used to be in a test plugin but i thought it would be useful in the future so i moved it here
|
// some part of the code used to be in a test plugin but i thought it would be useful in the future so i moved it here
|
||||||
public class PositionPlugin extends Bot.Listener {
|
public class PositionPlugin extends Bot.Listener {
|
||||||
|
@ -34,7 +36,16 @@ public class PositionPlugin extends Bot.Listener {
|
||||||
|
|
||||||
public PositionPlugin (Bot bot) {
|
public PositionPlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
bot.addListener(this);
|
bot.addListener(this);
|
||||||
|
|
||||||
|
// notchian clients also does this, sends the position packet every second
|
||||||
|
bot.executor.scheduleAtFixedRate(() -> bot.session.send(new ServerboundMovePlayerPosPacket(
|
||||||
|
false,
|
||||||
|
position.getX(),
|
||||||
|
position.getY(),
|
||||||
|
position.getZ()
|
||||||
|
)), 0, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue