Add Capability support to Ritual Sones, Finish TE support as well
This commit is contained in:
parent
7104138e2b
commit
33f05cd819
6 changed files with 144 additions and 16 deletions
|
@ -0,0 +1,59 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
|
||||
import WayofTime.bloodmagic.api.ritual.IRitualStone;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public final class CapabilityRuneType
|
||||
{
|
||||
public static class RuneTypeStorage implements Capability.IStorage<IRitualStone.Tile>
|
||||
{
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<IRitualStone.Tile> capability, IRitualStone.Tile instance, EnumFacing side)
|
||||
{
|
||||
return new NBTTagByte((byte)instance.getRuneType().ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IRitualStone.Tile> capability, IRitualStone.Tile instance, EnumFacing side, NBTBase nbt)
|
||||
{
|
||||
instance.setRuneType(EnumRuneType.byMetadata(((NBTTagByte)nbt).getByte()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class RuneTypeWrapper implements IRitualStone.Tile
|
||||
{
|
||||
private EnumRuneType type = EnumRuneType.BLANK;
|
||||
|
||||
@Override
|
||||
public boolean isRuneType(EnumRuneType runeType)
|
||||
{
|
||||
return type == runeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRuneType getRuneType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setRuneType(EnumRuneType runeType)
|
||||
{
|
||||
type = runeType;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Factory implements Callable<IRitualStone.Tile>
|
||||
{
|
||||
@Override
|
||||
public IRitualStone.Tile call() throws Exception
|
||||
{
|
||||
return new RuneTypeWrapper();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,8 +12,14 @@ public interface IRitualStone
|
|||
{
|
||||
boolean isRuneType(World world, BlockPos pos, EnumRuneType runeType);
|
||||
|
||||
void setRuneType(World world, BlockPos pos, EnumRuneType runeType);
|
||||
|
||||
interface Tile
|
||||
{
|
||||
boolean isRuneType(EnumRuneType runeType);
|
||||
|
||||
EnumRuneType getRuneType();
|
||||
|
||||
void setRuneType(EnumRuneType runeType);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue