Skip to content

Commit

Permalink
i mother ducking hate this.
Browse files Browse the repository at this point in the history
on linux i can code shit on intelij. on windows i cannot.
on linux i cannot put the mod in multimc. on windows i can
aiSDIUAHSIUDH
  • Loading branch information
Zane2b2t committed Apr 13, 2024
1 parent bdcdc90 commit 497cf3e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 108 deletions.
89 changes: 14 additions & 75 deletions src/main/java/me/zane/grassware/event/events/MotionUpdateEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -91,12 +87,14 @@ public class AutoCrystal extends Module {
ArrayList<EntityEnderCrystal> crystals = new ArrayList<>();
ArrayList<BlockPos> 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;
Expand All @@ -108,6 +106,7 @@ public class AutoCrystal extends Module {
public void onDisable() {
crystals.clear();
blackListedPos.clear();
rotating = false;
}

@Override
Expand All @@ -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()) {
Expand Down Expand Up @@ -156,19 +156,20 @@ public void placeCrystal(BlockPos pos) {
hasPlaced = false;
if (pos == null) {
placedPos = null;
rotating = false;
return;
}

if (blackListedPos.contains(pos)) return;
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();
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EntityPlayerSP.class)
public class MixinEntityPlayerSP extends AbstractClientPlayer {

@Unique
private float savedYaw, savedPitch;
public MixinEntityPlayerSP(final World worldIn, final GameProfile playerProfile) {
super(worldIn, playerProfile);
}
Expand Down Expand Up @@ -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<Boolean> info) {
final PushBlockEvent pushBlockEvent = new PushBlockEvent();
Expand Down
Loading

0 comments on commit 497cf3e

Please sign in to comment.