Skip to content

Commit

Permalink
Fix using the wrong IMC type (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven authored Jul 5, 2022
1 parent 8c222b0 commit cdb301e
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/main/java/mods/natura/Natura.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import mantle.lib.TabTools;
Expand Down Expand Up @@ -121,6 +123,7 @@ public void init(FMLInitializationEvent evt) {
DimensionManager.registerProviderType(-1, NetheriteWorldProvider.class, true);
}
MinecraftForge.EVENT_BUS.register(WorldHandler.instance);
FMLCommonHandler.instance().bus().register(this);

if (retrogen) {
FMLCommonHandler.instance().bus().register(new TickHandlerWorld());
Expand All @@ -138,10 +141,11 @@ public void postInit(FMLPostInitializationEvent evt) {
content.modIntegration();

pulsar.postInit(evt);
imcHandler();
}

/**
* IMC Handler
* Runtime IMC Handler
*
* Message tag: set-worldgen-overrides
* Message NBT data:
Expand All @@ -150,26 +154,35 @@ public void postInit(FMLPostInitializationEvent evt) {
* Both arrays must be of the same length
* Settings format: integer with bitfields, enable bits: 1 = crops (berry bushes), 2 = clouds, 4 = trees
*/
@EventHandler
public void imcHandler(FMLInterModComms.IMCEvent event) {
for (final FMLInterModComms.IMCMessage message : event.getMessages()) {
try {
if (message.key.equalsIgnoreCase("set-worldgen-overrides") && message.isNBTMessage()) {
NBTTagCompound tag = message.getNBTValue();
int[] dimensions = tag.getIntArray("dimensions");
int[] settings = tag.getIntArray("settings");
if (dimensions == null || settings == null || dimensions.length != settings.length) {
FMLLog.warning("Invalid Natura IMC format, mismatched array lengths");
continue;
}
synchronized (dimensionWorldgenOverrides) {
for (int i = 0; i < dimensions.length; i++) {
dimensionWorldgenOverrides.put(dimensions[i], settings[i]);
@SubscribeEvent
public void tickEvent(TickEvent.ServerTickEvent event) {
if (event.side.isServer() && event.phase.equals(TickEvent.Phase.START)) {
imcHandler();
}
}

private void imcHandler() {
List<FMLInterModComms.IMCMessage> imc = FMLInterModComms.fetchRuntimeMessages(this);
if (imc != null && !imc.isEmpty()) {
for (FMLInterModComms.IMCMessage message : imc) {
try {
if (message.key.equalsIgnoreCase("set-worldgen-overrides") && message.isNBTMessage()) {
NBTTagCompound tag = message.getNBTValue();
int[] dimensions = tag.getIntArray("dimensions");
int[] settings = tag.getIntArray("settings");
if (dimensions == null || settings == null || dimensions.length != settings.length) {
FMLLog.warning("Invalid Natura IMC format, mismatched array lengths");
return;
}
synchronized (dimensionWorldgenOverrides) {
for (int i = 0; i < dimensions.length; i++) {
dimensionWorldgenOverrides.put(dimensions[i], settings[i]);
}
}
}
} catch (Exception e) {
FMLLog.warning("Exception while handling a Natura IMC message `{}`", message.key, e);
}
} catch (Exception e) {
FMLLog.warning("Exception while handling a Natura IMC message `{}`", message.key, e);
}
}
}
Expand Down

0 comments on commit cdb301e

Please sign in to comment.