2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.block;
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-12-29 08:44:34 -05:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.world.Explosion;
|
|
|
|
import net.minecraft.world.World;
|
2015-11-02 12:39:44 -08:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2015-11-02 17:45:11 -08:00
|
|
|
import WayofTime.bloodmagic.api.BlockStack;
|
2015-11-28 18:25:46 -08:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2015-11-02 17:45:11 -08:00
|
|
|
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
|
2015-12-26 16:49:25 -08:00
|
|
|
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.RitualHelper;
|
2015-11-17 15:52:31 -08:00
|
|
|
import WayofTime.bloodmagic.block.base.BlockStringContainer;
|
2015-12-26 16:49:25 -08:00
|
|
|
import WayofTime.bloodmagic.registry.ModItems;
|
2015-11-02 17:45:11 -08:00
|
|
|
import WayofTime.bloodmagic.tile.TileImperfectRitualStone;
|
2015-11-02 13:20:29 -08:00
|
|
|
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
|
2016-01-03 08:30:59 -05:00
|
|
|
import WayofTime.bloodmagic.util.ChatUtil;
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class BlockRitualController extends BlockStringContainer
|
|
|
|
{
|
|
|
|
public static final String[] names = { "master", "imperfect" };
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public BlockRitualController()
|
|
|
|
{
|
2015-11-17 15:52:31 -08:00
|
|
|
super(Material.rock, names);
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-11-28 18:25:46 -08:00
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".stone.ritual.");
|
2016-01-18 22:34:12 -08:00
|
|
|
setRegistryName(Constants.BloodMagicBlock.RITUAL_CONTROLLER.getRegName());
|
2015-11-02 12:39:44 -08:00
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
2015-10-30 21:20:23 -07:00
|
|
|
setStepSound(soundTypeStone);
|
|
|
|
setHardness(2.0F);
|
2015-11-02 19:18:53 -08:00
|
|
|
setResistance(5.0F);
|
2015-10-30 21:20:23 -07:00
|
|
|
setHarvestLevel("pickaxe", 2);
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:45:11 -08:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
2015-11-02 17:45:11 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone)
|
|
|
|
{
|
|
|
|
if (player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.activationCrystal)
|
|
|
|
{
|
|
|
|
String key = RitualHelper.getValidRitual(world, pos);
|
|
|
|
EnumFacing direction = RitualHelper.getDirectionOfRitual(world, pos, key);
|
|
|
|
// TODO: Give a message stating that this ritual is not a valid
|
|
|
|
// ritual.
|
|
|
|
if (!key.isEmpty() && direction != null && RitualHelper.checkValidRitual(world, pos, key, direction))
|
|
|
|
{
|
|
|
|
if (((TileMasterRitualStone) tile).activateRitual(player.getHeldItem(), player, RitualRegistry.getRitualForId(key)))
|
|
|
|
{
|
|
|
|
((TileMasterRitualStone) tile).setDirection(direction);
|
2015-12-29 09:10:03 -05:00
|
|
|
}
|
2016-01-03 08:30:59 -05:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
ChatUtil.sendNoSpamUnloc(player, "chat.BloodMagic.ritual.notValid");
|
2015-12-29 08:44:34 -05:00
|
|
|
}
|
2015-12-26 16:49:25 -08:00
|
|
|
}
|
2015-12-30 15:34:40 -05:00
|
|
|
} else if (getMetaFromState(state) == 1 && tile instanceof TileImperfectRitualStone)
|
|
|
|
{
|
2015-11-02 17:45:11 -08:00
|
|
|
|
|
|
|
IBlockState determinerState = world.getBlockState(pos.up());
|
|
|
|
BlockStack determiner = new BlockStack(determinerState.getBlock(), determinerState.getBlock().getMetaFromState(determinerState));
|
|
|
|
|
|
|
|
return ((TileImperfectRitualStone) tile).performRitual(world, pos, ImperfectRitualRegistry.getRitualForBlock(determiner), player);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-26 16:49:25 -08:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player)
|
|
|
|
{
|
2015-12-26 16:49:25 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone)
|
|
|
|
((TileMasterRitualStone) tile).stopRitual(Ritual.BreakType.BREAK_MRS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosion)
|
|
|
|
{
|
2015-12-26 16:49:25 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone)
|
2015-12-26 16:49:25 -08:00
|
|
|
((TileMasterRitualStone) tile).stopRitual(Ritual.BreakType.EXPLOSION);
|
|
|
|
}
|
|
|
|
|
2015-10-31 17:58:47 -07:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public TileEntity createNewTileEntity(World world, int meta)
|
|
|
|
{
|
2015-12-29 14:22:33 -05:00
|
|
|
return meta == 0 ? (new TileMasterRitualStone()) : (new TileImperfectRitualStone());
|
2015-10-31 17:58:47 -07:00
|
|
|
}
|
2015-10-30 21:20:23 -07:00
|
|
|
}
|