This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
SorceryCraft/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinServerPlayerEntity.java

31 lines
1.3 KiB
Java

package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity;
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.CallbackInfo;
@SuppressWarnings("unused")
@Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity implements SpellPlayerEntity {
@Inject(at = @At("HEAD"), method = "copyFrom")
public void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci) {
SpellPlayerEntity oldSpellPlayer = (SpellPlayerEntity) oldPlayer;
SpellPlayerEntity newSpellPlayer = this;
newSpellPlayer.setSpells(oldSpellPlayer.getSpells());
}
@Inject(at = @At("HEAD"), method = "playerTick")
public void playerTick(CallbackInfo ignored) {
CompoundTag tag = new CompoundTag();
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(getSpells()));
//noinspection ConstantConditions
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
}
}