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/MixinPlayerEntity.java

52 lines
1.9 KiB
Java
Raw Normal View History

2020-03-01 18:19:59 +00:00
package com.thebrokenrail.sorcerycraft.mixin;
2020-03-24 17:05:03 +00:00
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
2020-03-01 18:19:59 +00:00
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier;
2020-03-01 18:19:59 +00:00
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
2020-03-27 18:07:47 +00:00
import org.spongepowered.asm.mixin.Unique;
2020-03-01 18:19:59 +00:00
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2020-03-02 22:11:37 +00:00
import java.util.HashMap;
2020-03-01 18:19:59 +00:00
import java.util.Map;
@SuppressWarnings("unused")
@Mixin(PlayerEntity.class)
public class MixinPlayerEntity implements SpellPlayerEntity {
2020-03-27 18:07:47 +00:00
@Shadow
public ScreenHandler currentScreenHandler;
@Unique
private Map<Identifier, Integer> discoveredSpells = new HashMap<>();
2020-03-01 18:19:59 +00:00
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
2020-03-27 18:07:47 +00:00
discoveredSpells = SpellHelper.getSpells(tag);
2020-03-01 18:19:59 +00:00
}
@Inject(at = @At("HEAD"), method = "writeCustomDataToTag")
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
2020-03-27 18:07:47 +00:00
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(discoveredSpells));
2020-03-01 18:19:59 +00:00
}
@Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
2020-03-27 18:07:47 +00:00
discoveredSpells = spells;
2020-03-24 17:05:03 +00:00
if (currentScreenHandler instanceof CastingTableScreenHandler) {
//noinspection ConstantConditions
((CastingTableScreenHandler) currentScreenHandler).setSpells((PlayerEntity) (Object) this);
}
2020-03-01 18:19:59 +00:00
}
@Override
public Map<Identifier, Integer> getDiscoveredSpells() {
2020-03-27 18:07:47 +00:00
return discoveredSpells;
2020-03-01 18:19:59 +00:00
}
}