Skip to content

Commit

Permalink
Fix command, FullBright, XRay
Browse files Browse the repository at this point in the history
  • Loading branch information
TangyKiwi committed Jun 11, 2022
1 parent 9b042da commit a42ad80
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 26 deletions.
23 changes: 17 additions & 6 deletions src/main/java/com/tangykiwi/kiwiclient/command/commands/Ez.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.tangykiwi.kiwiclient.command.Command;
import com.tangykiwi.kiwiclient.mixin.ClientPlayerEntityAccessor;
import com.tangykiwi.kiwiclient.util.Utils;
import net.minecraft.command.CommandSource;
import net.minecraft.network.message.ChatMessageSigner;
import net.minecraft.network.message.MessageSignature;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.text.Text;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

Expand All @@ -13,15 +17,22 @@ public Ez() {
super("ez", "Says a big EZ in chat");
}

String[] messages = {
"███████╗███████╗",
"███████╗███████╗",
"█████╗░░░░███╔═╝",
"██╔══╝░░██╔══╝░░",
"███████╗███████╗",
"╚══════╝╚══════╝"};

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {

builder.executes(context -> {
Utils.mc.player.sendChatMessage("███████╗███████╗");
Utils.mc.player.sendChatMessage("██╔════╝╚════██║");
Utils.mc.player.sendChatMessage("█████╗░░░░███╔═╝");
Utils.mc.player.sendChatMessage("██╔══╝░░██╔══╝░░");
Utils.mc.player.sendChatMessage("███████╗███████╗");
Utils.mc.player.sendChatMessage("╚══════╝╚══════╝");
for(String message : messages) {
MessageSignature messageSignature = ((ClientPlayerEntityAccessor) Utils.mc.player)._signChatMessage(ChatMessageSigner.create(Utils.mc.player.getUuid()), Text.literal(message));
Utils.mc.getNetworkHandler().sendPacket(new ChatMessageC2SPacket(message, messageSignature, false));
}
return SINGLE_SUCCESS;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.tangykiwi.kiwiclient.command.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.tangykiwi.kiwiclient.mixin.ClientPlayerEntityAccessor;
import com.tangykiwi.kiwiclient.util.Utils;
import net.minecraft.command.CommandSource;
import net.minecraft.network.message.ChatMessageSigner;
import net.minecraft.network.message.MessageSignature;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.text.Text;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
Expand All @@ -17,7 +21,9 @@ public FF() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
Utils.mc.player.sendChatMessage("I'm gonna FF, gg go next.");
String message = "I'm gonna FF, gg go next.";
MessageSignature messageSignature = ((ClientPlayerEntityAccessor) Utils.mc.player)._signChatMessage(ChatMessageSigner.create(Utils.mc.player.getUuid()), Text.literal(message));
Utils.mc.getNetworkHandler().sendPacket(new ChatMessageC2SPacket(message, messageSignature, false));
Utils.mc.player.networkHandler.getConnection().disconnect(Text.literal("Literally just FFed."));
return SINGLE_SUCCESS;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.tangykiwi.kiwiclient.command.Command;
import com.tangykiwi.kiwiclient.mixin.ClientPlayerEntityAccessor;
import com.tangykiwi.kiwiclient.util.Utils;
import net.minecraft.command.CommandSource;
import net.minecraft.network.message.ChatMessageSigner;
import net.minecraft.network.message.MessageSignature;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.text.Text;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

Expand All @@ -17,8 +21,9 @@ public Say() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(argument("message", StringArgumentType.greedyString()).executes(context -> {
String msg = context.getArgument("message", String.class);
Utils.mc.player.sendChatMessage(msg);
String message = context.getArgument("message", String.class);
MessageSignature messageSignature = ((ClientPlayerEntityAccessor) Utils.mc.player)._signChatMessage(ChatMessageSigner.create(Utils.mc.player.getUuid()), Text.literal(message));
Utils.mc.getNetworkHandler().sendPacket(new ChatMessageC2SPacket(message, messageSignature, false));

return SINGLE_SUCCESS;
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tangykiwi.kiwiclient.mixin;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.message.ChatMessageSigner;
import net.minecraft.network.message.MessageSignature;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ClientPlayerEntity.class)
public interface ClientPlayerEntityAccessor {
@Invoker("signChatMessage")
MessageSignature _signChatMessage(ChatMessageSigner signer, Text message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.tangykiwi.kiwiclient.KiwiClient;
import com.tangykiwi.kiwiclient.command.Command;
import com.tangykiwi.kiwiclient.command.CommandManager;
import com.tangykiwi.kiwiclient.event.OnMoveEvent;
import com.tangykiwi.kiwiclient.event.SendChatMessageEvent;
import com.tangykiwi.kiwiclient.event.TickEvent;
Expand All @@ -18,6 +16,7 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.MovementType;
import net.minecraft.network.encryption.PlayerPublicKey;
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -27,6 +26,8 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import javax.annotation.Nullable;

@Mixin(ClientPlayerEntity.class)
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity implements IClientPlayerEntity {
@Shadow
Expand All @@ -36,9 +37,9 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity

@Shadow public abstract void sendChatMessage(String string);

public ClientPlayerEntityMixin(ClientWorld world, GameProfile gameProfile)
public ClientPlayerEntityMixin(ClientWorld world, GameProfile gameProfile, @Nullable PlayerPublicKey publicKey)
{
super(world, gameProfile, Utils.mc.player.getPublicKey());
super(world, gameProfile, publicKey);
}

@Inject(method = "tick()V", at = @At("RETURN"), cancellable = true)
Expand All @@ -58,8 +59,8 @@ private void onMove(MovementType type, Vec3d offset, CallbackInfo callbackInfo)
KiwiClient.eventBus.post(event);
}

@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
public void onChatMessage(String message, CallbackInfo callbackInfo) {
@Inject(method = "sendChatMessage(Ljava/lang/String;Lnet/minecraft/text/Text;)V", at = @At("HEAD"), cancellable = true)
private void onSendChatMessage(String message, Text preview, CallbackInfo callbackInfo) {
if (ignoreChatMessage) return;

if (!message.startsWith(KiwiClient.PREFIX) && !message.startsWith("/")) {
Expand All @@ -86,12 +87,6 @@ public void onChatMessage(String message, CallbackInfo callbackInfo) {
}
}

@Override
public void setNoClip(boolean noClip)
{
this.noClip = noClip;
}

@Override
protected boolean clipAtLedge() {
return super.clipAtLedge() || KiwiClient.moduleManager.getModule(SafeWalk.class).isEnabled();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.tangykiwi.kiwiclient.mixin;

import com.tangykiwi.kiwiclient.mixininterface.ISimpleOption;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.SimpleOption;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Objects;
import java.util.function.Consumer;

@Mixin(SimpleOption.class)
public class SimpleOptionMixin<T> implements ISimpleOption<T> {
@Shadow
T value;

@Shadow
@Final
private Consumer<T> changeCallback;

@Override
public void forceSetValue(T newValue)
{
if(!MinecraftClient.getInstance().isRunning())
{
value = newValue;
return;
}

if(!Objects.equals(value, newValue))
{
value = newValue;
changeCallback.accept(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.tangykiwi.kiwiclient.mixininterface;

public interface IClientPlayerEntity {
void setNoClip(boolean noClip);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tangykiwi.kiwiclient.mixininterface;

public interface ISimpleOption<T> {
public void forceSetValue(T newValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.google.common.eventbus.Subscribe;
import com.tangykiwi.kiwiclient.event.TickEvent;
import com.tangykiwi.kiwiclient.mixininterface.ISimpleOption;
import com.tangykiwi.kiwiclient.modules.Category;
import com.tangykiwi.kiwiclient.modules.Module;
import net.minecraft.client.option.SimpleOption;

public class FullBright extends Module {

Expand All @@ -13,12 +15,22 @@ public FullBright() {

@Subscribe
public void onTick(TickEvent e) {
if(mc.options.getGamma().getValue() < 15) mc.options.getGamma().setValue(mc.options.getGamma().getValue() + 0.5);
if(mc.options.getGamma().getValue() < 16) {
SimpleOption<Double> gammaOption = mc.options.getGamma();
@SuppressWarnings("unchecked")
ISimpleOption<Double> gammaOption2 = (ISimpleOption<Double>)(Object)gammaOption;
gammaOption2.forceSetValue(gammaOption.getValue() + 0.5);
}
}

@Override
public void onDisable() {
super.onDisable();
while(mc.options.getGamma().getValue() > 1) mc.options.getGamma().setValue(mc.options.getGamma().getValue() - 0.5);
while(mc.options.getGamma().getValue() > 1) {
SimpleOption<Double> gammaOption = mc.options.getGamma();
@SuppressWarnings("unchecked")
ISimpleOption<Double> gammaOption2 = (ISimpleOption<Double>)(Object)gammaOption;
gammaOption2.forceSetValue(gammaOption.getValue() - 0.5);
}
}
}
12 changes: 10 additions & 2 deletions src/main/java/com/tangykiwi/kiwiclient/modules/render/XRay.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.tangykiwi.kiwiclient.event.RenderBlockEvent;
import com.tangykiwi.kiwiclient.event.RenderFluidEvent;
import com.tangykiwi.kiwiclient.event.TickEvent;
import com.tangykiwi.kiwiclient.mixininterface.ISimpleOption;
import com.tangykiwi.kiwiclient.modules.Category;
import com.tangykiwi.kiwiclient.modules.Module;
import com.tangykiwi.kiwiclient.modules.settings.SliderSetting;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.block.Blocks;
import net.minecraft.block.FernBlock;
import net.minecraft.block.TallPlantBlock;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.client.render.RenderLayer;

import java.util.ArrayList;
Expand Down Expand Up @@ -74,7 +76,10 @@ public void onEnable() {

@Override
public void onDisable() {
mc.options.getGamma().setValue(gamma);
SimpleOption<Double> gammaOption = mc.options.getGamma();
@SuppressWarnings("unchecked")
ISimpleOption<Double> gammaOption2 = (ISimpleOption<Double>)(Object)gammaOption;
gammaOption2.forceSetValue(gamma);
mc.chunkCullingEnabled = true;
mc.worldRenderer.reload();

Expand All @@ -84,7 +89,10 @@ public void onDisable() {
@Subscribe
@AllowConcurrentEvents
public void onTick(TickEvent e) {
mc.options.getGamma().setValue(69.420);
SimpleOption<Double> gammaOption = mc.options.getGamma();
@SuppressWarnings("unchecked")
ISimpleOption<Double> gammaOption2 = (ISimpleOption<Double>)(Object)gammaOption;
gammaOption2.forceSetValue(16.0);
}

@Subscribe
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/kiwiclient.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ChunkOcclusionDataBuilderMixin",
"ChunkRebuildTaskMixin",
"ClientConnectionMixin",
"ClientPlayerEntityAccessor",
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerAccessor",
"ClientPlayNetworkHandlerMixin",
Expand Down Expand Up @@ -49,6 +50,7 @@
"ScreenMixin",
"ShaderMixin",
"ShulkerBoxBlockMixin",
"SimpleOptionMixin",
"SodiumBlockOcclusionCacheMixin",
"SplashScreenMixin",
"TitleScreenMixin",
Expand Down

0 comments on commit a42ad80

Please sign in to comment.