cpw.mods.fml.common.eventhandler.Event.Result Java Examples

The following examples show how to use cpw.mods.fml.common.eventhandler.Event.Result. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoarseDirt.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public static void onHoeEvent(UseHoeEvent event) {
	if (EtFuturum.enableCoarseDirt) {
		World world = event.world;
		if (world.getBlock(event.x, event.y, event.z) == ModBlocks.coarse_dirt) {
			world.setBlock(event.x, event.y, event.z, Blocks.dirt);
			world.playSoundEffect(event.x + 0.5F, event.y + 0.5F, event.z + 0.5F, Block.soundTypeGravel.getStepResourcePath(), 1.0F, 0.8F);
			event.setResult(Result.ALLOW);
		}
	}
}
 
Example #2
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onFertilization(BonemealEvent event){
    if(event.world.isRemote) return; // why would we want to handle this on the client-side?

    if(event.block == Blocks.netherrack || event.block == Blocks.end_stone || event.block.canSustainPlant(event.world, event.x, event.y, event.z, ForgeDirection.UP, Blocks.red_flower)) { // can bonemeal Biomes O' Plenty grass, etc.    			    			
        boolean onGrass = event.block instanceof BlockGrass;
        if(onGrass && Config.includePlantsOnBonemeal || !onGrass && Config.allowDirtBonemealing) {
            // we'll try to spawn plants in a 5x5 area which is centered on the block that has been bonemealed
            for(int x = event.x - 2; x < event.x + 3; x++) {
                for(int z = event.z - 2; z < event.z + 3; z++) {
                    if(event.world.isAirBlock(x, event.y + 1, z)) {
                        if(event.world.rand.nextInt(8) == 1) { // increase .nextInt(x) to lower the chances of spawning a plant
                            BlockPneumaticPlantBase trySpawn = BlockPlants.allPlants.get(event.world.rand.nextInt(BlockPlants.allPlants.size() - 1)); // select a random plant    							
                            if(trySpawn.canPlantGrowOnThisBlock(event.world.getBlock(x, event.y, z), event.world, x, event.y, z)) { // make sure that the plant we selected can grow on the soil
                                event.world.setBlock(x, event.y + (trySpawn.isPlantHanging() ? -1 : 1), z, trySpawn);
                            }
                        }
                    }
                }

                /*
                 * vanilla mechanics will spawn flowers etc. when bonemeal is used on grass,
                 * so we cannot set Result.ALLOW in this case because it would stop event-propagation
                 */
                if(!onGrass) event.setResult(Result.ALLOW);
            }
        }
    }
}
 
Example #3
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void FillBucket(FillBucketEvent event){
    MovingObjectPosition p = event.target;
    if(event.current == null || event.current.getItem() != Items.bucket || event.world.getBlockMetadata(p.blockX, p.blockY, p.blockZ) != 0) return;
    ItemStack result = attemptFill(event.world, event.target);
    if(result != null) {
        event.result = result;
        AchievementHandler.giveAchievement(event.entityPlayer, result);
        event.setResult(Result.ALLOW);
    }
}
 
Example #4
Source File: BRLoader.java    From BigReactors with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onBucketFill(FillBucketEvent e)
{
    if(e.current.getItem() != Items.bucket)
    {
        return;
    }
    ItemStack filledBucket = fillBucket(e.world, e.target);
    if(filledBucket != null)
    {
        e.world.setBlockToAir(e.target.blockX, e.target.blockY, e.target.blockZ);
        e.result = filledBucket;
        e.setResult(Result.ALLOW);
    }
}