Skip to content

Commit

Permalink
Try and handle removal of mods a bit better. Currently no way to allo…
Browse files Browse the repository at this point in the history
…w a world which has missing

blocks to load - but i have the code in place to allow it i think.
  • Loading branch information
cpw committed Feb 8, 2014
1 parent 064b66a commit c890206
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 70 deletions.
23 changes: 6 additions & 17 deletions patches/minecraft/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@
}
else
{
@@ -466,6 +470,10 @@
{
try
{
+ if (FMLCommonHandler.instance().shouldServerBeKilledQuietly())
+ {
+ return;
+ }
this.func_71260_j();
this.field_71316_v = true;
}
@@ -475,6 +483,8 @@
@@ -475,6 +479,8 @@
}
finally
{
Expand All @@ -45,39 +34,39 @@
this.func_71240_o();
}
}
@@ -517,6 +527,7 @@
@@ -517,6 +523,7 @@
{
long i = System.nanoTime();
AxisAlignedBB.func_72332_a().func_72298_a();
+ FMLCommonHandler.instance().onPreServerTick();
++this.field_71315_w;

if (this.field_71295_T)
@@ -570,6 +581,7 @@
@@ -570,6 +577,7 @@

this.field_71304_b.func_76319_b();
this.field_71304_b.func_76319_b();
+ FMLCommonHandler.instance().onPostServerTick();
}

public void func_71190_q()
@@ -597,6 +609,7 @@
@@ -597,6 +605,7 @@
}

this.field_71304_b.func_76320_a("tick");
+ FMLCommonHandler.instance().onPreWorldTick(worldserver);
CrashReport crashreport;

try
@@ -621,6 +634,7 @@
@@ -621,6 +630,7 @@
throw new ReportedException(crashreport);
}

+ FMLCommonHandler.instance().onPostWorldTick(worldserver);
this.field_71304_b.func_76319_b();
this.field_71304_b.func_76320_a("tracker");
worldserver.func_73039_n().func_72788_a();
@@ -699,7 +713,7 @@
@@ -699,7 +709,7 @@

public String getServerModName()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
--- ../src-base/minecraft/net/minecraft/world/storage/SaveHandler.java
+++ ../src-work/minecraft/net/minecraft/world/storage/SaveHandler.java
@@ -6,6 +6,8 @@
@@ -6,6 +6,9 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.registry.GameRegistryException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -107,16 +109,24 @@
@@ -107,14 +110,22 @@
NBTTagCompound nbttagcompound;
NBTTagCompound nbttagcompound1;

Expand All @@ -26,16 +27,14 @@
+ FMLCommonHandler.instance().handleWorldDataLoad(this, worldInfo, nbttagcompound);
+ return worldInfo;
}
+ catch (GameRegistryException gre)
+ {
+ throw gre;
+ }
catch (Exception exception1)
{
+ if (FMLCommonHandler.instance().shouldServerBeKilledQuietly())
+ {
+ throw (RuntimeException)exception1;
+ }
exception1.printStackTrace();
}
}
@@ -129,10 +139,16 @@
@@ -129,8 +140,14 @@
{
nbttagcompound = CompressedStreamTools.func_74796_a(new FileInputStream(file1));
nbttagcompound1 = nbttagcompound.func_74775_l("Data");
Expand All @@ -44,16 +43,14 @@
+ FMLCommonHandler.instance().handleWorldDataLoad(this, worldInfo, nbttagcompound);
+ return worldInfo;
}
+ catch (GameRegistryException gre)
+ {
+ throw gre;
+ }
catch (Exception exception)
{
+ if (FMLCommonHandler.instance().shouldServerBeKilledQuietly())
+ {
+ throw (RuntimeException)exception;
+ }
exception.printStackTrace();
}
}
@@ -146,6 +162,8 @@
@@ -146,6 +163,8 @@
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
nbttagcompound2.func_74782_a("Data", nbttagcompound1);

Expand All @@ -62,7 +59,7 @@
try
{
File file1 = new File(this.field_75770_b, "level.dat_new");
@@ -184,6 +202,8 @@
@@ -184,6 +203,8 @@
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.func_74782_a("Data", nbttagcompound);

Expand Down
27 changes: 26 additions & 1 deletion src/main/java/cpw/mods/fml/client/FMLClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.WrongMinecraftVersionException;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent.Action;
import cpw.mods.fml.common.eventhandler.EventBus;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistryException;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.toposort.ModSortingException;
import cpw.mods.fml.relauncher.Side;
Expand Down Expand Up @@ -588,13 +591,21 @@ public void tryLoadExistingWorld(GuiSelectWorld selectWorldGUI, String dirName,
}
else
{

launchIntegratedServerCallback(dirName, saveName);
}
}

public void launchIntegratedServerCallback(String dirName, String saveName)
{
client.func_71371_a(dirName, saveName, (WorldSettings)null);
try
{
client.func_71371_a(dirName, saveName, (WorldSettings)null);
}
catch (GameRegistryException gre)
{
showGuiScreen(new GuiModItemsMissing(gre.getItems(), gre.getMessage()));
}
}

public void showInGameModOptions(GuiIngameMenu guiIngameMenu)
Expand Down Expand Up @@ -742,6 +753,7 @@ public void connectToServer(GuiScreen guiMultiplayer, ServerData serverEntry)
}

private CountDownLatch playClientBlock;

public void setPlayClient(NetHandlerPlayClient netHandlerPlayClient)
{
playClientBlock.countDown();
Expand Down Expand Up @@ -776,4 +788,17 @@ public void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<S
bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayServer>(manager, channelSet, channel, side, NetHandlerPlayServer.class));
}
}

public void setDefaultMissingAction(FMLMissingMappingsEvent.Action action)
{
this.defaultMissingAction = action;
}

private Action defaultMissingAction = FMLMissingMappingsEvent.Action.FAIL;

@Override
public Action getDefaultMissingAction()
{
return defaultMissingAction;
}
}
58 changes: 58 additions & 0 deletions src/main/java/cpw/mods/fml/client/GuiModItemsMissing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Forge Mod Loader
* Copyright (c) 2012-2013 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v2.1
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* Contributors:
* cpw - implementation
*/

package cpw.mods.fml.client;

import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;

public class GuiModItemsMissing extends GuiScreen
{
private List<String> missingItems;
private String message;

public GuiModItemsMissing(List<String> items, String message)
{
this.missingItems = items;
this.message = message;
}

@SuppressWarnings("unchecked")
@Override
public void func_73866_w_()
{
this.field_146292_n.add(new GuiButton(1, this.field_146294_l / 2 - 75, this.field_146295_m - 38, I18n.func_135052_a("gui.done")));
}

@Override
protected void func_146284_a(GuiButton p_73875_1_)
{
if (p_73875_1_.field_146124_l && p_73875_1_.field_146127_k == 1)
{
FMLClientHandler.instance().showGuiScreen(null);
}
}
@Override
public void func_73863_a(int p_73863_1_, int p_73863_2_, float p_73863_3_)
{
this.func_146276_q_();
int offset = 85;
this.func_73732_a(this.field_146289_q, "Forge Mod Loader could load this save", this.field_146294_l / 2, offset, 0xFFFFFF);
offset += 10;
this.func_73732_a(this.field_146289_q, String.format("There are %d unassigned blocks and items in this save", missingItems.size()), this.field_146294_l / 2, offset, 0xFFFFFF);
offset += 10;
this.func_73732_a(this.field_146289_q, "You will not be able to load until they are present again", this.field_146294_l / 2, offset, 0xFFFFFF);
super.func_73863_a(p_73863_1_, p_73863_2_, p_73863_3_);
}
}
6 changes: 6 additions & 0 deletions src/main/java/cpw/mods/fml/common/FMLCommonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.eventhandler.EventBus;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
Expand Down Expand Up @@ -503,4 +504,9 @@ public void fireNetRegistrationEvent(NetworkManager manager, Set<String> channel
{
sidedDelegate.fireNetRegistrationEvent(bus(), manager, channelSet, channel, side);
}

public FMLMissingMappingsEvent.Action getDefaultMissingAction()
{
return sidedDelegate.getDefaultMissingAction();
}
}
19 changes: 9 additions & 10 deletions src/main/java/cpw/mods/fml/common/FMLContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
import java.io.File;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.logging.log4j.Level;

import net.minecraft.item.Item;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo;

import org.apache.logging.log4j.Level;
import com.google.common.collect.Maps;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import cpw.mods.fml.client.FMLFileResourcePack;
import cpw.mods.fml.client.FMLFolderResourcePack;
import cpw.mods.fml.common.asm.FMLSanityChecker;
Expand All @@ -38,6 +36,7 @@
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistryException;
import cpw.mods.fml.relauncher.Side;

/**
Expand Down Expand Up @@ -173,10 +172,10 @@ public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> p
dataList.put(itemLabel, itemId);
}
}
boolean successfullyInjected = GameData.injectWorldIDMap(dataList, true);
if (!successfullyInjected)
List<String> failedElements = GameData.injectWorldIDMap(dataList, true, true);
if (!failedElements.isEmpty())
{
throw new RuntimeException("Failed to load the world - there are fatal block and item id issues");
throw new GameRegistryException("Failed to load the world - there are fatal block and item id issues", failedElements);
}
}
else if (tag.func_74764_b("ItemData"))
Expand All @@ -188,10 +187,10 @@ else if (tag.func_74764_b("ItemData"))
NBTTagCompound dataTag = list.func_150305_b(i);
dataList.put(dataTag.func_74779_i("K"), dataTag.func_74762_e("V"));
}
boolean successfullyInjected = GameData.injectWorldIDMap(dataList, true);
if (!successfullyInjected)
List<String> failedElements = GameData.injectWorldIDMap(dataList, true, true);
if (!failedElements.isEmpty())
{
throw new RuntimeException("Failed to load the world - there are fatal block and item id issues");
throw new GameRegistryException("Failed to load the world - there are fatal block and item id issues", failedElements);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/cpw/mods/fml/common/IFMLSidedHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetworkManager;
import net.minecraft.server.MinecraftServer;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.eventhandler.EventBus;
import cpw.mods.fml.relauncher.Side;

Expand Down Expand Up @@ -54,4 +55,6 @@ public interface IFMLSidedHandler
void waitForPlayClient();

void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side);

FMLMissingMappingsEvent.Action getDefaultMissingAction();
}
Loading

0 comments on commit c890206

Please sign in to comment.