This commit is contained in:
Michael Wain 2024-07-28 04:59:36 +03:00
parent 8b0a15413c
commit 96fd964539
7 changed files with 56 additions and 14 deletions

View File

@ -2,6 +2,8 @@ package alterwain.offlineskin;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.options.components.BooleanOptionComponent;
import net.minecraft.client.option.BooleanOption;
import net.minecraft.core.lang.I18n; import net.minecraft.core.lang.I18n;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -17,6 +19,8 @@ public class GuiSkinChanger extends GuiScreen {
private GuiButton buttonLoadSkin; private GuiButton buttonLoadSkin;
private GuiButton buttonLoadCape; private GuiButton buttonLoadCape;
private GuiButton buttonClose; private GuiButton buttonClose;
private GuiButton modelType;
private GuiButton hasCape;
public GuiSkinChanger(GuiScreen parent) { public GuiSkinChanger(GuiScreen parent) {
@ -27,6 +31,8 @@ public class GuiSkinChanger extends GuiScreen {
public void init() { public void init() {
I18n stringtranslate = I18n.getInstance(); I18n stringtranslate = I18n.getInstance();
this.controlList.clear(); this.controlList.clear();
this.controlList.add(this.modelType = new GuiButton(3, this.width / 2 - 100, this.height / 4 + 2, 200, 20, stringtranslate.translateKey("gui.options.page.edit_skin.button.model_slim")));
this.controlList.add(this.hasCape = new GuiButton(4, this.width / 2 - 100, this.height / 4 - 10 + 30 + 4, 200, 20, stringtranslate.translateKey("gui.options.page.edit_skin.button.has_cape_yes")));
this.controlList.add(this.buttonLoadSkin = new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, stringtranslate.translateKey("gui.options.page.edit_skin.button.load_skin"))); this.controlList.add(this.buttonLoadSkin = new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, stringtranslate.translateKey("gui.options.page.edit_skin.button.load_skin")));
this.controlList.add(this.buttonLoadCape = new GuiButton(1, this.width / 2 - 100, this.height / 4 - 10 + 50 + 18 + 20 + 4, 200, 20, stringtranslate.translateKey("gui.options.page.edit_skin.button.load_cape"))); this.controlList.add(this.buttonLoadCape = new GuiButton(1, this.width / 2 - 100, this.height / 4 - 10 + 50 + 18 + 20 + 4, 200, 20, stringtranslate.translateKey("gui.options.page.edit_skin.button.load_cape")));
this.controlList.add(this.buttonClose = new GuiButton(2, this.width / 2 - 100, this.height / 4 + 120 + 12, stringtranslate.translateKey("gui.options.page.edit_skin.button.close"))); this.controlList.add(this.buttonClose = new GuiButton(2, this.width / 2 - 100, this.height / 4 + 120 + 12, stringtranslate.translateKey("gui.options.page.edit_skin.button.close")));
@ -50,6 +56,10 @@ public class GuiSkinChanger extends GuiScreen {
OfflineSkinMod.capeImage = ImageIO.read(cape); OfflineSkinMod.capeImage = ImageIO.read(cape);
Files.copy(cape.toPath(), new File(configPath, "cape.png").toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(cape.toPath(), new File(configPath, "cape.png").toPath(), StandardCopyOption.REPLACE_EXISTING);
} }
} else if(button.id == 3) { // model type
} else if(button.id == 4) { // hasCape
} }
} }
} catch (IOException e) { } catch (IOException e) {

View File

@ -19,6 +19,7 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, RecipeEntrypoint { public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, RecipeEntrypoint {
@ -39,9 +40,11 @@ public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, Reci
public void beforeGameStart() { public void beforeGameStart() {
configPath.mkdirs(); configPath.mkdirs();
try { try {
if (new File(configPath, "skin.png").exists()) { if(!new File(configPath, "skin.png").exists()) {
skinImage = ImageIO.read(new File(configPath, "skin.png")); BufferedImage i = ImageIO.read(Objects.requireNonNull(OfflineSkinMod.class.getClassLoader().getResourceAsStream("char.png")));
ImageIO.write(i, "png", new File(configPath, "skin.png"));
} }
skinImage = ImageIO.read(new File(configPath, "skin.png"));
if (new File(configPath, "cape.png").exists()) { if (new File(configPath, "cape.png").exists()) {
capeImage = ImageIO.read(new File(configPath, "cape.png")); capeImage = ImageIO.read(new File(configPath, "cape.png"));
} }
@ -81,7 +84,7 @@ public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, Reci
ByteArrayInputStream is = new ByteArrayInputStream(b); ByteArrayInputStream is = new ByteArrayInputStream(b);
return ImageIO.read(is); return ImageIO.read(is);
} catch (IOException e) { } catch (IOException e) {
return null; // TODO: read default skin from resources. return null;
} }
} }

View File

@ -15,15 +15,20 @@ public class SendSet extends Thread {
@Override @Override
public void run() { public void run() {
int i = 0;
while(i < 10) {
try { try {
Thread.sleep(2500); Thread.sleep(2500);
if( isCape ) { if (isCape) {
((ForceDownloadHandler) EntityRenderDispatcher.instance.renderEngine).offlineSkinChanger$forceLoadDownloadableTexture("offlineCapeLocal:" + this.username, null, null); ((ForceDownloadHandler) EntityRenderDispatcher.instance.renderEngine).offlineSkinChanger$forceLoadDownloadableTexture("offlineCapeLocal:" + this.username, null, null);
return; return;
} }
((ForceDownloadHandler) EntityRenderDispatcher.instance.renderEngine).offlineSkinChanger$forceLoadDownloadableTexture("offlineSkinLocal:"+this.username, null, PlayerSkinParser.instance); ((ForceDownloadHandler) EntityRenderDispatcher.instance.renderEngine).offlineSkinChanger$forceLoadDownloadableTexture("offlineSkinLocal:" + this.username, null, PlayerSkinParser.instance);
return;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
i++;
}
} }
} }
} }

View File

@ -20,9 +20,17 @@ public abstract class NetClientHandlerMixin extends NetHandler implements SkinRe
@Override @Override
public void offlineSkinChanger$handleSkinRequest(Packet244SkinRequest request) { public void offlineSkinChanger$handleSkinRequest(Packet244SkinRequest request) {
byte[] skin = new byte[0];
byte[] cape = new byte[0];
if( request.isRequestSkin() && OfflineSkinMod.skinImage != null ) {
skin = OfflineSkinMod.imageToBytes(OfflineSkinMod.skinImage);
}
if( request.isRequestCape() && OfflineSkinMod.capeImage != null ) {
cape = OfflineSkinMod.imageToBytes(OfflineSkinMod.capeImage);
}
this.netManager.addToSendQueue(new Packet245SkinResponse(mc.thePlayer.username, this.netManager.addToSendQueue(new Packet245SkinResponse(mc.thePlayer.username,
OfflineSkinMod.imageToBytes(OfflineSkinMod.skinImage), skin,
OfflineSkinMod.imageToBytes(OfflineSkinMod.capeImage), cape,
false)); false));
} }
} }

View File

@ -45,4 +45,16 @@ public class Packet244SkinRequest extends Packet {
public int getPacketSize() { public int getPacketSize() {
return 3; return 3;
} }
public boolean isRequestSkin() {
return requestSkin;
}
public boolean isRequestCape() {
return requestCape;
}
public boolean isRequestModelType() {
return requestModelType;
}
} }

BIN
src/main/resources/char.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -3,3 +3,7 @@ gui.options.page.edit_skin.button.load_skin=Load skin
gui.options.page.edit_skin.button.load_cape=Load cape gui.options.page.edit_skin.button.load_cape=Load cape
gui.options.page.edit_skin.button.close=Close gui.options.page.edit_skin.button.close=Close
gui.options.page.edit_skin.label.title=Change skin/cape gui.options.page.edit_skin.label.title=Change skin/cape
gui.options.page.edit_skin.button.model_fat=Model type: Steve
gui.options.page.edit_skin.button.model_slim=Model type: Alex
gui.options.page.edit_skin.button.has_cape_yes=Has cape (yes)
gui.options.page.edit_skin.button.has_cape_no=Has cape (no)