1.20.2 update

This commit is contained in:
7cc5c4f330d47060 2024-09-05 17:03:53 -04:00
parent f146976177
commit 675af542c6
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
7 changed files with 12 additions and 131 deletions

View file

@ -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<FabricClientCommandSource> 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<FabricClientCommandSource> context, String username) throws CommandSyntaxException {
public static int updateSession (CommandContext<FabricClientCommandSource> 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;
}

View file

@ -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();
}
}

View file

@ -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<NbtElement> 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<NbtCompound> 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");
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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",