Update x2

This commit is contained in:
Michael Wain 2024-07-28 16:50:22 +03:00
parent 96fd964539
commit 10ac29ba47
8 changed files with 116 additions and 48 deletions

View File

@ -2,8 +2,6 @@ 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;
@ -12,7 +10,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import static alterwain.offlineskin.OfflineSkinMod.configPath; import static alterwain.offlineskin.OfflineSkinMod.*;
public class GuiSkinChanger extends GuiScreen { public class GuiSkinChanger extends GuiScreen {
@ -22,6 +20,8 @@ public class GuiSkinChanger extends GuiScreen {
private GuiButton modelType; private GuiButton modelType;
private GuiButton hasCape; private GuiButton hasCape;
private I18n stringtranslate;
public GuiSkinChanger(GuiScreen parent) { public GuiSkinChanger(GuiScreen parent) {
super(parent); super(parent);
@ -29,44 +29,77 @@ public class GuiSkinChanger extends GuiScreen {
@Override @Override
public void init() { public void init() {
I18n stringtranslate = I18n.getInstance(); OfflineSkinMod.readConfig();
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.modelType = new GuiButton(3, this.width / 2 - 100, this.height / 4 + 2, 200, 20, skinModel ? stringtranslate.translateKey("gui.options.page.edit_skin.button.model_slim") : stringtranslate.translateKey("gui.options.page.edit_skin.button.model_fat")));
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.hasCape = new GuiButton(4, this.width / 2 - 100, this.height / 4 - 10 + 30 + 4, 200, 20, showCape ? stringtranslate.translateKey("gui.options.page.edit_skin.button.has_cape_yes") : stringtranslate.translateKey("gui.options.page.edit_skin.button.has_cape_no")));
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")));
} }
@Override
protected void buttonPressed(GuiButton button) { private void processSkin() {
try {
if (button.enabled) {
if (button.id == 2) {
this.mc.displayGuiScreen(this.getParentScreen());
} else if (button.id == 0) { // skin
File skin = OfflineSkinMod.chooseFile(); File skin = OfflineSkinMod.chooseFile();
if (skin != null) { if (skin == null) return;
try {
OfflineSkinMod.skinImage = ImageIO.read(skin); OfflineSkinMod.skinImage = ImageIO.read(skin);
Files.copy(skin.toPath(), new File(configPath, "skin.png").toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(skin.toPath(), new File(configPath, "skin.png").toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} else if (button.id == 1) { // cape
File cape = OfflineSkinMod.chooseFile();
if (cape != null) {
OfflineSkinMod.capeImage = ImageIO.read(cape);
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) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private void processCape() {
File cape = OfflineSkinMod.chooseFile();
if (cape == null) return;
try {
OfflineSkinMod.capeImage = ImageIO.read(cape);
Files.copy(cape.toPath(), new File(configPath, "cape.png").toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
private void processClose() {
this.mc.displayGuiScreen(this.getParentScreen());
}
private void processModelType() {
skinModel = !skinModel;
this.modelType.displayString = skinModel ? stringtranslate.translateKey("gui.options.page.edit_skin.button.model_slim") : stringtranslate.translateKey("gui.options.page.edit_skin.button.model_fat");
writeConfig();
}
private void processHasCape() {
showCape = !showCape;
this.hasCape.displayString = showCape ? stringtranslate.translateKey("gui.options.page.edit_skin.button.has_cape_yes") : stringtranslate.translateKey("gui.options.page.edit_skin.button.has_cape_no");
writeConfig();
}
@Override
protected void buttonPressed(GuiButton button) {
if(!button.enabled) return;
switch (button.id) {
case 0:
processSkin();
break;
case 1:
processCape();
break;
case 2:
processClose();
break;
case 3:
processModelType();
break;
case 4:
processHasCape();
break;
}
}
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTick) { public void drawScreen(int mouseX, int mouseY, float partialTick) {
I18n stringtranslate = I18n.getInstance(); I18n stringtranslate = I18n.getInstance();

View File

@ -16,7 +16,10 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -29,17 +32,24 @@ public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, Reci
public static File configPath = new File(Global.accessor.getMinecraftDir(), "config/offlineskin"); public static File configPath = new File(Global.accessor.getMinecraftDir(), "config/offlineskin");
public static BufferedImage skinImage; public static BufferedImage skinImage;
public static BufferedImage capeImage; public static BufferedImage capeImage;
public static Boolean showCape = false;
public static Boolean skinModel = false;
public static final Map<String, SkinConfig> skins = new HashMap<>(); public static final Map<String, SkinConfig> skins = new HashMap<>();
@Override @Override
public void onInitialize() { public void onInitialize() {
LOGGER.info("ExampleMod initialized."); LOGGER.info("OfflineSkins initialized.");
} }
@Override @Override
public void beforeGameStart() { public void beforeGameStart() {
configPath.mkdirs(); configPath.mkdirs();
try { try {
if(!new File(configPath, "pref.conf").exists()) {
writeConfig();
} else {
readConfig();
}
if(!new File(configPath, "skin.png").exists()) { if(!new File(configPath, "skin.png").exists()) {
BufferedImage i = ImageIO.read(Objects.requireNonNull(OfflineSkinMod.class.getClassLoader().getResourceAsStream("char.png"))); BufferedImage i = ImageIO.read(Objects.requireNonNull(OfflineSkinMod.class.getClassLoader().getResourceAsStream("char.png")));
ImageIO.write(i, "png", new File(configPath, "skin.png")); ImageIO.write(i, "png", new File(configPath, "skin.png"));
@ -70,6 +80,7 @@ public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, Reci
public static File chooseFile() { public static File chooseFile() {
JFileChooser fileChooser = new JFileChooser(); JFileChooser fileChooser = new JFileChooser();
fileChooser.setAcceptAllFileFilterUsed(false);
FileFilter filter = new FileNameExtensionFilter("PNG File","png"); FileFilter filter = new FileNameExtensionFilter("PNG File","png");
fileChooser.addChoosableFileFilter(filter); fileChooser.addChoosableFileFilter(filter);
int returnValue = fileChooser.showOpenDialog(null); int returnValue = fileChooser.showOpenDialog(null);
@ -97,4 +108,24 @@ public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, Reci
} }
return baos.toByteArray(); return baos.toByteArray();
} }
public static void writeConfig() {
try {
Files.write(new File(configPath, "pref.conf").toPath(), (showCape + ";" + skinModel).getBytes(), StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void readConfig() {
try {
String s = new String(Files.readAllBytes(new File(configPath, "pref.conf").toPath()));
String[] args = s.split(";");
if( args.length != 2 ) return;
showCape = Boolean.parseBoolean(args[0]);
skinModel = Boolean.parseBoolean(args[1]);
} catch (IOException e) {
e.printStackTrace();
}
}
} }

View File

@ -14,9 +14,9 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(NetClientHandler.class) @Mixin(NetClientHandler.class)
public abstract class NetClientHandlerMixin extends NetHandler implements SkinRequestHandler { public abstract class NetClientHandlerMixin extends NetHandler implements SkinRequestHandler {
@Shadow @Final private NetworkManager netManager; @Shadow(remap = false) @Final private NetworkManager netManager;
@Shadow @Final private Minecraft mc; @Shadow(remap = false) @Final private Minecraft mc;
@Override @Override
public void offlineSkinChanger$handleSkinRequest(Packet244SkinRequest request) { public void offlineSkinChanger$handleSkinRequest(Packet244SkinRequest request) {
@ -25,12 +25,12 @@ public abstract class NetClientHandlerMixin extends NetHandler implements SkinRe
if( request.isRequestSkin() && OfflineSkinMod.skinImage != null ) { if( request.isRequestSkin() && OfflineSkinMod.skinImage != null ) {
skin = OfflineSkinMod.imageToBytes(OfflineSkinMod.skinImage); skin = OfflineSkinMod.imageToBytes(OfflineSkinMod.skinImage);
} }
if( request.isRequestCape() && OfflineSkinMod.capeImage != null ) { if( request.isRequestCape() && OfflineSkinMod.capeImage != null && OfflineSkinMod.showCape ) {
cape = OfflineSkinMod.imageToBytes(OfflineSkinMod.capeImage); cape = OfflineSkinMod.imageToBytes(OfflineSkinMod.capeImage);
} }
this.netManager.addToSendQueue(new Packet245SkinResponse(mc.thePlayer.username, this.netManager.addToSendQueue(new Packet245SkinResponse(mc.thePlayer.username,
skin, skin,
cape, cape,
false)); OfflineSkinMod.skinModel));
} }
} }

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(NetServerHandler.class) @Mixin(NetServerHandler.class)
public abstract class NetServerHandlerMixin extends net.minecraft.core.net.handler.NetHandler implements net.minecraft.core.net.ICommandListener, public abstract class NetServerHandlerMixin extends net.minecraft.core.net.handler.NetHandler implements net.minecraft.core.net.ICommandListener,
SkinResponseHandler { SkinResponseHandler {
@Shadow @Shadow(remap = false)
private net.minecraft.server.MinecraftServer mcServer; private net.minecraft.server.MinecraftServer mcServer;
@Override @Override

View File

@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(OptionsPages.class) @Mixin(OptionsPages.class)
public abstract class OptionsPagesMixin { public abstract class OptionsPagesMixin {
@Final @Final
@Shadow @Shadow(remap = false)
@Mutable @Mutable
private static Minecraft mc; private static Minecraft mc;

View File

@ -1,9 +1,7 @@
package alterwain.offlineskin.mixin; package alterwain.offlineskin.mixin;
import alterwain.offlineskin.OfflineSkinMod;
import alterwain.offlineskin.SendInfo; import alterwain.offlineskin.SendInfo;
import alterwain.offlineskin.packet.Packet244SkinRequest; import alterwain.offlineskin.packet.Packet244SkinRequest;
import alterwain.offlineskin.packet.Packet246SkinSet;
import net.minecraft.server.entity.player.EntityPlayerMP; import net.minecraft.server.entity.player.EntityPlayerMP;
import net.minecraft.server.player.PlayerManager; import net.minecraft.server.player.PlayerManager;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -24,7 +22,7 @@ public abstract class PlayerManagerMixin {
@Inject(method = "addPlayer", at = @At("HEAD"), remap = false) @Inject(method = "addPlayer", at = @At("HEAD"), remap = false)
private void onAddPlayer(EntityPlayerMP player, CallbackInfo ci) { private void onAddPlayer(EntityPlayerMP player, CallbackInfo ci) {
player.playerNetServerHandler.sendPacket(new Packet244SkinRequest(true, true, false)); player.playerNetServerHandler.sendPacket(new Packet244SkinRequest(true, true, true));
new SendInfo(player).start(); new SendInfo(player).start();
} }
} }

View File

@ -1,5 +1,6 @@
package alterwain.offlineskin.mixin; package alterwain.offlineskin.mixin;
import alterwain.offlineskin.OfflineSkinMod;
import net.minecraft.client.render.ImageParser; import net.minecraft.client.render.ImageParser;
import net.minecraft.client.render.PlayerSkinParser; import net.minecraft.client.render.PlayerSkinParser;
import net.minecraft.client.render.block.model.BlockModel; import net.minecraft.client.render.block.model.BlockModel;
@ -45,8 +46,13 @@ public abstract class PlayerRendererMixin extends LivingRenderer<EntityPlayer> {
public void drawFirstPersonHand(EntityPlayer player) { public void drawFirstPersonHand(EntityPlayer player) {
player.skinURL = "offlineSkinLocal:"+player.username; player.skinURL = "offlineSkinLocal:"+player.username;
if(OfflineSkinMod.skins.containsKey(player.username)) {
this.mainModel = OfflineSkinMod.skins.get(player.username).getModelType() ? this.modelSlim : this.modelThick;
this.modelBipedMain = OfflineSkinMod.skins.get(player.username).getModelType() ? this.modelSlim : this.modelThick;
} else {
this.mainModel = player.slimModel ? this.modelSlim : this.modelThick; this.mainModel = player.slimModel ? this.modelSlim : this.modelThick;
this.modelBipedMain = player.slimModel ? this.modelSlim : this.modelThick; this.modelBipedMain = player.slimModel ? this.modelSlim : this.modelThick;
}
this.modelBipedMain.onGround = 0.0F; this.modelBipedMain.onGround = 0.0F;
this.modelBipedMain.isRiding = false; this.modelBipedMain.isRiding = false;
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);

View File

@ -14,16 +14,16 @@ import java.util.Map;
@Mixin(RenderEngine.class) @Mixin(RenderEngine.class)
public abstract class RenderEngineMixin implements ForceDownloadHandler { public abstract class RenderEngineMixin implements ForceDownloadHandler {
@Shadow @Shadow(remap = false)
private Map<String, DownloadedTexture> downloadedTextures; private Map<String, DownloadedTexture> downloadedTextures;
@Shadow @Shadow(remap = false)
public abstract int allocateAndSetupTexture(BufferedImage bufferedimage); public abstract int allocateAndSetupTexture(BufferedImage bufferedimage);
@Shadow @Shadow(remap = false)
public abstract void bindTexture(int i); public abstract void bindTexture(int i);
@Shadow @Shadow(remap = false)
public abstract int getTexture(String name); public abstract int getTexture(String name);
@Override @Override
@ -68,7 +68,7 @@ public abstract class RenderEngineMixin implements ForceDownloadHandler {
return false; return false;
} }
} else { } else {
DownloadedTexture texture = (DownloadedTexture)this.downloadedTextures.get(url); DownloadedTexture texture = this.downloadedTextures.get(url);
if (texture == null) { if (texture == null) {
texture = new DownloadedTexture(null, imageParser); texture = new DownloadedTexture(null, imageParser);
if( url.startsWith("offlineSkinLocal") ) { if( url.startsWith("offlineSkinLocal") ) {