Search in sources :

Example 31 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project VoodooCraft by Mod-DevCafeTeam.

the class HexHandler method setLightSource.

/**
     * TODO: Update position of light source relative to player's position
     * TODO: and replace old position of light source with air
     * @param event
     */
@SubscribeEvent
public static void setLightSource(TickEvent.PlayerTickEvent event) {
    if (event.player.world.isRemote)
        return;
    EntityPlayer player = event.player;
    ItemStack stack = getDollWithHex(player, "fear_the_darkness");
    if (stack != null) {
        World world = player.world;
        BlockPos oldPos = new BlockPos(player.prevPosX, player.prevPosY, player.prevPosZ);
        if (player.motionX != 0F || player.motionZ != 0F) {
            BlockPos newPos = player.getPosition();
            if (world.getTotalWorldTime() % 15 == 0) {
                VoodooCraft.log.info("OldPos: " + oldPos + ", NewPos: " + newPos);
            }
            if (oldPos != newPos) {
                world.setBlockState(oldPos, Blocks.AIR.getDefaultState());
                world.setBlockState(newPos, VCBlocks.LIGHT_SOURCE.getDefaultState());
                VoodooCraft.log.info("Changing light source locationg...");
            }
        } else {
            world.setBlockState(player.getPosition(), VCBlocks.LIGHT_SOURCE.getDefaultState());
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 32 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project VoodooCraft by Mod-DevCafeTeam.

the class HexHandler method fallEvent.

/**
     * Feather Hex
     */
@SubscribeEvent
public static void fallEvent(LivingFallEvent event) {
    //Feather - Removes fall damage
    ItemStack stack = getDollWithHex(event.getEntityLiving(), "feather");
    if (stack != null) {
        event.setDistance(0);
        event.setDamageMultiplier(0);
        //Damage the doll
        stack.damageItem(1, event.getEntityLiving());
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 33 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.

the class BlockEnderProof method onEnderTeleport.

@SubscribeEvent
public void onEnderTeleport(EnderTeleportEvent e) {
    Entity ent = e.getEntity();
    List<BlockPos> l = rayTraceBlocks(ent.world, new Vec3d(ent.posX, ent.posY, ent.posZ), new Vec3d(e.getTargetX(), e.getTargetY(), e.getTargetZ()), false, new FloodFill.BlockMatcher(3).set(BlockEnderProof.class));
    if (l.size() > 0) {
        e.setCanceled(true);
    }
}
Also used : Entity(net.minecraft.entity.Entity) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 34 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.

the class CAGbookBookRegistry method onFirstSpawn.

@Optional.Method(modid = "gbook")
@SubscribeEvent
public static void onFirstSpawn(EntityJoinWorldEvent event) {
    if (!ModConfigCompat.gbook_onFirstSpawn)
        return;
    if (!event.getWorld().isRemote && event.getEntity() instanceof EntityPlayer) {
        EntityPlayer p = (EntityPlayer) event.getEntity();
        NBTTagCompound tag = Helper.getPersistentTag(p, ModConstants.Mod.MODID);
        if (!tag.getBoolean(TAG_BOOK_RECEIVED)) {
            Helper.insertOrDrop(p, GameRegistry.makeItemStack("gbook:guidebook", 0, 1, "{Book:\"convenientadditions:xml/book.xml\"}"));
            tag.setBoolean(TAG_BOOK_RECEIVED, true);
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 35 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project NetherEx by LogicTechCorp.

the class EventHandler method onLivingUpdate.

@SubscribeEvent
public static void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
    World world = event.getEntityLiving().getEntityWorld();
    BlockPos pos = new BlockPos(event.getEntityLiving());
    EntityLivingBase entity = event.getEntityLiving();
    boolean canFreeze = !(entity instanceof EntityPlayer) && !Arrays.asList(ConfigHandler.potionEffect.freeze.blacklist).contains(EntityList.getKey(entity).toString());
    if (world.getBiomeForCoordsBody(pos) == NetherExBiomes.ARCTIC_ABYSS) {
        if (canFreeze && !entity.isPotionActive(NetherExEffects.FREEZE) && world.rand.nextInt(ConfigHandler.biome.arcticAbyss.chanceOfFreezing) == 0) {
            entity.addPotionEffect(new PotionEffect(NetherExEffects.FREEZE, 300, 0));
        }
    }
    if (entity instanceof EntityLiving && canFreeze) {
        if (!entity.isPotionActive(NetherExEffects.FREEZE)) {
            if (((EntityLiving) entity).isAIDisabled()) {
                ((EntityLiving) entity).setNoAI(false);
                entity.setSilent(false);
            }
        } else {
            ((EntityLiving) entity).setNoAI(true);
            entity.setSilent(true);
            if (world.rand.nextInt(ConfigHandler.potionEffect.freeze.chanceOfThawing) == 0) {
                entity.removePotionEffect(NetherExEffects.FREEZE);
            }
        }
    }
    if (entity instanceof EntityPlayer && entity.isPotionActive(NetherExEffects.FREEZE)) {
        entity.setPosition(entity.prevPosX, entity.posY, entity.prevPosZ);
    }
    boolean canSpawnSpore = entity instanceof EntityPlayer || !Arrays.asList(ConfigHandler.potionEffect.spore.blacklist).contains(EntityList.getKey(entity).toString());
    if (canSpawnSpore && entity.isPotionActive(NetherExEffects.SPORE) && world.rand.nextInt(ConfigHandler.potionEffect.spore.chanceOfSporeSpawning) == 0) {
        if (world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos).expand(1, 1, 1)).size() < 3) {
            BlockPos newPos = pos.offset(EnumFacing.Plane.HORIZONTAL.random(world.rand));
            if (!world.isRemote && world.isAirBlock(newPos) && world.getBlockState(newPos.down()).isSideSolid(world, newPos.down(), EnumFacing.UP)) {
                EntitySpore spore = new EntitySpore(world, 0);
                spore.setPosition(newPos.getX(), newPos.getY(), newPos.getZ());
                world.spawnEntity(spore);
            }
        }
    }
    boolean canSpawnGhastling = entity instanceof EntityPlayer && world.provider.getDimension() == DimensionType.NETHER.getId();
    if (canSpawnGhastling && entity.isPotionActive(NetherExEffects.LOST) && world.rand.nextInt(ConfigHandler.potionEffect.lost.chanceOfGhastlingSpawning) == 0) {
        BlockPos newPos = pos.add(0, 5, 0).offset(entity.getHorizontalFacing().getOpposite(), 5);
        if (!world.isRemote && world.isAirBlock(newPos)) {
            EntityGhastling ghastling = new EntityGhastling(world);
            ghastling.setPosition(newPos.getX(), newPos.getY(), newPos.getZ());
            ghastling.setAttackTarget(entity);
            world.spawnEntity(ghastling);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntitySpore(nex.entity.monster.EntitySpore) EntityGhastling(nex.entity.monster.EntityGhastling) EntityLiving(net.minecraft.entity.EntityLiving) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1135 ItemStack (net.minecraft.item.ItemStack)316 EntityPlayer (net.minecraft.entity.player.EntityPlayer)314 World (net.minecraft.world.World)196 BlockPos (net.minecraft.util.math.BlockPos)179 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)136 IBlockState (net.minecraft.block.state.IBlockState)120 ResourceLocation (net.minecraft.util.ResourceLocation)102 Entity (net.minecraft.entity.Entity)93 Block (net.minecraft.block.Block)86 EntityLivingBase (net.minecraft.entity.EntityLivingBase)84 Minecraft (net.minecraft.client.Minecraft)72 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)66 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)64 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)55 Item (net.minecraft.item.Item)53 EntityItem (net.minecraft.entity.item.EntityItem)48 TileEntity (net.minecraft.tileentity.TileEntity)46 TextComponentString (net.minecraft.util.text.TextComponentString)42 Random (java.util.Random)37