125 lines
4.1 KiB
Java
125 lines
4.1 KiB
Java
package openonyx.features.combat;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
import meteordevelopment.orbit.EventHandler;
|
|
import net.minecraft.block.BlockBed;
|
|
import net.minecraft.network.Packet;
|
|
import net.minecraft.network.play.server.S02PacketChat;
|
|
import net.minecraft.network.play.server.S08PacketPlayerPosLook;
|
|
import net.minecraft.util.BlockPos;
|
|
import openonyx.configuration.internal.PacketDirection;
|
|
import openonyx.configuration.internal.PacketEvent;
|
|
import openonyx.configuration.internal.PreTickEvent;
|
|
import openonyx.configuration.internal.WorldChangeEvent;
|
|
import openonyx.core.MinecraftAccess;
|
|
import openonyx.utilities.Timer;
|
|
|
|
public final class BedTracker implements MinecraftAccess {
|
|
private final Set<BlockPos> blockPosList = new HashSet<>();
|
|
private final Timer timer = new Timer();
|
|
public static final BedTracker INSTANCE = new BedTracker();
|
|
private static final long I = 3000L;
|
|
private static final int d = 15;
|
|
private BlockPos blockPos;
|
|
private boolean f;
|
|
private static final int H = 35;
|
|
private boolean e;
|
|
|
|
public boolean L(BlockPos blockPos) {
|
|
return this.blockPosList.contains(blockPosx);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPreTick(PreTickEvent preTickEvent) {
|
|
if (this.f && this.timer.hasElapsed(3000L)) {
|
|
this.f = false;
|
|
this.d();
|
|
}
|
|
}
|
|
|
|
public BlockPos L() {
|
|
BedTracker bedTracker1 = this;
|
|
if (mc.thePlayer != null && mc.theWorld != null && !bedTracker1.blockPosList.isEmpty()) {
|
|
BlockPos blockPosx = new BlockPos(mc.thePlayer);
|
|
BlockPos blockPos2 = null;
|
|
double dx = Double.MAX_VALUE;
|
|
Iterator iterator = bedTracker1.blockPosList.iterator();
|
|
|
|
label25:
|
|
while (true) {
|
|
for (Iterator iterator1 = iterator; iterator1.hasNext(); iterator1 = iterator) {
|
|
BlockPos blockPos1 = (BlockPos)iterator.next();
|
|
if (mc.theWorld.getBlockState(blockPos1).getBlock() instanceof BlockBed) {
|
|
double ex;
|
|
if ((ex = blockPos1.distanceSq(blockPosx.getX(), blockPosx.getY(), blockPosx.getZ())) < dx) {
|
|
dx = ex;
|
|
blockPos2 = blockPos1;
|
|
}
|
|
continue label25;
|
|
}
|
|
}
|
|
|
|
return blockPos2;
|
|
}
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private void d() {
|
|
BedTracker bedTracker1 = this;
|
|
if (bedTracker1.blockPos != null && mc.theWorld != null) {
|
|
int i;
|
|
int j;
|
|
for (int n = i = -35; n <= 35; n = ++i) {
|
|
int k;
|
|
for (int l = j = -15; l <= 15; l = ++j) {
|
|
for (int m = k = -35; m <= 35; m = ++k) {
|
|
BlockPos blockPosx = bedTracker1.blockPos.add(i, j, k);
|
|
if (mc.theWorld.getBlockState(blockPosx).getBlock() instanceof BlockBed) {
|
|
bedTracker1.blockPosList.add(blockPosx);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPacket(PacketEvent packetEvent) {
|
|
if (packetEvent.getPacketDirection() == PacketDirection.INCOMING) {
|
|
Packet packet;
|
|
if ((packet = packetEvent.getPacket()) instanceof S02PacketChat) {
|
|
String string;
|
|
if ((string = ((S02PacketChat)packet).getChatComponent().getUnformattedText()).contains("Protect your bed and destroy the enemy bed")
|
|
|| string.contains("Destroy the enemy bed and then eliminate them")) {
|
|
this.e = true;
|
|
return;
|
|
}
|
|
} else if (packet instanceof S08PacketPlayerPosLook s08PacketPlayerPosLook && this.e) {
|
|
this.e = false;
|
|
this.blockPos = new BlockPos(s08PacketPlayerPosLook.getX(), s08PacketPlayerPosLook.getY(), s08PacketPlayerPosLook.getZ());
|
|
this.f = true;
|
|
this.timer.reset();
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onWorldChange(WorldChangeEvent worldChangeEvent) {
|
|
this.L();
|
|
}
|
|
|
|
private void L() {
|
|
this.blockPosList.clear();
|
|
this.e = false;
|
|
this.f = false;
|
|
this.blockPos = null;
|
|
}
|
|
|
|
private BedTracker() {
|
|
}
|
|
}
|