2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
|
import net.minecraft.client.gui.GuiErrorScreen;
|
|
|
|
|
import net.minecraft.client.gui.GuiMainMenu;
|
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
|
|
|
import net.minecraft.client.gui.GuiSelectWorld;
|
|
|
|
|
import net.minecraft.client.multiplayer.WorldClient;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2024-02-04 14:09:24 +02:00
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
2023-09-25 00:35:24 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
import org.apache.commons.csv.CSVFormat;
|
|
|
|
|
import org.apache.commons.csv.CSVParser;
|
|
|
|
|
import org.apache.commons.csv.CSVRecord;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
|
|
import codechicken.core.ClientUtils;
|
|
|
|
|
import codechicken.core.GuiModListScroll;
|
|
|
|
|
import codechicken.lib.packet.PacketCustom;
|
|
|
|
|
import codechicken.nei.api.API;
|
|
|
|
|
import codechicken.nei.api.ItemInfo;
|
2024-08-17 23:24:27 +03:00
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
2023-09-25 00:35:24 +02:00
|
|
|
import codechicken.nei.recipe.GuiRecipeTab;
|
|
|
|
|
import codechicken.nei.recipe.StackInfo;
|
|
|
|
|
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
2024-02-04 14:09:24 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class ClientHandler {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2021-10-16 11:31:43 -06:00
|
|
|
private static String[] defaultHandlerOrdering = {
|
2022-06-24 12:32:13 +01:00
|
|
|
"# Each line in this file should either be a comment (starts with '#') or an ordering.",
|
|
|
|
|
"# Ordering lines are <handler ID>,<ordering number>.",
|
|
|
|
|
"# Handlers will be sorted in order of number ascending, so smaller numbers first.",
|
|
|
|
|
"# Any handlers that are missing from this file will be assigned to 0.", "# Negative numbers are fine.",
|
|
|
|
|
"# If you delete this file, it will be regenerated with all registered handler IDs.", };
|
2014-04-29 10:54:20 +10:00
|
|
|
private static ClientHandler instance;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
private ArrayList<EntityItem> SMPmagneticItems = new ArrayList<>();
|
2014-04-29 10:54:20 +10:00
|
|
|
private World lastworld;
|
|
|
|
|
private GuiScreen lastGui;
|
|
|
|
|
|
|
|
|
|
public void addSMPMagneticItem(int i, World world) {
|
|
|
|
|
WorldClient cworld = (WorldClient) world;
|
|
|
|
|
Entity e = cworld.getEntityByID(i);
|
2019-12-30 20:19:16 -08:00
|
|
|
if (!(e instanceof EntityItem)) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SMPmagneticItems.add((EntityItem) e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateMagnetMode(World world, EntityPlayerSP player) {
|
|
|
|
|
if (!NEIClientConfig.getMagnetMode()) return;
|
|
|
|
|
|
|
|
|
|
float distancexz = 16;
|
|
|
|
|
float distancey = 8;
|
|
|
|
|
double maxspeedxz = 0.5;
|
|
|
|
|
double maxspeedy = 0.5;
|
|
|
|
|
double speedxz = 0.05;
|
|
|
|
|
double speedy = 0.07;
|
|
|
|
|
|
|
|
|
|
List<EntityItem> items;
|
|
|
|
|
if (world.isRemote) {
|
|
|
|
|
items = SMPmagneticItems;
|
|
|
|
|
} else {
|
2022-06-24 12:32:13 +01:00
|
|
|
items = world.getEntitiesWithinAABB(
|
|
|
|
|
EntityItem.class,
|
|
|
|
|
player.boundingBox.expand(distancexz, distancey, distancexz));
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
for (Iterator<EntityItem> iterator = items.iterator(); iterator.hasNext();) {
|
|
|
|
|
EntityItem item = iterator.next();
|
|
|
|
|
|
|
|
|
|
if (item.delayBeforeCanPickup > 0) continue;
|
|
|
|
|
if (item.isDead && world.isRemote) iterator.remove();
|
|
|
|
|
|
|
|
|
|
if (!NEIClientUtils.canItemFitInInventory(player, item.getEntityItem())) continue;
|
|
|
|
|
|
|
|
|
|
double dx = player.posX - item.posX;
|
|
|
|
|
double dy = player.posY + player.getEyeHeight() - item.posY;
|
|
|
|
|
double dz = player.posZ - item.posZ;
|
|
|
|
|
double absxz = Math.sqrt(dx * dx + dz * dz);
|
|
|
|
|
double absy = Math.abs(dy);
|
|
|
|
|
if (absxz > distancexz) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (absxz > 1) {
|
|
|
|
|
dx /= absxz;
|
|
|
|
|
dz /= absxz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (absy > 1) {
|
|
|
|
|
dy /= absy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double vx = item.motionX + speedxz * dx;
|
|
|
|
|
double vy = item.motionY + speedy * dy;
|
|
|
|
|
double vz = item.motionZ + speedxz * dz;
|
|
|
|
|
|
|
|
|
|
double absvxz = Math.sqrt(vx * vx + vz * vz);
|
|
|
|
|
double absvy = Math.abs(vy);
|
|
|
|
|
|
|
|
|
|
double rationspeedxz = absvxz / maxspeedxz;
|
|
|
|
|
if (rationspeedxz > 1) {
|
|
|
|
|
vx /= rationspeedxz;
|
|
|
|
|
vz /= rationspeedxz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double rationspeedy = absvy / maxspeedy;
|
|
|
|
|
if (rationspeedy > 1) {
|
|
|
|
|
vy /= rationspeedy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (absvxz < 0.2 && absxz < 0.2 && world.isRemote) {
|
|
|
|
|
item.setDead();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.setVelocity(vx, vy, vz);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public static void preInit() {
|
2021-04-13 20:16:56 -07:00
|
|
|
loadSerialHandlers();
|
2021-10-16 11:31:43 -06:00
|
|
|
loadHeightHackHandlers();
|
2024-02-04 14:09:24 +02:00
|
|
|
loadHiddenHandlers();
|
2024-06-11 12:18:49 -06:00
|
|
|
loadEnableAutoFocus();
|
2014-06-29 20:31:37 +10:00
|
|
|
ItemInfo.preInit();
|
2022-02-06 17:42:11 +02:00
|
|
|
StackInfo.loadGuidFilters();
|
2014-06-29 20:31:37 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-04-13 20:16:56 -07:00
|
|
|
public static void loadSerialHandlers() {
|
|
|
|
|
File file = NEIClientConfig.serialHandlersFile;
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!file.exists()) {
|
|
|
|
|
try (FileWriter writer = new FileWriter(file)) {
|
2021-04-13 20:16:56 -07:00
|
|
|
NEIClientConfig.logger.info("Creating default serial handlers list {}", file);
|
2023-07-08 23:23:19 +02:00
|
|
|
URL defaultSerialHandlersResource = ClientHandler.class
|
|
|
|
|
.getResource("/assets/nei/cfg/serialhandlers.cfg");
|
|
|
|
|
if (defaultSerialHandlersResource != null) {
|
|
|
|
|
IOUtils.copy(defaultSerialHandlersResource.openStream(), writer);
|
|
|
|
|
}
|
2021-04-13 20:16:56 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to save default serial handlers list to file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try (FileReader reader = new FileReader(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Loading serial handlers from file {}", file);
|
2023-07-08 23:23:19 +02:00
|
|
|
NEIClientConfig.serialHandlers = IOUtils.readLines(reader).stream().filter((line) -> !line.startsWith("#"))
|
|
|
|
|
.collect(Collectors.toCollection(HashSet::new));
|
2021-04-13 20:16:56 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to load serial handlers from file {}", file, e);
|
|
|
|
|
}
|
2021-10-16 11:31:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void loadHeightHackHandlers() {
|
|
|
|
|
File file = NEIClientConfig.heightHackHandlersFile;
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
try (FileWriter writer = new FileWriter(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Creating default height hack handlers list {}", file);
|
2023-07-08 23:23:19 +02:00
|
|
|
URL defaultHeightHackHandlersResource = ClientHandler.class
|
|
|
|
|
.getResource("/assets/nei/cfg/heighthackhandlers.cfg");
|
|
|
|
|
if (defaultHeightHackHandlersResource != null) {
|
|
|
|
|
IOUtils.copy(defaultHeightHackHandlersResource.openStream(), writer);
|
|
|
|
|
}
|
2021-10-16 11:31:43 -06:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to save default height hack handlers list to file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (FileReader reader = new FileReader(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Loading height hack handlers from file {}", file);
|
2023-07-08 23:23:19 +02:00
|
|
|
NEIClientConfig.heightHackHandlerRegex = IOUtils.readLines(reader).stream()
|
|
|
|
|
.filter((line) -> !line.startsWith("#")).map(Pattern::compile)
|
2022-06-24 12:32:13 +01:00
|
|
|
.collect(Collectors.toCollection(HashSet::new));
|
2021-10-16 11:31:43 -06:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to load height hack handlers from file {}", file, e);
|
|
|
|
|
}
|
2021-04-13 20:16:56 -07:00
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
public static void loadHiddenHandlers() {
|
|
|
|
|
File file = NEIClientConfig.hiddenHandlersFile;
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
try (FileWriter writer = new FileWriter(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Creating default hidden handlers list {}", file);
|
|
|
|
|
URL defaultHeightHackHandlersResource = ClientHandler.class
|
|
|
|
|
.getResource("/assets/nei/cfg/hiddenhandlers.cfg");
|
|
|
|
|
if (defaultHeightHackHandlersResource != null) {
|
|
|
|
|
IOUtils.copy(defaultHeightHackHandlersResource.openStream(), writer);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to save default hidden handlers list to file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (FileReader reader = new FileReader(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Loading hidden handlers from file {}", file);
|
|
|
|
|
NEIClientConfig.hiddenHandlers = IOUtils.readLines(reader).stream().filter((line) -> !line.startsWith("#"))
|
|
|
|
|
.collect(Collectors.toCollection(HashSet::new));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to load hidden handlers from file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 14:19:25 -06:00
|
|
|
public static void loadEnableAutoFocus() {
|
|
|
|
|
File file = NEIClientConfig.enableAutoFocusFile;
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
try (FileWriter writer = new FileWriter(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Creating default enable auto focus list {}", file);
|
|
|
|
|
URL defaultEnableAutoFocusResource = ClientHandler.class
|
|
|
|
|
.getResource("/assets/nei/cfg/enableautofocus.cfg");
|
|
|
|
|
if (defaultEnableAutoFocusResource != null) {
|
|
|
|
|
IOUtils.copy(defaultEnableAutoFocusResource.openStream(), writer);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to save default enable auto focus list to file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (FileReader reader = new FileReader(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Loading enable auto focus from file {}", file);
|
2024-08-17 23:24:27 +03:00
|
|
|
AutoFocusWidget.enableAutoFocusPrefixes = IOUtils.readLines(reader).stream()
|
2024-06-10 14:19:25 -06:00
|
|
|
.filter((line) -> !line.startsWith("#")).collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to load enable auto focus from file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public static void load() {
|
2014-04-29 10:54:20 +10:00
|
|
|
instance = new ClientHandler();
|
|
|
|
|
|
2014-08-05 00:09:34 +10:00
|
|
|
GuiModListScroll.register("NotEnoughItems");
|
2014-04-29 10:54:20 +10:00
|
|
|
PacketCustom.assignHandler(NEICPH.channel, new NEICPH());
|
|
|
|
|
FMLCommonHandler.instance().bus().register(instance);
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(instance);
|
|
|
|
|
|
|
|
|
|
API.registerHighlightHandler(new DefaultHighlightHandler(), ItemInfo.Layout.HEADER);
|
|
|
|
|
HUDRenderer.load();
|
|
|
|
|
WorldOverlayRenderer.load();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-16 11:31:43 -06:00
|
|
|
public static void postInit() {
|
|
|
|
|
loadHandlerOrdering();
|
2024-08-17 23:24:27 +03:00
|
|
|
GuiContainerManager.registerReloadResourceListener();
|
2021-10-16 11:31:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void loadHandlerOrdering() {
|
|
|
|
|
File file = NEIClientConfig.handlerOrderingFile;
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
try (FileWriter writer = new FileWriter(file)) {
|
|
|
|
|
NEIClientConfig.logger.info("Creating default handler ordering CSV {}", file);
|
|
|
|
|
|
|
|
|
|
List<String> toWrite = Lists.newArrayList(defaultHandlerOrdering);
|
|
|
|
|
GuiRecipeTab.handlerMap.keySet().stream().sorted()
|
|
|
|
|
.forEach(handlerId -> toWrite.add(String.format("%s,0", handlerId)));
|
|
|
|
|
|
|
|
|
|
IOUtils.writeLines(toWrite, "\n", writer);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to save default handler ordering to file {}", file, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URL url;
|
|
|
|
|
try {
|
|
|
|
|
url = file.toURI().toURL();
|
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
|
NEIClientConfig.logger.info("Invalid URL for handler ordering CSV.");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
|
|
|
|
|
NEIClientConfig.logger.info("Loading handler ordering from file {}", file);
|
|
|
|
|
CSVParser csvParser = CSVFormat.EXCEL.withCommentMarker('#').parse(reader);
|
|
|
|
|
for (CSVRecord record : csvParser) {
|
|
|
|
|
final String handlerId = record.get(0);
|
|
|
|
|
|
|
|
|
|
int ordering;
|
|
|
|
|
try {
|
|
|
|
|
ordering = Integer.parseInt(record.get(1));
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Error parsing CSV record {}: {}", record, e);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NEIClientConfig.handlerOrdering.put(handlerId, ordering);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
NEIClientConfig.logger.info("Error parsing CSV");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void tickEvent(TickEvent.ClientTickEvent event) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (event.phase == Phase.END) return;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2022-06-24 12:32:13 +01:00
|
|
|
if (mc.theWorld != null) {
|
2014-04-29 10:54:20 +10:00
|
|
|
loadWorld(mc.theWorld, false);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!NEIClientConfig.isEnabled()) return;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2023-05-05 21:01:50 +02:00
|
|
|
/*
|
|
|
|
|
* NEI plugins are loaded in a separate thread. Make sure loading them has finished otherwise a CME might
|
|
|
|
|
* occur in KeyManager if a plugin calls API.addKeyBind() during initialization.
|
|
|
|
|
*/
|
|
|
|
|
if (NEIClientConfig.isLoaded()) KeyManager.tickKeyStates();
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
NEIController.updateUnlimitedItems(mc.thePlayer.inventory);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (mc.currentScreen == null) NEIController.processCreativeCycling(mc.thePlayer.inventory);
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
updateMagnetMode(mc.theWorld, mc.thePlayer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GuiScreen gui = mc.currentScreen;
|
|
|
|
|
if (gui != lastGui) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (gui instanceof GuiMainMenu) lastworld = null;
|
|
|
|
|
else if (gui instanceof GuiSelectWorld) NEIClientConfig.reloadSaves();
|
|
|
|
|
else if (gui == null) {
|
2022-06-06 11:05:02 -04:00
|
|
|
/* prevent WorldClient reference being held in the Gui */
|
|
|
|
|
NEIController.manager = null;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
lastGui = gui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void tickEvent(TickEvent.RenderTickEvent event) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (event.phase == Phase.END && NEIClientConfig.isEnabled()) HUDRenderer.renderOverlay();
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void renderLastEvent(RenderWorldLastEvent event) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (NEIClientConfig.isEnabled()) WorldOverlayRenderer.render(event.partialTicks);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onWorldUnload(WorldEvent.Unload event) {
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
if (event.world == mc.theWorld) {
|
|
|
|
|
NEIClientConfig.unloadWorld();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public void loadWorld(World world, boolean fromServer) {
|
2014-04-29 10:54:20 +10:00
|
|
|
if (world != lastworld) {
|
|
|
|
|
SMPmagneticItems.clear();
|
|
|
|
|
WorldOverlayRenderer.reset();
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
if (!fromServer) {
|
2014-04-29 10:54:20 +10:00
|
|
|
NEIClientConfig.setHasSMPCounterPart(false);
|
|
|
|
|
NEIClientConfig.setInternalEnabled(false);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!Minecraft.getMinecraft().isSingleplayer()) // wait for server to initiate in singleplayer
|
|
|
|
|
NEIClientConfig.loadWorld("remote/" + ClientUtils.getServerIP().replace(':', '~'));
|
2022-06-06 11:05:02 -04:00
|
|
|
|
|
|
|
|
ItemMobSpawner.clearEntityReferences(world);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastworld = world;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ClientHandler instance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static RuntimeException throwCME(final String message) {
|
2022-06-24 12:32:13 +01:00
|
|
|
final GuiScreen errorGui = new GuiErrorScreen(null, null) {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
|
|
|
|
public void handleMouseInput() {}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void handleKeyboardInput() {}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawScreen(int par1, int par2, float par3) {
|
|
|
|
|
drawDefaultBackground();
|
|
|
|
|
String[] s_msg = message.split("\n");
|
|
|
|
|
for (int i = 0; i < s_msg.length; ++i)
|
|
|
|
|
drawCenteredString(fontRendererObj, s_msg[i], width / 2, height / 3 + 12 * i, 0xFFFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
2022-06-24 12:32:13 +01:00
|
|
|
CustomModLoadingErrorDisplayException e = new CustomModLoadingErrorDisplayException() {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
|
|
|
|
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
|
|
|
|
|
Minecraft.getMinecraft().displayGuiScreen(errorGui);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY,
|
|
|
|
|
float tickTime) {}
|
2014-04-29 10:54:20 +10:00
|
|
|
};
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|