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.ChatComponentText;
|
|
|
|
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.ritual.RitualComponent;
|
|
|
|
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.ModBlocks;
|
|
|
|
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;
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-11-17 15:52:31 -08:00
|
|
|
public class BlockRitualController extends BlockStringContainer {
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-11-28 18:25:46 -08:00
|
|
|
public static final String[] names = {"master", "imperfect"};
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2015-10-31 13:47:43 -07: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.");
|
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
|
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
2015-12-26 16:49:25 -08:00
|
|
|
if (player.getHeldItem() == null && tile instanceof TileMasterRitualStone) {
|
|
|
|
Ritual send = ((TileMasterRitualStone) tile).getCurrentRitual();
|
|
|
|
if (send != null)
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(send.getName()));
|
|
|
|
else {
|
|
|
|
Ritual place = RitualRegistry.getRitualForId("ritualTest");
|
|
|
|
for (RitualComponent ritualComponent : place.getComponents()) {
|
|
|
|
IBlockState toPlace = ModBlocks.ritualStone.getStateFromMeta(ritualComponent.getRuneType().ordinal());
|
|
|
|
world.setBlockState(pos.add(ritualComponent.getOffset()), toPlace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone) {
|
|
|
|
if (player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.activationCrystal) {
|
2015-12-29 08:44:34 -05:00
|
|
|
String key = RitualHelper.getValidRitual(world, pos, null);
|
|
|
|
//TODO: Give a message stating that this ritual is not a valid ritual.
|
|
|
|
if (!key.isEmpty() && RitualHelper.checkValidRitual(world, pos, key, null)) {
|
|
|
|
((TileMasterRitualStone) tile).activateRitual(player.getHeldItem(), player, RitualRegistry.getRitualForId(key));
|
|
|
|
}
|
2015-12-26 16:49:25 -08: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
|
|
|
|
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone)
|
|
|
|
((TileMasterRitualStone) tile).stopRitual(Ritual.BreakType.BREAK_MRS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
|
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone)
|
|
|
|
((TileMasterRitualStone) tile).stopRitual(Ritual.BreakType.EXPLOSION);
|
|
|
|
}
|
|
|
|
|
2015-10-31 17:58:47 -07:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World world, int meta) {
|
2015-11-02 17:45:11 -08:00
|
|
|
return meta == 0 ? new TileMasterRitualStone() : new TileImperfectRitualStone();
|
2015-10-31 17:58:47 -07:00
|
|
|
}
|
2015-10-30 21:20:23 -07:00
|
|
|
}
|