Updated PullDown module to be more consistent

Tracing the entity's hull now instead of just a straight line
This commit is contained in:
Daniel E 2019-10-28 15:07:27 -06:00
parent 8a3e2c1133
commit 08fd10e9f7
2 changed files with 87 additions and 65 deletions

View File

@ -3,52 +3,88 @@ package me.rigamortis.seppuku.impl.module.movement;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.value.BooleanValue;
import me.rigamortis.seppuku.api.value.NumberValue;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.util.ArrayList;
import java.util.List;
/**
* // todo; needs further testing
*
* @author cookiedragon234
* @author Daniel E
*/
public class PullDownModule extends Module
{
public final NumberValue<Float> speed = new NumberValue<>("Speed", new String[]{"velocity"}, 10f, Float.class, 0f, 20f, 1f);
public PullDownModule()
{
super("PullDown", new String[]{"FastFall"}, "Increase your downwards velocity when falling", "NONE", -1, ModuleType.MOVEMENT);
}
@Listener
public void onUpdate(EventPlayerUpdate event)
{
if (event.getStage() == EventStageable.EventStage.PRE)
{
final Minecraft mc = Minecraft.getMinecraft();
// obvs dont do this when flying or when using elytras
if(mc.player.isElytraFlying() || mc.player.capabilities.isFlying || mc.player.onGround) return;
// dont trigger when they could just be jumping, 3 blocks is maybe overkill? But its probably the best thing to do
RayTraceResult rayTraceResult = mc.world.rayTraceBlocks(
mc.player.getPositionVector(),
mc.player.getPositionVector()
.add(
new Vec3d(
0,
-3,
0
)
)
);
if(rayTraceResult == null || rayTraceResult.typeOfHit == RayTraceResult.Type.MISS)
{
// Pull the player down
mc.player.motionY = -(speed.getFloat());
}
}
}
public class PullDownModule extends Module {
private static final float VELOCITY_MAX = 10.0f;
private static final float DOWNWARD_VELOCITY_MAX = -VELOCITY_MAX;
public final BooleanValue jumpDisables = new BooleanValue("JumpDisables", new String[] { "jump" }, true);
public final NumberValue<Float> speed =
new NumberValue<>("Speed", new String[]{"velocity"}, 4.0f, Float.class,
0f, DOWNWARD_VELOCITY_MAX, 1f);
public PullDownModule() {
super("PullDown", new String[]{"FastFall"}, "Increase your downwards velocity when falling",
"NONE", -1, ModuleType.MOVEMENT);
}
@Listener
public void onUpdate(EventPlayerUpdate event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
final Minecraft mc = Minecraft.getMinecraft();
if (jumpDisables.getBoolean() && mc.gameSettings.keyBindJump.isKeyDown())
return;
if (mc.player.isElytraFlying() || mc.player.capabilities.isFlying ||
mc.player.onGround || mc.player.fallDistance <= 0.0f)
return;
final Vec3d playerPosition = mc.player.getPositionVector();
final boolean doesPlayerCollide = traceEntityHull(mc.player, playerPosition
.subtract(0.0d, 3.0d, 0.0d)).stream()
.anyMatch(this::hitsCollidableBlock);
if (!doesPlayerCollide)
mc.player.motionY = -speed.getFloat();
}
}
private boolean hitsCollidableBlock(final RayTraceResult rayTraceResult) {
return rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK;
}
private List<RayTraceResult> traceEntityHull(final Entity entity, final Vec3d nextPosition) {
final AxisAlignedBB boundingBox = entity.getEntityBoundingBox();
final Vec3d[] boundingBoxCorners = {
new Vec3d(boundingBox.minX, boundingBox.minY, boundingBox.minZ),
new Vec3d(boundingBox.minX, boundingBox.minY, boundingBox.maxZ),
new Vec3d(boundingBox.minX, boundingBox.maxY, boundingBox.minZ),
new Vec3d(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ),
new Vec3d(boundingBox.maxX, boundingBox.minY, boundingBox.minZ),
new Vec3d(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ),
new Vec3d(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ),
new Vec3d(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ),
};
final Vec3d entityPosition = entity.getPositionVector();
final List<RayTraceResult> rayTraceResults = new ArrayList<>(8);
for (final Vec3d entityBoxCorner : boundingBoxCorners) {
final Vec3d nextBoxCorner = entityBoxCorner.subtract(entityPosition).add(nextPosition);
final RayTraceResult rayTraceResult = entity.world.rayTraceBlocks(entityBoxCorner,
nextBoxCorner, true, false, true);
if (rayTraceResult == null)
continue;
rayTraceResults.add(rayTraceResult);
}
return rayTraceResults;
}
}

View File

@ -1,16 +1,13 @@
package me.rigamortis.seppuku.impl.module.player;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.network.EventSendPacket;
import me.rigamortis.seppuku.api.event.player.EventRightClickBlock;
import me.rigamortis.seppuku.api.module.Module;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
import net.minecraft.network.play.client.CPacketUseEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
@ -42,11 +39,8 @@ public final class InteractModule extends Module {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.currentScreen == null) {
final Block block = mc.world.getBlockState(packet.getPos()).getBlock();
if (block != null) {
if (block.onBlockActivated(mc.world, packet.getPos(), mc.world.getBlockState(packet.getPos()), mc.player, packet.getHand(), packet.getDirection(), packet.getFacingX(), packet.getFacingY(), packet.getFacingZ())) {
return;
}
if (block.onBlockActivated(mc.world, packet.getPos(), mc.world.getBlockState(packet.getPos()), mc.player, packet.getHand(), packet.getDirection(), packet.getFacingX(), packet.getFacingY(), packet.getFacingZ())) {
return;
}
final BlockPos usable = findUsableBlock(packet.getHand(), packet.getDirection(), packet.getFacingX(), packet.getFacingY(), packet.getFacingZ());
@ -73,14 +67,12 @@ public final class InteractModule extends Module {
for (int i = 0; i <= mc.playerController.getBlockReachDistance(); i++) {
final AxisAlignedBB bb = this.traceToBlock(i, mc.getRenderPartialTicks());
if (bb != null) {
float maxDist = mc.playerController.getBlockReachDistance();
for (Entity e : mc.world.getEntitiesWithinAABBExcludingEntity(mc.player, bb)) {
float currentDist = mc.player.getDistance(e);
if (currentDist <= maxDist) {
entity = e;
maxDist = currentDist;
}
float maxDist = mc.playerController.getBlockReachDistance();
for (Entity e : mc.world.getEntitiesWithinAABBExcludingEntity(mc.player, bb)) {
float currentDist = mc.player.getDistance(e);
if (currentDist <= maxDist) {
entity = e;
maxDist = currentDist;
}
}
}
@ -92,16 +84,10 @@ public final class InteractModule extends Module {
for (int i = 0; i <= mc.playerController.getBlockReachDistance(); i++) {
final AxisAlignedBB bb = this.traceToBlock(i, mc.getRenderPartialTicks());
if (bb != null) {
final BlockPos pos = new BlockPos(bb.minX, bb.minY, bb.minZ);
if (pos != null) {
final Block block = mc.world.getBlockState(pos).getBlock();
if (block != null) {
if (block.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, hand, dir, x, y, z)) {
return new BlockPos(pos);
}
}
}
final BlockPos pos = new BlockPos(bb.minX, bb.minY, bb.minZ);
final Block block = mc.world.getBlockState(pos).getBlock();
if (block.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, hand, dir, x, y, z)) {
return new BlockPos(pos);
}
}