Posted May 13, 201510 yr Hey, I got a question. Is it possible to add icons (not clickable buttons) to a gui screen that switches to a different one when a condition is met? By the way, the gui screen is opened from an entity and the condition is whether the entity is a female or a male (something I'm trying out to make breeding more realistic and to make it easier to address the entity since it is a tameable entity). Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 13, 201510 yr Is it possible to add icons (not clickable buttons) to a gui screen that switches to a different one when a condition is met? Yes. drawModalRect Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
May 13, 201510 yr You could just create the gui with a different texture depending on what opened it.
May 13, 201510 yr Author Is it possible to add icons (not clickable buttons) to a gui screen that switches to a different one when a condition is met? Yes. drawModalRect Hey, I got this: this.drawModalRectWithCustomSizedTexture(x, y, u, v, xMouse, yMouse, textureWidth, textureHeight); So what do I put in these parameters? Here is my GUI code: package common.zeroquest.client.gui; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import common.zeroquest.api.interfaces.ITalent; import common.zeroquest.api.registry.TalentRegistry; import common.zeroquest.entity.util.ModeUtil.EnumMode; import common.zeroquest.entity.zertum.EntityZertumEntity; import common.zeroquest.lib.Constants; import common.zeroquest.network.PacketHandler; import common.zeroquest.network.imessage.ZertumMode; import common.zeroquest.network.imessage.ZertumName; import common.zeroquest.network.imessage.ZertumObey; import common.zeroquest.network.imessage.ZertumTalents; /** * @author ProPercivalalb */ public class GuiDogInfo extends GuiScreen { public EntityZertumEntity dog; public EntityPlayer player; private ScaledResolution resolution; private final List<GuiTextField> textfieldList = new ArrayList<GuiTextField>(); private GuiTextField nameTextField; private int currentPage = 0; private int maxPages = 1; public int btnPerPages = 0; private final DecimalFormat dfShort = new DecimalFormat("0.00"); public GuiDogInfo(EntityZertumEntity dog, EntityPlayer player) { this.dog = dog; this.player = player; } @Override public void initGui() { super.initGui(); this.buttonList.clear(); this.labelList.clear(); this.textfieldList.clear(); this.resolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); Keyboard.enableRepeatEvents(true); int topX = this.width / 2; int topY = this.height / 2; GuiTextField nameTextField = new GuiTextField(0, this.fontRendererObj, topX - 100, topY + 50, 200, 20) { @Override public boolean textboxKeyTyped(char character, int keyId) { boolean typed = super.textboxKeyTyped(character, keyId); if (typed) { PacketHandler.sendToServer(new ZertumName(dog.getEntityId(), this.getText())); } return typed; } }; nameTextField.setFocused(false); nameTextField.setMaxStringLength(32); nameTextField.setText(this.dog.getPetName()); this.nameTextField = nameTextField; this.textfieldList.add(nameTextField); int size = TalentRegistry.getTalents().size(); int temp = 0; while ((temp + 2) * 21 + 10 < this.resolution.getScaledHeight()) { temp += 1; } this.btnPerPages = temp; if (temp < size) { this.buttonList.add(new GuiButton(-1, 25, temp * 21 + 10, 20, 20, "<")); this.buttonList.add(new GuiButton(-2, 48, temp * 21 + 10, 20, 20, ">")); } if (this.btnPerPages < 1) { this.btnPerPages = 1; } this.maxPages = (int) Math.ceil((double) TalentRegistry.getTalents().size() / (double) this.btnPerPages); if (this.currentPage >= this.maxPages) { this.currentPage = 0; } for (int i = 0; i < this.btnPerPages; ++i) { if ((this.currentPage * this.btnPerPages + i) >= TalentRegistry.getTalents().size()) { continue; } this.buttonList.add(new GuiButton(1 + this.currentPage * this.btnPerPages + i, 25, 10 + i * 21, 20, 20, "+")); } if (this.dog.isOwner(this.player)) { this.buttonList.add(new GuiButton(-5, this.width - 64, topY + 65, 42, 20, String.valueOf(this.dog.willObeyOthers()))); } this.buttonList.add(new GuiButton(-6, topX + 40, topY + 25, 60, 20, this.dog.mode.getMode().modeName())); } @Override public void drawScreen(int xMouse, int yMouse, float partialTickTime) { this.drawDefaultBackground(); // Background int topX = this.width / 2; int topY = this.height / 2; String health = dfShort.format(this.dog.getHealth()); String healthMax = dfShort.format(this.dog.getMaxHealth()); String healthRel = dfShort.format(this.dog.getHealthRelative() * 100); String healthState = health + "/" + healthMax + "(" + healthRel + "%)"; String damageValue = dfShort.format(this.dog.getAIAttackDamage()); String damageState = damageValue; String speedValue = dfShort.format(this.dog.getAIMoveSpeed()); String speedState = speedValue; String tamedString = null; if (this.dog.isTamed()) { if (this.dog.getOwnerName().equals(this.player.getDisplayNameString())) { tamedString = "Yes (You)"; } else { tamedString = "Yes (" + StringUtils.abbreviate(this.dog.getOwnerName(), 22) + ")"; } } String evoString = null; if (!this.dog.hasEvolved() && !this.dog.isChild() && this.dog.levels.getLevel() < Constants.maxLevel) { evoString = "Not at Alpha Level!"; } else if (!this.dog.hasEvolved() && this.dog.isChild() && this.dog.levels.getLevel() < Constants.maxLevel) { evoString = "Too Young!"; } else if (!this.dog.hasEvolved() && !this.dog.isChild() && this.dog.levels.getLevel() >= Constants.maxLevel) { evoString = "Ready!"; } else if (this.dog.hasEvolved() && !this.dog.isChild()) { evoString = "Already Evolved!"; } this.fontRendererObj.drawString("New name:", topX - 100, topY + 38, 4210752); this.fontRendererObj.drawString("Level: " + this.dog.levels.getLevel(), topX - 75, topY + 75, 0xFF10F9); this.fontRendererObj.drawString("Points Left: " + this.dog.spendablePoints(), topX, topY + 75, 0xFFFFFF); this.fontRendererObj.drawString("Health: " + healthState, topX + 190, topY - 170, 0xFFFFFF); this.fontRendererObj.drawString("Damage: " + damageState, topX + 190, topY - 160, 0xFFFFFF); this.fontRendererObj.drawString("Speed: " + speedState, topX + 190, topY - 150, 0xFFFFFF); this.fontRendererObj.drawString("Tamed: " + tamedString, topX + 190, topY - 140, 0xFFFFFF); this.fontRendererObj.drawString("State: " + evoString, topX + 190, topY - 130, 0xFFFFFF); if (this.dog.isOwner(this.player)) { this.fontRendererObj.drawString("Obey Others?", this.width - 76, topY + 55, 0xFFFFFF); } this.drawModalRectWithCustomSizedTexture(x, y, u, v, xMouse, yMouse, textureWidth, textureHeight); for (int i = 0; i < this.btnPerPages; ++i) { if ((this.currentPage * this.btnPerPages + i) >= TalentRegistry.getTalents().size()) { continue; } this.fontRendererObj.drawString(TalentRegistry.getTalent(this.currentPage * this.btnPerPages + i).getLocalisedName(), 50, 17 + i * 21, 0xFFFFFF); } for (GuiTextField field : this.textfieldList) { field.drawTextBox(); } GL11.glDisable(GL12.GL_RESCALE_NORMAL); RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_DEPTH_TEST); super.drawScreen(xMouse, yMouse, partialTickTime); RenderHelper.enableGUIStandardItemLighting(); // Foreground GL11.glPushMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); for (int k = 0; k < this.buttonList.size(); ++k) { GuiButton button = (GuiButton) this.buttonList.get(k); if (button.mousePressed(this.mc, xMouse, yMouse)) { List list = new ArrayList(); if (button.id >= 1 && button.id <= TalentRegistry.getTalents().size()) { ITalent talent = TalentRegistry.getTalent(button.id - 1); list.add(EnumChatFormatting.GREEN + talent.getLocalisedName()); list.add("Level: " + this.dog.talents.getLevel(talent)); list.add(EnumChatFormatting.GRAY + "--------------------------------"); list.addAll(this.splitInto(talent.getLocalisedInfo(), 200, this.mc.fontRendererObj)); } else if (button.id == -1) { list.add(EnumChatFormatting.ITALIC + "Previous Page"); } else if (button.id == -2) { list.add(EnumChatFormatting.ITALIC + "Next Page"); } else if (button.id == -6) { String str = StatCollector.translateToLocal("modeinfo." + button.displayString.toLowerCase()); list.addAll(splitInto(str, 150, this.mc.fontRendererObj)); } this.drawHoveringText(list, xMouse, yMouse, this.mc.fontRendererObj); } } GL11.glPopMatrix(); } @Override protected void actionPerformed(GuiButton button) { if (button.id >= 1 && button.id <= TalentRegistry.getTalents().size()) { ITalent talent = TalentRegistry.getTalent(button.id - 1); int level = this.dog.talents.getLevel(talent); if (level < talent.getHighestLevel(this.dog) && this.dog.spendablePoints() >= talent.getCost(this.dog, level + 1)) { PacketHandler.sendToServer(new ZertumTalents(this.dog.getEntityId(), TalentRegistry.getTalent(button.id - 1).getKey())); } } else if (button.id == -1) { if (this.currentPage > 0) { this.currentPage -= 1; this.initGui(); } } else if (button.id == -2) { if (this.currentPage + 1 < this.maxPages) { this.currentPage += 1; this.initGui(); } } if (button.id == -5) { if (!this.dog.willObeyOthers()) { button.displayString = "true"; PacketHandler.sendToServer(new ZertumObey(this.dog.getEntityId(), true)); } else { button.displayString = "false"; PacketHandler.sendToServer(new ZertumObey(this.dog.getEntityId(), false)); } } if (button.id == -6) { int newMode = (dog.mode.getMode().ordinal() + 1) % EnumMode.values().length; EnumMode mode = EnumMode.values()[newMode]; button.displayString = mode.modeName(); PacketHandler.sendToServer(new ZertumMode(this.dog.getEntityId(), newMode)); } } @Override public void updateScreen() { for (GuiTextField field : this.textfieldList) { field.updateCursorCounter(); } } @Override public void mouseClicked(int xMouse, int yMouse, int mouseButton) throws IOException { super.mouseClicked(xMouse, yMouse, mouseButton); for (GuiTextField field : this.textfieldList) { field.mouseClicked(xMouse, yMouse, mouseButton); } } @Override public void keyTyped(char character, int keyId) { for (GuiTextField field : this.textfieldList) { field.textboxKeyTyped(character, keyId); } if (keyId == Keyboard.KEY_ESCAPE) { this.mc.thePlayer.closeScreen(); } } @Override public void onGuiClosed() { Keyboard.enableRepeatEvents(false); } @Override public boolean doesGuiPauseGame() { return false; } public List splitInto(String text, int maxLength, FontRenderer font) { List list = new ArrayList(); String temp = ""; String[] split = text.split(" "); for (int i = 0; i < split.length; ++i) { String str = split[i]; int length = font.getStringWidth(temp + str); if (length > maxLength) { list.add(temp); temp = ""; } temp += str + " "; if (i == split.length - 1) { list.add(temp); } } return list; } } Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 13, 201510 yr Exactly the same as you would for drawing the progress bar on a furnace, only the size isn't changing, just the uv coordinates based on your state. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
May 13, 201510 yr Author Exactly the same as you would for drawing the progress bar on a furnace, only the size isn't changing, just the uv coordinates based on your state. Oh wait, I found something else this.drawTexturedModalRect(x, y, textureSprite, p_175175_4_, p_175175_5_); But with this, I need something that is a TextureAtlasSprite.. I tried making something you would with the ResourecLocation class but it's not visible. And also for the other method, where would I get these states from? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 13, 201510 yr YOU are defining the states. It's some property of the entity you're displaying information for. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
May 13, 201510 yr Author Ok, I started on something like this but I don't see the texture public static final ResourceLocation male = new ResourceLocation(Constants.modid + ":" + "textures/gui/maleFemaleButtons.png"); ... mc.renderEngine.bindTexture(male); // TODO this.drawTexturedModalRect(topX + 20, topY + 20, 0, 0, 2, 2); Here is the textures I want to be able to see: http://i1319.photobucket.com/albums/t661/Nova_Leary/maleFemaleButtons_zpsg0poboz5.png[/img] Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr Author Nvm, I fixed it and also, how do I make it randomly set a gender when the entity spawns? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr There is Random class for a reason. Don't make new one. Use random field in either entity or world. 1.7.10 is no longer supported by forge, you are on your own.
May 14, 201510 yr Author I started this.. but with no success DataValues and NBT @Override protected void entityInit() { // TODO super.entityInit(); this.dataWatcher.addObject(DataValues.gender, Byte.valueOf((byte)0)); //Gender } //@formatter:on @Override public void writeEntityToNBT(NBTTagCompound tagCompound) { super.writeEntityToNBT(tagCompound); tagCompound.setBoolean("gender", this.isMale()); } @Override public void readEntityFromNBT(NBTTagCompound tagCompound) { super.readEntityFromNBT(tagCompound); this.setMale(tagCompound.getBoolean("gender")); } Methods public boolean isMale() { return (this.dataWatcher.getWatchableObjectByte(DataValues.gender) & 2) != 0; } public void setMale(boolean isMale) { byte b0 = this.dataWatcher.getWatchableObjectByte(DataValues.gender); if (isMale) { this.dataWatcher.updateObject(DataValues.gender, Byte.valueOf((byte) (b0 | 2))); } else { this.dataWatcher.updateObject(DataValues.gender, Byte.valueOf((byte) (b0 & -3))); } } public boolean isFemale() { return (this.dataWatcher.getWatchableObjectByte(DataValues.gender) & 4) != 0; } public void setFemale(boolean isFemale) { byte b0 = this.dataWatcher.getWatchableObjectByte(DataValues.gender); if (isFemale) { this.dataWatcher.updateObject(DataValues.gender, Byte.valueOf((byte) (b0 | 4))); } else { this.dataWatcher.updateObject(DataValues.gender, Byte.valueOf((byte) (b0 & -5))); } } Event @SubscribeEvent public void genderSet(LivingSpawnEvent event) { if (event.entity instanceof EntityZertumEntity) { EntityZertumEntity dog = (EntityZertumEntity) event.entity; if (dog.getRNG().nextInt(3) == 0) { dog.setMale(true); } else { dog.setFemale(true); } System.out.println("Is Male?: " + dog.isMale() + " Is Female? " + dog.isFemale()); } } Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr Author I changed the gender tasks to these DataValue @Override protected void entityInit() { // TODO super.entityInit(); this.dataWatcher.addObject(DataValues.gender, new String("")); //Gender } NBT @Override public void writeEntityToNBT(NBTTagCompound tagCompound) { super.writeEntityToNBT(tagCompound); tagCompound.setString("gender", this.getGender()); } @Override public void readEntityFromNBT(NBTTagCompound tagCompound) { super.readEntityFromNBT(tagCompound); this.setGender(tagCompound.getString("gender")); } Methods public void setGender(String gender) { this.dataWatcher.updateObject(DataValues.gender, gender); } public String getGender() { return this.dataWatcher.getWatchableObjectString(DataValues.gender); } Update Event for Gender if (this.isEntityAlive()) { if (this.rand.nextInt(2) == 0) { this.setGender("male"); } else { this.setGender("female"); } } I want it where the entity randomly selects a gender when it spawns, but I have this event so far in onUpdate() in the entity. How do I make it randomly select the gender ONLY one every time it spawns? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr Author I changed it because it was harder to use the bits like the tame methods did. What I want the entity to do is start a randomizer to select either female or male ONLY once, once i start it though it never stops. Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr Author *shudders* Copy pasted bitmasks used wrongly... Great. What does that mean? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr Author But would it go on forever in entityInt and make the methods I have useless since it comes before the NBT write and read? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 14, 201510 yr Setup ONE DataWatcher for this entity with BOOLEAN (true = male, false = female). In entityInit (or constructor): 1. You generate 1 or 0 value using Random (on how to use it - look vanilla or google it) -> setObject (DataWatcher of gender) to true or false depending on what you randomed. In readNBT do: 1. check if nbt has boolean "Gender" key. 2. If it has: setObject (DataWatcher of gender) to true or false (from vale of "Gender" key) -> DONE 3. If it doesn't have this key - it means it was never set! DONE (genders that were not set are alredy handled by constructor) 4. DONE In writeNBT: 1. you getObject from DataWatcher - you get boolean value of 1 or 0 and save it using nbt.setBoolean("Gender", gender); 1.7.10 is no longer supported by forge, you are on your own.
May 15, 201510 yr Author Thanks, that works perfectly and the icons switch exactly Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 15, 201510 yr Author Oh and now my question, how do I have the mating methods check for the genders? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 15, 201510 yr Are you using EntityAnimal? There is: public boolean canMateWith(EntityAnimal otherAnimal) { return otherAnimal == this ? false : (otherAnimal.getClass() != this.getClass() ? false : this.isInLove() && otherAnimal.isInLove()); } You can use it to check whatever you want 1.7.10 is no longer supported by forge, you are on your own.
May 15, 201510 yr Author Yeah and let me try it out Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 15, 201510 yr Author And it works! Thanks guys! Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 15, 201510 yr Author Whoooooa wait, I noticed something whenever I leave and came back to the same world OR close the client and come back, the genders of the entity change to opposite ones Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 15, 201510 yr Well, I noticed that Jamie is now dating Kate who just broke up with Steve, who turned out to be Gay after 5 years of relationship. You don't understand who those people are, do you? The point is - we don't know your code. 1.7.10 is no longer supported by forge, you are on your own.
May 15, 201510 yr Author No? Well, for some reason when the world loads up, the randomizer starts up again and switches the genders Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 15, 201510 yr Loading NBT happens after constructor, therefore if you are loading boolean and putting it into dataWatcher after initialization of entity, I don't really see posibility. Post code. I am out for today (~7 hours), so don't wait 1.7.10 is no longer supported by forge, you are on your own.
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.