Merge pull request #641 from Alex-hawks/1.8

Add Capability support to Ritual Sones, Finish TE support as well
This commit is contained in:
Nick Ignoffo 2016-02-23 21:33:55 -08:00
commit 5c5cda1917
6 changed files with 144 additions and 16 deletions

View file

@ -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();
}
}
}

View file

@ -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);
}
}

View file

@ -2,8 +2,10 @@ package WayofTime.bloodmagic.api.util.helper;
import java.util.ArrayList;
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
@ -11,9 +13,14 @@ import WayofTime.bloodmagic.api.registry.RitualRegistry;
import WayofTime.bloodmagic.api.ritual.IRitualStone;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.ritual.RitualComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
public class RitualHelper
{
@CapabilityInject(IRitualStone.Tile.class)
static Capability<IRitualStone.Tile> RUNE_CAPABILITY = null;
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel)
{
return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual);
@ -93,14 +100,9 @@ public class RitualHelper
for (RitualComponent component : components)
{
BlockPos newPos = pos.add(component.getOffset(direction));
IBlockState worldState = world.getBlockState(newPos);
Block block = worldState.getBlock();
if (block instanceof IRitualStone)
if (isRuneType(world, newPos, component.getRuneType()))
{
if (!((IRitualStone) block).isRuneType(world, newPos, component.getRuneType()))
{
return false;
}
continue;
} else
{
return false;
@ -109,4 +111,56 @@ public class RitualHelper
return true;
}
public static boolean isRuneType(World world, BlockPos pos, EnumRuneType type)
{
if (world == null)
return false;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
return ((IRitualStone) block).isRuneType(world, pos, type);
else if(tile instanceof IRitualStone.Tile)
return ((IRitualStone.Tile) tile).isRuneType(type);
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
return tile.getCapability(RUNE_CAPABILITY, null).isRuneType(type);
return false;
}
public static boolean isRune(World world, BlockPos pos)
{
if (world == null)
return false;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
return true;
else if(tile instanceof IRitualStone.Tile)
return true;
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
return true;
return false;
}
public static void setRuneType(World world, BlockPos pos, EnumRuneType type)
{
if (world == null)
return;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
((IRitualStone) block).setRuneType(world, pos, type);
else if(tile instanceof IRitualStone.Tile)
((IRitualStone.Tile) tile).setRuneType(type);
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
{
tile.getCapability(RUNE_CAPABILITY, null).setRuneType(type);
world.notifyBlockOfStateChange(pos, block);
}
}
}