package ru.meow.module.impl.combat;
import com.google.common.eventbus.Subscribe;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Box;
import ru.meow.domain.event.impl.EventUpdate;
import ru.meow.domain.module.Module;
import ru.meow.domain.module.ModuleCategory;
import ru.meow.domain.module.ModuleInfo;
import ru.meow.domain.setting.SliderSetting;
/**
* Expands other players' hitboxes for the duration of the module.
*/
public class HitBoxes extends Module {
private static final double DEFAULT_HALF = 0.3D;
private final SliderSetting width = new SliderSetting(
"hitBoxWidth", 1.0F, 0.0F, 5.0F, 0.1F);
private final SliderSetting height = new SliderSetting(
"hitBoxHeight", 1.0F, 0.0F, 5.0F, 0.1F);
public HitBoxes() {
super(new ModuleInfo("HitBoxes", ModuleCategory.Combat));
addSettings(this.width, this.height);
}
@Subscribe
public void onUpdate(EventUpdate.Post event) {
if (!isEnabled() || mc.world == null) {
return;
}
float expandW = this.width.getValue();
float expandH = this.height.getValue();
for (Entity entity : mc.world.getEntities()) {
if (!(entity instanceof PlayerEntity player)) {
continue;
}
if (player == mc.player) {
continue;
}
Box base = new Box(
player.getX() - expandW,
player.getY(),
player.getZ() - expandW,
player.getX() + expandW,
player.getY() + player.getHeight() + expandH,
player.getZ() + expandW);
player.setBoundingBox(base);
}
}
@Override
public void onDisable() {
if (mc.world == null) {
super.onDisable();
return;
}
for (Entity entity : mc.world.getEntities()) {
if (!(entity instanceof PlayerEntity player) || player == mc.player) {
continue;
}
Box box = player.getBoundingBox();
player.setBoundingBox(new Box(
box.minX + DEFAULT_HALF,
box.minY,
box.minZ + DEFAULT_HALF,
box.maxX - DEFAULT_HALF,
box.maxY,
box.maxZ - DEFAULT_HALF));
}
super.onDisable();
}
}