net.minecraftforge.event.world.BlockEvent Java Examples

The following examples show how to use net.minecraftforge.event.world.BlockEvent. 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: BlockManipulator.java    From OpenModsLib with MIT License 6 votes vote down vote up
public boolean remove() {
	if (!world.isBlockLoaded(blockPos)) return false;

	if (spawnProtection) {
		if (!world.isBlockModifiable(player, blockPos)) return false;
	}

	if (eventCheck) {
		final IBlockState blockState = world.getBlockState(blockPos);
		BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockState, player);
		event.setExpToDrop(0);

		MinecraftForge.EVENT_BUS.post(event);

		if (event.isCanceled()) return false;
	}

	if (silentTeRemove) world.removeTileEntity(blockPos);

	return world.setBlockToAir(blockPos);
}
 
Example #2
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onBreak(BlockEvent.BreakEvent event) {
    if (!event.world.isRemote) {
        if (event.block == RegisteredBlocks.blockNodeManipulator) {
            TileEntity te = event.world.getTileEntity(event.x, event.y, event.z);
            if (te != null && te instanceof TileNodeManipulator) {
                if (((TileNodeManipulator) te).isInMultiblock())
                    ((TileNodeManipulator) te).breakMultiblock();
            }
        }
        if (event.block == RegisteredBlocks.blockStoneMachine && event.blockMetadata == 5) {
            TileAIShutdown.removeTrackedEntities(event.world, event.x, event.y, event.z);
        }
        if (event.world.provider.dimensionId == ModConfig.dimOuterId) {
            if(event.block == ConfigBlocks.blockEldritchNothing) {
                if(event.getPlayer().capabilities.isCreativeMode && MiscUtils.isANotApprovedOrMisunderstoodPersonFromMoreDoor(event.getPlayer())) return;
                event.setCanceled(true);
                event.getPlayer().addChatMessage(new ChatComponentText(EnumChatFormatting.ITALIC + "" + EnumChatFormatting.GRAY + StatCollector.translateToLocal("gadomancy.eldritch.nobreakPortalNothing")));
            }
        }
    }
}
 
Example #3
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void on(BlockEvent.PlaceEvent e) {
    if (e.isCanceled()) {
        if (interacts != null)
            interacts.remove(e.player);
    } else {
        if (!e.world.isRemote && isStickyJar(e.itemInHand)) {
            TileEntity parent = e.world.getTileEntity(e.x, e.y, e.z);
            if (parent instanceof TileJarFillable) {
                int metadata = e.world.getBlockMetadata(e.x, e.y, e.z);
                e.world.setBlock(e.x, e.y, e.z, RegisteredBlocks.blockStickyJar, metadata, 2);

                TileEntity tile = e.world.getTileEntity(e.x, e.y, e.z);
                if (tile instanceof TileStickyJar) {
                    Integer sideHit = interacts.get(e.player);
                    ((TileStickyJar) tile).init((TileJarFillable) parent, e.placedBlock, metadata,
                            ForgeDirection.getOrientation(sideHit == null ? 1 : sideHit).getOpposite());
                    RegisteredBlocks.blockStickyJar.onBlockPlacedBy(e.world, e.x, e.y, e.z, e.player, e.itemInHand);
                }
            }
        }
    }
}
 
Example #4
Source File: HandlerHammer.java    From ExNihiloAdscensio with MIT License 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 #5
Source File: BlockUtils.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Tries breaking a block safely and fires an event for it.
 *
 * @return Whether the block was successfully broken
 */
public static boolean breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nullable IBlockState oldState, @Nonnull EntityPlayerMP player) {
	if (!world.isBlockLoaded(pos)) return false;

	if (!(player instanceof FakePlayer) && !hasEditPermission(pos, player)) return false;

	if (oldState == null) oldState = world.getBlockState(pos);

	BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, oldState, player);
	MinecraftForge.EVENT_BUS.post(event);

	if (event.isCanceled()) return false;

	TileEntity tile = world.getTileEntity(pos);
	Block block = oldState.getBlock();
	if (block.removedByPlayer(oldState, world, pos, player, true)) {
		block.onPlayerDestroy(world, pos, oldState);
		block.harvestBlock(world, player, pos, oldState, tile, player.getHeldItemMainhand());
		world.notifyBlockUpdate(pos, oldState, Blocks.AIR.getDefaultState(), 3);
	} else return false;

	return true;
}
 
Example #6
Source File: ArenaManager.java    From Wizardry with GNU Lesser General Public License v3.0 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 #7
Source File: ArenaManager.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
	public void blockBreak(BlockEvent.BreakEvent 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.getState());


//			if (!event.getWorld().isRemote)
//				for (ZachTimeManager timeManager : zachHourGlasses) {
//					if (timeManager.getEntityZachriel().getEntityId() == arena.getBossID()) {
//						timeManager.trackBlock(event.getState(), event.getPos());
//					}
//				}
		}
	}
 
Example #8
Source File: EventHandler.java    From customstuff4 with GNU General Public License v3.0 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 #9
Source File: EventHandler.java    From customstuff4 with GNU General Public License v3.0 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 #10
Source File: ToolMetaItemListener.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public static void onHarvestDrops(BlockEvent.HarvestDropsEvent event) {
    EntityPlayer harvester = event.getHarvester();
    List<ItemStack> drops = event.getDrops();
    if (harvester == null)
        return;
    ItemStack stackInHand = harvester.getHeldItem(EnumHand.MAIN_HAND);
    if (stackInHand.isEmpty() || !(stackInHand.getItem() instanceof ToolMetaItem<?>))
        return;

    ToolMetaItem<? extends MetaToolValueItem> toolMetaItem = (ToolMetaItem<?>) stackInHand.getItem();
    boolean isRecursiveCall = harvesting.get() == DUMMY_OBJECT;
    if (!isRecursiveCall) {
        harvesting.set(DUMMY_OBJECT);
        toolMetaItem.onBlockDropsHarvested(stackInHand, event.getWorld(), event.getPos(), event.getState(), harvester, drops);
        harvesting.set(null);
    }
}
 
Example #11
Source File: GTEventNeighborNotifyEvent.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onNeighborNotified(BlockEvent.NeighborNotifyEvent event) {
	World world = event.getWorld();
	for (EnumFacing side : event.getNotifiedSides()) {
		BlockPos sidePos = event.getPos().offset(side);
		IBlockState sideState = world.getBlockState(sidePos);
		Block block = sideState.getBlock();
		if (block.isLeaves(sideState, world, sidePos))
			world.scheduleUpdate(sidePos, block, 8 + world.rand.nextInt(16));
	}
}
 
Example #12
Source File: Ticker.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent
public void onPlayerBreaksBlock(BlockEvent.BreakEvent ev) {
    if (VisualsHandler.instance.isBlockMarked(ev.x, ev.y, ev.z, ev.world.provider.dimensionId, (EntityPlayerMP) ev.getPlayer())) {
        // Cancel event if it's a border that has been broken
        ev.setCanceled(true);
    }
}
 
Example #13
Source File: GrassDropHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void interceptGrassDrop(BlockEvent.HarvestDropsEvent event) {

    // Skip silk touch.
    if (event.isSilkTouching()) {
        return;
    }

    // Fetch the blockstate.
    final IBlockState state = event.getState();

    // Skip Air or Error
    if (state == null || state.getBlock() == null) {
        return;
    }

    // Fetch the world random.
    final Random rand = event.getWorld().rand;

    // Log
    // This line was oddly ignoring the debug settings...
    //AgriCore.getLogger("agricraft").debug("Intercepted! Block: {0}", state.getBlock());
    // Add grass drops if grass block.
    if (state.getBlock() instanceof BlockTallGrass) {
        // Wipe other drops, if needed.
        if (AgriCraftConfig.wipeGrassDrops) {
            event.getDrops().clear();
        }
        // Log
        // Commenented out to prevent spam.
        //AgriCore.getLogger("agricraft").debug("Inserting Drops!");
        // Add the drops.
        addGrassDrops(event.getDrops(), rand);
    }
}
 
Example #14
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@SubscribeEvent
public void harvestEvent(BlockEvent.HarvestDropsEvent event) {
	if (EtFuturum.enableSilkTouchingMushrooms && event.isSilkTouching)
		if (event.block == Blocks.brown_mushroom_block) {
			event.drops.clear();
			event.drops.add(new ItemStack(ModBlocks.brown_mushroom_block));
		} else if (event.block == Blocks.red_mushroom_block) {
			event.drops.clear();
			event.drops.add(new ItemStack(ModBlocks.red_mushroom_block));
		}

	if (EtFuturum.enableSticksFromDeadBushes)
		if (event.block == Blocks.deadbush) {
			boolean isShears = event.harvester != null && event.harvester.getCurrentEquippedItem() != null && event.harvester.getCurrentEquippedItem().getItem() instanceof ItemShears;
			if (event.harvester == null || event.harvester.getCurrentEquippedItem() == null || !isShears)
				for (int i = 0; i < event.world.rand.nextInt(3); i++)
					event.drops.add(new ItemStack(Items.stick));
		}

	if (EtFuturum.enableShearableCobwebs)
		if (event.block == Blocks.web && event.harvester != null) {
			ItemStack stack = event.harvester.getCurrentEquippedItem();
			if (stack != null && stack.getItem() instanceof ItemShears) {
				event.drops.clear();
				event.drops.add(new ItemStack(Blocks.web));
			}
		}
}
 
Example #15
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public void onAnyBlockPlacement(EntityPlayer player, BlockEvent.PlaceEvent ev) {
    if(ev.world.isRemote || ev.isCanceled()) {
        return;
    }

    if(player instanceof FakePlayer) {
        if(!ProtectionManager.getFlagValueAtLocation(FlagType.FAKERS, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
            ev.setCanceled(true);
        }
    } else {
        Resident res = MyTownUniverse.instance.getOrMakeResident(player);

        if (!MyTownUniverse.instance.blocks.contains(ev.world.provider.dimensionId, ev.x >> 4, ev.z >> 4)) {
            int range = Config.instance.placeProtectionRange.get();
            Volume placeBox = new Volume(ev.x-range, ev.y-range, ev.z-range, ev.x+range, ev.y+range, ev.z+range);

            if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, placeBox)) {
                ev.setCanceled(true);
                return;
            }
        } else {
            if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
                ev.setCanceled(true);
                return;
            }
        }

        if(ev.block instanceof ITileEntityProvider && ev.itemInHand != null) {
            TileEntity te = ((ITileEntityProvider) ev.block).createNewTileEntity(MinecraftServer.getServer().worldServerForDimension(ev.world.provider.dimensionId), ev.itemInHand.getItemDamage());
            if (te != null && ProtectionManager.isOwnable(te.getClass())) {
                ThreadPlacementCheck thread = new ThreadPlacementCheck(res, ev.x, ev.y, ev.z, ev.world.provider.dimensionId);
                activePlacementThreads++;
                thread.start();
            }
        }
    }
}
 
Example #16
Source File: ForgeMod.java    From BlueMap with MIT License 5 votes vote down vote up
private void onBlockChange(BlockEvent evt) {
	if (!(evt.getWorld() instanceof ServerWorld)) return;
	
	try {
		UUID world = getUUIDForWorld((ServerWorld) evt.getWorld());
		Vector3i position = new Vector3i(
				evt.getPos().getX(),
				evt.getPos().getY(),
				evt.getPos().getZ()
			);
		
		for (ServerEventListener listener : eventListeners) listener.onBlockChange(world, position);
		
	} catch (IOException ignore) {}
}
 
Example #17
Source File: NeatNether.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onCropGrow(BlockEvent.CropGrowEvent.Post event)
{
	if(event.getWorld().provider.getDimension() == -1 && event.getState().getBlock() == Blocks.NETHER_WART)
	{
		int age =  event.getState().getValue(BlockNetherWart.AGE);
		if(age < 3 && event.getWorld().rand.nextBoolean())
		{
			event.getWorld().setBlockState(event.getPos(), event.getState().withProperty(BlockNetherWart.AGE, age + 1));
		}

	}
}
 
Example #18
Source File: ModifierSmashing.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event)
{
    List<ItemStack> rewards = HammerRegistry.getRewardDrops(event.getWorld().rand, event.getState(), ToolHelper.getHarvestLevelStat(tool), event.getFortuneLevel());
    
    if (rewards != null && rewards.size() > 0)
    {
        event.getDrops().clear();
        event.setDropChance(1.0F);
        event.getDrops().addAll(rewards);
    }
}
 
Example #19
Source File: NearbyCraftCommandsImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onBlockDestroy(BlockEvent.BreakEvent event) {
    if (!event.isCanceled() && event.getState().getBlock() instanceof BlockWorkbench)
        for (int i = craftingTables.size() - 1; i >= 0; i--)
            if (craftingTables.get(i).equals(event.getPos()))
                craftingTables.remove(i);
}
 
Example #20
Source File: ChiselLeftClick.java    From Chisel with GNU General Public License v2.0 5 votes vote down vote up
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event)
{
    if(!Configurations.enableChiseling) return;
    EntityPlayer player = event.getPlayer();
    ItemStack stack = player.getHeldItem();
    if(stack == null || stack.getItem() != Chisel.chisel) return;

    event.setCanceled(true);
}
 
Example #21
Source File: NearbySmeltCommandsImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onBlockDestroy(BlockEvent.BreakEvent event) {
    if (!event.isCanceled() && event.getState().getBlock() instanceof BlockFurnace)
        for (int i = furnaces.size() - 1; i >= 0; i--)
            if (furnaces.get(i).equals(event.getPos()))
                furnaces.remove(i);
}
 
Example #22
Source File: FakePlayerItemInWorldManager.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attempts to harvest a block at the given coordinate
 */
@Override
public boolean tryHarvestBlock(int x, int y, int z){
    BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(theWorld, getGameType(), thisPlayerMP, x, y, z);
    if(event.isCanceled()) {
        return false;
    } else {
        ItemStack stack = thisPlayerMP.getCurrentEquippedItem();
        if(stack != null && stack.getItem().onBlockStartBreak(stack, x, y, z, thisPlayerMP)) {
            return false;
        }
        Block block = theWorld.getBlock(x, y, z);
        int l = theWorld.getBlockMetadata(x, y, z);
        theWorld.playAuxSFXAtEntity(thisPlayerMP, 2001, x, y, z, Block.getIdFromBlock(block) + (theWorld.getBlockMetadata(x, y, z) << 12));
        boolean flag = false;

        ItemStack itemstack = thisPlayerMP.getCurrentEquippedItem();

        if(itemstack != null) {
            itemstack.func_150999_a(theWorld, block, x, y, z, thisPlayerMP);

            if(itemstack.stackSize == 0) {
                thisPlayerMP.destroyCurrentEquippedItem();
            }
        }

        if(removeBlock(x, y, z)) {
            block.harvestBlock(theWorld, thisPlayerMP, x, y, z, l);
            flag = true;
        }

        // Drop experience
        if(!isCreative() && flag && event != null) {
            block.dropXpOnBlockBreak(theWorld, x, y, z, event.getExpToDrop());
        }
        drone.addAir(null, -PneumaticValues.DRONE_USAGE_DIG);
        return true;
    }
}
 
Example #23
Source File: RewardForDiscardingItemImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlaceBlock(BlockEvent.PlaceEvent event)
{
    if (event.getPlayer().getHeldItem(event.getHand()) != null && event.getPlayer() instanceof EntityPlayerMP )
    {
        // This event is received on the server side, so we need to pass it to the client.
        sendItemStackToClient((EntityPlayerMP)event.getPlayer(), MalmoMessageType.SERVER_DISCARDITEM, event.getPlayer().getHeldItem(event.getHand()));
    }
}
 
Example #24
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockBreakFirst(BlockEvent event) {
    BlockPos pos = event.getPos();
    Chunk chunk = event.getWorld()
        .getChunk(pos);
    IPhysicsChunk physicsChunk = (IPhysicsChunk) chunk;
    if (physicsChunk.getPhysicsObjectOptional()
        .isPresent()) {
        event.setResult(Result.ALLOW);
    }
}
 
Example #25
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onBlockDestroyed(BlockEvent.BreakEvent event) {
    EventData data = new EventData(event);
    if (data.getPlayer() == null || data.getPlayer().world.isRemote) return;
    if (!testCooldown(data.getPlayer())) return;
    if (generateComplaint(StringType.BREAK, data.getPlayer(), data.getBlock(), data)) {
        resetCooldown(data.getPlayer());
    }
}
 
Example #26
Source File: BlockUtils.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Places the specified block into the world at the specified position if it is possible to do so without violating permission restrictions.
 *
 * @return <tt>true</tt> if the specified block was successfully placed into the world
 */
public static boolean placeBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayerMP player) {
	if (!world.isBlockLoaded(pos)) return false;

	if (!hasEditPermission(pos, player)) return false;

	BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent(BlockSnapshot.getBlockSnapshot(world, pos), Blocks.AIR.getDefaultState(), player, player.getActiveHand());
	MinecraftForge.EVENT_BUS.post(event);

	if (event.isCanceled()) return false;

	world.setBlockState(pos, state);
	world.notifyBlockUpdate(pos, state, state, 3);
	return true;
}
 
Example #27
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onBlockPlace(BlockEvent.PlaceEvent event) {
    EventData data = new EventData(event);
    if (data.getPlayer() == null || data.getPlayer().world.isRemote) return;
    if (!testCooldown(data.getPlayer())) return;
    if (generateComplaint(StringType.PLACE, data.getPlayer(), data.getBlock(), data)) {
        resetCooldown(data.getPlayer());
    }
}
 
Example #28
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onFarmlandTrample(BlockEvent.FarmlandTrampleEvent event) {
    EventData data = new EventData(event);
    if (data.getPlayer() == null || data.getPlayer().world.isRemote) return;
    if (!testCooldown(data.getPlayer())) return;
    if (generateComplaint(StringType.TRAMPLE, data.getPlayer(), data.getBlock(), data)) {
        resetCooldown(data.getPlayer());
    }
}
 
Example #29
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public EventData(BlockEvent event) {
    this.event = event;
    this.pos = event.getPos();
    this.world = event.getWorld();
    this.state = event.getState();
    this.random = world.rand;
    this.block = this.state.getBlock();
    this.hand = null;
    this.player = null;
}
 
Example #30
Source File: BreakBlockAction.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public List<EntityItem> usePlayer(OpenModsFakePlayer fakePlayer) {
	if (!worldObj.isBlockModifiable(fakePlayer, blockPos)) return Lists.newArrayList();

	// this mirrors PlayerInteractionManager.tryHarvestBlock
	final IBlockState state = worldObj.getBlockState(blockPos);

	fakePlayer.inventory.currentItem = 0;
	selectTool(state, fakePlayer);

	final CaptureContext dropsCapturer = DropCapture.instance.start(blockPos);

	final List<EntityItem> drops;
	try {
		BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldObj, blockPos, state, fakePlayer);
		if (MinecraftForge.EVENT_BUS.post(event)) return Lists.newArrayList();

		final TileEntity te = worldObj.getTileEntity(blockPos); // OHHHHH YEEEEAAAH

		boolean canHarvest = state.getBlock().canHarvestBlock(worldObj, blockPos, fakePlayer);
		boolean isRemoved = removeBlock(fakePlayer, blockPos, state, canHarvest);
		if (isRemoved && canHarvest) {
			state.getBlock().harvestBlock(worldObj, fakePlayer, blockPos, state, te, stackToUse);
			worldObj.playEvent(fakePlayer, 2001, blockPos, Block.getStateId(state));
		}

	} finally {
		drops = dropsCapturer.stop();
	}

	return drops;
}