Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakePlayer Rewrite #4283

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("add")
.executes(context -> {
FakePlayer fakePlayer = Modules.get().get(FakePlayer.class);
FakePlayerManager.add(fakePlayer.name.get(), fakePlayer.health.get(), fakePlayer.copyInv.get());
FakePlayerManager.add(fakePlayer.name.get(), fakePlayer.health.get(), fakePlayer.copyInv.get(), Modules.get().get(FakePlayer.class).allowDamage.get());
return SINGLE_SUCCESS;
})
.then(argument("name", StringArgumentType.word())
.executes(context -> {
FakePlayer fakePlayer = Modules.get().get(FakePlayer.class);
FakePlayerManager.add(StringArgumentType.getString(context, "name"), fakePlayer.health.get(), fakePlayer.copyInv.get());
FakePlayerManager.add(StringArgumentType.getString(context, "name"), fakePlayer.health.get(), fakePlayer.copyInv.get(), Modules.get().get(FakePlayer.class).allowDamage.get());
CrytoPal marked this conversation as resolved.
Show resolved Hide resolved
return SINGLE_SUCCESS;
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Blink() {
@Override
public void onActivate() {
if (renderOriginal.get()) {
model = new FakePlayerEntity(mc.player, mc.player.getGameProfile().getName(), 20, true);
model = new FakePlayerEntity(mc.player, mc.player.getGameProfile().getName(), 20, true, false);
model.doNotPush = true;
model.hideWhenInsideCamera = true;
model.spawn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public class FakePlayer extends Module {
.build()
);

public final Setting<Boolean> allowDamage = sgGeneral.add(new BoolSetting.Builder()
.name("Allow Damage")
CrytoPal marked this conversation as resolved.
Show resolved Hide resolved
.description("Allows FakePlayer taking Damage and Popping Totems")
CrytoPal marked this conversation as resolved.
Show resolved Hide resolved
.defaultValue(true)
.build()
);


public FakePlayer() {
super(Categories.Player, "fake-player", "Spawns a client-side fake player for testing usages. No need to be active.");
}
Expand All @@ -68,7 +76,7 @@ private void fillTable(GuiTheme theme, WTable table) {

WButton spawn = table.add(theme.button("Spawn")).expandCellX().right().widget();
spawn.action = () -> {
FakePlayerManager.add(name.get(), health.get(), copyInv.get());
FakePlayerManager.add(name.get(), health.get(), copyInv.get(), allowDamage.get());
table.clear();
fillTable(theme, table);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private class GhostPlayer extends FakePlayerEntity {
private double timer, scale = 1;

public GhostPlayer(PlayerEntity player) {
super(player, "ghost", 20, false);
super(player, "ghost", 20, false, false);

uuid = player.getUuid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,37 @@
package meteordevelopment.meteorclient.utils.entity.fakeplayer;

import com.mojang.authlib.GameProfile;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.utils.player.DamageUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

import static meteordevelopment.meteorclient.MeteorClient.mc;

public class FakePlayerEntity extends OtherClientPlayerEntity {
public boolean doNotPush, hideWhenInsideCamera;
public boolean doNotPush, hideWhenInsideCamera, Pop, allowDamage, swapToTotem;
public float chosenHealth;

public FakePlayerEntity(PlayerEntity player, String name, float health, boolean copyInv) {
public int ticks;

public FakePlayerEntity(PlayerEntity player, String name, float health, boolean copyInv, boolean allowDamage) {
super(mc.world, new GameProfile(UUID.randomUUID(), name));

copyPositionAndRotation(player);
Expand All @@ -29,6 +47,9 @@ public FakePlayerEntity(PlayerEntity player, String name, float health, boolean
prevHeadYaw = headYaw;
bodyYaw = player.bodyYaw;
prevBodyYaw = bodyYaw;
this.allowDamage = allowDamage;
chosenHealth = health;
ticks = 0;

Byte playerModel = player.getDataTracker().get(PlayerEntity.PLAYER_MODEL_PARTS);
dataTracker.set(PlayerEntity.PLAYER_MODEL_PARTS, playerModel);
Expand All @@ -40,24 +61,96 @@ public FakePlayerEntity(PlayerEntity player, String name, float health, boolean
capeY = getY();
capeZ = getZ();

if (health <= 20) {
setHealth(health);
this.setHealth(health);

if (copyInv) getInventory().clone(player.getInventory());
}

private void setDamage(float allowDamage) {
float health = this.getHealth() - allowDamage;

if (health < .5) {
health = chosenHealth;
Pop = true;
}

ticks = 0;
this.setHealth(health);
this.animateDamage(this.getYaw());
}

@EventHandler
private void onPacket(PacketEvent.Receive event) {
Packet<?> eventPacket = event.packet;
if (eventPacket instanceof ExplosionS2CPacket packet) {
if (!allowDamage) return;
if (ticks < 10) return;
float crystalDamage = (float) DamageUtils.crystalDamage(this, new Vec3d(packet.getX(), packet.getY(), packet.getZ()));
setDamage(crystalDamage);
}
}

@EventHandler
public void onTick(TickEvent.Post event) {
ticks++;
if ((mc.options.attackKey.isPressed() && mc.targetedEntity == this && mc.player.handSwinging)) {
if (ticks < 10) return;

if (canCrit()) {
mc.particleManager.addEmitter(this, ParticleTypes.CRIT);
mc.world.playSound(mc.player, this.getBlockPos(), SoundEvent.of(SoundEvents.ENTITY_PLAYER_ATTACK_CRIT.getId()), SoundCategory.PLAYERS, 1.0F, 1.0F);
} else {
mc.world.playSound(mc.player, this.getBlockPos(), SoundEvent.of(SoundEvents.ENTITY_PLAYER_ATTACK_STRONG.getId()), SoundCategory.PLAYERS, 1.0F, 1.0F);
}

setDamage((float) DamageUtils.getSwordDamage(this, canCrit()));
ticks = 0;
}
this.tick();

if (allowDamage) {
if (swapToTotem && ticks < 3) return;
swapToTotem = false;
this.setStackInHand(Hand.OFF_HAND, Items.TOTEM_OF_UNDYING.getDefaultStack());
} else {
setHealth(health);
setAbsorptionAmount(health - 20);
this.setStackInHand(Hand.OFF_HAND, Items.AIR.getDefaultStack());
return;
}

if (copyInv) getInventory().clone(player.getInventory());
if (!Pop) return;

afterPop(this);
mc.world.playSound(mc.player, this.getBlockPos(), SoundEvent.of(SoundEvents.ITEM_TOTEM_USE.getId()), SoundCategory.PLAYERS, 1.0F, 1.0F);
mc.particleManager.addEmitter(this, ParticleTypes.TOTEM_OF_UNDYING, 30);
Pop = false;
}

private void afterPop(PlayerEntity player) {
if (player.getMainHandStack().getItem() == Items.TOTEM_OF_UNDYING) {
player.setStackInHand(Hand.MAIN_HAND, Items.AIR.getDefaultStack());
return;
}

if (player.getMainHandStack().getItem() == Items.TOTEM_OF_UNDYING && player.getOffHandStack().getItem() != Items.TOTEM_OF_UNDYING)
return;
player.setStackInHand(Hand.OFF_HAND, Items.AIR.getDefaultStack());
swapToTotem = true;
}

private boolean canCrit() {
return mc.player.getAttackCooldownProgress(0.5f) > 0.9f && mc.player.fallDistance > 0.0F && !mc.player.isOnGround() && !mc.player.isClimbing() && !mc.player.isSubmergedInWater() && !mc.player.hasStatusEffect(StatusEffects.BLINDNESS) && !mc.player.isSprinting();
}

public void spawn() {
unsetRemoved();
mc.world.addEntity(this);
MeteorClient.EVENT_BUS.subscribe(this);
}

public void despawn() {
mc.world.removeEntity(getId(), RemovalReason.DISCARDED);
setRemoved(RemovalReason.DISCARDED);
MeteorClient.EVENT_BUS.unsubscribe(this);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public static FakePlayerEntity get(String name) {
return null;
}

public static void add(String name, float health, boolean copyInv) {
public static void add(String name, float health, boolean copyInv, boolean allowDamage) {
if (!Utils.canUpdate()) return;

FakePlayerEntity fakePlayer = new FakePlayerEntity(mc.player, name, health, copyInv);
FakePlayerEntity fakePlayer = new FakePlayerEntity(mc.player, name, health, copyInv, allowDamage);
fakePlayer.spawn();
ENTITIES.add(fakePlayer);
}
Expand Down