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;
}
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));
}
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));
}
}
}
}
Aggregations