Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport MC-186052 #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.dimdev.vanillafix.bugs;

import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.util.ResourceLocation;

import java.util.Map;

public interface IPatched$TextureManager {
Map<ResourceLocation, ITextureObject> getTextures();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import org.dimdev.vanillafix.bugs.IPatched$TextureManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Iterator;
import java.util.Map;

/**
* Makes interdimensional teleportation nearly as fast as same-dimension
* teleportation by removing the "Downloading terrain..." screen. This will cause
* the player to see partially loaded terrain rather than waiting for the whole
* render distance to load, but that's also the vanilla behaviour for same-dimension
* teleportation.
*
* Forces {@link TextureManager} to unload all skins it has.
* See https://bugs.mojang.com/browse/MC-186052
*/
@Mixin(value = NetHandlerPlayClient.class, priority = 500)
public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient {
@Shadow private Minecraft client;

@Redirect(method = "handleJoinGame", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;displayGuiScreen(Lnet/minecraft/client/gui/GuiScreen;)V"))
private void onGuiDisplayJoin(Minecraft mc, GuiScreen guiScreenIn) {
Expand All @@ -27,4 +44,23 @@ private void onGuiDisplayJoin(Minecraft mc, GuiScreen guiScreenIn) {
private void onGuiDisplayRespawn(Minecraft mc, GuiScreen guiScreenIn) {
mc.displayGuiScreen(null);
}

@Inject(method = "onDisconnect", at = @At("HEAD"))
private void onDisconnect(ITextComponent reason, CallbackInfo ci) {
TextureManager renderEngine = this.client.getTextureManager();
Map<ResourceLocation, ITextureObject> textures = ((IPatched$TextureManager)renderEngine).getTextures();
Iterator<Map.Entry<ResourceLocation, ITextureObject>> iterator = textures.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<ResourceLocation, ITextureObject> entry = iterator.next();
if (entry.getKey().getPath().startsWith("skins/")) {
iterator.remove();
ITextureObject texture = entry.getValue();
if (texture instanceof AbstractTexture) {
((AbstractTexture) texture).deleteGlTexture();
} else {
GlStateManager.deleteTexture(texture.getGlTextureId());
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.dimdev.vanillafix.bugs.mixins.client;

import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import org.dimdev.vanillafix.bugs.IPatched$TextureManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Map;

@Mixin(TextureManager.class)
public class MixinTextureManager implements IPatched$TextureManager {
@Shadow @Final private Map<ResourceLocation, ITextureObject> mapTextureObjects;

@Override
public Map<ResourceLocation, ITextureObject> getTextures() {
return mapTextureObjects;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/mixins.vanillafix.bugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"client.MixinEntityRenderer",
"client.MixinServerPinger$1",
"client.MixinThreadDownloadImageData",
"client.MixinEnumConnectionState"
"client.MixinEnumConnectionState",
"client.MixinTextureManager"
],
"injectors": {
"maxShiftBy": 10
Expand Down