Search in sources :

Example 1 with TileImperfectRitualStone

use of WayofTime.bloodmagic.tile.TileImperfectRitualStone in project BloodMagic by WayofTime.

the class BlockRitualController method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItem(hand);
    TileEntity tile = world.getTileEntity(pos);
    if (state.getValue(getProperty()) != EnumRitualController.IMPERFECT && tile instanceof TileMasterRitualStone) {
        if (heldItem.getItem() == RegistrarBloodMagicItems.ACTIVATION_CRYSTAL) {
            if (((IBindable) heldItem.getItem()).getBinding(heldItem) == null)
                return false;
            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(heldItem, player, RitualRegistry.getRitualForId(key))) {
                    ((TileMasterRitualStone) tile).setDirection(direction);
                    if (state.getValue(getProperty()) == EnumRitualController.INVERTED)
                        ((TileMasterRitualStone) tile).setInverted(true);
                }
            } else {
                player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true);
            }
        }
    } else if (state.getValue(getProperty()) == EnumRitualController.IMPERFECT && tile instanceof TileImperfectRitualStone) {
        IBlockState ritualBlock = world.getBlockState(pos.up());
        ImperfectRitual ritual = ImperfectRitualRegistry.getRitualForBlock(ritualBlock);
        if (ritual == null)
            return false;
        RitualEvent.ImperfectRitualActivatedEvent event = new RitualEvent.ImperfectRitualActivatedEvent((IImperfectRitualStone) tile, player, ritual);
        return !MinecraftForge.EVENT_BUS.post(event) && ((TileImperfectRitualStone) tile).performRitual(world, pos, ritual, player);
    }
    return false;
}
Also used : RitualEvent(WayofTime.bloodmagic.event.RitualEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) TileMasterRitualStone(WayofTime.bloodmagic.tile.TileMasterRitualStone) EnumFacing(net.minecraft.util.EnumFacing) IImperfectRitualStone(WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone) TileEntity(net.minecraft.tileentity.TileEntity) TileImperfectRitualStone(WayofTime.bloodmagic.tile.TileImperfectRitualStone) ImperfectRitual(WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual) ItemStack(net.minecraft.item.ItemStack)

Aggregations

RitualEvent (WayofTime.bloodmagic.event.RitualEvent)1 IImperfectRitualStone (WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone)1 ImperfectRitual (WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual)1 TileImperfectRitualStone (WayofTime.bloodmagic.tile.TileImperfectRitualStone)1 TileMasterRitualStone (WayofTime.bloodmagic.tile.TileMasterRitualStone)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1