private void explodeBlock(BlockPos pos) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(!world.isRemote && block.canDropFromExplosion(explosion)) { List<ItemStack> drops = block.getDrops(world, pos, state, 0); ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1f, false, null); droppedItems.addAll(drops); } if(world instanceof WorldServer) { ((WorldServer) world).spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, true, pos.getX(), pos.getY(), pos.getZ(), 2, 0, 0, 0, 0d); ((WorldServer) world).spawnParticle(EnumParticleTypes.SMOKE_LARGE, true, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 0d); } block.onBlockExploded(world, pos, explosion); } }
ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND); player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, world, player, i, !itemstack.isEmpty() || flag); if (i < 0) return;
entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, world.rand.nextFloat() * 360.0F, 0.0F); if(entityliving == null || net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(entityliving, world, (float) entity.posX, (float) entity.posY, (float) entity.posZ)) { if(logic.spawnData.getNbt().getSize() == 1 && logic.spawnData.getNbt().hasKey("id", 8) && entity instanceof EntityLiving) { if(!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entityliving, logic.getSpawnerWorld(), (float) entity.posX, (float) entity.posY, (float) entity.posZ)) ((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData) null);
boolean hasAmmo = !findAmmo(itemStackIn, playerIn).isEmpty(); ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemStackIn, worldIn, playerIn, hand, hasAmmo); if(ret != null) { return ret; useTime = ForgeEventFactory.onArrowLoose(stack, worldIn, player, useTime, !ammo.isEmpty());
predicate ); net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(world, explosion, list, r * 2);
public boolean place(IBlockState state, EnumFacing direction, EnumHand hand) { if (!world.isBlockLoaded(blockPos)) return false; if (spawnProtection) { if (!world.isBlockModifiable(player, blockPos)) return false; } final BlockSnapshot snapshot = BlockSnapshot.getBlockSnapshot(world, blockPos); if (!world.setBlockState(blockPos, state, blockPlaceFlags)) return false; if (ForgeEventFactory.onPlayerBlockPlace(player, snapshot, direction, hand).isCanceled()) { world.restoringBlockSnapshots = true; snapshot.restore(true, false); world.restoringBlockSnapshots = false; return false; } return true; } }
net.minecraftforge.fml.common.eventhandler.Event.Result canSpawn = net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(entity, machineWorld, x, y, z, false); if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entity, machineWorld, x, y, z)) { entity.onInitialSpawn(machineWorld.getDifficultyForLocation(new BlockPos(entity)), null);
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); // Copy from superclass with our own check boolean flag = canFire(stack, player); ActionResult<ItemStack> ret = ForgeEventFactory.onArrowNock(stack, world, player, hand, flag); if (ret != null) return ret; if (!player.capabilities.isCreativeMode && !flag) { return new ActionResult<>(EnumActionResult.FAIL, stack); } else { player.setActiveHand(hand); return new ActionResult<>(EnumActionResult.SUCCESS, stack); } }
placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side, hand); } else if (blockSnapshots.size() == 1) { placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side, hand);
protected boolean canSpawnEntity(EntityLiving entityliving) { // this is the logic from ForgeEventFactory.canEntitySpawnSpawner() with some additions switch (SpawnerConfig.poweredSpawnerUseForgeSpawnChecks.get() ? ForgeEventFactory.canEntitySpawn(entityliving, entityliving.world, (float) entityliving.posX, (float) entityliving.posY, (float) entityliving.posZ, true) : Result.DEFAULT) { case ALLOW: return true; case DEFAULT: if (SpawnerConfig.poweredSpawnerUseVanillaSpawnChecks.get()) { return entityliving.getCanSpawnHere() && entityliving.isNotColliding(); // vanilla logic } else { return entityliving.isNotColliding(); } case DENY: default: spawner.setNotification(SpawnerNotification.DENIED); return false; } }
if (pos == null || !ForgeEventFactory.doSpecialSpawn((EntityLiving) entity, world, pos.getX(), pos.getY(), pos.getZ(), null)) { ((EntityLiving) entity).onInitialSpawn(difficulty, null);
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(world, explosion, Collections.emptyList(), r * 2);
public static boolean validBlock(World world, BlockPos voidPos, EntityPlayer player) { IBlockState currentBlock = world.getBlockState(voidPos); TileEntity te = world.getTileEntity(voidPos); if (currentBlock.getMaterial() == Material.AIR) return false; //if (currentBlock.getBlock().getMaterial(currentBlock).isLiquid()) return false; if (currentBlock.equals(ModBlocks.effectBlock.getDefaultState())) return false; if ((te != null) && !(te instanceof ConstructionBlockTileEntity)) return false; if (currentBlock.getBlockHardness(world, voidPos) < 0) return false; ItemStack tool = getGadget(player); if (tool.isEmpty()) return false; if (!player.isAllowEdit()) { return false; } if (!world.isBlockModifiable(player, voidPos)) { return false; } if (!world.isRemote) { BlockSnapshot blockSnapshot = BlockSnapshot.getBlockSnapshot(world, voidPos); if (ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshot, EnumFacing.UP, EnumHand.MAIN_HAND).isCanceled()) { return false; } BlockEvent.BreakEvent e = new BlockEvent.BreakEvent(world, voidPos, currentBlock, player); if (MinecraftForge.EVENT_BUS.post(e)) { return false; } } return true; }
final Result canSpawn = ForgeEventFactory.canEntitySpawn(spawnedMob, world, spawnX, spawnY, spawnZ, false); if (!ForgeEventFactory.doSpecialSpawn(spawnedMob, world, spawnX, spawnY, spawnZ)) {
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) { ItemStack itemStackIn = playerIn.getHeldItem(hand); boolean flag = this.findAmmo(playerIn) != null; ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemStackIn, worldIn, playerIn, hand, flag); if (ret != null) return ret; if (!playerIn.capabilities.isCreativeMode && !flag) { return !flag ? new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn) : new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn); } else { playerIn.setActiveHand(hand); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn); } }
private void trySpawn(World world, BlockPos pos, Random rand) throws Exception { //if radius is 3, then go be float x = pos.getX() + MathHelper.getInt(rand, -1 * RADIUS, RADIUS); float y = pos.getY(); float z = pos.getZ() + MathHelper.getInt(rand, -1 * RADIUS, RADIUS); BlockPos posTarget = new BlockPos(x, y, z); EntityLiving monster = findMonsterToSpawn(world, posTarget, rand); if (monster == null) { return; } monster.setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F); //null means not from a spawner Event.Result canSpawn = ForgeEventFactory.canEntitySpawn(monster, world, x, y, z, null); if (canSpawn == Event.Result.DENY || monster.getCanSpawnHere() == false) { ModCyclic.logger.log("[CANDLE] spawneing " + monster.getName() + "?" + world.isAirBlock(posTarget) + posTarget); afterSpawnFailure(world, posTarget); } else if (world.spawnEntity(monster)) { ModCyclic.logger.log("[CANDLE] FAILED TO spawn " + monster.getName()); afterSpawnSuccess(monster, world, posTarget, rand); } }
NonNullList<ItemStack> drops = NonNullList.create(); state.getBlock().getDrops(drops, world, pos, state, fortune); chance = ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, fortune, chance, false, player);
public void playerDestroyItem( final @Nonnull ItemStack stack, final EnumHand hand ) { if ( realPlayer ) { net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem( innerPlayer, stack, hand ); } }
final List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity( this, area ); net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate( this.world, ex, list, 0.2f * 2d );