Fix chunkgenerate and chunkpopulate trigger on 1.10.2

This commit is contained in:
Mike Primm 2018-12-08 22:43:44 -06:00
parent ec8df4a23e
commit ced39e8b29

View File

@ -54,10 +54,15 @@ import net.minecraft.world.IWorldEventListener;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.ForgeChunkManager.Ticket; import net.minecraftforge.common.ForgeChunkManager.Ticket;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -93,6 +98,8 @@ import org.dynmap.forge_1_10_2.DynmapMod;
import org.dynmap.forge_1_10_2.permissions.FilePermissions; import org.dynmap.forge_1_10_2.permissions.FilePermissions;
import org.dynmap.forge_1_10_2.permissions.OpPermissions; import org.dynmap.forge_1_10_2.permissions.OpPermissions;
import org.dynmap.forge_1_10_2.permissions.PermissionProvider; import org.dynmap.forge_1_10_2.permissions.PermissionProvider;
import org.dynmap.forge_1_10_2.ForgeWorld;
import org.dynmap.forge_1_10_2.DynmapPlugin.WorldUpdateTracker;
import org.dynmap.permissions.PermissionsHandler; import org.dynmap.permissions.PermissionsHandler;
import org.dynmap.renderer.DynmapBlockState; import org.dynmap.renderer.DynmapBlockState;
import org.dynmap.utils.DynIntHashMap; import org.dynmap.utils.DynIntHashMap;
@ -950,9 +957,7 @@ public class DynmapPlugin
} }
/* Check for idle worlds */ /* Check for idle worlds */
if((cur_tick % 20) == 0) { if((cur_tick % 20) == 0) {
/*NOTYET - need rest of forge
doIdleOutOfWorlds(); doIdleOutOfWorlds();
*/
} }
} }
@ -1609,26 +1614,27 @@ public class DynmapPlugin
} }
} }
/**NOTYET - need rest of forge
public class WorldTracker { public class WorldTracker {
@SubscribeEvent @SubscribeEvent
public void handleWorldLoad(WorldEvent.Load event) { public void handleWorldLoad(WorldEvent.Load event) {
if(!core_enabled) return; if(!core_enabled) return;
if(!(event.world instanceof WorldServer)) return; World w = event.getWorld();
final ForgeWorld w = getWorld(event.world); if(!(w instanceof WorldServer)) return;
final ForgeWorld fw = getWorld(w);
// This event can be called from off server thread, so push processing there // This event can be called from off server thread, so push processing there
core.getServer().scheduleServerTask(new Runnable() { core.getServer().scheduleServerTask(new Runnable() {
public void run() { public void run() {
if(core.processWorldLoad(w)) // Have core process load first - fire event listeners if good load after if(core.processWorldLoad(fw)) // Have core process load first - fire event listeners if good load after
core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, w); core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, fw);
} }
}, 0); }, 0);
} }
@SubscribeEvent @SubscribeEvent
public void handleWorldUnload(WorldEvent.Unload event) { public void handleWorldUnload(WorldEvent.Unload event) {
if(!core_enabled) return; if(!core_enabled) return;
if(!(event.world instanceof WorldServer)) return; World w = event.getWorld();
final ForgeWorld fw = getWorld(event.world); if(!(w instanceof WorldServer)) return;
final ForgeWorld fw = getWorld(w);
if(fw != null) { if(fw != null) {
// This event can be called from off server thread, so push processing there // This event can be called from off server thread, so push processing there
core.getServer().scheduleServerTask(new Runnable() { core.getServer().scheduleServerTask(new Runnable() {
@ -1644,14 +1650,16 @@ public class DynmapPlugin
if(wut != null) wut.world = null; if(wut != null) wut.world = null;
} }
} }
@SubscribeEvent @SubscribeEvent
public void handleChunkLoad(ChunkEvent.Load event) { public void handleChunkLoad(ChunkEvent.Load event) {
if(!core_enabled) return; if(!core_enabled) return;
if(!onchunkgenerate) return; if(!onchunkgenerate) return;
if(!(event.world instanceof WorldServer)) return; World w = event.getWorld();
if(!(w instanceof WorldServer)) return;
Chunk c = event.getChunk(); Chunk c = event.getChunk();
if((c != null) && (c.lastSaveTime == 0)) { // If new chunk? if((c != null) && (!c.isTerrainPopulated())) { // If new chunk?
ForgeWorld fw = getWorld(event.world, false); ForgeWorld fw = getWorld(w, false);
if(fw == null) { if(fw == null) {
return; return;
} }
@ -1674,11 +1682,12 @@ public class DynmapPlugin
public void handleChunkPopulate(PopulateChunkEvent.Post event) { public void handleChunkPopulate(PopulateChunkEvent.Post event) {
if(!core_enabled) return; if(!core_enabled) return;
if(!onchunkpopulate) return; if(!onchunkpopulate) return;
if(!(event.world instanceof WorldServer)) return; World w = event.getWorld();
Chunk c = event.chunkProvider.loadChunk(event.chunkX, event.chunkZ); if(!(w instanceof WorldServer)) return;
Chunk c = w.getChunkFromChunkCoords(event.getChunkX(), event.getChunkZ());
int ymin = 0, ymax = 0; int ymin = 0, ymax = 0;
if(c != null) { if(c != null) {
ForgeWorld fw = getWorld(event.world, false); ForgeWorld fw = getWorld(event.getWorld(), false);
if (fw == null) return; if (fw == null) return;
ExtendedBlockStorage[] sections = c.getBlockStorageArray(); ExtendedBlockStorage[] sections = c.getBlockStorageArray();
@ -1693,24 +1702,7 @@ public class DynmapPlugin
mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+16, "chunkpopulate"); mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+16, "chunkpopulate");
} }
} }
@SubscribeEvent
public void handleCommandEvent(CommandEvent event) {
if(event.isCanceled()) return;
if(event.command.getCommandName().equals("say")) {
String s = "";
for(String p : event.parameters) {
s += p + " ";
}
s = s.trim();
ChatMessage cm = new ChatMessage();
cm.message = s;
cm.sender = null;
msgqueue.add(cm);
}
}
} }
*/
private boolean onblockchange = false; private boolean onblockchange = false;
private boolean onlightingchange = false; private boolean onlightingchange = false;
@ -1778,19 +1770,15 @@ public class DynmapPlugin
} }
} }
/*NOTYET - need rest of forge
private WorldTracker worldTracker = null; private WorldTracker worldTracker = null;
*/
private HashMap<String, WorldUpdateTracker> updateTrackers = new HashMap<String, WorldUpdateTracker>(); private HashMap<String, WorldUpdateTracker> updateTrackers = new HashMap<String, WorldUpdateTracker>();
private void registerEvents() private void registerEvents()
{ {
/*NOTYET - need rest of forge
if(worldTracker == null) { if(worldTracker == null) {
worldTracker = new WorldTracker(); worldTracker = new WorldTracker();
MinecraftForge.EVENT_BUS.register(worldTracker); MinecraftForge.EVENT_BUS.register(worldTracker);
} }
*/
// To trigger rendering. // To trigger rendering.
onblockchange = core.isTrigger("blockupdate"); onblockchange = core.isTrigger("blockupdate");
onlightingchange = core.isTrigger("lightingupdate"); onlightingchange = core.isTrigger("lightingupdate");