phase / PhaseBot

Stand-alone Minecraft bot with a turing complete scripting language (MC 1.8)
30 stars 4 forks source link

Break blocks in Survival #15

Open lukesmith02 opened 8 years ago

lukesmith02 commented 8 years ago
public void breakBlock(double rx, double ry, double rz) {
    final Position p = new Position((int) Math.floor(pos.x + rx), (int) Math.floor(pos.y + ry),
            (int) Math.floor(pos.z + rz));
    // PhaseBot.getConsole().println("Digging at: " + p.getX() + " " +
    // p.getY() + " " + p.getZ());
    client.getSession().send(new ClientPlayerActionPacket(PlayerAction.START_DIGGING, p, Face.TOP));
    swing();
    client.getSession().send(new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, p, Face.TOP));
phase commented 8 years ago

I doesn't work in survival because I haven't done the timings yet, but creative works fine.

lukesmith02 commented 8 years ago

Does the swing() method just swing once?

What i'm getting at is would it be possible to get the block id what what is trying to be broken, then swing at it until the block id has changed (broken). I tried implement this logic myself, but it still didn't work.

phase commented 8 years ago

swing() does one swing. Here is how long to wait.

rom1504 commented 8 years ago

fyi, here is an implementation of computing the digging time in js https://github.com/PrismarineJS/prismarine-block/blob/master/index.js#L58 Since you're using minecraft-data, implementing that function shouldn't be too hard. (toolMultipliers is materials.json)

phase commented 8 years ago

Awesome! Can't wait to implement it!

lukesmith02 commented 8 years ago

This is now fixed in your latest build. Thanks, you beat me to it. :)

public void breakBlock(double rx, double ry, double rz) {
    final Position p = new Position((int) Math.floor(pos.x + rx), (int) Math.floor(pos.y + ry),
            (int) Math.floor(pos.z + rz));
    PhaseBot.getConsole().println("Digging at: " + p.getX() + " " + p.getY() + " " + p.getZ());
    //if((gamemode == GameMode.CREATIVE))
    //  swing();
    //else{
    client.getSession().send(new ClientPlayerActionPacket(PlayerAction.START_DIGGING, p, Face.TOP));
    BlockType block = Block.getBlock(relativeToAbsolute(new Vector3d(rx, ry, rz))).getMaterial().toBlock();
    try {
        double waitTime = ToolStrength.getWaitTime(Material.getMaterial(inventory.getHeldItem().getId()).toItem(),
                block, false, true);
        PhaseBot.getConsole().println("Block wait time: " + waitTime);
        Thread.sleep((int) waitTime);
        PhaseBot.getConsole().println(" done");
        client.getSession().send(new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, p, Face.TOP));
    }
    catch (InterruptedException e) {
        e.printStackTrace();
    }
    PhaseBot.getConsole().println("Done digging at: " + p.getX() + " " + p.getY() + " " + p.getZ());
    //}
}
phase commented 8 years ago

That doesn't have the correct time, only an approximation I made while testing (I'm surprised how accurate it is).