finally add place block for core

This commit is contained in:
ChomeNS 2023-03-22 17:57:51 +07:00
parent 49ea908577
commit 847105c514
4 changed files with 39 additions and 24 deletions

View file

@ -13,7 +13,7 @@ public class Configuration {
public static class Core {
@Getter public int layers = 3;
// @Getter public int refillInterval = 60 * 1000;
@Getter public int refillInterval = 60 * 1000;
@Getter public String customName = "[{\"text\":\"ChomeNS \",\"color\":\"yellow\"},{\"text\":\"Core\",\"color\":\"green\"},{\"text\":\"\",\"color\":\"gold\"}]";
}

View file

@ -1,13 +1,28 @@
package me.chayapak1.chomensbot_mabe.plugins;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.packetlib.Session;
import com.nukkitx.math.vector.Vector3i;
import lombok.Getter;
import me.chayapak1.chomensbot_mabe.Bot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class CorePlugin extends PositionPlugin.PositionListener {
private final Bot bot;
@ -92,13 +107,14 @@ public class CorePlugin extends PositionPlugin.PositionListener {
if (!ready) {
ready = true;
bot.executor().schedule(this::refill, bot.config().core().refillInterval(), TimeUnit.MILLISECONDS);
for (Listener listener : listeners) listener.ready();
}
}
public void refill () {
final String command = String.format(
"/minecraft:fill %s %s %s %s %s %s minecraft:command_block{CustomName:'%s'}",
"minecraft:fill %s %s %s %s %s %s minecraft:command_block{CustomName:'%s'}",
coreStart.getX() + origin.getX(),
coreStart.getY(),
@ -111,26 +127,25 @@ public class CorePlugin extends PositionPlugin.PositionListener {
bot.config().core().customName()
);
bot.chat().send(command);
// bot.chat().send(command);
// no work :(
// CompoundTag tag = new CompoundTag("tag");
// CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag");
// blockEntityTag.getValue().put("Command", new StringTag("Command", command));
// blockEntityTag.getValue().put("auto", new ByteTag("auto", (byte) 1));
// blockEntityTag.getValue().put("TrackOutput", new ByteTag("TrackOutput", (byte) 1));
// tag.getValue().put("BlockEntityTag", blockEntityTag);
//
// final Vector3i temporaryBlockPosition = Vector3i.from(
// bot.position().position().getX(),
// bot.position().position().getX() - 1,
// bot.position().position().getZ()
// );
//
// final Session session = bot.session();
// session.send(new ServerboundSetCreativeModeSlotPacket(45, new ItemStack(347 /* command block id */, 64, tag)));
// session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0));
// session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.NORTH, Hand.OFF_HAND, 0.5f, 0.5f, 0.5f, false, 0));
Map<String, Tag> tag = new HashMap<>();
Map<String, Tag> blockEntityTag = new HashMap<>();
blockEntityTag.put("Command", new StringTag("Command", command));
blockEntityTag.put("auto", new ByteTag("auto", (byte) 1));
blockEntityTag.put("TrackOutput", new ByteTag("TrackOutput", (byte) 1));
tag.put("BlockEntityTag", new CompoundTag("BlockEntityTag", blockEntityTag));
final Vector3i temporaryBlockPosition = Vector3i.from(
bot.position().position().getX(),
bot.position().position().getY() - 1,
bot.position().position().getZ()
);
final Session session = bot.session();
session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(347 /* command block id */, 64, new CompoundTag("", tag))));
session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0));
session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1));
}
public static class Listener {

View file

@ -32,9 +32,10 @@ public class PositionPlugin extends SessionAdapter {
}
public void packetReceived (ClientboundPlayerPositionPacket packet) {
bot.session().send(new ServerboundAcceptTeleportationPacket(packet.getTeleportId()));
position = Vector3i.from(packet.getX(), packet.getY(), packet.getZ());
for (PositionListener listener : listeners) { listener.positionChange(position); }
bot.session().send(new ServerboundAcceptTeleportationPacket(packet.getTeleportId()));
}
public void addListener (PositionListener listener) { listeners.add(listener); }

View file

@ -4,8 +4,7 @@ keys:
ownerKey: 'OwnerHash™ key here'
core:
layers: 3
# will add refill interval later after the bot can place command blocks to refill core
# refillInterval: 60000
refillInterval: 60000
# PLEASE give valid JSON component here else the core don't refill at all
customName: '[{"text":"ChomeNS ","color":"yellow"},{"text":"Core","color":"green"},{"text":"™","color":"gold"}]'
selfCare: