diff --git a/src/main/java/me/zane/grassware/event/events/MotionUpdateEvent.java b/src/main/java/me/zane/grassware/event/events/MotionUpdateEvent.java index e1f4235..a494bc2 100644 --- a/src/main/java/me/zane/grassware/event/events/MotionUpdateEvent.java +++ b/src/main/java/me/zane/grassware/event/events/MotionUpdateEvent.java @@ -4,110 +4,49 @@ public class MotionUpdateEvent extends Event { private double x, y, z; - private final double prevX, prevY, prevZ; + private double prevX, prevY, prevZ; private float rotationYaw; private float rotationPitch; - private final float prevYaw, prevPitch; + private float prevYaw, prevPitch; private boolean onGround; - private final boolean prevOnGround; + private boolean prevOnGround; - public MotionUpdateEvent(MotionUpdateEvent event){ - this(event.getX(), event.getY(), event.getZ(), event.getRotationYaw(), event.getRotationPitch(), event.isOnGround()); - } + private float yaw; + private float pitch; - public MotionUpdateEvent(double x, double y, double z, float rotationYaw, float rotationPitch, boolean onGround) { + public MotionUpdateEvent(double x, double y, double z, float yaw, float pitch) { this.x = x; this.y = y; this.z = z; - this.rotationYaw = rotationYaw; - this.rotationPitch = rotationPitch; - this.onGround = onGround; - this.prevX = x; - this.prevY = y; - this.prevZ = z; - this.prevYaw = rotationYaw; - this.prevPitch = rotationPitch; - this.prevOnGround = onGround; - } - - - public double getPrevX() { - return prevX; - } - - public double getPrevY() { - return prevY; - } - - public double getPrevZ() { - return prevZ; - } - - public float getPrevYaw() { - return prevYaw; - } - - public float getPrevPitch() { - return prevPitch; - } - - public boolean isPrevOnGround() { - return prevOnGround; - } - - public float getRotationYaw() { - return rotationYaw; - } - - public float getRotationPitch() { - return rotationPitch; + this.yaw = yaw; + this.pitch = pitch; } public double getX() { return x; } - public void setX(double x) { - this.x = x; - } - public double getY() { return y; } - public void setY(double y) { - this.y = y; - } - public double getZ() { return z; } - public void setZ(double z) { - this.z = z; - } - public float getYaw() { - return rotationYaw; + return yaw; } - public void setYaw(float rotationYaw) { - this.rotationYaw = rotationYaw; + public void setYaw(float yaw) { + this.yaw = yaw; } public float getPitch() { - return rotationPitch; - } - - public void setPitch(float rotationPitch) { - this.rotationPitch = rotationPitch; - } - - public boolean isOnGround() { - return onGround; + return pitch; } - public void setOnGround(boolean onGround) { - this.onGround = onGround; + public void setPitch(float pitch) { + this.pitch = pitch; } } \ No newline at end of file diff --git a/src/main/java/me/zane/grassware/features/modules/combat/AutoCrystal.java b/src/main/java/me/zane/grassware/features/modules/combat/AutoCrystal.java index e37aae6..d039033 100644 --- a/src/main/java/me/zane/grassware/features/modules/combat/AutoCrystal.java +++ b/src/main/java/me/zane/grassware/features/modules/combat/AutoCrystal.java @@ -4,10 +4,7 @@ import com.mojang.realmsclient.gui.ChatFormatting; import me.zane.grassware.GrassWare; import me.zane.grassware.event.bus.EventListener; -import me.zane.grassware.event.events.PacketEvent; -import me.zane.grassware.event.events.Render3DEvent; -import me.zane.grassware.event.events.Render3DPreEvent; -import me.zane.grassware.event.events.UpdatePlayerWalkingEvent; +import me.zane.grassware.event.events.*; import me.zane.grassware.features.modules.Module; import me.zane.grassware.features.modules.client.ClickGui; import me.zane.grassware.features.setting.impl.BooleanSetting; @@ -27,7 +24,6 @@ import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; -import net.minecraft.network.play.client.CPacketPlayer; import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock; import net.minecraft.network.play.client.CPacketUseEntity; import net.minecraft.network.play.server.SPacketDestroyEntities; @@ -91,12 +87,14 @@ public class AutoCrystal extends Module { ArrayList crystals = new ArrayList<>(); ArrayList blackListedPos = new ArrayList<>(); + private boolean rotating; private BlockPos placedPos; private BlockPos lastPos; private BlockPos savedPos; private long placeTime; private long breakTime; private float i = 0.0f; + private float[] rotations; private EnumHand enumHand; private boolean hasPlaced = false; private boolean hasBroken = false; @@ -108,6 +106,7 @@ public class AutoCrystal extends Module { public void onDisable() { crystals.clear(); blackListedPos.clear(); + rotating = false; } @Override @@ -120,6 +119,7 @@ public void onUpdate(final UpdatePlayerWalkingEvent event) { final EntityPlayer entityPlayer = target(targetRange.getValue()); if (entityPlayer == null) { placedPos = null; + rotating = false; } else { final BlockPos pos = pos(entityPlayer); switch (logic.getValue()) { @@ -156,6 +156,7 @@ public void placeCrystal(BlockPos pos) { hasPlaced = false; if (pos == null) { placedPos = null; + rotating = false; return; } @@ -163,12 +164,12 @@ public void placeCrystal(BlockPos pos) { if (waitForBreak.getValue() && !hasBroken) { return; } - float[] rotations = calculateRotations(pos); if (System.currentTimeMillis() - placeTime > placeDelay.getValue()) { if (enumHand != null) { if (rotateMode.getValue().equals("PlaceBreak") || rotateMode.getValue().equals("Place")) - mc.getConnection().sendPacket(new CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround)); + rotating = true; + rotations = calculateRotations(pos); (mc.getConnection()).sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, EnumFacing.UP, enumHand, OFFSET, OFFSET, OFFSET)); swingHand(); @@ -190,14 +191,14 @@ public void breakCrystal(EntityPlayer entityPlayer) { if (entityEnderCrystal == null) { return; } - float[] rotations = calculateRotations(entityEnderCrystal.getPosition()); - + rotating = false; hasBroken = false; final boolean isCrystalNotListed = !inhibit.getValue() || !crystals.contains(entityEnderCrystal); if (System.currentTimeMillis() - breakTime > breakDelay.getValue() && isCrystalNotListed) { crystals.add(entityEnderCrystal); if (rotateMode.getValue().equals("PlaceBreak") || rotateMode.getValue().equals("Break")) - mc.getConnection().sendPacket(new CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround)); + rotating = true; + rotations = calculateRotations(entityEnderCrystal.getPosition()); (mc.getConnection()).sendPacket(new CPacketUseEntity(entityEnderCrystal)); hasBroken = true; @@ -241,10 +242,8 @@ public void onPacketReceive(PacketEvent.Receive event) { if (selfDamage > mc.player.getHealth() + mc.player.getAbsorptionAmount()) { return; } - float[] rotations = calculateRotations(crystal.getPosition()); - - if (rotateMode.getValue().equals("PlaceBreak") || rotateMode.getValue().equals("Break")) - mc.getConnection().sendPacket(new CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround)); + rotating = rotateMode.getValue().equals("PlaceBreak") || rotateMode.getValue().equals("Break"); + rotations = calculateRotations(crystal.getPosition()); (mc.getConnection()).sendPacket(new CPacketUseEntity(crystal)); if (predict.getValue()) { @@ -298,7 +297,7 @@ public void onPacketReceive(PacketEvent.Receive event) { }); } } - SPacketSpawnObject spawnedCrystal = new SPacketSpawnObject(); + SPacketSpawnObject spawnedCrystal; if (event.getPacket() instanceof SPacketSpawnObject && (spawnedCrystal = event.getPacket()).getType() == 51 && this.instantExplode.getValue()) { CPacketUseEntity attackPacket = new CPacketUseEntity(); ((ICPacketUseEntity) attackPacket).setEntityId(spawnedCrystal.getEntityID()); @@ -349,11 +348,6 @@ public void onPacketSend(PacketEvent.Send event) { (packet.getEntityFromWorld(AutoCrystal.mc.world)).setDead(); AutoCrystal.mc.world.removeEntityFromWorld(packet.entityId); } - // if (event.getPacket() instanceof CPacketPlayerTryUseItemOnBlock) { - // handleCPacketPlayerTryUseItemOnBlock(event); - // } else if (event.getPacket() instanceof CPacketUseEntity) { - // handleCPacketUseEntity(event); - // } } @EventListener @@ -365,9 +359,9 @@ public void onPredict(PacketEvent.Receive event) { } EntityEnderCrystal crystal = new EntityEnderCrystal(AutoCrystal.mc.world, packet.getX(), packet.getY(), packet.getZ()); - float[] rotations = calculateRotations(crystal.getPosition()); if (rotateMode.getValue().equals("PlaceBreak") || rotateMode.getValue().equals("Place")) - mc.getConnection().sendPacket(new CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround)); + rotating = true; + rotations = calculateRotations(crystal.getPosition()); CPacketUseEntity crystalPacket = new CPacketUseEntity(); crystalPacket.entityId = packet.getEntityID(); @@ -387,9 +381,15 @@ public void onPredict(PacketEvent.Receive event) { } + @EventListener + public void onMotionUpdate(MotionUpdateEvent event) { + if (rotating) { + event.setYaw(rotations[0]); + event.setPitch(rotations[1]); + } + } private void handleSetDead(EntityEnderCrystal crystal) { - mc.getConnection().sendPacket(new CPacketUseEntity(crystal)); if (setDead.getValue().equals("Set Dead") || setDead.getValue().equals("Both")) crystal.setDead(); if (setDead.getValue().equals("Remove") || setDead.getValue().equals("Both")) diff --git a/src/main/java/me/zane/grassware/mixin/mixins/MixinEntityPlayerSP.java b/src/main/java/me/zane/grassware/mixin/mixins/MixinEntityPlayerSP.java index 95302c2..e96c4a0 100644 --- a/src/main/java/me/zane/grassware/mixin/mixins/MixinEntityPlayerSP.java +++ b/src/main/java/me/zane/grassware/mixin/mixins/MixinEntityPlayerSP.java @@ -2,15 +2,15 @@ import com.mojang.authlib.GameProfile; import me.zane.grassware.GrassWare; -import me.zane.grassware.event.events.ChatEvent; -import me.zane.grassware.event.events.MoveEvent; -import me.zane.grassware.event.events.PushBlockEvent; -import me.zane.grassware.event.events.UpdatePlayerWalkingEvent; +import me.zane.grassware.event.EventStage; +import me.zane.grassware.event.events.*; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.MoverType; import net.minecraft.world.World; +import net.minecraftforge.fml.common.eventhandler.Event; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -18,7 +18,8 @@ @Mixin(EntityPlayerSP.class) public class MixinEntityPlayerSP extends AbstractClientPlayer { - + @Unique + private float savedYaw, savedPitch; public MixinEntityPlayerSP(final World worldIn, final GameProfile playerProfile) { super(worldIn, playerProfile); } @@ -47,13 +48,32 @@ public void move(final MoverType type, final double x, final double y, final dou @Inject(method = "onUpdateWalkingPlayer", at = @At("HEAD"), cancellable = true) private void onUpdateWalkingPlayer(final CallbackInfo ci) { + final EntityPlayerSP player = EntityPlayerSP.class.cast(this); final UpdatePlayerWalkingEvent updatePlayerWalkingEvent = new UpdatePlayerWalkingEvent(); GrassWare.eventBus.invoke(updatePlayerWalkingEvent); if (updatePlayerWalkingEvent.isCancelled()) { ci.cancel(); } - } + final MotionUpdateEvent motionUpdateEvent = new MotionUpdateEvent(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch); + GrassWare.eventBus.invoke(motionUpdateEvent); + if (motionUpdateEvent.isCancelled()) { + ci.cancel(); + return; + } + savedYaw = player.rotationYaw; + savedPitch = player.rotationPitch; + player.rotationYaw = motionUpdateEvent.getYaw(); + player.rotationPitch = motionUpdateEvent.getPitch(); + } + @Inject(method = "onUpdateWalkingPlayer", at = @At("TAIL")) + private void onUpdateWalkingPlayerTail(CallbackInfo callback) { + final EntityPlayerSP player = EntityPlayerSP.class.cast(this); + + GrassWare.eventBus.invoke(new MotionUpdateEvent(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch)); + player.rotationYaw = savedYaw; + player.rotationPitch = savedPitch; + } @Inject(method = "pushOutOfBlocks", at = @At("HEAD"), cancellable = true) protected void pushOutOfBlocksHook(final double x, final double y, final double z, final CallbackInfoReturnable info) { final PushBlockEvent pushBlockEvent = new PushBlockEvent(); diff --git a/src/main/java/me/zane/grassware/util/BlockUtil.java b/src/main/java/me/zane/grassware/util/BlockUtil.java index a5ae9a9..cbc54ef 100644 --- a/src/main/java/me/zane/grassware/util/BlockUtil.java +++ b/src/main/java/me/zane/grassware/util/BlockUtil.java @@ -26,7 +26,7 @@ import java.util.List; public class BlockUtil implements MC { - // EntityOtherPlayerMP futurePlayer = new EntityOtherPlayerMP(mc.world, entityPlayer.getGameProfile()); + // EntityOtherPlayerMP futurePlayer = new EntityOtherPlayerMP(mc.world, entityPlayer.getGameProfile()); private static final Vec3i[] hole = new Vec3i[]{ new Vec3i(-1, 0, 0), new Vec3i(1, 0, 0), @@ -44,17 +44,19 @@ public static boolean valid(BlockPos pos, boolean updated) { } - public static BlockPos center() { return new BlockPos(Math.floor(mc.player.posX), Math.floor(mc.player.posY), Math.floor(mc.player.posZ)); } + public static BlockPos getPosition() { return new BlockPos(Math.floor(mc.player.posX), Math.floor(mc.player.posY), Math.floor(mc.player.posZ)); } + public static boolean empty(BlockPos pos) { return mc.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(new BlockPos(pos.getX() + 0.5f, pos.getY() + 1.0f, pos.getZ() + 0.5f))).isEmpty(); } - public static boolean isReplaceable(BlockPos pos){ + + public static boolean isReplaceable(BlockPos pos) { return mc.world.getBlockState(pos).getMaterial().isReplaceable(); } @@ -69,12 +71,15 @@ public static boolean hasCrystal(BlockPos pos) { public static float distance(BlockPos pos) { return (float) Math.sqrt(mc.player.getDistanceSq(pos)); } + public static BlockPos center(BlockPos pos) { return pos.add(0.5f, 0.5f, 0.5f); } + public static boolean is(BlockPos pos, Block block) { return mc.world.getBlockState(pos).getBlock().equals(block); } + public static boolean isPlayerSafe(EntityPlayer entityPlayer) { final BlockPos pos = entityPlayer.getPosition(); if (isNotIntersecting(entityPlayer)) { @@ -83,6 +88,7 @@ public static boolean isPlayerSafe(EntityPlayer entityPlayer) { return isIntersectingSafe(entityPlayer); } } + public static boolean isNotIntersecting(EntityPlayer entityPlayer) { final BlockPos pos = entityPlayer.getPosition(); final AxisAlignedBB bb = entityPlayer.getEntityBoundingBox(); @@ -113,6 +119,7 @@ public static boolean isIntersectingSafe(EntityPlayer entityPlayer) { } return true; } + public static boolean isBedrockOrObsidianOrEchest(final BlockPos pos) { return mc.world.getBlockState(pos).getBlock().equals(Blocks.BEDROCK) || mc.world.getBlockState(pos).getBlock().equals(Blocks.OBSIDIAN) || mc.world.getBlockState(pos).getBlock().equals(Blocks.ENDER_CHEST); } @@ -122,7 +129,6 @@ public static boolean air(final BlockPos pos) { } - public static float calculateEntityDamage(final EntityEnderCrystal crystal, final EntityPlayer entityPlayer) { return calculatePosDamage(crystal.posX, crystal.posY, crystal.posZ, entityPlayer); } @@ -130,6 +136,7 @@ public static float calculateEntityDamage(final EntityEnderCrystal crystal, fina public static float calculatePosDamage(final BlockPos position, final EntityPlayer entityPlayer) { return calculatePosDamage(position.getX() + 0.5, position.getY() + 1.0, position.getZ() + 0.5, entityPlayer); } + public static float calculatePosDamageEx(final BlockPos position, final Vec3d futurePos) { // Calculate the damage based on the position // This is just a placeholder, replace with your actual damage calculation @@ -255,6 +262,7 @@ public static List getBlocksInRadius(final float range) { } return posses; } + public static boolean canPlaceCrystal(final BlockPos pos, boolean second) { final Chunk chunk = mc.world.getChunk(pos); final Block block = chunk.getBlockState(pos).getBlock(); @@ -279,6 +287,7 @@ public static boolean canPlaceCrystal(final BlockPos pos, boolean second) { } return true; } + public static void lookAtPos(BlockPos pos) { double diffX = pos.getX() + 0.5 - mc.player.posX; double diffY = pos.getY() + 0.5 - (mc.player.posY + mc.player.getEyeHeight()); @@ -295,6 +304,7 @@ private static void setPlayerRotations(float yaw, float pitch) { mc.player.rotationYaw = yaw % 360; mc.player.rotationPitch = pitch; } + public static float[] calculateRotations(BlockPos pos) { double diffX = pos.getX() + 0.5 - mc.player.posX; double diffY = pos.getY() + 0.5 - (mc.player.posY + mc.player.getEyeHeight());