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
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue