forked from ChomeNS/chomens-bot-java
add world min y and max y check + clamp the core y to min y and max y
This commit is contained in:
parent
5cbeeefe6f
commit
7a3b5f4baf
4 changed files with 77 additions and 6 deletions
|
@ -53,6 +53,8 @@ public class Bot {
|
||||||
public ChatPlugin chat;
|
public ChatPlugin chat;
|
||||||
public CommandSpyPlugin commandSpy;
|
public CommandSpyPlugin commandSpy;
|
||||||
public PositionPlugin position;
|
public PositionPlugin position;
|
||||||
|
public ServerPluginsManagerPlugin serverPluginsManager;
|
||||||
|
public PluginCheckerPlugin pluginChecker;
|
||||||
public SelfCarePlugin selfCare;
|
public SelfCarePlugin selfCare;
|
||||||
public CorePlugin core;
|
public CorePlugin core;
|
||||||
public TeamPlugin team;
|
public TeamPlugin team;
|
||||||
|
@ -75,8 +77,7 @@ public class Bot {
|
||||||
public PacketSnifferPlugin packetSniffer;
|
public PacketSnifferPlugin packetSniffer;
|
||||||
public VoiceChatPlugin voiceChat;
|
public VoiceChatPlugin voiceChat;
|
||||||
public TagPlugin tag;
|
public TagPlugin tag;
|
||||||
public ServerPluginsManagerPlugin serverPluginsManager;
|
public WorldPlugin world;
|
||||||
public PluginCheckerPlugin pluginChecker;
|
|
||||||
|
|
||||||
public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) {
|
public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) {
|
||||||
this.host = botOption.host;
|
this.host = botOption.host;
|
||||||
|
@ -101,6 +102,8 @@ public class Bot {
|
||||||
this.chat = new ChatPlugin(this);
|
this.chat = new ChatPlugin(this);
|
||||||
this.commandSpy = new CommandSpyPlugin(this);
|
this.commandSpy = new CommandSpyPlugin(this);
|
||||||
this.position = new PositionPlugin(this);
|
this.position = new PositionPlugin(this);
|
||||||
|
this.serverPluginsManager = new ServerPluginsManagerPlugin(this);
|
||||||
|
this.pluginChecker = new PluginCheckerPlugin(this);
|
||||||
this.selfCare = new SelfCarePlugin(this);
|
this.selfCare = new SelfCarePlugin(this);
|
||||||
this.core = new CorePlugin(this);
|
this.core = new CorePlugin(this);
|
||||||
this.team = new TeamPlugin(this);
|
this.team = new TeamPlugin(this);
|
||||||
|
@ -123,8 +126,7 @@ public class Bot {
|
||||||
this.packetSniffer = new PacketSnifferPlugin(this);
|
this.packetSniffer = new PacketSnifferPlugin(this);
|
||||||
this.voiceChat = new VoiceChatPlugin(this);
|
this.voiceChat = new VoiceChatPlugin(this);
|
||||||
this.tag = new TagPlugin(this);
|
this.tag = new TagPlugin(this);
|
||||||
this.serverPluginsManager = new ServerPluginsManagerPlugin(this);
|
this.world = new WorldPlugin(this);
|
||||||
this.pluginChecker = new PluginCheckerPlugin(this);
|
|
||||||
|
|
||||||
for (Listener listener : listeners) listener.loadedPlugins();
|
for (Listener listener : listeners) listener.loadedPlugins();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||||
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;
|
||||||
|
import land.chipmunk.chayapak.chomens_bot.util.MathUtilities;
|
||||||
import org.cloudburstmc.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -330,11 +331,11 @@ public class CorePlugin extends PositionPlugin.Listener {
|
||||||
"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'}",
|
||||||
|
|
||||||
from.getX(),
|
from.getX(),
|
||||||
from.getY(),
|
MathUtilities.clamp(from.getY(), bot.world.minY, bot.world.maxY),
|
||||||
from.getZ(),
|
from.getZ(),
|
||||||
|
|
||||||
to.getX(),
|
to.getX(),
|
||||||
to.getY(),
|
MathUtilities.clamp(to.getY(), bot.world.minY, bot.world.maxY),
|
||||||
to.getZ(),
|
to.getZ(),
|
||||||
|
|
||||||
bot.config.core.customName
|
bot.config.core.customName
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.github.steveice10.packetlib.Session;
|
||||||
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WorldPlugin extends Bot.Listener {
|
||||||
|
public int minY = 0;
|
||||||
|
public int maxY = 256;
|
||||||
|
|
||||||
|
public CompoundTag registry = null;
|
||||||
|
|
||||||
|
private final List<Listener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public WorldPlugin (Bot bot) {
|
||||||
|
bot.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void packetReceived(Session session, Packet packet) {
|
||||||
|
if (packet instanceof ClientboundLoginPacket) packetReceived((ClientboundLoginPacket) packet);
|
||||||
|
else if (packet instanceof ClientboundRespawnPacket) packetReceived((ClientboundRespawnPacket) packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void worldChanged (String dimension) {
|
||||||
|
final Tag dimensionType = ((LinkedHashMap<String, Tag>) registry.get("minecraft:dimension_type").getValue()).get("value");
|
||||||
|
|
||||||
|
final ArrayList<CompoundTag> dimensions = (ArrayList<CompoundTag>) dimensionType.getValue();
|
||||||
|
|
||||||
|
final CompoundTag currentDimension = dimensions.stream()
|
||||||
|
.filter((eachDimension) -> eachDimension.get("name").getValue().equals(dimension))
|
||||||
|
.toArray(CompoundTag[]::new)[0];
|
||||||
|
|
||||||
|
final CompoundTag element = currentDimension.get("element");
|
||||||
|
|
||||||
|
minY = (int) element.get("min_y").getValue();
|
||||||
|
maxY = (int) element.get("height").getValue();
|
||||||
|
|
||||||
|
for (Listener listener : listeners) listener.worldChanged(dimension);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packetReceived (ClientboundLoginPacket packet) {
|
||||||
|
registry = packet.getRegistry();
|
||||||
|
|
||||||
|
worldChanged(packet.getDimension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packetReceived (ClientboundRespawnPacket packet) {
|
||||||
|
worldChanged(packet.getDimension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Listener {
|
||||||
|
public void worldChanged (String dimension) {}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,10 @@ public class MathUtilities {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int clamp (int value, int min, int max) {
|
||||||
|
return Math.max(Math.min(value, max), min);
|
||||||
|
}
|
||||||
|
|
||||||
public static float clamp (float value, float min, float max) {
|
public static float clamp (float value, float min, float max) {
|
||||||
return Math.max(Math.min(value, max), min);
|
return Math.max(Math.min(value, max), min);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue