Search in sources :

Example 1 with TileEntityGlyph

use of com.bewitchment.common.block.tile.entity.TileEntityGlyph in project Bewitchment by Um-Mitternacht.

the class BlockGlyph method updateTick.

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    if (world.getTileEntity(pos) instanceof TileEntityGlyph) {
        TileEntityGlyph tile = (TileEntityGlyph) world.getTileEntity(pos);
        if (tile.casterId != null)
            tile.caster = Util.findPlayer(tile.casterId);
        tile.syncToClient();
    }
    if (world.getBlockState(pos.down()).getBlockFaceShape(world, pos, EnumFacing.UP) != BlockFaceShape.SOLID)
        world.destroyBlock(pos, true);
}
Also used : TileEntityGlyph(com.bewitchment.common.block.tile.entity.TileEntityGlyph)

Example 2 with TileEntityGlyph

use of com.bewitchment.common.block.tile.entity.TileEntityGlyph 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 3 with TileEntityGlyph

use of com.bewitchment.common.block.tile.entity.TileEntityGlyph in project Bewitchment by Um-Mitternacht.

the class RitualTeleport method onFinished.

@Override
public void onFinished(World world, BlockPos altarPos, BlockPos effectivePos, EntityPlayer caster, ItemStackHandler inventory) {
    world.playSound(null, effectivePos, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.BLOCKS, 0.7f, 0.7f);
    BlockPos pos0 = null;
    int dimension = 0;
    if (world.getTileEntity(effectivePos) instanceof TileEntityGlyph) {
        for (int i = 0; i < inventory.getSlots(); i++) {
            ItemStack stack = inventory.getStackInSlot(i);
            if (stack.getItem() instanceof ItemWaystone) {
                pos0 = BlockPos.fromLong(stack.getTagCompound().getLong("location"));
                dimension = stack.getTagCompound().getInteger("dimension");
                stack.damageItem(1, caster);
                break;
            }
            if (stack.getItem() instanceof ItemTaglock) {
                for (Entity entity : world.loadedEntityList) {
                    if (entity.getPersistentID().equals(UUID.fromString(stack.getTagCompound().getString("boundId")))) {
                        pos0 = entity.getPosition();
                        dimension = entity.dimension;
                        stack.shrink(1);
                        break;
                    }
                }
            }
        }
    }
    if (pos0 == null || dimension != world.provider.getDimension())
        return;
    for (Entity entity : world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(effectivePos).grow(3))) {
        world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
        if (entity instanceof EntityPlayer)
            Util.teleportPlayer((EntityPlayer) entity, pos0.getX() + 0.5, pos0.getY(), pos0.getZ() + 0.5);
        else
            entity.setPositionAndUpdate(pos0.getX() + 0.5, pos0.getY(), pos0.getZ() + 0.5);
        world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntityGlyph(com.bewitchment.common.block.tile.entity.TileEntityGlyph) ItemWaystone(com.bewitchment.common.item.ItemWaystone) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemTaglock(com.bewitchment.common.item.ItemTaglock)

Example 4 with TileEntityGlyph

use of com.bewitchment.common.block.tile.entity.TileEntityGlyph in project Bewitchment by Um-Mitternacht.

the class ItemChalk method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing face, float hitX, float hitY, float hitZ) {
    boolean isReplacing = world.getBlockState(pos).getBlock().isReplaceable(world, pos);
    if (!world.isRemote && (face == EnumFacing.UP && ModObjects.glyph.canPlaceBlockAt(world, pos.up()) || isReplacing)) {
        ItemStack stack = player.getHeldItem(hand);
        BlockPos toPlace = isReplacing ? pos : pos.up();
        world.setBlockState(toPlace, ModObjects.glyph.getDefaultState().withProperty(BlockGlyph.TYPE, stack.getItem() == ModObjects.focal_chalk ? BlockGlyph.GOLDEN : stack.getItem() == ModObjects.ritual_chalk ? BlockGlyph.NORMAL : stack.getItem() == ModObjects.fiery_chalk ? BlockGlyph.NETHER : BlockGlyph.ENDER).withProperty(BlockHorizontal.FACING, EnumFacing.HORIZONTALS[player.getRNG().nextInt(4)]));
        if (world.getTileEntity(toPlace) instanceof TileEntityGlyph)
            ((ModBlockContainer) world.getBlockState(toPlace).getBlock()).refreshAltarPos(world, toPlace);
        world.playSound(null, pos, ModSounds.CHALK_SCRIBBLE, SoundCategory.BLOCKS, 0.5f, 1 + 0.5f * player.getRNG().nextFloat());
        if (!player.isCreative())
            stack.damageItem(1, player);
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntityGlyph(com.bewitchment.common.block.tile.entity.TileEntityGlyph) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TileEntityGlyph (com.bewitchment.common.block.tile.entity.TileEntityGlyph)4 BlockPos (net.minecraft.util.math.BlockPos)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 Ritual (com.bewitchment.api.registry.Ritual)1 ItemTaglock (com.bewitchment.common.item.ItemTaglock)1 ItemWaystone (com.bewitchment.common.item.ItemWaystone)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1