Skip to content

Commit

Permalink
Merge pull request #9 from ThePixelbrain/master
Browse files Browse the repository at this point in the history
Workaround for unreliable world load / unload events, possibly fixes #4
  • Loading branch information
Su5eD authored Jun 29, 2023
2 parents 2811bf9 + b87a55e commit 5760730
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ repositories {
dependencies {
minecraft(group = "net.minecraftforge", name = "forge", version = "1.12.2-14.23.5.2855")

implementation(group = "net.industrial-craft", name = "industrialcraft-2", version = "${versionIC2}-ex112", classifier = "dev")
implementation(project(":IC2-Patched"))
implementation(fg.deobf(group = "mezz.jei", name = "jei_1.12.2", version = versionJEI))
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ org.gradle.jvmargs=-Xmx3G
mappingsChannel=snapshot
mappingsVersion=20171003-1.12

versionIC2=2.8.221
versionIC2=2.8.222
versionJEI=4.15.0.293
versionBuildCraft=7.99.24.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--- a/ic2/core/WorldData.java
+++ b/ic2/core/WorldData.java
@@ -3,6 +3,7 @@
import ic2.core.block.personal.TradingMarket;
import ic2.core.energy.grid.EnergyNetLocal;
import ic2.core.network.TeUpdateDataServer;
+import ic2.core.util.LogCategory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -28,6 +29,7 @@
boolean continuousUpdatesInUse = false;
final List<IWorldTickCallback> continuousUpdatesToAdd = new ArrayList<IWorldTickCallback>();
final List<IWorldTickCallback> continuousUpdatesToRemove = new ArrayList<IWorldTickCallback>();
+ private final World world;
public final EnergyNetLocal energyNet;
public final Map<TileEntity, TeUpdateDataServer> tesToUpdate = new IdentityHashMap<TileEntity, TeUpdateDataServer>();
public final TradingMarket tradeMarket;
@@ -46,7 +48,7 @@
this.tradeMarket = null;
this.windSim = null;
}
-
+ this.world = world;
}

public static WorldData get(World world) {
@@ -65,9 +67,16 @@
if (worlddata1 != null) {
worlddata = worlddata1;
}
+ IC2.log.debug(LogCategory.EnergyNet, "World with id %d loaded.", world.provider.getDimension());

return worlddata;
} else {
+ if (load && world != worlddata.world) {
+ worlddata = new WorldData(world);
+ concurrentmap.put(world.provider.getDimension(), worlddata);
+ IC2.log.warn(LogCategory.EnergyNet, "The dimension %d had the wrong world referenced and was replaced with the current one.", world.provider.getDimension());
+ IC2.log.warn(LogCategory.EnergyNet, "This is likely caused by missing or incorrect ordered world load / unload events.");
+ }
return worlddata;
}
}
@@ -75,6 +84,14 @@

public static void onWorldUnload(World world) {
getIndex(!world.isRemote).remove(Integer.valueOf(world.provider.getDimension()));
+ IC2.log.debug(LogCategory.EnergyNet, "World with id %d unloaded.", world.provider.getDimension());
+ }
+
+ public static void resetMaps() {
+ idxServer.clear();
+ if (idxClient != null) {
+ idxClient.clear();
+ }
}

private static ConcurrentMap<Integer, WorldData> getIndex(boolean simulating) {
11 changes: 7 additions & 4 deletions src/main/java/mods/su5ed/ic2patcher/Patcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import ic2.api.item.IC2Items;
import ic2.core.IC2;
import ic2.core.WorldData;
import ic2.core.util.StackUtil;
import mods.su5ed.ic2patcher.util.RecipeUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLConstructionEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.*;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistryModifiable;
Expand Down Expand Up @@ -40,6 +38,11 @@ public static void init(FMLInitializationEvent event) {}
@Mod.EventHandler
public static void postInit(FMLPostInitializationEvent event) {}

@Mod.EventHandler
public void onServerStopped(FMLServerStoppedEvent event) {
WorldData.resetMaps();
}

private static void fixUraniumCellRecipe() {
ItemStack cell = IC2Items.getItem("cell", "empty");
IRecipe recipe = RecipeUtil.getCraftingRecipe(cell, cell, cell, cell, IC2Items.getItem("ingot", "uranium"), cell, cell, cell, cell);
Expand Down

0 comments on commit 5760730

Please sign in to comment.