Search in sources :

Example 1 with BlockEvent

use of net.minecraftforge.event.world.BlockEvent in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createBlockEvent.

// Block events
public static BlockEvent createBlockEvent(Event event) {
    ChangeBlockEvent spongeEvent = (ChangeBlockEvent) event;
    Location<World> location = spongeEvent.getTransactions().get(0).getOriginal().getLocation().get();
    net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent();
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    BlockEvent forgeEvent = new BlockEvent(world, pos, world.getBlockState(pos));
    return forgeEvent;
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) BlockPos(net.minecraft.util.math.BlockPos) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) NotifyNeighborBlockEvent(org.spongepowered.api.event.block.NotifyNeighborBlockEvent)

Example 2 with BlockEvent

use of net.minecraftforge.event.world.BlockEvent in project MinecraftForge by MinecraftForge.

the class ForgeHooks method onCropsGrowPre.

public static boolean onCropsGrowPre(World worldIn, BlockPos pos, IBlockState state, boolean def) {
    BlockEvent ev = new BlockEvent.CropGrowEvent.Pre(worldIn, pos, state);
    MinecraftForge.EVENT_BUS.post(ev);
    return (ev.getResult() == Event.Result.ALLOW || (ev.getResult() == Event.Result.DEFAULT && def));
}
Also used : NoteBlockEvent(net.minecraftforge.event.world.NoteBlockEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 3 with BlockEvent

use of net.minecraftforge.event.world.BlockEvent in project AgriCraft by AgriCraft.

the class TileEntityCropBase method executePlantGrowthTick.

protected void executePlantGrowthTick() {
    if (!this.getGrowthStage().isFinal()) {
        BlockState state = this.getBlockState();
        if (this.calculateGrowthRate() > this.getRandom().nextDouble() && !MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Grow.Plant.Pre(this))) {
            // also do the MinecraftForge BlockEvent for crop growth
            BlockEvent.CropGrowEvent.Pre blockEvent = new BlockEvent.CropGrowEvent.Pre(this.getWorld(), this.getPos(), state);
            MinecraftForge.EVENT_BUS.post(blockEvent);
            if (blockEvent.getResult() == Event.Result.ALLOW || blockEvent.getResult() == Event.Result.DEFAULT) {
                this.setGrowthStage(this.getGrowthStage().getNextStage(this, this.getRandom()));
                this.getPlant().onGrowth(this);
                MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Grow.Plant.Post(this));
                MinecraftForge.EVENT_BUS.post(new BlockEvent.CropGrowEvent.Post(this.getWorld(), this.getPos(), state, state));
            }
        }
    }
}
Also used : NoPlant(com.infinityraider.agricraft.impl.v1.plant.NoPlant) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) BlockState(net.minecraft.block.BlockState) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Aggregations

BlockEvent (net.minecraftforge.event.world.BlockEvent)3 AgriCropEvent (com.infinityraider.agricraft.api.v1.event.AgriCropEvent)1 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)1 NoPlant (com.infinityraider.agricraft.impl.v1.plant.NoPlant)1 BlockState (net.minecraft.block.BlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 NoteBlockEvent (net.minecraftforge.event.world.NoteBlockEvent)1 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)1 InteractBlockEvent (org.spongepowered.api.event.block.InteractBlockEvent)1 NotifyNeighborBlockEvent (org.spongepowered.api.event.block.NotifyNeighborBlockEvent)1 World (org.spongepowered.api.world.World)1 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)1