Search in sources :

Example 1 with Ritual

use of com.bewitchment.api.registry.Ritual in project Bewitchment by Um-Mitternacht.

the class BlockGlyph method livingDeath.

@SubscribeEvent
public void livingDeath(LivingDeathEvent event) {
    EntityLivingBase living = event.getEntityLiving();
    if (!living.world.isRemote) {
        BlockPos pos = living.getPosition();
        EntityPlayer player = living.world.getClosestPlayer(living.posX, living.posY, living.posZ, 10, false);
        if (player != null) {
            for (BlockPos pos0 : BlockPos.getAllInBoxMutable(pos.add(-2, -2, -2), pos.add(2, 2, 2))) {
                if (living.world.getTileEntity(pos0) instanceof TileEntityGlyph) {
                    TileEntityGlyph tile = (TileEntityGlyph) living.world.getTileEntity(pos0);
                    Ritual ritual = GameRegistry.findRegistry(Ritual.class).getValuesCollection().stream().filter(r -> r.matches(living.world, pos0, tile.getInventories()[0])).findFirst().orElse(null);
                    if (ritual != null && ritual.sacrificePredicate != null && ritual.sacrificePredicate.test(living))
                        tile.startRitual(player, ritual);
                }
            }
        }
    }
}
Also used : TileEntityGlyph(com.bewitchment.common.block.tile.entity.TileEntityGlyph) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Ritual(com.bewitchment.api.registry.Ritual) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with Ritual

use of com.bewitchment.api.registry.Ritual in project Bewitchment by Um-Mitternacht.

the class TileEntityGlyph method activate.

@Override
public boolean activate(World world, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing face) {
    if (!world.isRemote) {
        if (player.isSneaking()) {
            int last = getLastNonEmptySlot(inventory);
            if (last > -1) {
                InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inventory.extractItem(last, inventory.getStackInSlot(last).getCount(), false));
                stopRitual(false);
            }
        } else {
            ItemStack stack = player.getHeldItem(hand);
            if (ritual == null) {
                if (!stack.isEmpty()) {
                    int slot = getFirstEmptySlot(inventory);
                    if (slot < 10 && slot > -1)
                        inventory.insertItem(slot, stack.splitStack(1), false);
                } else {
                    Ritual rit = GameRegistry.findRegistry(Ritual.class).getValuesCollection().stream().filter(r -> r.matches(world, pos, inventory)).findFirst().orElse(null);
                    if (rit != null) {
                        if (rit.isValid(world, pos, player, inventory))
                            startRitual(player, rit);
                        else
                            player.sendStatusMessage(new TextComponentTranslation(rit.getPreconditionMessage()), true);
                    } else
                        player.sendStatusMessage(new TextComponentTranslation("ritual.null"), true);
                }
            } else {
                if (stack.getItem() == ModObjects.waystone && stack.hasTagCompound() && stack.getTagCompound().hasKey("location")) {
                    if (ritual.canBePerformedRemotely) {
                        effectivePos = BlockPos.fromLong(stack.getTagCompound().getLong("location"));
                        effectiveDim = stack.getTagCompound().getInteger("dimension");
                        stack.damageItem(1, player);
                        syncToClient();
                    }
                } else
                    stopRitual(false);
            }
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Ritual(com.bewitchment.api.registry.Ritual) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Ritual (com.bewitchment.api.registry.Ritual)2 TileEntityGlyph (com.bewitchment.common.block.tile.entity.TileEntityGlyph)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1