Skip to content

Commit

Permalink
Fix cape toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Nov 25, 2021
1 parent 0f3bc33 commit 907a4dd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.authlib.properties.PropertyMap;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -21,7 +22,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static org.samo_lego.fabrictailor.FabricTailor.config;
import static org.samo_lego.fabrictailor.FabricTailor.errorLog;
import static org.samo_lego.fabrictailor.mixin.accessors.PlayerEntityAccessor.getPLAYER_MODEL_PARTS;

@Mixin(ServerPlayerEntity.class)
public class ServerPlayerEntityMixin_TailoredPlayer implements TailoredPlayer {
Expand Down Expand Up @@ -159,6 +162,17 @@ public void resetLastSkinChange() {
this.lastSkinChangeTime = 0;
}

@Inject(method = "setClientSettings", at = @At("TAIL"))
private void disableCapeIfNeeded(ClientSettingsC2SPacket packet, CallbackInfo ci) {
if(!config.allowCapes) {
byte playerModel = (byte) packet.playerModelBitMask();

// Fake cape rule to be off
playerModel = (byte) (playerModel & ~(1));
this.player.getDataTracker().set(getPLAYER_MODEL_PARTS(), playerModel);
}
}


@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
private void writeCustomDataToNbt(NbtCompound tag, CallbackInfo ci) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.samo_lego.fabrictailor.mixin.accessors;

import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(PlayerEntity.class)
public interface PlayerEntityAccessor {
@Accessor("PLAYER_MODEL_PARTS")
static TrackedData<Byte> getPLAYER_MODEL_PARTS() {
throw new AssertionError();
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabrictailor.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"required": true,
"minVersion": "0.8",
"package": "org.samo_lego.fabrictailor.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_13",
"client": [
"accessors.client.AdvancementsScreenAccessor"
],
"mixins": [
"MixinPlayerManager",
"ServerPlayerEntityMixin_TailoredPlayer",
"ServerPlayNetworkHandlerMixin_PacketListener",
"accessors.ClientSettingsC2SAccessor",
"accessors.EntityTrackerAccessor",
"accessors.PlayerEntityAccessor",
"accessors.ThreadedAnvilChunkStorageAccessor"
],
"injectors": {
Expand Down

0 comments on commit 907a4dd

Please sign in to comment.