Java Code Examples for net.minecraftforge.event.world.BlockEvent

The following are top voted examples for showing how to use net.minecraftforge.event.world.BlockEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Uranium   File: CaptureBlock.java   View source code 6 votes vote down vote up
/**
 * 激活方块破坏事件
 * <p>
 * 此方法应该在方块被真实的放置到世界<i><b>之前</b></i>调用
 * </p>
 * 
 * @param pSnapshot
 *            被破坏的方块
 * @param pSimulate
 *            是否为模拟
 * @return 事件是否被允许
 */
public boolean fireBlockBreak(BlockSnapshot pSnapshot,boolean pSimulate){
    if(!this.mEnable||this.isChecked(pSnapshot.world,pSnapshot.x,pSnapshot.y,pSnapshot.z,pSimulate))
        return true;
    if(!this.mAllow) return false;

    this.mEnable=false; // 设置未false,防止BlockEvent中添加检查过方块
    BlockEvent tEvent=new BlockEvent.BreakEvent(pSnapshot.x,pSnapshot.y,pSnapshot.z,pSnapshot.world,
            pSnapshot.getReplacedBlock(),pSnapshot.meta,this.mCapturePlayer);
    MinecraftForge.EVENT_BUS.post(tEvent);
    this.mEnable=true;

    if(!pSimulate){
        this.mergeBlockChangeResult(!tEvent.isCanceled());
    }
    return !tEvent.isCanceled();
}
 
Example 2
Project: RunicArcana   File: ScriptActivationEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void blockBreakEvent(BlockEvent.BreakEvent event)
{
    EntityPlayer player = event.getPlayer();
    ItemStack OmniItem = null;
    if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.MAIN_HAND) )>0)
        OmniItem = player.getHeldItem(EnumHand.MAIN_HAND);
    else if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.OFF_HAND) )>0)
        OmniItem = player.getHeldItem(EnumHand.OFF_HAND);
    else return;

    CompiledSymbol[] script = ModDust.getScriptFromItem(OmniItem);
    if(script==null)return;

    new ScriptExecutor(script, player, OmniItem, ScriptExecutor.StartPoint.BLOCK_BREAK, event.getPos());
}
 
Example 3
Project: Adventurers-Toolbox   File: SpecialToolAbilityHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onWitherBoneHarvestEvent(BlockEvent.HarvestDropsEvent event) {
	if (event.getHarvester() == null) {
		return;
	}

	EntityPlayer player = event.getHarvester();
	ItemStack stack = player.getHeldItemMainhand();

	boolean flag = false;

	if (stack.getItem() instanceof IHaftTool) {
		if (IHaftTool.getHaftMat(stack) == ModMaterials.HAFT_WITHER_BONE) {
			flag = true;
		}
	}

	if (flag) {
		if (player.dimension != DimensionType.NETHER.getId()) {
			stack.damageItem(7, player);
		}
	}
}
 
Example 4
Project: customstuff4   File: EventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void canCreateFluidSource(BlockEvent.CreateFluidSourceEvent event)
{
    if (event.getResult() != Event.Result.DEFAULT)
        return;

    if (applyModifiers(event))
        return;

    Block block = event.getState().getBlock();

    if (block instanceof CSBlock)
    {
        ContentBlockBase content = ((CSBlock) block).getContent();
        if (content instanceof ContentBlockFluid)
        {
            ContentBlockFluid fluid = (ContentBlockFluid) content;
            event.setResult(fluid.canCreateSource ? Event.Result.ALLOW : Event.Result.DENY);
        }
    }
}
 
Example 5
Project: customstuff4   File: EventHandler.java   View source code 6 votes vote down vote up
private static boolean applyModifiers(BlockEvent.CreateFluidSourceEvent event)
{
    Block block = event.getState().getBlock();

    for (FluidModifier modifier : FluidModifier.getModifiers())
    {
        if (block.getRegistryName() != null && block.getRegistryName().equals(modifier.block))
        {
            if (modifier.canCreateSource != null)
            {
                event.setResult(modifier.canCreateSource ? Event.Result.ALLOW : Event.Result.DENY);
                return true;
            }
        }
    }

    return false;
}
 
Example 6
Project: Mods   File: TF2EventsCommon.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void stopBreak(BlockEvent.BreakEvent event) {

	if (event.getPlayer().getHeldItem(EnumHand.MAIN_HAND) != null && event.getPlayer().getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemUsable) {
		event.setCanceled(true);
	}
	if (event.getPlayer().getActivePotionEffect(TF2weapons.bonk) != null) {
		event.setCanceled(true);
	}
	if (event.getPlayer().getCapability(TF2weapons.WEAPONS_CAP, null).invisTicks > 0) {
		event.setCanceled(true);
	}
	if (event.getPlayer().getActivePotionEffect(TF2weapons.stun) != null) {
		event.setCanceled(true);
	}
	if (WeaponsCapability.get(event.getPlayer()).isDisguised()) {
		disguise(event.getPlayer(), false);
	}
}
 
Example 7
Project: ThaumOres   File: TOEvents.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void eventBreakEvent(BlockEvent.BreakEvent event) {
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	EntityPlayer player = event.getPlayer();

	if (player != null && player.getHeldItem() != null && player.getHeldItem().getItem() == Items.stick) {
		if (TOConfig.debugEnable && TOConfig.debugRemover && !world.isRemote
				&& player.capabilities.isCreativeMode) {
			int radius = TOConfig.debugRemoverScannerRadius;
			for (int xx = x - radius; xx < x + radius; xx++)
				for (int zz = z - radius; zz < z + radius; zz++)
					for (int yy = 0; yy < 257; yy++)
						if (!(world.getBlock(xx, yy, zz) instanceof BlockInfusedBlockOre))
							world.setBlock(xx, yy, zz, Blocks.air, 0, 2);
			String text = "[DEBUG " + ThaumOresMod.NAME + "] Removed blocks at " + x + ";" + z + " with radius "
					+ radius;
			player.addChatMessage(new ChatComponentText(text));
			ThaumOresMod.log.info(text);
		}
	}
}
 
Example 8
Project: BetterWithAddons   File: HarvestHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void playerTick(BlockEvent.BreakEvent breakEvent)
{
    World world = breakEvent.getWorld();
    BlockPos pos = breakEvent.getPos();
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();

    if(block instanceof BlockWorldScaleOre)
    {
        if(state.getValue(BlockWorldScaleOre.CRACKED) < 5) {
            ((BlockWorldScaleOre)block).addCracks(world,pos,state,1);
            breakEvent.setCanceled(true);
        }
    }
}
 
Example 9
Project: Factorization   File: BlockUndo.java   View source code 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST) // Act after any cancellations
public void recordBlock(BlockEvent.PlaceEvent event) {
    IBlockState bs = event.placedBlock;
    Block block = bs.getBlock();
    if (event.player == null) return;
    if (event.world.isRemote) return;
    if (event.player instanceof FakePlayer) return;
    if (block.getBlockHardness(event.world, event.pos) <= 0F) return;
    if (PlayerUtil.isPlayerCreative(event.player)) return;

    int idmd = hash(bs);
    final ItemStack theItem = toItem(block, event.world, event.pos, bs);
    final PlacedBlock at = new PlacedBlock(FzUtil.getWorldDimension(event.world), event.pos, idmd, theItem);
    markPlacement(event.player, at);
    if (event.player instanceof EntityPlayerMP) {
        send(event.player, at);
    }
}
 
Example 10
Project: BetterWithAddons   File: RedstoneBoilHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void redstoneUpdate(BlockEvent.NeighborNotifyEvent event)
{
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getState();

    if(state.getBlock() != Blocks.REDSTONE_WIRE)
        return;

    if(!willRedstoneBoil(world,pos))
        return;

    if(state.getValue(BlockRedstoneWire.POWER) > 0)
        return;

    scheduleRedstone(world,pos,9);
}
 
Example 11
Project: Snitch-Master   File: SnitchListeners.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onSnitchBreak(BlockEvent.BreakEvent event)
{
    BlockPos pos = event.getPos();
    Location loc = new Location(pos.getX(), pos.getY(), pos.getZ(), snitchMaster.getCurrentWorld());

    Snitch snitch = manager.getSnitches().remove(loc);
    if (snitch != null)
    {
        snitchMaster.individualJourneyMapUpdate(snitch);

        manager.saveSnitches();

        SnitchMaster.SendMessageToPlayer("Removed snitch at " + loc.toString());
    }

}
 
Example 12
Project: CrystalMod   File: EventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void breakE(BlockEvent.BreakEvent event)
{
	if(event.getWorld() !=null && !event.getWorld().isRemote && event.getWorld().provider.getDimension() == ModDimensions.CUBE_ID){
		PlayerCube cube = CubeManager.getInstance().getPlayerCubeFromPos(event.getWorld(), event.getPos());
		if(cube !=null){
			for(TileEntityPlayerCubePortal portal : cube.watchers){
				if (portal.mobileChunk.addBlockWithState(event.getPos(), Blocks.AIR.getDefaultState())) {
	                portal.mobileChunk.removeChunkBlockTileEntity(event.getPos());
	            }
	            portal.mobileChunk.setChunkModified();
	            portal.mobileChunk.onChunkLoad();
			}
		}
	}
}
 
Example 13
Project: CrystalMod   File: EventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onBlockPlace(BlockEvent.PlaceEvent e) {
    if (!e.getWorld().isRemote) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            TileEntity tile = e.getWorld().getTileEntity(e.getBlockSnapshot().getPos().offset(facing));

            if (tile != null && TileEntityPipeEStorage.isNetworkTile(tile)) {
                EStorageNetwork network = TileEntityPipeEStorage.getTileNetwork(tile);
                if (network != null && !network.hasAbility(e.getPlayer(), NetworkAbility.BUILD)) {
                    ChatUtil.sendNoSpam(e.getPlayer(), Lang.localize("gui.networkability."+NetworkAbility.BUILD.getId()));

                    e.setCanceled(true);

                    return;
                }
            }
        }
    }
}
 
Example 14
Project: CrystalMod   File: EventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent e) {
    if (!e.getWorld().isRemote) {
        TileEntity tile = e.getWorld().getTileEntity(e.getPos());

        if (tile != null && TileEntityPipeEStorage.isNetworkTile(tile)) {
        	 EStorageNetwork network = TileEntityPipeEStorage.getTileNetwork(tile);

            if (network != null && !network.hasAbility(e.getPlayer(), NetworkAbility.BUILD)) {
            	ChatUtil.sendNoSpam(e.getPlayer(), Lang.localize("gui.networkability."+NetworkAbility.BUILD.getId()));

                e.setCanceled(true);
            }
        }
    }
}
 
Example 15
Project: Wizardry   File: ArenaManager.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void placeBlock(BlockEvent.PlaceEvent event) {
	for (Arena arena : arenas) {
		if (!arena.getPlayers().contains(event.getPlayer().getUniqueID()) || arena.getWorld() != event.getWorld())
			continue;

		if (!event.getWorld().isRemote && arena.getBoss() instanceof EntityZachriel)
			((EntityZachriel) arena.getBoss()).nemezDrive.trackBlock(event.getPos(), event.getWorld().getBlockState(event.getPos()));

		//if (!event.getWorld().isRemote)
		//	for (ZachTimeManager timeManager : zachHourGlasses) {
		//		if (timeManager.getEntityZachriel().getEntityId() == arena.getBossID()) {
		//			timeManager.trackBlock(Blocks.AIR.getDefaultState(), event.getPos());
		//		}
		//	}
	}
}
 
Example 16
Project: TAIGA   File: TraitTantrum.java   View source code 6 votes vote down vote up
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
    World w = event.getWorld();
    if (!w.isRemote) {
        if (event.getState().getBlock().equals(tiberiumOre)) {
            event.getDrops().clear();
            NBTTagCompound tag = TagUtil.getExtraTag(tool);
            Data data = Data.read(tag);
            if (data.amount >= max_charges) {
                return;
            }
            data.amount += (0.25f + Utils.round2(random.nextDouble() / 4));
            if (data.amount >= max_charges) {
                TagUtil.setEnchantEffect(tool, true);
                if (event.getHarvester() instanceof EntityPlayerMP) {
                    Sounds.PlaySoundForPlayer(event.getHarvester(), Sounds.shocking_discharge, 1f, 0.8f + .2f * random.nextFloat());
                }
            }
            data.write(tag);
            TagUtil.setExtraTag(tool, tag);
        }
    }
}
 
Example 17
Project: OpenHarvest   File: HarvestEvents.java   View source code 6 votes vote down vote up
/** Harvest a log */
@SubscribeEvent
public void onHarvestLog(BlockEvent.HarvestDropsEvent event) {
	World world = event.getWorld();
	if(world.isRemote || !HarvestConfig.doTreeChop || skip || event.getHarvester() == null) return; // do nothing here

	EntityPlayerMP player = (EntityPlayerMP)event.getHarvester();
	BlockPos pos = event.getPos();
	IBlockState state = event.getState();

	// make sure treecapitation is possible
	if(canTreecapitate(player, pos, state)) {
		// now perform the treecapitation while checking for stack overflow
		try {
			clearInvalidBlocks();
			blocks = leaves = 0;
			skip = true;
			treecapitate(world, pos, state, player, player.getHeldItemMainhand()); // c h o p
		} catch (StackOverflowError e) {}
		clearInvalidBlocks();
		skip = false;
		return; // nothing more to do here
	}

}
 
Example 18
Project: SeasonsAPI   File: WorldHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onBlockUpdate(BlockEvent.NeighborNotifyEvent e) {
	if (!Seasons.enabled)
		return;
	try {
		if (e.getState() == null)
			return;
		if ((e.getState().getBlock() instanceof ITemperatureUpdater ? !((ITemperatureUpdater)e.getState().getBlock()).requiresTemperatureUpdate(e.getWorld(), e.getState(), e.getPos()): !SeasonsAPI.instance.getBlockTemperatureRegistry().hasTemperature(e.getState())))
			return;
		if (!tempMap.containsKey(e.getWorld().getChunkFromBlockCoords(e.getPos()).getChunkCoordIntPair()))
			return;
		tempMap.get(e.getWorld().getChunkFromBlockCoords(e.getPos()).getChunkCoordIntPair()).calcBlockTemp(e.getWorld(), e.getPos());
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example 19
Project: ExNihiloAdscensio   File: HandlerHammer.java   View source code 6 votes vote down vote up
@SubscribeEvent(priority=EventPriority.LOWEST)
public void hammer(BlockEvent.HarvestDropsEvent event)
{
	if (event.getWorld().isRemote || event.getHarvester() == null || event.isSilkTouching())
		return;

	ItemStack held = event.getHarvester().getHeldItemMainhand();
	
	if (!isHammer(held))
		return;
	
	List<ItemStack> rewards = HammerRegistry.getRewardDrops(event.getWorld().rand, event.getState(), ((IHammer) held.getItem()).getMiningLevel(held), event.getFortuneLevel());
	
	if (rewards != null && rewards.size() > 0)
	{
		event.getDrops().clear();
		event.setDropChance(1.0F);
		event.getDrops().addAll(rewards);
	}
}
 
Example 20
Project: CraftingHarmonics   File: BlockRegistry.java   View source code 6 votes vote down vote up
/**
 * Handles checking for any interactions we need to run for the given block.
 * @param evt    The event to handle
 * @return       True if the interaction should continue, false otherwise.
 */
public boolean handleInteraction(PlayerInteractEvent.RightClickBlock evt) {
    // Figure out what we clicked...
    IBlockState targetBlock = evt.getWorld().getBlockState(evt.getPos());

    // Get our handlers...
    Collection<BlockInteractionHandler> handlers = interactionHandlers.get(targetBlock);

    // Bail early if we can:
    if(handlers.size() <= 0) return true;

    // Simulate the harvest drops event:
    // TODO: Abstract block drops from general block matchers so we don't have to do this...
    BlockEvent.HarvestDropsEvent simulatedEvt = new BlockEvent.HarvestDropsEvent(evt.getWorld(), evt.getPos(),
            targetBlock, 0, 0.0f, new ArrayList<>(), evt.getEntityPlayer(), false);

    // ... and process them
    for (BlockInteractionHandler handler : handlers) {
        // Check if we should cancel:
        if(!handler.handle(evt, simulatedEvt)) return false;
    }

    // If we made it here, we can tell the parent handler it can continue:
    return true;
}
 
Example 21
Project: CraftingHarmonics   File: BlockInteractionHandler.java   View source code 6 votes vote down vote up
/**
 * Handle the event, returning if processing should continue
 *
 * @param evt          The event to handle
 * @param simulatedEvt A simulated drop event to pass on to the matchers
 * @return True if processing should continue; false to cancel the underlying event.
 */
public boolean handle(PlayerInteractEvent.RightClickBlock evt, BlockEvent.HarvestDropsEvent simulatedEvt) {
    List<Runnable> matcherCallbacks = new ArrayList<>();

    // Check our matchers:
    for (IBlockDropMatcher matcher : matchers) {
        BaseMatchResult result = matcher.isMatch(simulatedEvt, dummy);
        if (!result.isMatch()) return true;
        if (result.getCallback() != null) matcherCallbacks.add(result.getCallback());
    }

    // Run our matcher callbacks:
    for (Runnable matcherCallback : matcherCallbacks) {
        matcherCallback.run();
    }

    // Run our callbacks, only for the main hand:
    // TODO: Consider moving this to the event handler to prevent going through everything else...
    if(evt.getHand() == EnumHand.MAIN_HAND) {
        MobTickRegistry.addCallbackSet(evt.getEntity(), callbacks, new BaseEntityMatcherData(evt.getEntity()));
    }

    return !cancelAfterMatch;
}
 
Example 22
Project: Event-Tweaks   File: ForestEventHandlers.java   View source code 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void HarvestDropsEvent(BlockEvent.HarvestDropsEvent e){
    try {
        if (e != null && e.getHarvester() == null && !e.getDrops().isEmpty() && ((e.getState().getBlock().equals(Blocks.LEAVES))
                || e.getState().getBlock().equals(Blocks.LEAVES2)) && !e.getWorld().isRemote) {
            Block block = Block.getBlockFromItem(e.getDrops().get(0).getItem());
            int meta = e.getDrops().get(0).getMetadata();
            BlockPos pos = findGround(e.getWorld(), e.getPos());
            if (pos != null && e.getWorld() != null) {
                e.getWorld().setBlockState(pos, block.getStateFromMeta(meta));
                deleteCopySapling(e.getWorld(), pos, Item.getItemFromBlock(block));
            }
        }
    }catch(Throwable throwable){
        System.out.println("    EXCEPTION FOUND IN EVENT TWEAKS FOREST REPLANTING: PLEASE REPORT LOGS TO EVENT TWEAKS WITH INFORMATION ON REPRODUCING");
        throwable.printStackTrace();
    }
}
 
Example 23
Project: MakeClayValuableAgain   File: ClayProgressionImprovements.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void suppressClayDrops(BlockEvent.HarvestDropsEvent event) {
    List<ItemStack> drops = event.getDrops();
    if (drops.stream().noneMatch(this::isClay)) {
        return;
    }
    EntityPlayer harvester = event.getHarvester();
    if (harvester != null && ModItems.getInstance().isValidClayHarvester(harvester.getHeldItemMainhand())) {
        return;
    }
    drops.clear();
}
 
Example 24
Project: Lanolin   File: EventHandlerCommon.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event){
    EntityPlayer player = event.getPlayer();
    if(player.isInsideOfMaterial(Material.WATER)) {
        //Player is inside water, check for lanolin
        if (player.getHeldItemMainhand().hasTagCompound() && player.getHeldItemMainhand().getTagCompound().hasKey("lanolin")) {
            int newLanolin = player.getHeldItemMainhand().getTagCompound().getInteger("lanolin") - 1;
            if (newLanolin <= 0)
                player.getHeldItemMainhand().getTagCompound().removeTag("lanolin");
            else
                player.getHeldItemMainhand().getTagCompound().setInteger("lanolin", newLanolin);
        }
    }
}
 
Example 25
Project: ThermionicsWorld   File: ThermionicsWorld.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void cropGrowEvent(BlockEvent.CropGrowEvent.Pre event) {
	//IBlockState cropState = event.getState();
	Block land = event.getWorld().getBlockState(event.getPos().down()).getBlock();
	if (land instanceof BlockMeat) {
		//vanilla ticks give a 1 in 10 chance. We're forcing it on a 1 in 4, with the remaining 3 potentially ALSO
		//growing at the normal 10%. So this should be pretty fast.
		int growthChance = (int)(Math.random()*4);
		if (growthChance==0) event.setResult(Event.Result.ALLOW);
	}
}
 
Example 26
Project: genera   File: EventHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event) {
    if (event.getState().getBlock() == Blocks.TALLGRASS) {
        float randomValue = event.getWorld().rand.nextFloat();
        if (randomValue >= 0.9) {
            event.getWorld().spawnEntity(new EntityItem(event.getWorld(),
                    event.getPos().getX(),
                    event.getPos().getY(),
                    event.getPos().getZ(),
                    new ItemStack(GeneraItems.ItemSeedNightshade, 1)));
        }
    }
}
 
Example 27
Project: Industrial-Foregoing   File: PlantInteractorTile.java   View source code 5 votes vote down vote up
public void harvestDrops(BlockEvent.HarvestDropsEvent event) {
    for (ItemStack stack : event.getDrops()) {
        ItemHandlerHelper.insertItem(outItems, stack, false);
        sludge.fill(new FluidStack(FluidsRegistry.SLUDGE, 10 * stack.getCount()), true);
    }
    event.getDrops().clear();
    hasWorked = true;
}
 
Example 28
Project: Industrial-Foregoing   File: PlantInteractorHarvestDropsHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onHarvest(BlockEvent.HarvestDropsEvent event) {
    for (PlantInteractorTile tile : PlantInteractorTile.WORKING_TILES) {
        if (tile.getWorld().equals(event.getWorld()) && BlockUtils.getBlockPosInAABB(tile.getWorkingArea()).contains(event.getPos())) {
            tile.harvestDrops(event);
            return;
        }
    }
}
 
Example 29
Project: Uranium   File: CaptureBlock.java   View source code 5 votes vote down vote up
/**
 * 激活方块放置事件
 * <p>
 * 此方法应该在方块被真实的放置到世界<i><b>之后</b></i>调用
 * </p>
 * 
 * @param pSnapshot
 *            被替换的方块
 * @param pPlaced
 *            放置了的方块
 * @param pSimulate
 *            是否为模拟
 * @return 事件是否被允许
 */
public boolean fireBlockPlace(BlockSnapshot pSnapshot,Block pPlaced,boolean pSimulate){
    if(!this.mEnable||this.isChecked(pSnapshot.world,pSnapshot.x,pSnapshot.y,pSnapshot.z,pSimulate))
        return true;
    if(!this.mAllow) return false;

    this.mEnable=false; // 设置未false,防止BlockEvent中添加检查过方块
    BlockEvent tEvent=ForgeEventFactory.onPlayerBlockPlace(this.mCapturePlayer,pSnapshot,this.mSide);
    this.mEnable=true;

    if(!pSimulate){
        this.mergeBlockChangeResult(!tEvent.isCanceled());
    }
    return !tEvent.isCanceled();
}
 
Example 30
Project: Bewitchment   File: HarvestEvent.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onHarvestAllium(BlockEvent.HarvestDropsEvent harvest) {
	if (harvest.getState().getBlock() == Blocks.RED_FLOWER && harvest.getState().getBlock().getMetaFromState(harvest.getState()) == 2 && harvest.getWorld().rand.nextInt(5) == 0) {
		harvest.getDrops().clear();
		harvest.getDrops().add(new ItemStack(ModItems.seed_garlic, 1));
	}
}
 
Example 31
Project: Bewitchment   File: HarvestEvent.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onHarvestDeadBush(BlockEvent.HarvestDropsEvent harvest) {
	if ((harvest.getState().getBlock() == Blocks.DEADBUSH && harvest.getWorld().rand.nextInt(150) < 25)) {
		harvest.getDrops().clear();
		harvest.getDrops().add(new ItemStack(ModItems.seed_white_sage, 1));
	}
}
 
Example 32
Project: Bewitchment   File: HarvestEvent.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onHarvestOakLeaves(BlockEvent.HarvestDropsEvent event) {
	if ((event.getState().getBlock() == Blocks.LEAVES && event.getWorld().rand.nextInt(150) < 25)) {
		event.getDrops().clear();
		event.getDrops().add(new ItemStack(ModItems.oak_apple_gall, 1));
	}
}
 
Example 33
Project: Bewitchment   File: HarvestEvent.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onScoopGravel(BlockEvent.HarvestDropsEvent event) {
	if ((event.getState().getBlock() == Blocks.GRAVEL && event.getWorld().rand.nextInt(400) < 25)) {
		event.getDrops().clear();
		event.getDrops().add(new ItemStack(ModItems.gem, 1, 1));
	}
}
 
Example 34
Project: Bewitchment   File: HarvestEvent.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onMineCoquina(BlockEvent.HarvestDropsEvent event) {
	if ((event.getState().getBlock() == ModBlocks.coquina && event.getWorld().rand.nextInt(345) < 25)) {
		event.getDrops().clear();
		event.getDrops().add(new ItemStack(Blocks.GRAVEL, 1));
	}
}
 
Example 35
Project: Bewitchment   File: HarvestEvent.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onHarvestWormwood(BlockEvent.HarvestDropsEvent event) {
	if ((event.getState().getBlock() == ModBlocks.crop_wormwood && event.getWorld().rand.nextInt(450) < 25)) {
		event.getDrops().clear();
		event.getDrops().add(new ItemStack(ModItems.absinthe_green, 1));
		event.getDrops().add(new ItemStack(ModItems.wormwood, 3));
		event.getDrops().add(new ItemStack(ModItems.seed_wormwood, 2));
	}
}
 
Example 36
Project: PAYDAY   File: MEventHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent evt) {
	/*
	if (evt.block instanceof LobbyBlock) {
		// RESETS DATA AND CANCELS EVENT
		LobbyTileEntity t = (LobbyTileEntity) evt.world.getTileEntity(evt.x, evt.y, evt.z);

		if (t != null) {
			PlayerData data;
			
			for (EntityPlayer p : UUIDUtil.getPlayersFromProfileUUIDs(evt.world, t.players)) {
				data = PlayerData.get(p);
				
				data.setReady(false);
				data.setInLobby(false);
				
				if (evt.world.isRemote)
					data.sendToServer();
				
				t.removePlayer(p);
				
				//PAYDAY.INSTANCE.sendToServer(new LobbyPlayerActionPacket(evt.x, evt.y, evt.z, true));
			}
		}
		//evt.setCanceled(true);
	}*/
}
 
Example 37
Project: needtobreath   File: ForgeEventHandlers.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent evt) {
    World world = evt.getWorld();
    DimensionData data = getDimensionData(world);
    if (data != null) {
        data.fillCleanAir(evt.getPos().toLong());
    }
}
 
Example 38
Project: needtobreath   File: ForgeEventHandlers.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onCropGrowth(BlockEvent.CropGrowEvent.Pre evt) {
    World world = evt.getWorld();
    DimensionData data = getDimensionData(world);
    if (data != null) {
        if (preventPlantGrowth(world, data, evt.getPos())) {
            evt.setResult(Event.Result.DENY);
        }
    }
}
 
Example 39
Project: BetterThanWeagles   File: EventHandlerBlockDrops.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void modifyHarvestDrops(BlockEvent.HarvestDropsEvent event)
{
	if (event.getState().getBlock() == Blocks.GRAVEL)
	{
		Random rand = event.getWorld().rand;

		if (rand.nextInt(100) < Config.shiny_stone_drop_rate)
		{
			event.getDrops().add(new ItemStack(ModItems.shiny_stone));
		}
	}
}
 
Example 40
Project: MeeCreeps   File: WorkerHelper.java   View source code 5 votes vote down vote up
@Override
public boolean allowedToHarvest(IBlockState state, World world, BlockPos pos, EntityPlayer entityPlayer) {
    if (state.getBlock().getBlockHardness(state, world, pos) < 0) {
        return false;
    }
    if (!state.getBlock().canEntityDestroy(state, world, pos, entityPlayer)) {
        return false;
    }
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, entityPlayer);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled()) {
        return false;
    }
    return state.getBlock().canHarvestBlock(world, pos, entityPlayer);
}