@‘AymericRed’:
Par contre fait attention, quand tu vas compiler ton mod les field.getDeclaredField vont pas trouver les fields vu qu’il faut leur nom obfusqué (tu peux heureusement lui proposer plusieurs noms à tester).
Oui, j’ai eu l’erreur quelques minutes après avoir écrits mon message.
Maintenant, pour récupérer les fields, j’utilise ObfuscationReflectionHelper.
Et donc voilà le code final (car j’ai modifié 2-3 petites choses) :
:::
package fr.alexandre1156.mugiwara.gui;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import fr.alexandre1156.mugiwara.MugiwaraMod;
import fr.alexandre1156.mugiwara.members.FrameMember;
import fr.alexandre1156.mugiwara.members.MugiMember;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ServerSelectionList;
import net.minecraft.client.multiplayer.ServerList;
import net.minecraft.client.network.LanServerDetector;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
public class GuiMultiplayerMugi extends GuiMultiplayer {
private Timer timer = new Timer();
private boolean isStarted;
private ArrayList <framemember>frame = new ArrayList<framemember>();
/** Augmente de 17 à chaque icone*/
private int x = 0;
/** Augmente de 17 quand il y a plus de 6 joueurs connectés*/
private int y = 0;
public GuiMultiplayerMugi(GuiScreen parentScreen) {
super(parentScreen);
x = 0;
y = 0;
isStarted = false;
this.startTimer();
for(MugiMember member : MugiwaraMod.memUtils.getAllMembersConnected()){
frame.add(new FrameMember(475 + x, 35 + y, member));
x += 19;
if(x == 171){
y = 17;
x = 0;
}
}
}
@Override
public void initGui() {
try {
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
// boolean devEnv = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
// System.out.println("DEV MODE : "+devEnv);
boolean initialized = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 16);
ServerSelectionList serverListSelector = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 3);
ServerList savedServerList = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 4);
LanServerDetector.LanServerList lanServerList = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 14);
LanServerDetector.ThreadLanServerFind lanServerDetector = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 15);
Logger LOGGER = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 0);
if (initialized) {
serverListSelector.setDimensions(this.width, this.height, 32, this.height - 64);
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, serverListSelector, 3);
} else {
initialized = true;
savedServerList = new ServerList(this.mc);
savedServerList.loadServerList();
lanServerList = new LanServerDetector.LanServerList();
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, initialized, 16);
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, savedServerList, 4);
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, lanServerDetector, 15);
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, lanServerList, 14);
try {
lanServerDetector = new LanServerDetector.ThreadLanServerFind(lanServerList);
lanServerDetector.start();
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, lanServerDetector, 15);
} catch (Exception exception) {
LOGGER.warn("Unable to start LAN server detection: {}", new Object[] {exception.getMessage()});
}
serverListSelector = new ServerSelectionList(this, this.mc, this.width, this.height, 32, this.height - 64, 36){
@Override
public void drawScreen(int mouseXIn, int mouseYIn, float partialTicks) {
if (this.visible)
{
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
int i = this.getScrollBarX();
int j = i + 6;
this.bindAmountScrolled();
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
// Forge: background rendering moved into separate method.
this.drawContainerBackground(tessellator);
int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int l = this.top + 4 - (int)this.amountScrolled;
if (this.hasListHeader)
{
this.drawListHeader(k, l, tessellator);
}
this.drawSelectionBox(k, l, mouseXIn, mouseYIn);
GlStateManager.disableDepth();
ServerSelectionList serverListSelector = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, GuiMultiplayerMugi.this, 3);
int slotServer = MugiwaraMod.utils.getSlotServer(GuiMultiplayerMugi.this);
int yScreen = this.height;
int xScreen = this.width;
if((xScreen == 640 && yScreen == 334) || Minecraft.getMinecraft().isFullScreen()){
if(!frame.isEmpty() && slotServer > -1){
RenderHelper.disableStandardItemLighting();
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
for(FrameMember memberFrame : frame){
try {
if(serverListSelector != null)
memberFrame.setY(memberFrame.getOriginalY() + (slotServer * 36) + serverListSelector.getAmountScrolled()*-1);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
//if(!(memberFrame.getY() > 254 || memberFrame.getY() < 33)){
Minecraft.getMinecraft().renderEngine.bindTexture(memberFrame
.getTheMember()
.getHeadTextureLocation());
GuiMultiplayerMugi.this.drawTexturedModalRect(memberFrame.getX(), memberFrame.getY(), 0, 0, 16, 16);
//}
}
RenderHelper.enableStandardItemLighting();
}
}
this.overlayBackground(0, this.top, 255, 255);
this.overlayBackground(this.bottom, this.height, 255, 255);
int slotText = slotServer * 36;
if(!frame.isEmpty()){
for(FrameMember memberFrame : frame){
if(memberFrame.isMouseOver16px(mouseX, mouseY)){
String name = memberFrame.getTheMember().getUsername();
GuiMultiplayerMugi.this.drawCenteredString(Minecraft.getMinecraft().fontRendererObj, name, memberFrame.getX()+10, memberFrame.getY()-10, MugiwaraMod.memUtils.getColorByGrade(memberFrame.getTheMember().getGroup()));
}
}
}
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
GlStateManager.disableAlpha();
GlStateManager.shadeModel(7425);
GlStateManager.disableTexture2D();
int i1 = 4;
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
vertexbuffer.pos((double)this.left, (double)(this.top + 4), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
vertexbuffer.pos((double)this.right, (double)(this.top + 4), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
vertexbuffer.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
vertexbuffer.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
vertexbuffer.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
vertexbuffer.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
vertexbuffer.pos((double)this.right, (double)(this.bottom - 4), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
vertexbuffer.pos((double)this.left, (double)(this.bottom - 4), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
tessellator.draw();
int j1 = this.getMaxScroll();
if (j1 > 0)
{
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
k1 = MathHelper.clamp(k1, 32, this.bottom - this.top - 8);
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
if (l1 < this.top)
{
l1 = this.top;
}
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
vertexbuffer.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
vertexbuffer.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
vertexbuffer.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
vertexbuffer.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
vertexbuffer.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
vertexbuffer.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
vertexbuffer.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
vertexbuffer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
tessellator.draw();
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
vertexbuffer.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
vertexbuffer.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
vertexbuffer.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
vertexbuffer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
this.renderDecorations(mouseXIn, mouseYIn);
GlStateManager.enableTexture2D();
GlStateManager.shadeModel(7424);
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
}
}
};
serverListSelector.updateOnlineServers(savedServerList);
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, serverListSelector, 3);
}
this.createButtons();
} catch(Exception e){
e.printStackTrace();
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
try {
ObfuscationReflectionHelper.setPrivateValue(GuiMultiplayer.class, this, null, 12);
//this.drawDefaultBackground();
ServerSelectionList ssl = ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 3);
ssl.drawScreen(mouseX, mouseY, partialTicks);
for (int i = 0; i < this.buttonList.size(); ++i)
{
((GuiButton)this.buttonList.get(i)).drawButton(this.mc, mouseX, mouseY);
}
for (int j = 0; j < this.labelList.size(); ++j)
{
((GuiLabel)this.labelList.get(j)).drawLabel(this.mc, mouseX, mouseY);
}
this.drawCenteredString(this.fontRendererObj, I18n.format("multiplayer.title", new Object[0]), this.width / 2, 20, 16777215);
if (ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 12) != null) {
this.drawHoveringText(Lists.newArrayList(Splitter.on("\n").split((CharSequence) ObfuscationReflectionHelper.getPrivateValue(GuiMultiplayer.class, this, 12))), mouseX, mouseY);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}
public void startTimer(){
TimerTask timerTask = new TimerTask(){
@Override
public void run() {
MugiwaraMod.memUtils.reloadMembersConnected(false);
frame.clear();
x = 0;
y = 0;
for(MugiMember member : MugiwaraMod.memUtils.getAllMembersConnected()){
frame.add(new FrameMember(475 + x, 35 + y, member));
x += 19;
if(x == 171){ // 153
y = 17;
x = 0;
}
}
}
};
timer.scheduleAtFixedRate(timerTask, 0, 30000);
}
}
:::</framemember></framemember>