當前位置: 首頁>>代碼示例>>Java>>正文


Java Event類代碼示例

本文整理匯總了Java中cpw.mods.fml.common.eventhandler.Event的典型用法代碼示例。如果您正苦於以下問題:Java Event類的具體用法?Java Event怎麽用?Java Event使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Event類屬於cpw.mods.fml.common.eventhandler包,在下文中一共展示了Event類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyEnrichment

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
public boolean applyEnrichment (ItemStack itemStack, World world, int x, int y, int z, EntityPlayer player) {
    ConfigManager config = GardenCore.config;
    Block block = world.getBlock(x, y, z);

    EnrichedSoilEvent event = new EnrichedSoilEvent(player, world, block, x, y, z);
    if (MinecraftForge.EVENT_BUS.post(event))
        return false;

    if (!config.enableCompostBonemeal)
        return false;

    if (event.getResult() == Event.Result.ALLOW) {
        if (!world.isRemote)
            itemStack.stackSize--;
        return true;
    }

    int prob = (config.compostBonemealStrength == 0) ? 0 : (int)(1 / config.compostBonemealStrength);
    if (world.rand.nextInt(prob) == 0)
        return ItemDye.applyBonemeal(itemStack, world, x, y, z, player);
    else
        --itemStack.stackSize;

    return true;
}
 
開發者ID:jaquadro,項目名稱:GardenCollection,代碼行數:26,代碼來源:ItemCompost.java

示例2: onItemUse

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
public boolean onItemUse(final ItemStack p_77648_1_, final EntityPlayer p_77648_2_, final World p_77648_3_, final int p_77648_4_, final int p_77648_5_, final int p_77648_6_, final int p_77648_7_, final float p_77648_8_, final float p_77648_9_, final float p_77648_10_) {
    if (!p_77648_2_.canPlayerEdit(p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_1_)) {
        return false;
    }
    final UseHoeEvent event = new UseHoeEvent(p_77648_2_, p_77648_1_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_);
    if (MinecraftForge.EVENT_BUS.post((Event)event)) {
        return false;
    }
    if (event.getResult() == Event.Result.ALLOW) {
        return true;
    }
    final Block block = p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_);
    if (p_77648_7_ == 0 || !p_77648_3_.getBlock(p_77648_4_, p_77648_5_ + 1, p_77648_6_).isAir((IBlockAccess)p_77648_3_, p_77648_4_, p_77648_5_ + 1, p_77648_6_) || (block != Blocks.grass && block != Blocks.dirt)) {
        return false;
    }
    final Block block2 = Blocks.farmland;
    p_77648_3_.playSoundEffect((double)(p_77648_4_ + 0.5f), (double)(p_77648_5_ + 0.5f), (double)(p_77648_6_ + 0.5f), block2.stepSound.getStepResourcePath(), (block2.stepSound.getVolume() + 1.0f) / 2.0f, block2.stepSound.getPitch() * 0.8f);
    if (p_77648_3_.isRemote) {
        return true;
    }
    p_77648_3_.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, block2);
    return true;
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:24,代碼來源:ItemTemporalHoe.java

示例3: SiegeCheckSpawn

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent
public void SiegeCheckSpawn(final LivingSpawnEvent.CheckSpawn event) {
    if (EventHandlerSiege.SiegeParticipants.isEmpty()) {
        return;
    }
    if (event.entity.worldObj.isRemote) {
        return;
    }
    if (event.world.provider.dimensionId != 1) {
        return;
    }
    if (event.entityLiving instanceof EntityMob && event.entityLiving.worldObj.checkNoEntityCollision(event.entityLiving.boundingBox) && event.entityLiving.worldObj.getCollidingBoundingBoxes((Entity)event.entityLiving, event.entityLiving.boundingBox).isEmpty() && !event.entityLiving.worldObj.isAnyLiquid(event.entityLiving.boundingBox)) {
        event.entityLiving.getEntityData().setBoolean("Siege", true);
        event.entityLiving.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 7200, 2));
        event.setResult(Event.Result.ALLOW);
    }
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:18,代碼來源:EventHandlerSiege.java

示例4: noMobs

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent
public void noMobs(final LivingSpawnEvent.CheckSpawn event) {
    if (event.getResult() == Event.Result.DEFAULT && event.world.provider.dimensionId == ExtraUtils.underdarkDimID && event.entity instanceof EntityMob) {
        if (EventHandlerUnderdark.rand.nextDouble() < Math.min(0.95, event.entity.posY / 80.0)) {
            event.setResult(Event.Result.DENY);
        }
        else {
            IAttributeInstance t = ((EntityMob)event.entity).getEntityAttribute(SharedMonsterAttributes.maxHealth);
            t.setBaseValue(t.getBaseValue() * 2.0);
            ((EntityMob)event.entity).heal((float)t.getAttributeValue());
            t = ((EntityMob)event.entity).getEntityAttribute(SharedMonsterAttributes.attackDamage);
            t.setBaseValue(t.getBaseValue() * 2.0);
            if (!EventHandlerServer.isInRangeOfTorch(event.entity) && event.entityLiving.worldObj.checkNoEntityCollision(event.entityLiving.boundingBox) && event.entityLiving.worldObj.getCollidingBoundingBoxes((Entity)event.entityLiving, event.entityLiving.boundingBox).isEmpty() && !event.entityLiving.worldObj.isAnyLiquid(event.entityLiving.boundingBox)) {
                event.setResult(Event.Result.ALLOW);
            }
        }
    }
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:19,代碼來源:EventHandlerUnderdark.java

示例5: initIC

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
protected void initIC()
{
    if (EnergyConfigHandler.isIndustrialCraft2Loaded())
    {
        try
        {
            Class<?> tileLoadEvent = Class.forName("ic2.api.energy.event.EnergyTileLoadEvent");
            Class<?> energyTile = Class.forName("ic2.api.energy.tile.IEnergyTile");
            Constructor<?> constr = tileLoadEvent.getConstructor(energyTile);
            Object o = constr.newInstance(this);

            if (o != null && o instanceof Event)
            {
                MinecraftForge.EVENT_BUS.post((Event) o);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    this.isAddedToEnergyNet = true;
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:25,代碼來源:TileBaseUniversalElectrical.java

示例6: initIC

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
protected void initIC()
{
    if (EnergyConfigHandler.isIndustrialCraft2Loaded() && !this.worldObj.isRemote)
    {
        try
        {
            Class<?> tileLoadEvent = Class.forName("ic2.api.energy.event.EnergyTileLoadEvent");
            Class<?> energyTile = Class.forName("ic2.api.energy.tile.IEnergyTile");
            Constructor<?> constr = tileLoadEvent.getConstructor(energyTile);
            Object o = constr.newInstance(this);

            if (o != null && o instanceof Event)
            {
                MinecraftForge.EVENT_BUS.post((Event) o);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:23,代碼來源:TileBaseUniversalConductor.java

示例7: onSleepCancelled

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
public static void onSleepCancelled()
{
	try
	{
		if (MicdoodlePlugin.sleepCancelledConstructor == null)
		{
			MicdoodlePlugin.sleepCancelledConstructor = Class.forName(MicdoodlePlugin.galacticraftCoreClass + "$SleepCancelledEvent").getConstructor();
		}

		MinecraftForge.EVENT_BUS.post((Event) MicdoodlePlugin.sleepCancelledConstructor.newInstance());
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:17,代碼來源:MicdoodlePlugin.java

示例8: orientCamera

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
public static void orientCamera()
{
	try
	{
		if (MicdoodlePlugin.orientCameraConstructor == null)
		{
			MicdoodlePlugin.orientCameraConstructor = Class.forName(MicdoodlePlugin.galacticraftCoreClass + "$OrientCameraEvent").getConstructor();
		}

		MinecraftForge.EVENT_BUS.post((Event) MicdoodlePlugin.orientCameraConstructor.newInstance());
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:17,代碼來源:MicdoodlePlugin.java

示例9: onPlayerInteract

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event)
{
    EntityPlayer player = event.entityPlayer;
    World world = event.world;
    int x = event.x;
    int y = event.y;
    int z = event.z;

    if ((event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && (!player.isSneaking()))
    {
        Block clickedBlock = world.getBlock(x, y, z);
        if (clickedBlock == Blocks.crafting_table)
            if (validMultiblock(world, x, y, z))
            {
                event.useBlock = Event.Result.DENY;
                player.openGui(DualCraft.instance, GUIs.DUAL_WORKBENCH.ordinal(), world, x, y, z);
            }
    }
}
 
開發者ID:SamRaven2,項目名稱:DualCraft,代碼行數:21,代碼來源:WorldEventHandler.java

示例10: hoeBlock

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
public static boolean hoeBlock(ItemStack stack, World world, int x, int y, int z, int sideHit, EntityPlayer player){
    Block block = world.getBlock(x, y, z);

    UseHoeEvent event = new UseHoeEvent(player, stack, world, x, y, z);
    if(MinecraftForge.EVENT_BUS.post(event)) //if the event got canceled
        return false;

    if (event.getResult() == Event.Result.ALLOW) //if another mod handled this block using the event
        return true;

    //vanilla hoe behaviour
    if (sideHit != 0 && world.isAirBlock(x, y + 1, z) && (block == Blocks.grass || block == Blocks.dirt) && player.canPlayerEdit(x, y, z, sideHit, stack)) {
        if (!world.isRemote)
            world.setBlock(x, y, z, Blocks.farmland);
        return true;
    }

    return false;
}
 
開發者ID:goldenapple3,項目名稱:RFDrills,代碼行數:20,代碼來源:ToolHelper.java

示例11: allowPlantGrowth

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent
public void allowPlantGrowth(PlantGrowthEvent.AllowGrowthTick event)
{
    Chunk chunk = event.world.getChunkFromBlockCoords(event.x, event.z);
    BioSystem bioSystem = BioSystemHandler.getBioSystem(event.world, chunk);

    if (bioSystem != null)
    {
        int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
        float lowestNutrientPart = PlantConfig.getLowestNutrientPart(event.block, meta, bioSystem.getPhosphorus(), bioSystem.getPotassium(), bioSystem.getNitrogen());
        float nutrientGrowChance = MathLib.getFittedValue(lowestNutrientPart, Settings.NUTRIENT_AMOUNT_FOR_STOP_GROWTH, Settings.NUTRIENT_AMOUNT_FOR_NORMAL_GROWTH, Settings.NUTRIENT_AMOUNT_FOR_MAX_GROWTH);

        int lightValue = event.block.isOpaqueCube() ? WorldHelper.getLightValue(event.world, event.x, event.y + 1, event.z) : WorldHelper.getLightValue(event.world, event.x, event.y, event.z);
        float lightGrowChance = MathLib.getFittedValue(lightValue, Settings.LIGHT_VALUE_FOR_STOP_GROWTH, Settings.LIGHT_VALUE_FOR_NORMAL_GROWTH, Settings.LIGHT_VALUE_FOR_MAX_GROWTH);

        if (Math.min(nutrientGrowChance, lightGrowChance) < event.world.rand.nextFloat())
        {
            event.setResult(Event.Result.DENY);
        }
    }
}
 
開發者ID:Dynious,項目名稱:Biota,代碼行數:22,代碼來源:CommonEventHandler.java

示例12: onBiomeDecoration

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onBiomeDecoration(DecorateBiomeEvent.Decorate event)
{
    if (event.type == DecorateBiomeEvent.Decorate.EventType.FLOWERS && (event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT))
    {
        for (int i = 0; i < Settings.FLOWER_QUANTITY; i++)
        {
            int x = event.chunkX + event.rand.nextInt(16) + 8;
            int z = event.chunkZ + event.rand.nextInt(16) + 8;
            int y = event.world.getTopSolidOrLiquidBlock(x, z);
            Block randomPlant = ModBlocks.plants[event.rand.nextInt(ModBlocks.plants.length)];

            if (event.world.isAirBlock(x, y, z) && (!event.world.provider.hasNoSky || y < 255) && randomPlant.canBlockStay(event.world, x, y, z))
            {
                event.world.setBlock(x, y, z, randomPlant, 0, 2);
            }
        }
    }
}
 
開發者ID:Dynious,項目名稱:Biota,代碼行數:20,代碼來源:TerrainEventHandler.java

示例13: BlockSpawnEvent

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent
public void BlockSpawnEvent(LivingSpawnEvent.CheckSpawn event){
    List<MobInhibitorReference> RefList;
    if (event.getResult() != Event.Result.DEFAULT){ return;} // If the event is already forced Allow or Deny, let it through
    if (event.entity.isCreatureType(EnumCreatureType.monster,false)){ //decide which list to use.
        RefList = MobInhibitor.HostileInhibitors;
    } else if (event.entity.isCreatureType(EnumCreatureType.waterCreature,false)){
        RefList = MobInhibitor.AquaInhibitors;
    } else { // this will also catch ambient creatures like bats.
        if (!ConfigurationHandler.InhibitAmbient && event.entity.isCreatureType(EnumCreatureType.ambient,false)){
            return; //If the InhibitAmbient config is not set, and the creature type is ambient, don't do anything.
            //If the config is set, fall through. The remaining category is Creature, which includes passives.
        }
        RefList = MobInhibitor.PassiveInhibitors;
    }
    for (MobInhibitorReference Ref : RefList){
        if (TestRange(Ref, event.entity.posX, event.entity.posY, event.entity.posZ, event.world.provider.dimensionId)) {
            event.setResult(Event.Result.DENY);
            LogHelper.debug("Blocked a spawn based on inhibitor at:"+Ref.i+", "+Ref.j+", "+Ref.k);
            return;
        }
    }
}
 
開發者ID:yarrim,項目名稱:MobInhibitor,代碼行數:24,代碼來源:ServerEventHandler.java

示例14: onWorldDecoration

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onWorldDecoration(DecorateBiomeEvent.Decorate event) {
    BiomeGenBase biome = event.world.getBiomeGenForCoords(event.chunkX, event.chunkZ);
    if (biome != null && isValidBiomeType(biome)) {
        if ((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT) && event.type == DecorateBiomeEvent.Decorate.EventType.FLOWERS) {
            for (int i = 0; i < ModLibs.manaFlowerQuantity; i++) {
                int x = event.chunkX + event.rand.nextInt(16) + 8;
                int z = event.chunkZ + event.rand.nextInt(16) + 8;
                int y = event.world.getTopSolidOrLiquidBlock(x, z);

                for (int j = 0; j < ModLibs.manaFlowerDensity; j++) {
                    int x1 = x + event.rand.nextInt(8) - event.rand.nextInt(8);
                    int y1 = y + event.rand.nextInt(4) - event.rand.nextInt(4);
                    int z1 = z + event.rand.nextInt(8) - event.rand.nextInt(8);

                    if (event.world.isAirBlock(x1, y1, z1) && (!event.world.provider.hasNoSky || y1 < 127) && ModBlocks.manaFlower.canBlockStay(event.world, x1, y1, z1))
                        event.world.setBlock(x1, y1, z1, ModBlocks.manaFlower, event.rand.nextInt(3), 2);
                }
            }
        }
    }
}
 
開發者ID:Lomeli12,項目名稱:MagicalRings,代碼行數:23,代碼來源:BiomeDecorHandler.java

示例15: onPlayerInteract

import cpw.mods.fml.common.eventhandler.Event; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent ev) {
    if (ev.entityPlayer.worldObj.isRemote || ev.isCanceled()) {
        return;
    }

    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.entityPlayer);
    if(ev.entityPlayer.getHeldItem() != null) {
        ProtectionManager.checkUsage(ev.entityPlayer.getHeldItem(), res, ev.action, createBlockPos(ev), ev.face, ev);
    }
    if (!ev.isCanceled()) {
        ProtectionManager.checkBlockInteraction(res, new BlockPos(ev.x, ev.y, ev.z, ev.world.provider.dimensionId), ev.action, ev);
    }

    // Some things (Autonomous Activator) only care about these. So always deny them if the event is canceled.
    if (ev.isCanceled()) {
        ev.useBlock = Event.Result.DENY;
        ev.useItem = Event.Result.DENY;
    }
}
 
開發者ID:MyEssentials,項目名稱:MyTown2,代碼行數:22,代碼來源:ProtectionHandlers.java


注:本文中的cpw.mods.fml.common.eventhandler.Event類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。