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

The following examples show how to use net.minecraftforge.event.world.BlockEvent#PlaceEvent . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: NearbySmeltCommandsImplementation.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onBlockPlace(BlockEvent.PlaceEvent event) {
    if (!event.isCanceled() && event.getPlacedBlock().getBlock() instanceof BlockFurnace)
        furnaces.add(event.getPos());
}
 
Example 8
Source File: NearbyCraftCommandsImplementation.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onBlockPlace(BlockEvent.PlaceEvent event) {
    if (!event.isCanceled() && event.getPlacedBlock().getBlock() instanceof BlockWorkbench)
        craftingTables.add(event.getPos());
}
 
Example 9
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 4 votes vote down vote up
@SubscribeEvent
public void onBlockPlacement(BlockEvent.PlaceEvent ev) {
    onAnyBlockPlacement(ev.player, ev);
}