2020-03-01 18:19:59 +00:00
|
|
|
package com.thebrokenrail.sorcerycraft.mixin;
|
|
|
|
|
2020-03-24 13:35:42 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
|
2020-03-01 18:19:59 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
|
2020-03-21 02:05:32 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
2020-03-06 23:35:29 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
2020-03-24 13:35:42 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellServerPlayerEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
2020-03-24 13:35:42 +00:00
|
|
|
import net.minecraft.util.Identifier;
|
2020-03-01 18:19:59 +00:00
|
|
|
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;
|
|
|
|
|
2020-03-24 13:35:42 +00:00
|
|
|
import java.util.Map;
|
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
@Mixin(ServerPlayerEntity.class)
|
2020-03-24 13:35:42 +00:00
|
|
|
public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implements SpellServerPlayerEntity {
|
2020-03-01 18:19:59 +00:00
|
|
|
@Inject(at = @At("HEAD"), method = "copyFrom")
|
2020-03-14 22:11:28 +00:00
|
|
|
public void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
|
2020-03-01 18:19:59 +00:00
|
|
|
SpellPlayerEntity oldSpellPlayer = (SpellPlayerEntity) oldPlayer;
|
|
|
|
SpellPlayerEntity newSpellPlayer = this;
|
|
|
|
|
2020-03-16 15:21:06 +00:00
|
|
|
newSpellPlayer.setDiscoveredSpells(oldSpellPlayer.getDiscoveredSpells());
|
2020-03-01 18:19:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 13:35:42 +00:00
|
|
|
@Override
|
|
|
|
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
|
|
|
|
super.setDiscoveredSpells(spells);
|
2020-03-24 17:05:03 +00:00
|
|
|
if (currentScreenHandler instanceof CastingTableScreenHandler) {
|
|
|
|
sync();
|
|
|
|
}
|
2020-03-24 13:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sync() {
|
2020-03-01 18:19:59 +00:00
|
|
|
CompoundTag tag = new CompoundTag();
|
2020-03-21 02:05:32 +00:00
|
|
|
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells()));
|
2020-03-01 18:19:59 +00:00
|
|
|
//noinspection ConstantConditions
|
|
|
|
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
|
|
|
|
}
|
|
|
|
}
|