Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/main/java/CoroUtil/difficulty/DynamicDifficulty.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,21 @@ public class DynamicDifficulty {

public static HashMap<Integer, AttackData> lookupEntToDamageLog = new HashMap<Integer, AttackData>();

public static void tickServer(ServerTickEvent event) {
World world = DimensionManager.getWorld(0);
if (world != null) {
for (Object player : world.playerEntities) {
if (player instanceof EntityPlayer) {
tickPlayer((EntityPlayer)player);
}
public static void tickServer(ServerTickEvent event, World overworld) {
if (overworld != null) {
for (EntityPlayer player : overworld.playerEntities) {
tickPlayer(player);
}


if (ConfigCoroUtil.cleanupStrayMobs) {
long dayNumber = (world.getWorldTime() / CoroUtilWorldTime.getDayLength()) + 1;
long dayNumber = (overworld.getWorldTime() / CoroUtilWorldTime.getDayLength()) + 1;
if (dayNumber % ConfigCoroUtil.cleanupStrayMobsDayRate == 0) {
long timeOfDay = world.getWorldTime() % CoroUtilWorldTime.getDayLength();
long timeOfDay = overworld.getWorldTime() % CoroUtilWorldTime.getDayLength();
int killTimeRange = 10;
if (timeOfDay >= (long) ConfigCoroUtil.cleanupStrayMobsTimeOfDay && timeOfDay < (long)(2000+killTimeRange)) {
CULog.dbg("KILLING ALL ZOMBIES!");
for (Object obj : world.loadedEntityList) {
for (Object obj : overworld.loadedEntityList) {
if (obj instanceof EntityZombie) {
((EntityZombie) obj).setDead();
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/CoroUtil/forge/AsyncSaveTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package CoroUtil.forge;

import java.io.FileOutputStream;
import java.io.IOException;

import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;

public class AsyncSaveTask extends Thread {
private final NBTTagCompound data;
private final FileOutputStream fos;

public AsyncSaveTask(NBTTagCompound data, FileOutputStream fos)
{
this.data = data;
this.fos = fos;
}

@Override
public void run()
{
try {
CompressedStreamTools.writeCompressed(data, fos);
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
19 changes: 10 additions & 9 deletions src/main/java/CoroUtil/forge/EventHandlerFML.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ public void tickServer(ServerTickEvent event) {
if (event.phase == Phase.START) {
//System.out.println("tick coroutil");
//if (formationManager == null) formationManager = new Manager();
World worlds[] = DimensionManager.getWorlds();
if(worlds.length == 0)
return;

//might not account for dynamic dimension addition during runtime
if (lastWorld != DimensionManager.getWorld(0)) {
lastWorld = DimensionManager.getWorld(0);
if (lastWorld != worlds[0]) {
lastWorld = worlds[0];

World worlds[] = DimensionManager.getWorlds();
for (int i = 0; i < worlds.length; i++) {
worlds[i].addEventListener(new CoroAIWorldAccess());
for (World world: worlds) {
world.addEventListener(new CoroAIWorldAccess());
}
}

//if (formationManager != null) formationManager.tickUpdate();

//Quest system
World worlds[] = DimensionManager.getWorlds();
for (int i = 0; i < worlds.length; i++) {
PlayerQuestManager.i().tick(worlds[i]);
for (World world: worlds) {
PlayerQuestManager.i().tick(world);
}

WorldDirectorManager.instance().onTick();
Expand Down Expand Up @@ -93,7 +94,7 @@ public void tickServer(ServerTickEvent event) {

}

DynamicDifficulty.tickServer(event);
DynamicDifficulty.tickServer(event, worlds[0]);
}

}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/CoroUtil/pets/PetsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.UUID;

import CoroUtil.forge.AsyncSaveTask;
import CoroUtil.forge.CULog;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLiving;
Expand Down Expand Up @@ -110,9 +111,7 @@ public void nbtWriteToDisk() {

FileOutputStream fos = new FileOutputStream(URL + "tamedPets" + ".dat");

CompressedStreamTools.writeCompressed(nbt, fos);

fos.close();
new AsyncSaveTask(nbt, fos).start();

} catch (Exception ex) {
ex.printStackTrace();
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/CoroUtil/quest/PlayerQuestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ public class PlayerQuestManager {
//public static PlayerQuestManager i;
public HashMap<String, PlayerQuests> playerQuests;

private static PlayerQuestManager serverManager;
private static PlayerQuestManager clientManager;
private static PlayerQuestManager manager;

public static PlayerQuestManager i() {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
if (serverManager == null) {
serverManager = new PlayerQuestManager();
}
return serverManager;
} else {
if (clientManager == null) {
clientManager = new PlayerQuestManager();
}
return clientManager;
if (manager == null) {
manager = new PlayerQuestManager();
}
return manager;
}

public PlayerQuestManager() {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/CoroUtil/quest/PlayerQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import CoroUtil.forge.AsyncSaveTask;
import CoroUtil.forge.CoroUtil;
import CoroUtil.packet.PacketHelper;
import CoroUtil.quest.quests.ActiveQuest;
Expand Down Expand Up @@ -301,9 +302,7 @@ public void diskSaveToFile() {

FileOutputStream fos = new FileOutputStream(URL + playerName + ".dat");

CompressedStreamTools.writeCompressed(nbt, fos);

fos.close();
new AsyncSaveTask(nbt, fos).start();

} catch (Exception ex) {
ex.printStackTrace();
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/CoroUtil/world/WorldDirector.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraftforge.common.DimensionManager;
import CoroUtil.config.ConfigCoroUtil;
import CoroUtil.event.WorldEvent;
import CoroUtil.forge.AsyncSaveTask;
import CoroUtil.pathfinding.PathPointEx;
import CoroUtil.util.BlockCoord;
import CoroUtil.util.CoroUtilFile;
Expand Down Expand Up @@ -195,12 +196,12 @@ public ISimulationTickable getTickingSimulationByLocation(BlockCoord parCoords)
return lookupTickingManagedLocations.get(hash);
}

public void tick() {
for (int i = 0; i < worldEvents.size(); i++) {
WorldEvent event = worldEvents.get(i);
public void tick(World world) {
for (Iterator<WorldEvent> iter = worldEvents.iterator(); iter.hasNext(); ) {
WorldEvent event = iter.next();
if (event.isComplete()) {
event.cleanup();
worldEvents.remove(i--);
iter.remove();
}
}

Expand All @@ -221,8 +222,6 @@ public void tick() {
entry.tickUpdate();
}

World world = getWorld();

//update occupance chunk data for each player
if (ConfigCoroUtil.trackPlayerData) {
if (world.getTotalWorldTime() % PlayerDataGrid.playerTimeSpentUpdateInterval == 0) {
Expand Down Expand Up @@ -326,8 +325,7 @@ public void writeToFile(boolean unloadInstances) {
//Write out to file
if (!(new File(saveFolder).exists())) (new File(saveFolder)).mkdirs();
FileOutputStream fos = new FileOutputStream(saveFolder + "WorldData_" + modID + "_" + dimID + "_" + type + ".dat");
CompressedStreamTools.writeCompressed(nbt, fos);
fos.close();
new AsyncSaveTask(nbt, fos).start();

} catch (Exception ex) {
ex.printStackTrace();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/CoroUtil/world/WorldDirectorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ public void onTick() {
while (it.hasNext()) {
WorldDirector wd = it.next();
//check if world is loaded
if (DimensionManager.getWorld(wd.dimID) != null) {
wd.tick();
World world = DimensionManager.getWorld(wd.dimID);
if (world != null) {
wd.tick(world);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/CoroUtil/world/grid/block/BlockDataGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Iterator;

import CoroUtil.forge.AsyncSaveTask;
import CoroUtil.forge.CULog;
import net.minecraft.block.Block;
import net.minecraft.nbt.CompressedStreamTools;
Expand Down Expand Up @@ -162,8 +163,8 @@ public void writeToFile(boolean unloadInstances) {

NBTTagCompound data = new NBTTagCompound();

Collection playerDataCl = grid.values();
Iterator it = playerDataCl.iterator();
Collection<BlockDataPoint> playerDataCl = grid.values();
Iterator<BlockDataPoint> it = playerDataCl.iterator();

while (it.hasNext()) {
BlockDataPoint bdp = (BlockDataPoint)it.next();
Expand All @@ -175,8 +176,7 @@ public void writeToFile(boolean unloadInstances) {
//Write out to file
if (!(new File(saveFolder).exists())) (new File(saveFolder)).mkdirs();
FileOutputStream fos = new FileOutputStream(saveFolder + "BlockDataDim_" + world.provider.getDimension() + ".dat");
CompressedStreamTools.writeCompressed(data, fos);
fos.close();
new AsyncSaveTask(data, fos).start();

} catch (Exception ex) {
ex.printStackTrace();
Expand Down