net.minecraftforge.event.world.WorldEvent Java Examples

The following examples show how to use net.minecraftforge.event.world.WorldEvent. 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: CyberwareDataHandler.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void worldLoad(WorldEvent.Load event)
{
	GameRules rules = event.getWorld().getGameRules();
	if(!rules.hasRule(KEEP_WARE_GAMERULE))
	{
		rules.addGameRule(KEEP_WARE_GAMERULE, Boolean.toString(CyberwareConfig.DEFAULT_KEEP), ValueType.BOOLEAN_VALUE);
	}
	if(!rules.hasRule(DROP_WARE_GAMERULE))
	{
		rules.addGameRule(DROP_WARE_GAMERULE, Boolean.toString(CyberwareConfig.DEFAULT_DROP), ValueType.BOOLEAN_VALUE);
	}
}
 
Example #2
Source File: WRCoreEventHandler.java    From WirelessRedstone with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
    if (event.world.isRemote)
        RedstoneEther.loadClientEther(event.world);
    else
        RedstoneEther.loadServerWorld(event.world);
}
 
Example #3
Source File: WorldExtensionManager.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onWorldSave(WorldEvent.Save event)
{
    if(worldMap.containsKey(event.world))
        for(WorldExtension extension : worldMap.get(event.world))
            extension.save();
}
 
Example #4
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event){
    if(!event.world.isRemote) {
        if(event.world.provider.dimensionId == 0) {
            GlobalVariableManager.overworld = event.world;
            event.world.loadItemData(GlobalVariableManager.class, GlobalVariableManager.DATA_KEY);
        }
    }
}
 
Example #5
Source File: FreecamMod.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
  if (originalPlayer == null || getLocalPlayer() == null) {
    return;
  }
  
  pos = getLocalPlayer().getPositionVector();
  angle = LocalPlayerUtils.getViewAngles();
}
 
Example #6
Source File: WorldEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<Biome.SpawnEntry> getPotentialSpawns(IWorld world, EntityCategory type, BlockPos pos, List<Biome.SpawnEntry> oldSpawns) {
	WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, pos, oldSpawns);

	if (MinecraftForge.EVENT_BUS.post(event)) {
		return Collections.emptyList();
	}

	return event.getList();
}
 
Example #7
Source File: TofuNetwork.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@SubscribeEvent
public static void onUnloadWorld(WorldEvent.Unload event) {
    World world = event.getWorld();
    for (String uid : toUUIDs(Instance.getTEWithinDim(world.provider.getDimension()))) {
        //It is a world unload, so isSystem is here to prevent bugs from misdetailed event.
        Instance.unload(uid, true);
    }
}
 
Example #8
Source File: CellDataStorage.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onLoad(WorldEvent.Load event) {
	if (event.getWorld().isRemote)
		return;
	if (event.getWorld().provider.getDimensionType() != StorageDimReg.storageDimensionType)
		return;

	MapStorage storage = event.getWorld().getPerWorldStorage();
	CellSavedWorldData instance = (CellSavedWorldData) storage.getOrLoadData(CellSavedWorldData.class, DATA_NAME);
}
 
Example #9
Source File: ForgeMod.java    From BlueMap with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldSave(WorldEvent.Save evt) {
	if (!(evt.getWorld() instanceof ServerWorld)) return;
	
	try {
		UUID world = getUUIDForWorld((ServerWorld) evt.getWorld());
		
		for (ServerEventListener listener : eventListeners) listener.onWorldSaveToDisk(world);
		
	} catch (IOException ignore) {}
}
 
Example #10
Source File: TofuEventLoader.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@SubscribeEvent
public void worldTick(WorldEvent.Load event) {
    String s = TofuVillageCollection.fileNameForProvider(event.getWorld().provider);

    TofuVillageCollection tofuVillageCollection = (TofuVillageCollection) event.getWorld().getPerWorldStorage().getOrLoadData(TofuVillageCollection.class, s);

    if (tofuVillageCollection == null) {
        tofuVillageCollection = new TofuVillageCollection(event.getWorld());
        event.getWorld().getPerWorldStorage().setData(s, tofuVillageCollection);
    } else {
        tofuVillageCollection.setWorldsForAll(event.getWorld());
    }
}
 
Example #11
Source File: YUNoMakeGoodMap.java    From YUNoMakeGoodMap with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event)
{
    //Load a 3x3 around spawn to make sure that it populates and calls our hooks.
    if (!event.getWorld().isRemote && event.getWorld() instanceof WorldServer)
    {
        WorldServer world = (WorldServer)event.getWorld();
        int spawnX = (int)(event.getWorld().getWorldInfo().getSpawnX() / world.provider.getMovementFactor() / 16);
        int spawnZ = (int)(event.getWorld().getWorldInfo().getSpawnZ() / world.provider.getMovementFactor() / 16);
        for (int x = -1; x <= 1; x++)
            for (int z = -1; z <= 1; z++)
                world.getChunkProvider().loadChunk(spawnX + x, spawnZ + z);
    }
}
 
Example #12
Source File: WorldLoadHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event)
{
	if(event.getWorld().provider.getDimension() == 0)
	{
		Timekeeper.initialize(event.getWorld());
	}
}
 
Example #13
Source File: CreateSpawnHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onCreateSpawn(WorldEvent.CreateSpawnPosition event)
{
	World world = event.getWorld();

	world.findingSpawnPoint = true;
	Random random = new Random(world.getSeed());
	BlockPos blockpos = findTerrainPositionForSpawn(random);
	int i = 0;
	int j = world.provider.getAverageGroundLevel();
	int k = 0;

	if (blockpos != null)
	{
		i = blockpos.getX();
		k = blockpos.getZ();
	}

	int l = 0;

	/*while (!world.provider.canCoordinateBeSpawn(i, k))
	{
		i += random.nextInt(64) - random.nextInt(64);
		k += random.nextInt(64) - random.nextInt(64);
		++l;

		if (l == 1000)
		{
			break;
		}
	}*/

	world.getWorldInfo().setSpawn(new BlockPos(i, j, k));
	world.findingSpawnPoint = false;
	event.setCanceled(true);
}
 
Example #14
Source File: MatrixNotifications.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
  once = false;
  position = 0;
  
  if (MC.getCurrentServerData() != null) {
    serverName = getServerName();
  }
}
 
Example #15
Source File: CyberwareConfig.java    From Cyberware with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event)
{
	if (event.getWorld().isRemote && !Minecraft.getMinecraft().getConnection().getNetworkManager().isChannelOpen())
	{
		loadConfig();
	}
}
 
Example #16
Source File: Markers.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldUnload(WorldEvent.Load event) {
  try {
    // shutdown vbos
    vboShutdown();
  } catch (Throwable e) {
    handleException(e);
  }
}
 
Example #17
Source File: EssentialsMissingHandlerClient.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleWorldUnload(WorldEvent.Unload event)
{
	if (missingArm)
	{
		GameSettings settings = Minecraft.getMinecraft().gameSettings;
		missingArm = false;
		settings.mainHand = oldHand;
	}
}
 
Example #18
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onWorldLoad(WorldEvent.Load event) {
    World world = event.getWorld();
    event.getWorld().addEventListener(new VSWorldEventListener(world));
    IHasShipManager shipManager = (IHasShipManager) world;
    if (!event.getWorld().isRemote) {
        ValkyrienSkiesMod.VS_CHUNK_MANAGER.initWorld(world);
        shipManager.setManager(WorldServerShipManager::new);
    } else {
        shipManager.setManager(WorldClientShipManager::new);
    }
}
 
Example #19
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onWorldUnload(WorldEvent.Unload event) {
    if (!event.getWorld().isRemote) {
        ValkyrienSkiesMod.VS_CHUNK_MANAGER.removeWorld(event.getWorld());
    } else {
        // Fixes memory leak; @DaPorkChop please don't leave static maps lying around D:
        lastPositions.clear();
    }
    ValkyrienSkiesMod.VS_PHYSICS_MANAGER.removeWorld(event.getWorld());
    IHasShipManager shipManager = (IHasShipManager) event.getWorld();
    shipManager.getManager().onWorldUnload();
}
 
Example #20
Source File: TankSynchroniser.java    From EnderStorage with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
    if (event.getWorld().isRemote()) {
        clientState = new PlayerItemTankCache();
    } else if (playerItemTankStates == null) {
        playerItemTankStates = new HashMap<>();
    }
}
 
Example #21
Source File: PlanetEventHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@SubscribeEvent
public void worldSaveEvent(WorldEvent.Save event) {
	//TODO: save only the one dimension
	if(event.getWorld().provider.getDimension() == 0)
		try {
			DimensionManager.getInstance().saveDimensions(DimensionManager.workingPath);
		} catch (Exception e) {
			AdvancedRocketry.logger.fatal("!!!!!!!!!!!!!! An error has occured saving planet data, please report to the mod dev with the entire fml-latest.log file!  This report may contain information relevent to solving a longstanding bug.");
			e.printStackTrace();
		}
}
 
Example #22
Source File: NetworkStorage.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onWorldLoad(WorldEvent.Load event){
    if(!event.getWorld().isRemote && event.getWorld().provider.getDimension() == 0) {
        overworld = event.getWorld();
        overworld.loadData(NetworkStorage.class, DATA_KEY);
    }
}
 
Example #23
Source File: PlanetEventHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@SubscribeEvent
public void worldLoadEvent(WorldEvent.Load event) {
	if(!event.getWorld().isRemote)
		AtmosphereHandler.registerWorld(event.getWorld().provider.getDimension());
	else if(Configuration.skyOverride && event.getWorld().provider.getDimension() == 0)
		event.getWorld().provider.setSkyRenderer(new RenderPlanetarySky());
}
 
Example #24
Source File: LookingGlassForgeEventHandler.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
	if (!event.world.isRemote) return;
	// When we unload a world client side, we want to make sure that any view entities clean up. Not strictly necessary, but a good practice.
	// I don't trust vanilla to unload entity references quickly/correctly/completely.
	for (Object entity : event.world.loadedEntityList) {
		if (entity instanceof EntityPortal) ((EntityPortal) entity).releaseActiveView();
	}
}
 
Example #25
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unloadWorld(World world, boolean save) {
    if (world == null) {
        return false;
    }

    net.minecraft.world.WorldServer handle = ((CraftWorld) world).getHandle();

    if (!(console.worlds.contains(handle))) {
        return false;
    }

    if (handle.playerEntities.size() > 0) {
        return false;
    }

    WorldUnloadEvent e = new WorldUnloadEvent(handle.getWorld());
    pluginManager.callEvent(e);

    if (e.isCancelled()) {
        return false;
    }

    if (save) {
        try {
            handle.saveAllChunks(true, null);
            handle.flush();
            WorldSaveEvent event = new WorldSaveEvent(handle.getWorld());
            getPluginManager().callEvent(event);
        } catch (net.minecraft.world.MinecraftException ex) {
            getLogger().log(Level.SEVERE, null, ex);
            FMLLog.log(org.apache.logging.log4j.Level.ERROR, ex, "Failed to save world " + handle.getWorld().getName() + " while unloading it.");
        }
    }
    MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(handle)); // Cauldron - fire unload event before removing world
    worlds.remove(world.getName().toLowerCase());
    DimensionManager.setWorld(handle.provider.dimensionId, null); // Cauldron - remove world from DimensionManager
    return true;
}
 
Example #26
Source File: MCRetentionManager.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void worldSave(WorldEvent evt) {
	//Current time milli-seconds is used to prevent the files from saving 20 times when the world loads
	if (System.nanoTime() - lastSaveTime > 2_000_000_000) {
		lastSaveTime = System.nanoTime();
		saveAll();
	}
}
 
Example #27
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(WorldEvent.Unload e) {
    if (!e.world.isRemote && e.world.provider.dimensionId == 0) {
        Gadomancy.unloadModData();

        TCMazeHandler.closeAllSessionsAndCleanup();
    }
}
 
Example #28
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(WorldEvent.Load e) {
    if (!e.world.isRemote && e.world.provider.dimensionId == 0) {
        Gadomancy.loadModData();

        GolemEnumHelper.validateSavedMapping();
        GolemEnumHelper.reorderEnum();

        TCMazeHandler.init();
    }

    GameRules rules = e.world.getGameRules();
    rules.theGameRules.put("mobGriefing", new ValueOverride(this, String.valueOf(rules.getGameRuleBooleanValue("mobGriefing"))));
}
 
Example #29
Source File: MCRetentionManager.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void worldSave(WorldEvent evt) {
	//Current time milli-seconds is used to prevent the files from saving 20 times when the world loads
	if (System.nanoTime() - lastSaveTime > 2_000_000_000) {
		lastSaveTime = System.nanoTime();
		saveAll();
	}
}
 
Example #30
Source File: MCRetentionManager.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void worldSave(WorldEvent evt) {
	//Current time milli-seconds is used to prevent the files from saving 20 times when the world loads
	if (System.nanoTime() - lastSaveTime > 2_000_000_000) {
		lastSaveTime = System.nanoTime();
		saveAll();
	}
}