Jump to content

Recommended Posts

Posted

I have a GUI with some buttons in it, and when i click those buttons i want the gui to change appearance (basically some buttons will be replaced with others). How can i do so that the gui automatically refresh without closing it and reopening it to see the changes? Also i've noticed that the gui repaint itself when i resize the window, doing something like this
MgTIRet.png

How can i made so the gui doesn't do this every time i resize? This is my gui code, thanks in advance to everyone who will help me understand these problems :)

	package com.cf.gui;
	import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
	import org.lwjgl.opengl.GL11;
	import com.cf.CoreFaction;
import com.cf.network.GuiCoreAddExpansionServerMessage;
import com.cf.network.GuiCoreRemoveServerMessage;
import com.cf.network.GuiCoreSaveServerMessage;
import com.cf.utils.Settings;
import com.cf.utils.Utils;
	import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
	public class GuiCore extends GuiScreen {
    private static final ResourceLocation BG = new ResourceLocation(CoreFaction.MODID, "textures/gui/core.png");
	    private String territory;
    private String faction;
    private int coreLevel;
    private int expansions;
    private int primaryEffect;
    private int secondaryEffect;
    private int primaryLevel;
    private int secondaryLevel;
	    private GuiCore.UpgradeButton upgradeCoreButton;
    private GuiCore.ExpansionButton expansionButton;
    private GuiCore.RemoveButton removeButton;
	    private int guiLeft;
    private int guiTop;
    private int xSize = 256;
    private int ySize = 181;
    private ArrayList<AllyEffectButton> allyButtons = new ArrayList<AllyEffectButton>();
    private ArrayList<EnemyEffectButton> enemyButtons = new ArrayList<EnemyEffectButton>();
    private ArrayList<AllyActiveEffectButton> allyActiveButtons = new ArrayList<AllyActiveEffectButton>();
    private ArrayList<EnemyActiveEffectButton> enemyActiveButtons = new ArrayList<EnemyActiveEffectButton>();
    private ArrayList<Potion> allyEffects = new ArrayList<Potion>();
    private ArrayList<Potion> enemyEffects = new ArrayList<Potion>();
    private int maxCoreLevel = 10;
	    public GuiCore(String t, String f, int l, int e, int e1, int e2, int l1, int l2) {
        this.territory = t;
        this.faction = f;
        this.coreLevel = l;
        this.expansions = e;
        this.primaryEffect = e1;
        this.secondaryEffect = e2;
        this.primaryLevel = l1;
        this.secondaryLevel = l2;
    }
	    @Override
    public void initGui() {
        this.guiLeft = (this.width - xSize) / 2;
        this.guiTop = (this.height - ySize) / 2;
        this.upgradeCoreButton = new GuiCore.UpgradeButton(-1, this.guiLeft + 19, this.guiTop + 144);
        this.expansionButton = new GuiCore.ExpansionButton(-2, this.guiLeft + 116, this.guiTop + 144);
        this.removeButton = new GuiCore.RemoveButton(-3, this.guiLeft + 213, this.guiTop + 144);
	        this.buttonList.add(upgradeCoreButton);
        this.buttonList.add(expansionButton);
        this.buttonList.add(removeButton);
	        this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.JUMP_BOOST)));
        this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.SPEED)));
        this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.RESISTANCE)));
        this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.HASTE)));
        this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.ABSORPTION)));
	        this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.HUNGER)));
        this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.WEAKNESS)));
        this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.SLOWNESS)));
        this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.BLINDNESS)));
        this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.MINING_FATIGUE)));
	        for (int i = 0; i < 5; i++) {
            this.allyButtons.add(
                    new AllyEffectButton(i, this.guiLeft + 11 + 5, this.guiTop + 20 + (24 * i), allyEffects.get(i), 0));
            this.allyActiveButtons.add(new AllyActiveEffectButton(i, this.guiLeft + 11 + 5, this.guiTop + 20 + (24 * i),
                    allyEffects.get(i), 0));
            this.enemyButtons.add(new EnemyEffectButton(i + 5, this.guiLeft + (this.xSize - 106 - 11 - 5),
                    this.guiTop + 20 + (24 * i), enemyEffects.get(i), 0));
            this.enemyActiveButtons.add(new EnemyActiveEffectButton(i + 5, this.guiLeft + (this.xSize - 106 - 11 - 5),
                    this.guiTop + 20 + (24 * i), enemyEffects.get(i), 0));
        }
	        this.buttonList.addAll(allyButtons);
        this.buttonList.addAll(enemyButtons);
    }
	    @Override
    public void updateScreen() {
        if (this.primaryLevel != -999) {
            for (int i = 0; i < allyEffects.size(); i++) {
                if (Potion.getIdFromPotion(allyEffects.get(i)) == this.primaryEffect) {
                    this.buttonList.remove(allyButtons.get(i));
                    this.buttonList.add(allyActiveButtons.get(i));
                }
            }
            for (int i = 0; i < enemyEffects.size(); i++) {
                if (Potion.getIdFromPotion(enemyEffects.get(i)) == this.primaryEffect) {
                    this.buttonList.remove(enemyEffects.get(i));
                    this.buttonList.add(enemyActiveButtons.get(i));
                }
            }
        }
        if (this.secondaryLevel != -999) {
            for (int i = 0; i < enemyEffects.size(); i++) {
                if (Potion.getIdFromPotion(enemyEffects.get(i)) == this.secondaryEffect) {
                    this.buttonList.remove(enemyButtons.get(i));
                    this.buttonList.add(enemyActiveButtons.get(i));
                }
            }
            for (int i = 0; i < enemyEffects.size(); i++) {
                if (Potion.getIdFromPotion(enemyEffects.get(i)) == this.secondaryEffect) {
                    this.buttonList.remove(enemyEffects.get(i));
                    this.buttonList.add(enemyActiveButtons.get(i));
                }
            }
        }
        super.updateScreen();
    }
	    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glDisable(GL11.GL_LIGHTING);
        this.mc.getTextureManager().bindTexture(getBg());
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 256, 181);
        String terr = Utils.getTranslation("gui.core.territory", TextFormatting.GREEN);
        terr += ": " + territory;
        if (terr.length() >= 38) {
            if (coreLevel == maxCoreLevel) {
                this.fontRendererObj.drawString(terr.substring(0, 37) + "...", this.guiLeft + 19, this.guiTop + 10,
                        4210752);
                this.fontRendererObj.drawString(" | " + Utils.getTranslation("gui.core.level", TextFormatting.GOLD)
                        + ": " + String.valueOf(coreLevel), this.guiLeft + this.xSize - 64, this.guiTop + 10, 4210752);
            } else {
                this.fontRendererObj.drawString(terr.substring(0, 38) + "...", this.guiLeft + 19, this.guiTop + 10,
                        4210752);
                this.fontRendererObj.drawString(" | " + Utils.getTranslation("gui.core.level", TextFormatting.GOLD)
                        + ": " + String.valueOf(coreLevel), this.guiLeft + this.xSize - 58, this.guiTop + 10, 4210752);
            }
        } else {
            this.fontRendererObj.drawString(terr, this.guiLeft + 19, this.guiTop + 10, 4210752);
            this.fontRendererObj.drawString(
                    " | " + Utils.getTranslation("gui.core.level", TextFormatting.GOLD) + ": "
                            + String.valueOf(coreLevel),
                    coreLevel == maxCoreLevel ? this.guiLeft + this.xSize - 64 : this.guiLeft + this.xSize - 58,
                    this.guiTop + 10, 4210752);
        }
	        for (int i = 0; i < this.buttonList.size(); ++i) {
            ((GuiButton) this.buttonList.get(i)).drawButton(this.mc, mouseX, mouseY);
        }
	        for (int i = 0; i < this.buttonList.size(); ++i) {
            if (this.buttonList.get(i) instanceof AllyActiveEffectButton
                    || this.buttonList.get(i) instanceof AllyEffectButton)
                this.drawString(Minecraft.getMinecraft().fontRendererObj,
                        Utils.getTranslation(((HoverEffectButton) this.buttonList.get(i)).getEffect()) + " "
                                + (((HoverEffectButton) this.buttonList.get(i)).getTier() == 0 ? ""
                                        : (((HoverEffectButton) this.buttonList.get(i)).getTier() + 1)),
                        ((HoverEffectButton) this.buttonList.get(i)).xPosition + 25,
                        ((HoverEffectButton) this.buttonList.get(i)).yPosition + 7, 0xFFFFFF);
            else if (this.buttonList.get(i) instanceof EnemyActiveEffectButton
                    || this.buttonList.get(i) instanceof EnemyEffectButton)
                this.drawString(Minecraft.getMinecraft().fontRendererObj,
                        Utils.getTranslation(((HoverEffectButton) this.buttonList.get(i)).getEffect()) + " "
                                + (((HoverEffectButton) this.buttonList.get(i)).getTier() == 0 ? ""
                                        : (((HoverEffectButton) this.buttonList.get(i)).getTier() + 1)),
                        ((HoverEffectButton) this.buttonList.get(i)).xPosition + 5,
                        ((HoverEffectButton) this.buttonList.get(i)).yPosition + 7, 0xFFFFFF);
        }
	        this.mc.getTextureManager().bindTexture(getBg());
	        if (coreLevel < Settings.expansionLevel || expansions >= Settings.maxPurchasableExpansions)
            this.expansionButton.setEnabled(false);
	        if (coreLevel == maxCoreLevel)
            this.upgradeCoreButton.setEnabled(false);
	        if (this.coreLevel < 2) {
            this.drawTexturedModalRect(this.allyButtons.get(0).xPosition + 3, this.allyButtons.get(0).yPosition + 2, 0,
                    192, 18, 18);
            this.drawTexturedModalRect(this.enemyButtons.get(0).xPosition + 84, this.enemyButtons.get(0).yPosition + 2,
                    0, 192, 18, 18);
            this.allyButtons.get(0).setEnabled(false);
            this.enemyButtons.get(0).setEnabled(false);
        }
        if (this.coreLevel < 4) {
            this.drawTexturedModalRect(this.allyButtons.get(1).xPosition + 3, this.allyButtons.get(1).yPosition + 2, 0,
                    192, 16, 18);
            this.drawTexturedModalRect(this.enemyButtons.get(1).xPosition + 84, this.enemyButtons.get(1).yPosition + 2,
                    0, 192, 16, 18);
            this.allyButtons.get(1).setEnabled(false);
            this.enemyButtons.get(1).setEnabled(false);
        }
        if (this.coreLevel < 6) {
            this.drawTexturedModalRect(this.allyButtons.get(2).xPosition + 3, this.allyButtons.get(2).yPosition + 2, 0,
                    192, 16, 18);
            this.drawTexturedModalRect(this.enemyButtons.get(2).xPosition + 84, this.enemyButtons.get(2).yPosition + 2,
                    0, 192, 16, 18);
            this.allyButtons.get(2).setEnabled(false);
            this.enemyButtons.get(2).setEnabled(false);
        }
        if (this.coreLevel <  {
            this.drawTexturedModalRect(this.allyButtons.get(3).xPosition + 3, this.allyButtons.get(3).yPosition + 2, 0,
                    192, 16, 18);
            this.drawTexturedModalRect(this.enemyButtons.get(3).xPosition + 84, this.enemyButtons.get(3).yPosition + 2,
                    0, 192, 16, 18);
            this.allyButtons.get(3).setEnabled(false);
            this.enemyButtons.get(3).setEnabled(false);
        }
        if (this.coreLevel < 10) {
            this.drawTexturedModalRect(this.allyButtons.get(4).xPosition + 3, this.allyButtons.get(4).yPosition + 2, 0,
                    192, 16, 18);
            this.drawTexturedModalRect(this.enemyButtons.get(4).xPosition + 84, this.enemyButtons.get(4).yPosition + 2,
                    0, 192, 16, 18);
            this.allyButtons.get(4).setEnabled(false);
            this.enemyButtons.get(4).setEnabled(false);
        }
	        for (GuiButton button : this.buttonList) {
            if (button.isMouseOver()) {
                if (button instanceof HoverEffectButton) {
                    this.zLevel = 100;
                    if (button.enabled) {
                        this.drawCreativeTabHoveringText(((HoverEffectButton) button).getHoverText(), mouseX, mouseY);
                    } else {
                        if (button.id == 0 || button.id == 5)
                            this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.2"), mouseX, mouseY);
                        else if (button.id == 1 || button.id == 6)
                            this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.4"), mouseX, mouseY);
                        else if (button.id == 2 || button.id == 7)
                            this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.6"), mouseX, mouseY);
                        else if (button.id == 3 || button.id == 
                            this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.8"), mouseX, mouseY);
                        else if (button.id == 4 || button.id == 9)
                            this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.10"), mouseX,
                                    mouseY);
                    }
                    this.zLevel = 0;
                } else {
                    if (button.id == -1) {
                        if (coreLevel < maxCoreLevel) {
                            int g = Settings.baseUpgradeCost * coreLevel;
                            String up = Utils.getTranslation("gui.core.upgrade", TextFormatting.GOLD) + " "
                                    + String.valueOf(coreLevel + 1);
                            String down = (g != 0
                                    ? String.valueOf(g) + Utils.getTranslation("gui.core.gemstones", TextFormatting.LIGHT_PURPLE)
                                    : "");
                            this.drawHoveringText(Arrays.<String>asList(up, down), mouseX, mouseY);
                        } else
                            this.drawCreativeTabHoveringText(
                                    Utils.getTranslation("gui.core.upgrade.max", TextFormatting.RED), mouseX, mouseY);
                    } else if (button.id == -2) {
                        if (coreLevel >= Settings.expansionLevel) {
                            if (this.expansions < Settings.maxPurchasableExpansions) {
                                int g = Settings.expansionBaseCost.getGold() * (expansions + 1);
                                int s = Settings.expansionBaseCost.getSilver() * (expansions + 1);
                                int c = Settings.expansionBaseCost.getCopper() * (expansions + 1);
                                String up = Utils.getTranslation("gui.core.expansion", TextFormatting.GREEN) + " ("
                                        + Utils.getTranslation("gui.core.purchased") + ": " + String.valueOf(expansions)
                                        + "/" + String.valueOf(Settings.maxPurchasableExpansions) + ")";
                                String down = (g != 0 ? String.valueOf(g)
                                        + Utils.getTranslation("gui.core.golds", TextFormatting.YELLOW) : "")
                                        + (s != 0
                                                ? String.valueOf(s)
                                                        + Utils.getTranslation("gui.core.silvers", TextFormatting.GRAY)
                                                : "")
                                        + (c != 0 ? String.valueOf(c)
                                                + Utils.getTranslation("gui.core.coppers", TextFormatting.DARK_RED)
                                                : "");
                                this.drawHoveringText(Arrays.<String>asList(up, down), mouseX, mouseY);
                            } else
                                this.drawCreativeTabHoveringText(
                                        Utils.getTranslation("gui.core.expansion.max", TextFormatting.RED), mouseX,
                                        mouseY);
                        } else
                            this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.expansion.locked") + " "
                                    + String.valueOf(Settings.expansionLevel), mouseX, mouseY);
                    } else if (button.id == -3) {
                        String up = Utils.getTranslation("gui.core.remove", TextFormatting.RED);
                        String down = Utils.getTranslation("gui.core.remove.back");
                        this.drawHoveringText(Arrays.<String>asList(up, down), mouseX, mouseY);
                    }
                }
            }
        }
    }
	    @Override
    protected void actionPerformed(GuiButton button) throws IOException {
        if (button.enabled) {
            int id = button.id;
            if (id == -1) {
                int g = Settings.baseUpgradeCost * coreLevel;
                if (Utils.canPayGemstones(this.mc.thePlayer, g) && coreLevel < 10) {
                    Utils.payGemstones(this.mc.thePlayer, g);
                    coreLevel++;
                    if (coreLevel >= maxCoreLevel / 2 && coreLevel < maxCoreLevel) {
                        primaryLevel = 2;
                        secondaryLevel = 2;
                    } else if (coreLevel == maxCoreLevel) {
                        primaryLevel = 3;
                        secondaryLevel = 3;
                    }
                    Utils.sendMessage(this.mc.thePlayer,
                            Utils.getTranslation("gui.core.upgrade.success", TextFormatting.GREEN));
                    CoreFaction.NETWORK.sendToServer(new GuiCoreSaveServerMessage(this.territory,
                            String.valueOf(this.coreLevel), String.valueOf(this.expansions), String.valueOf(this.primaryEffect),
                            String.valueOf(this.secondaryEffect), String.valueOf(this.primaryLevel),
                            String.valueOf(this.secondaryLevel)));
                } else
                    Utils.sendMessage(this.mc.thePlayer,
                            Utils.getTranslation("gui.core.upgrade.fail", TextFormatting.RED));
                this.mc.displayGuiScreen((GuiScreen)null);
            } else if (id == -2) {
                int g = Settings.expansionBaseCost.getGold() * expansions;
                int s = Settings.expansionBaseCost.getSilver() * expansions;
                int c = Settings.expansionBaseCost.getCopper() * expansions;
                if (Utils.canPay(this.mc.thePlayer, g, s, c) && coreLevel >= Settings.expansionLevel
                        && this.expansions < Settings.maxPurchasableExpansions) {
                    Utils.pay(this.mc.thePlayer, g, s, c);
                    CoreFaction.NETWORK.sendToServer(new GuiCoreAddExpansionServerMessage(territory));
                    expansions++;
                    Utils.sendMessage(this.mc.thePlayer,
                            Utils.getTranslation("gui.core.expansion.success", TextFormatting.GREEN));
                } else {
                    this.mc.displayGuiScreen((GuiScreen)null);
                    Utils.sendMessage(this.mc.thePlayer,
                            Utils.getTranslation("gui.core.expansion.fail", TextFormatting.RED));
                }
                
            } else if (id == -3) {
                CoreFaction.NETWORK.sendToServer(new GuiCoreRemoveServerMessage(territory, faction));
                Utils.sendMessage(this.mc.thePlayer,
                        Utils.getTranslation("gui.core.remove.success", TextFormatting.RED));
                this.mc.displayGuiScreen((GuiScreen) null);
                return;
            } else if (id == 0) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(0)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(0)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(0));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(0)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(0));
                }
            } else if (id == 1) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(1)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(1)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(1));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(1)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(1));
                }
            } else if (id == 2) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(2)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(2)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(2));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(2)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(2));
                }
            } else if (id == 3) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(3)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(3)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(3));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(3)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(3));
                }
            } else if (id == 4) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(4)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(4)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(4));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(4)) ? -999
                            : Potion.getIdFromPotion(allyEffects.get(4));
                }
            } else if (id == 5) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(0)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(0)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(0));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(0)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(0));
                }
            } else if (id == 6) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(1)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(1)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(1));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(1)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(1));
                }
            } else if (id == 7) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(2)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(2)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(2));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(2)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(2));
                }
	            } else if (id ==  {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(3)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(3)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(3));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(3)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(3));
                }
            } else if (id == 9) {
                if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(4)) && coreLevel == maxCoreLevel) {
                    this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(4)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(4));
                } else {
                    this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(4)) ? -999
                            : Potion.getIdFromPotion(enemyEffects.get(4));
                }
                
            }
            CoreFaction.NETWORK.sendToServer(new GuiCoreSaveServerMessage(this.territory,
                    String.valueOf(this.coreLevel), String.valueOf(this.expansions), String.valueOf(this.primaryEffect),
                    String.valueOf(this.secondaryEffect), String.valueOf(this.primaryLevel),
                    String.valueOf(this.secondaryLevel)));
        }
        super.actionPerformed(button);
    }
	    @Override
    public boolean doesGuiPauseGame() {
        return false;
    }
	    public static ResourceLocation getBg() {
        return BG;
    }
	    @SideOnly(Side.CLIENT)
    class UpgradeButton extends ActionButton {
        public UpgradeButton(int buttonId, int x, int y) {
            super(buttonId, x, y, GuiCore.getBg(), 0, 237);
        }
	        public void drawButtonForegroundLayer(int mouseX, int mouseY) {
            GuiCore.this.drawCreativeTabHoveringText(
                    Utils.getTranslation("gui.core.upgrade", TextFormatting.GOLD) + "\n" + "Test", mouseX, mouseY);
        }
    }
	    @SideOnly(Side.CLIENT)
    class ExpansionButton extends ActionButton {
        public ExpansionButton(int buttonId, int x, int y) {
            super(buttonId, x, y, GuiCore.getBg(), 0, 237);
        }
	        public void drawButtonForegroundLayer(int mouseX, int mouseY) {
            GuiCore.this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.expansion", TextFormatting.GREEN),
                    mouseX, mouseY);
        }
    }
	    @SideOnly(Side.CLIENT)
    class RemoveButton extends ActionButton {
        public RemoveButton(int buttonId, int x, int y) {
            super(buttonId, x, y, GuiCore.getBg(), 23, 210);
        }
	        public void drawButtonForegroundLayer(int mouseX, int mouseY) {
            GuiCore.this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.remove", TextFormatting.RED),
                    mouseX, mouseY);
        }
    }
}

Don't blame me if i always ask for your help. I just want to learn to be better :)

  • 3 weeks later...
Posted (edited)

Clear the relevant lists in your initGui method. By default vanilla clears the button list on gui's resize. If you setup something else in that method you need to clear it beforehand too or you end up with stuff duplicating in your lists.

To clarify:

On 6/23/2017 at 0:49 AM, JimiIT92 said:

this.buttonList.addAll(allyButtons);         this.buttonList.addAll(enemyButtons);

This is your culprit. The butonList is cleared before initGui is called, but your allyButtons and enemyButtons are not.

Edited by V0idWa1k3r

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://mclo.gs/9y5ciD2 anyone ever had this issue?  Internal exception illegal argument exception: unable to fit 3194354 into 3
    • Hoffman Law Recovery helped me recovered my lost funds
    • Hi! I'm trying to add my custom models/textures renderer like this: public class PonyPlayerWrapperRenderer extends EntityRenderer<Player> { // wrapper class under my LivingEntityRenderer class implementation private final PonyPlayerRenderer innerRenderer; private final PonyPlayerRenderer innerSlimRenderer; public PonyPlayerWrapperRenderer(final EntityRendererProvider.Context context) { super(context); System.out.println("creating new PonyPlayerWrapperRenderer"); this.innerRenderer = new PonyPlayerRenderer(context, false); this.innerSlimRenderer = new PonyPlayerRenderer(context, true); } @Override public void render(final Player entity, final float yaw, final float partialTicks, final PoseStack poseStack, final MultiBufferSource bufferSource, final int packedLight) { System.out.println("PonyPlayerWrapperRenderer render: " + entity.toString()); if (entity instanceof AbstractClientPlayer clientPlayer) { if (clientPlayer.getModelName().contains("slim")) { innerSlimRenderer.render(clientPlayer, yaw, partialTicks, poseStack, bufferSource, packedLight); } else { innerRenderer.render(clientPlayer, yaw, partialTicks, poseStack, bufferSource, packedLight); } } } @Override public ResourceLocation getTextureLocation(final Player player) { System.out.println("PonyPlayerWrapperRenderer getTextureLocation"); if (player instanceof AbstractClientPlayer clientPlayer) { return clientPlayer.getSkinTextureLocation(); } System.out.println("player instanceof AbstractClientPlayer is false"); return getDefaultSkin(player.getUUID()); } } public class PonyPlayerRenderer extends LivingEntityRenderer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> { private final PlayerModel<AbstractClientPlayer> earthModel; private final PlayerModel<AbstractClientPlayer> pegasusModel; private final PlayerModel<AbstractClientPlayer> unicornModel; public PonyPlayerRenderer(final EntityRendererProvider.Context context, final boolean slim) { super( context, slim ? new PonyModelSlim(context.bakeLayer(PonyModelSlim.LAYER_LOCATION)) : new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)), 0.5f ); System.out.println("creating new PonyPlayerRenderer"); this.earthModel = slim ? new PonyModelSlim(context.bakeLayer(PonyModelSlim.LAYER_LOCATION)) : new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)); this.pegasusModel = new PegasusModel(context.bakeLayer(PegasusModel.LAYER_LOCATION)); this.unicornModel = new UnicornModel(context.bakeLayer(UnicornModel.LAYER_LOCATION)); } @Override public void render(final AbstractClientPlayer player, final float entityYaw, final float partialTicks, final PoseStack poseStack, final MultiBufferSource buffer, final int packedLight) { final PonyRace race = player.getCapability(PONY_DATA) .map(data -> ofNullable(data.getRace()).orElse(PonyRace.EARTH)) .orElse(PonyRace.EARTH); this.model = switch (race) { case PEGASUS -> pegasusModel; case UNICORN -> unicornModel; case EARTH -> earthModel; }; super.render(player, entityYaw, partialTicks, poseStack, buffer, packedLight); } @Override public ResourceLocation getTextureLocation(final AbstractClientPlayer player) { final PonyRace race = player.getCapability(PONY_DATA) .map(data -> ofNullable(data.getRace()).orElse(PonyRace.EARTH)) .orElse(PonyRace.EARTH); return switch (race) { case EARTH -> fromNamespaceAndPath(MODID, "textures/entity/earth_pony.png"); case PEGASUS -> fromNamespaceAndPath(MODID, "textures/entity/pegasus.png"); case UNICORN -> fromNamespaceAndPath(MODID, "textures/entity/unicorn.png"); }; } } @Mod.EventBusSubscriber(modid = MODID, bus = MOD, value = CLIENT) public class ClientRenderers { // mod bus render registration config @SubscribeEvent public static void onRegisterLayerDefinitions(final EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(PonyModel.LAYER_LOCATION, PonyModel::createBodyLayer); event.registerLayerDefinition(PonyModelSlim.LAYER_LOCATION, PonyModelSlim::createBodyLayer); event.registerLayerDefinition(PegasusModel.LAYER_LOCATION, PegasusModel::createBodyLayer); event.registerLayerDefinition(UnicornModel.LAYER_LOCATION, UnicornModel::createBodyLayer); event.registerLayerDefinition(InnerPonyArmorModel.LAYER_LOCATION, InnerPonyArmorModel::createBodyLayer); event.registerLayerDefinition(OuterPonyArmorModel.LAYER_LOCATION, OuterPonyArmorModel::createBodyLayer); } @SubscribeEvent public static void onRegisterRenderers(final EntityRenderersEvent.RegisterRenderers event) { event.registerEntityRenderer(EntityType.PLAYER, PonyPlayerWrapperRenderer::new); System.out.println("onRegisterRenderers end"); } } Method onRegisterRenderers() is called and I can see it being logged. But when I enter the world, my PonyWrapperRenderer render() method doesn't ever seem to be called. I also tried to put my renderer to EntityRenderDispatcher's playerRenderers via reflection: @Mod.EventBusSubscriber(modid = MODID, bus = MOD, value = CLIENT) public class ClientRenderers { @SubscribeEvent public static void onRegisterLayerDefinitions(final EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(PonyModel.LAYER_LOCATION, PonyModel::createBodyLayer); event.registerLayerDefinition(PonyModelSlim.LAYER_LOCATION, PonyModelSlim::createBodyLayer); event.registerLayerDefinition(PegasusModel.LAYER_LOCATION, PegasusModel::createBodyLayer); event.registerLayerDefinition(UnicornModel.LAYER_LOCATION, UnicornModel::createBodyLayer); event.registerLayerDefinition(InnerPonyArmorModel.LAYER_LOCATION, InnerPonyArmorModel::createBodyLayer); event.registerLayerDefinition(OuterPonyArmorModel.LAYER_LOCATION, OuterPonyArmorModel::createBodyLayer); } @SubscribeEvent public static void onClientSetup(final FMLClientSetupEvent event) { event.enqueueWork(() -> { try { final EntityRenderDispatcher dispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); final Field renderersField = getEntityRenderDispatcherField("playerRenderers"); final Field itemInHandRenderer = getEntityRenderDispatcherField("itemInHandRenderer"); @SuppressWarnings("unchecked") final Map<String, EntityRenderer<? extends Player>> playerRenderers = (Map<String, EntityRenderer<? extends Player>>)renderersField.get(dispatcher); final PonyPlayerWrapperRenderer renderer = new PonyPlayerWrapperRenderer( new EntityRendererProvider.Context( dispatcher, Minecraft.getInstance().getItemRenderer(), Minecraft.getInstance().getBlockRenderer(), (ItemInHandRenderer)itemInHandRenderer.get(dispatcher), Minecraft.getInstance().getResourceManager(), Minecraft.getInstance().getEntityModels(), Minecraft.getInstance().font ) ); playerRenderers.put("default", renderer); playerRenderers.put("slim", renderer); System.out.println("Player renderers replaced"); } catch (final Exception e) { throw new RuntimeException("Failed to replace player renderers", e); } }); } private static Field getEntityRenderDispatcherField(final String fieldName) throws NoSuchFieldException { final Field field = EntityRenderDispatcher.class.getDeclaredField(fieldName); field.setAccessible(true); return field; } } But I receive the error before Minecraft Client appears (RuntimeException: Failed to replace player renderers - from ClientRenderers onClientSetup() method - and its cause below): java.lang.IllegalArgumentException: No model for layer anotherlittlepony:earth_pony#main at net.minecraft.client.model.geom.EntityModelSet.bakeLayer(EntityModelSet.java:18) ~[forge-1.20.1-47.4.0_mapped_official_1.20.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.client.renderer.entity.EntityRendererProvider$Context.bakeLayer(EntityRendererProvider.java:69) ~[forge-1.20.1-47.4.0_mapped_official_1.20.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at com.thuggeelya.anotherlittlepony.client.renderer.pony.PonyPlayerRenderer.<init>(PonyPlayerRenderer.java:32) ~[main/:?] {re:classloading} at com.thuggeelya.anotherlittlepony.client.renderer.pony.PonyPlayerWrapperRenderer.<init>(PonyPlayerWrapperRenderer.java:24) ~[main/:?] {re:classloading} at com.thuggeelya.anotherlittlepony.client.renderer.ClientRenderers.lambda$onClientSetup$0(ClientRenderers.java:79) ~[main/:?] {re:classloading} ... 33 more Problem appears when EntityRendererProvider context tries to bakeLayer with my model layer location: new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)); // PonyPlayerRenderer.java:32 public class PonyModel extends PlayerModel<AbstractClientPlayer> { // the model class itself public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation( ResourceLocation.fromNamespaceAndPath(MODID, "earth_pony"), "main" ); public PonyModel(final ModelPart root) { super(root, false); } public static LayerDefinition createBodyLayer() { // some CubeListBuilder stuff for model appearance } } Textures PNGs are placed at: resources/assets/[my mod id]/textures/entity. My forge version is 1.20.1. Would appreciate any help.
    • Well, a bit more information about what you're trying to do would be helpful. e.g. why you're trying to use "INVOKE_ASSIGN" instead of "INVOKE". "INVOKE_ASSIGN" calls your code after the "target" is called and its value is stored, if applicable. "INVOKE" calls your code before the target is called. "target" expects a fully qualified name, as per the SpongePowered docs, if that name is going to be remapped (which it will be if your injecting into Minecraft itself and not another mod). For more information on fully qualified names versus canonical names, see the Java specifications. Here's an example of a working "@At" from my own code that targets the "getClosestsVulnerablePlayerToEntity" call inside a mob's logic: @At(value = "INVOKE_ASSIGN", target = "net.minecraft.world.World.getClosestVulnerablePlayerToEntity(Lnet/minecraft/entity/Entity;D)Lnet/minecraft/entity/player/EntityPlayer;") Hope this helps!
    • Ran it one more time just to check, and there's no errors this time on the log??? Log : https://mclo.gs/LnuaAiu I tried allocating more memory to the modpack, around 8000MB and it's still the same; stopping at "LOAD_REGISTRIES". Are some of the mods clashing, maybe? I have no clue what to do LOL
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.