Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gnembon/carpetmod
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed Oct 9, 2018
2 parents 8b78a19 + 0e54b25 commit 078aef5
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.project
/build/
/ForgeGradle/
/.idea/
/out/
21 changes: 21 additions & 0 deletions patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- a/net/minecraft/client/Minecraft.java
+++ b/net/minecraft/client/Minecraft.java
@@ -195,6 +195,8 @@
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;

+import carpet.CarpetServer;
+
@OnlyIn(Dist.CLIENT)
public class Minecraft implements IThreadListener, ISnooperInfo, IGuiEventListenerDeferred
{
@@ -516,6 +518,9 @@
this.mainWindow.updateVsyncFromGameSettings();
this.mainWindow.setLogOnGlError();
this.renderGlobal.makeEntityOutlineShader();
+
+ //CM start game hook
+ CarpetServer.onGameStarted();
}

private void checkForGLFWInitError()
12 changes: 12 additions & 0 deletions patches/net/minecraft/client/gui/GuiIngame.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/net/minecraft/client/gui/GuiIngame.java
+++ b/net/minecraft/client/gui/GuiIngame.java
@@ -353,7 +353,8 @@
GlStateManager.popMatrix();
scoreobjective1 = scoreboard.getObjectiveInDisplaySlot(0);

- if (!this.mc.gameSettings.keyBindPlayerList.isKeyDown() || this.mc.isIntegratedServerRunning() && this.mc.player.connection.getPlayerInfoMap().size() <= 1 && scoreobjective1 == null)
+ //CM display player list if footer or header exists to make logs visible in singleplayer
+ if (!this.mc.gameSettings.keyBindPlayerList.isKeyDown() || this.mc.isIntegratedServerRunning() && this.mc.player.connection.getPlayerInfoMap().size() <= 1 && scoreobjective1 == null && !overlayPlayerList.hasFooterOrHeader())
{
this.overlayPlayerList.setVisible(false);
}
15 changes: 15 additions & 0 deletions patches/net/minecraft/client/gui/GuiPlayerTabOverlay.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/net/minecraft/client/gui/GuiPlayerTabOverlay.java
+++ b/net/minecraft/client/gui/GuiPlayerTabOverlay.java
@@ -375,6 +375,12 @@
this.footer = null;
}

+ //CM accessor
+ public boolean hasFooterOrHeader()
+ {
+ return footer != null || header != null;
+ }
+
@OnlyIn(Dist.CLIENT)
static class PlayerComparator implements Comparator<NetworkPlayerInfo>
{
11 changes: 11 additions & 0 deletions patches/net/minecraft/command/Commands.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@

this.dispatcher.findAmbiguities((p_201302_1_, p_201302_2_, p_201302_3_, p_201302_4_) ->
{
@@ -259,6 +262,10 @@
itextcomponent.appendText("\n\n").appendText(astacktraceelement[j].getMethodName()).appendText("\n ").appendText(astacktraceelement[j].getFileName()).appendText(":").appendText(String.valueOf(astacktraceelement[j].getLineNumber()));
}
}
+ else //CM print errors in production too
+ {
+ exception.printStackTrace();
+ }

p_197059_1_.sendErrorMessage((new TextComponentTranslation("command.failed", new Object[0])).applyTextStyle((p_211704_1_) ->
{
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfileRepository;
@@ -268,6 +269,10 @@
@@ -268,6 +269,12 @@
TileEntitySkull.setProfileCache(this.getPlayerProfileCache());
TileEntitySkull.setSessionService(this.getMinecraftSessionService());
PlayerProfileCache.setOnlineMode(this.isServerInOnlineMode());
+
+ //CM init - all stuff loaded from the server, just before worlds loading
+ CarpetServer.onServerLoaded(this);
+ //CM start game hook
+ CarpetServer.onGameStarted();
+
LOGGER.info("Preparing level \"{}\"", (Object)this.getFolderName());
JsonObject jsonobject = new JsonObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/net/minecraft/server/integrated/IntegratedServer.java
+++ b/net/minecraft/server/integrated/IntegratedServer.java
@@ -38,6 +38,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

+import carpet.CarpetServer;
+
@OnlyIn(Dist.CLIENT)
public class IntegratedServer extends MinecraftServer
{
@@ -101,6 +103,8 @@
this.setAllowFlight(true);
LOGGER.info("Generating keypair");
this.setKeyPair(CryptManager.generateKeyPair());
+ //CM init - all stuff loaded from the server, just before worlds loading
+ CarpetServer.onServerLoaded(this);
this.loadAllWorlds(this.getFolderName(), this.getWorldName(), this.worldSettings.getSeed(), this.worldSettings.getTerrainType(), this.worldSettings.getGeneratorOptions());
this.setMOTD(this.getServerOwner() + " - " + this.getWorld(DimensionType.OVERWORLD).getWorldInfo().getWorldName());
return true;
5 changes: 4 additions & 1 deletion src/main/java/carpet/CarpetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public static void onServerLoaded(MinecraftServer server)
{
CarpetSettings.apply_settings_from_conf(server);
//CarpetSettings.reload_all_statics(); // not needed anymore due to validators
LoggerRegistry.initLoggers(server);
}
// Separate from onServerLoaded, because a server can be loaded multiple times in singleplayer
public static void onGameStarted() {
LoggerRegistry.initLoggers();
}
/*public static void onLoadAllWorlds(MinecraftServer server)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/logging/HUDLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

public class HUDLogger extends Logger
{
public HUDLogger(MinecraftServer server, String logName, String def, String[] options)
public HUDLogger(String logName, String def, String[] options)
{
super(server, logName, def, options);
super(logName, def, options);
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/carpet/logging/Logger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package carpet.logging;

import carpet.CarpetServer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.ITextComponent;
Expand All @@ -11,9 +12,6 @@

public class Logger
{
// Reference to the minecraft server. Used to look players up by name.
private MinecraftServer server;

// The set of subscribed and online players.
private Map<String, String> subscribedOnlinePlayers;

Expand All @@ -27,9 +25,8 @@ public class Logger

private String[] options;

public Logger(MinecraftServer server, String logName, String def, String [] options)
public Logger(String logName, String def, String [] options)
{
this.server = server;
subscribedOnlinePlayers = new HashMap<>();
subscribedOfflinePlayers = new HashMap<>();
this.logName = logName;
Expand Down Expand Up @@ -160,7 +157,7 @@ public void sendPlayerMessage(EntityPlayer player, ITextComponent ... messages)
*/
protected EntityPlayer playerFromName(String name)
{
return server.getPlayerList().getPlayerByUsername(name);
return CarpetServer.minecraft_server.getPlayerList().getPlayerByUsername(name);
}

// ----- Event Handlers ----- //
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/carpet/logging/LoggerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public class LoggerRegistry
public static boolean __packets;
public static boolean __weather;

public static void initLoggers(MinecraftServer server)
public static void initLoggers()
{
registerLogger("tnt", new Logger(server, "tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", new Logger(server, "projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",new Logger(server, "fallingBlocks", "brief", new String[]{"brief", "full"}));
registerLogger("kills", new Logger(server, "kills", null, null));
registerLogger("damage", new Logger(server, "damage", "all", new String[]{"all","players","me"}));
registerLogger("weather", new Logger(server, "weather", null, null));

registerLogger("tps", new HUDLogger(server, "tps", null, null));
registerLogger("packets", new HUDLogger(server, "packets", null, null));
registerLogger("counter",new HUDLogger(server, "counter","white", Arrays.stream(EnumDyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", new HUDLogger(server, "mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
registerLogger("tnt", new Logger("tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", new Logger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",new Logger("fallingBlocks", "brief", new String[]{"brief", "full"}));
registerLogger("kills", new Logger("kills", null, null));
registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
registerLogger("weather", new Logger("weather", null, null));

registerLogger("tps", new HUDLogger("tps", null, null));
registerLogger("packets", new HUDLogger("packets", null, null));
registerLogger("counter",new HUDLogger("counter","white", Arrays.stream(EnumDyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", new HUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
}

/**
Expand Down

0 comments on commit 078aef5

Please sign in to comment.