2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.api.util.helper;
|
2015-11-01 00:58:47 +00:00
|
|
|
|
2016-03-17 20:00:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.IRitualStone;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
2015-12-29 13:44:34 +00:00
|
|
|
import net.minecraft.block.Block;
|
2016-02-23 17:52:52 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-12-29 13:44:34 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-17 20:00:44 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-12-29 13:44:34 +00:00
|
|
|
import net.minecraft.world.World;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.common.capabilities.CapabilityInject;
|
2016-03-17 20:00:44 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-11-01 00:58:47 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class RitualHelper
|
|
|
|
{
|
2016-02-23 17:52:52 +00:00
|
|
|
@CapabilityInject(IRitualStone.Tile.class)
|
|
|
|
static Capability<IRitualStone.Tile> RUNE_CAPABILITY = null;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel)
|
|
|
|
{
|
2015-11-01 00:58:47 +00:00
|
|
|
return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual);
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static String getNextRitualKey(String currentKey)
|
|
|
|
{
|
2015-11-01 00:58:47 +00:00
|
|
|
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
|
|
|
int nextIndex = RitualRegistry.getRituals().listIterator(currentIndex).nextIndex();
|
|
|
|
|
|
|
|
return RitualRegistry.getIds().get(nextIndex);
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static String getPrevRitualKey(String currentKey)
|
|
|
|
{
|
2015-11-01 00:58:47 +00:00
|
|
|
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
|
|
|
int previousIndex = RitualRegistry.getIds().listIterator(currentIndex).previousIndex();
|
|
|
|
|
|
|
|
return RitualRegistry.getIds().get(previousIndex);
|
|
|
|
}
|
|
|
|
|
2015-12-29 13:44:34 +00:00
|
|
|
/**
|
2015-12-30 20:34:40 +00:00
|
|
|
* Checks the RitualRegistry to see if the configuration of the ritual
|
|
|
|
* stones in the world is valid for the given EnumFacing.
|
2016-01-02 22:56:37 +00:00
|
|
|
*
|
2016-01-01 18:52:42 +00:00
|
|
|
* @param world
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The world
|
2016-01-01 18:52:42 +00:00
|
|
|
* @param pos
|
2016-01-02 22:56:37 +00:00
|
|
|
* - Location of the MasterRitualStone
|
|
|
|
*
|
2015-12-29 13:44:34 +00:00
|
|
|
* @return The ID of the valid ritual
|
|
|
|
*/
|
2015-12-30 20:34:40 +00:00
|
|
|
public static String getValidRitual(World world, BlockPos pos)
|
|
|
|
{
|
|
|
|
for (String key : RitualRegistry.getIds())
|
|
|
|
{
|
|
|
|
for (EnumFacing direction : EnumFacing.HORIZONTALS)
|
|
|
|
{
|
|
|
|
boolean test = checkValidRitual(world, pos, key, direction);
|
|
|
|
if (test)
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2015-12-29 13:44:34 +00:00
|
|
|
}
|
2015-12-30 20:34:40 +00:00
|
|
|
|
|
|
|
public static EnumFacing getDirectionOfRitual(World world, BlockPos pos, String key)
|
|
|
|
{
|
|
|
|
for (EnumFacing direction : EnumFacing.HORIZONTALS)
|
|
|
|
{
|
|
|
|
boolean test = checkValidRitual(world, pos, key, direction);
|
|
|
|
if (test)
|
|
|
|
{
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2015-12-29 14:10:03 +00:00
|
|
|
}
|
2015-12-30 20:34:40 +00:00
|
|
|
|
|
|
|
public static boolean checkValidRitual(World world, BlockPos pos, String ritualId, EnumFacing direction)
|
|
|
|
{
|
|
|
|
Ritual ritual = RitualRegistry.getRitualForId(ritualId);
|
|
|
|
if (ritual == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-29 13:44:34 +00:00
|
|
|
ArrayList<RitualComponent> components = ritual.getComponents();
|
2015-12-30 20:34:40 +00:00
|
|
|
|
2015-12-27 00:49:25 +00:00
|
|
|
if (components == null)
|
|
|
|
return false;
|
2015-12-30 20:34:40 +00:00
|
|
|
|
|
|
|
for (RitualComponent component : components)
|
|
|
|
{
|
|
|
|
BlockPos newPos = pos.add(component.getOffset(direction));
|
2016-02-23 17:52:52 +00:00
|
|
|
if (isRuneType(world, newPos, component.getRuneType()))
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2016-02-23 17:52:52 +00:00
|
|
|
continue;
|
2015-12-30 20:34:40 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
return false;
|
2015-12-27 00:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-23 17:52:52 +00:00
|
|
|
|
|
|
|
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);
|
2016-03-16 22:41:06 +00:00
|
|
|
else if (tile instanceof IRitualStone.Tile)
|
2016-02-23 17:52:52 +00:00
|
|
|
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;
|
2016-03-16 22:41:06 +00:00
|
|
|
else if (tile instanceof IRitualStone.Tile)
|
2016-02-23 17:52:52 +00:00
|
|
|
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);
|
2016-03-16 22:41:06 +00:00
|
|
|
else if (tile instanceof IRitualStone.Tile)
|
2016-02-23 17:52:52 +00:00
|
|
|
((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);
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 00:58:47 +00:00
|
|
|
}
|