diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java index 205625d..a085c7b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java @@ -7,9 +7,6 @@ import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.command.CommandManager.argument; - -import land.chipmunk.chipmunkmod.ChipmunkMod; -import land.chipmunk.chipmunkmod.util.SharedVariables; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ConnectScreen; @@ -26,6 +23,7 @@ import java.util.UUID; import land.chipmunk.chipmunkmod.mixin.MinecraftClientAccessor; public class UsernameCommand { + private static final Session ORIGINAL_SESSION = ((MinecraftClientAccessor) MinecraftClient.getInstance()).session(); private static final SimpleCommandExceptionType USERNAME_TOO_LONG = new SimpleCommandExceptionType(Text.translatable("The specified username is longer than 16 characters")); public static void register (CommandDispatcher dispatcher) { @@ -35,9 +33,13 @@ public class UsernameCommand { literal("set") .then( argument("username", greedyString()) - .executes(UsernameCommand::updateUsername) + .executes(c -> updateUsername(c)) ) ) + .then( + literal("revert") + .executes(c -> updateSession(c, ORIGINAL_SESSION)) + ) ); } @@ -48,17 +50,18 @@ public class UsernameCommand { return updateSession(context, session); } - public static int updateSession (CommandContext context, String username) throws CommandSyntaxException { + public static int updateSession (CommandContext context, Session session) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final MinecraftClient client = source.getClient(); - ChipmunkMod.CONFIG.defaultUsername = username; + ((MinecraftClientAccessor) client).session(session); + // TODO: Put this in a separate class final ServerInfo info = client.getCurrentServerEntry(); client.world.disconnect(); client.disconnect(); - ConnectScreen.connect(new MultiplayerScreen(new TitleScreen()), client, ServerAddress.parse(info.address), info, false); + ConnectScreen.connect(new TitleScreen(), client, ServerAddress.parse(info.address), info, false); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoInvoker.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoInvoker.java deleted file mode 100644 index bf6ebb7..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoInvoker.java +++ /dev/null @@ -1,17 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtIo; -import net.minecraft.nbt.NbtTagSizeTracker; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -import java.io.DataInput; - -@Mixin(NbtIo.class) -public interface NbtIoInvoker { - @Invoker(value = "read") - static NbtElement readInvoker(DataInput input, int depth, NbtTagSizeTracker tracker) { - throw new AssertionError(); - } -} \ No newline at end of file diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoMixin.java deleted file mode 100644 index 49c3da5..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import land.chipmunk.chipmunkmod.ChipmunkMod; -import land.chipmunk.chipmunkmod.util.Chat; -import net.minecraft.nbt.*; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.DataInput; -import java.io.IOException; - -@Mixin(NbtIo.class) -public class NbtIoMixin { - - @Inject(method = "read(Ljava/io/DataInput;ILnet/minecraft/nbt/NbtTagSizeTracker;)Lnet/minecraft/nbt/NbtElement;",at = @At("HEAD"), cancellable = true) - private static void testclient$preventNbtKick(DataInput input, int depth, NbtTagSizeTracker tracker, CallbackInfoReturnable cir) throws IOException { - byte b = input.readByte(); - if (b == 0) { - cir.setReturnValue(NbtEnd.INSTANCE); - } else { - NbtString.skip(input); - - try { - cir.setReturnValue(NbtTypes.byId(b).read(input, depth, tracker)); - } catch (Exception var7) { - Chat.sendGold("ChipmunkMod prevented an NBT kick!"); - cir.setReturnValue(NbtEnd.INSTANCE); // i don't fucking know i just copied - } - } - } - - @Inject(method = "read(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtTagSizeTracker;)Lnet/minecraft/nbt/NbtCompound;", at = @At("HEAD"), cancellable = true) - private static void testclient$antiNbtKickPreventLag(DataInput input, NbtTagSizeTracker tracker, CallbackInfoReturnable cir) { - NbtElement nbtElement = NbtIoInvoker.readInvoker(input, 0, tracker); - if (nbtElement instanceof NbtCompound) { - cir.setReturnValue((NbtCompound)nbtElement); - } else { - ChipmunkMod.LOGGER.warn("ChipmunkMod hopefully prevented lag lol idk"); - } - } - -} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/PacketBundleHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/PacketBundleHandlerMixin.java index 8e80aa5..d60d3a4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/PacketBundleHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/PacketBundleHandlerMixin.java @@ -1,6 +1,6 @@ package land.chipmunk.chipmunkmod.mixin; -import net.minecraft.network.PacketBundleHandler; +import net.minecraft.network.handler.PacketBundleHandler; import net.minecraft.network.listener.PacketListener; import net.minecraft.network.packet.BundlePacket; import net.minecraft.network.packet.BundleSplitterPacket; diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/SessionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/SessionMixin.java index 623bbd8..514a1e5 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/SessionMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/SessionMixin.java @@ -3,7 +3,7 @@ package land.chipmunk.chipmunkmod.mixin; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.testclient.gui.Gui; import land.chipmunk.chipmunkmod.util.SharedVariables; -import net.minecraft.client.util.Session; +import net.minecraft.client.session.Session; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/AttributeModifier.java b/src/main/java/land/chipmunk/chipmunkmod/util/AttributeModifier.java deleted file mode 100644 index 1a8e121..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/util/AttributeModifier.java +++ /dev/null @@ -1,58 +0,0 @@ -package land.chipmunk.chipmunkmod.util; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeModifier; - -public class AttributeModifier { - /* - EntityAttributeInstance movementSpeedAttribute = MC.player.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED); - EntityAttributeModifier tempModifier = new EntityAttributeModifier( - "TestClient@Speed", // Modifier name - 3, // Modifier value - EntityAttributeModifier.Operation.MULTIPLY_TOTAL); // Modifier operation - movementSpeedAttribute.addPersistentModifier(tempModifier); - */ - String name; - EntityAttribute attribute; - float value; - EntityAttributeModifier.Operation operation; - EntityAttributeModifier modifier; - EntityAttributeInstance instance; - public AttributeModifier(EntityAttribute attribute, float value, EntityAttributeModifier.Operation operation) { - this.attribute = attribute; - this.value = value; - this.operation = operation; - name = "TestClient@"+(new Throwable().getStackTrace()[1].getClassName())+"."+(new Throwable().getStackTrace()[1].getMethodName()); -// Chat.send("Created new attribute modifier " + name); - instance = MinecraftClient.getInstance().player.getAttributeInstance(attribute); - modifier = new EntityAttributeModifier(name, value, operation); - } - - public void add() { - instance.addPersistentModifier(modifier); - } - - public void remove() { - instance.removeModifier(modifier); - } - - public boolean isOnPlayer() { - return instance.hasModifier(modifier); - } - - public void setValue(float value) { - this.value = value; - modifier = new EntityAttributeModifier(name, value, operation); - // remove and add multiplier to refresh value - if(isOnPlayer()){ - remove(); - add(); - } - } - - public float getValue() { - return value; - } -} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index a9f226f..061d7a7 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -13,7 +13,6 @@ "ClientPlayerEntityMixin", "ClientPlayNetworkHandlerAccessor", "ClientPlayNetworkHandlerMixin", - "DecoderHandlerMixin", "DecoratedPotBlockEntitySherdsMixin", "MinecraftClientAccessor", "StringHelperMixin", @@ -24,7 +23,6 @@ "KeyboardMixin", "MinecraftClientAccessor", "MultiplayerScreenMixin", - "NbtIoMixin", "PlayerListEntryAccessor", "SessionMixin", "SharedConstantsMixin", @@ -40,7 +38,6 @@ "defaultRequire": 1 }, "mixins": [ - "NbtIoInvoker", "PacketBundleHandlerMixin", "PlayerEntityMixin", "TextMixin",