2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.api.util.helper;
|
2015-11-01 00:58:47 +00:00
|
|
|
|
2015-12-29 13:44:34 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.world.World;
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
2015-12-30 16:34:04 +00:00
|
|
|
import WayofTime.bloodmagic.api.ritual.IRitualStone;
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
2015-12-27 00:49:25 +00:00
|
|
|
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
2015-11-01 00:58:47 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class RitualHelper
|
|
|
|
{
|
|
|
|
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));
|
2015-12-29 13:44:34 +00:00
|
|
|
IBlockState worldState = world.getBlockState(newPos);
|
|
|
|
Block block = worldState.getBlock();
|
2015-12-30 20:34:40 +00:00
|
|
|
if (block instanceof IRitualStone)
|
|
|
|
{
|
|
|
|
if (!((IRitualStone) block).isRuneType(world, newPos, component.getRuneType()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return false;
|
2015-12-27 00:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-01 00:58:47 +00:00
|
|
|
}
|