Skip to content

Commit

Permalink
Make world load faster, enable GUIs in nether portal
Browse files Browse the repository at this point in the history
  • Loading branch information
Runemoro committed May 5, 2018
1 parent 5785fd5 commit 167a5d6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.dimdev.vanillafix.mixins.client;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@SuppressWarnings({"unused", "NonConstantFieldWithUpperCaseName", "RedundantThrows"}) // Shadow
@Mixin(EntityPlayerSP.class)
public class MixinEntityPlayerSP {
@Redirect(method = "onLivingUpdate", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;currentScreen:Lnet/minecraft/client/gui/GuiScreen;", ordinal = 0))
public GuiScreen getCurrentScreen(Minecraft mc) {
return null; // Enable GUIs in portals
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import net.minecraft.util.IThreadListener;
import net.minecraft.util.MinecraftError;
import net.minecraft.util.ReportedException;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.Logger;
import org.dimdev.vanillafix.GuiCrashScreen;
import org.dimdev.vanillafix.IPatchedMinecraft;
import org.lwjgl.LWJGLException;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import javax.annotation.Nullable;
import java.io.File;
Expand All @@ -29,7 +28,6 @@
import java.util.Date;

@SuppressWarnings({"unused", "NonConstantFieldWithUpperCaseName", "RedundantThrows"}) // Shadow
@SideOnly(Side.CLIENT)
@Mixin(Minecraft.class)
@Implements(@Interface(iface = IPatchedMinecraft.class, prefix = "minecraft$"))
public abstract class MixinMinecraft implements IThreadListener, ISnooperInfo, IPatchedMinecraft {
Expand All @@ -47,11 +45,17 @@ public abstract class MixinMinecraft implements IThreadListener, ISnooperInfo, I
@Shadow public EntityRenderer entityRenderer;

@Shadow private void init() throws LWJGLException, IOException {}

@Shadow private void runGameLoop() throws IOException {}

@Shadow public void displayGuiScreen(@Nullable GuiScreen guiScreenIn) {}

@Shadow public CrashReport addGraphicsAndWorldToCrashReport(CrashReport theCrash) { return null; }

@Shadow public void shutdownMinecraftApplet() {}

@Shadow public void displayCrashReport(CrashReport crashReportIn) {}

@Shadow public abstract void loadWorld(@Nullable WorldClient worldClientIn);

private CrashReport currentReport = null;
Expand Down Expand Up @@ -188,7 +192,6 @@ public void clearCurrentReport() {
currentReport = null;
}


@ModifyConstant(method = "runTickKeyboard", constant = @Constant(longValue = 6000L, ordinal = 0))
public long getDebugCrashKeyPressTime(long value) {
return 0; // TODO: config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.dimdev.vanillafix.mixins.client;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.PacketThreadUtil;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.network.play.server.SPacketRespawn;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.world.WorldSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@SuppressWarnings({"unused", "NonConstantFieldWithUpperCaseName"}) // Shadow
@Mixin(NetHandlerPlayClient.class)
public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient {
@Shadow private boolean doneLoadingTerrain;
@Shadow private WorldClient world;
@Shadow private Minecraft client;

@Overwrite
@Override
public void handleRespawn(SPacketRespawn packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, client);

if (packetIn.getDimensionID() != client.player.dimension) {
doneLoadingTerrain = false;
client.displayGuiScreen(null);

Scoreboard scoreboard = world.getScoreboard();
world = new WorldClient((NetHandlerPlayClient) (Object) this, new WorldSettings(0L, packetIn.getGameType(), false, client.world.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), client.mcProfiler);
world.setWorldScoreboard(scoreboard);
client.loadWorld(world);
client.player.dimension = packetIn.getDimensionID();
}

client.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
client.playerController.setGameType(packetIn.getGameType());
}

// @Redirect(method = "handleRespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;displayGuiScreen(Lnet/minecraft/client/gui/GuiScreen;)V", ordinal = 0))
// public void patchDisplayGuiScreen(Minecraft minecraft, GuiScreen screen) {}
//
// @Inject(method = "handleRespawn", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/NetHandlerPlayClient;doneLoadingTerrain:Z", ordinal = 0))
// public void setDoneLoadingTerrain(boolean value) {
// client.displayGuiScreen(null);
// }
}
4 changes: 3 additions & 1 deletion src/main/resources/mixins.vanillafix.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"MixinNetHandlerPlayServer"
],
"client": [
"client.MixinMinecraft"
"client.MixinMinecraft",
"client.MixinNetHandlerPlayClient",
"client.MixinEntityPlayerSP"
]
}

0 comments on commit 167a5d6

Please sign in to comment.