Jump to content

Recommended Posts

Posted

Yep, sure :

 

 

 

My GuiUpdaterScreen class (superclass of most of my GuiScreens, doesn't change much) :

package com.franckyi.itemeditor.api.gui;

import java.io.IOException;

import com.franckyi.itemeditor.ItemEditorMod;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;

public abstract class GuiUpdaterScreen extends GuiScreen {

protected GuiButton cancelButton, doneButton;
protected int previousScreen;

public GuiUpdaterScreen(int previousScreen) {
	this.previousScreen = previousScreen;
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
	if (button == doneButton)
		updateServer();
	if (button == cancelButton || button == doneButton)
		switchGui(previousScreen);
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	this.drawDefaultBackground();
	super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
public final boolean doesGuiPauseGame() {
	return ItemEditorMod.config.pauseGame;
}

public abstract void initGui();

protected abstract void updateServer();

protected void switchGui(int screen) {
	mc.player.openGui(ItemEditorMod.instance, screen, mc.world, (int) mc.player.posX, (int) mc.player.posY,
			(int) mc.player.posZ);
}

}

 

GuiEditLore, the screen, parent of my list :

package com.franckyi.itemeditor.client.gui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.franckyi.itemeditor.api.gui.GuiUpdaterScreen;
import com.franckyi.itemeditor.client.gui.child.GuiLoreList;
import com.franckyi.itemeditor.client.gui.child.GuiLoreList.LoreListEntry;
import com.franckyi.itemeditor.network.EditLoreMessage;
import com.franckyi.itemeditor.network.ModPacketHandler;

import net.minecraft.client.gui.GuiButton;

public class GuiEditLore extends GuiUpdaterScreen {

public GuiEditLore(int previousScreen) {
	super(previousScreen);
}

private GuiLoreList loreList;
private List<String> loreMessage = new ArrayList<String>();

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	super.drawScreen(mouseX, mouseY, partialTicks);
	drawString(fontRendererObj, "Edit Item Lore", this.width / 2 - 35, this.height / 2 - 90, 0x5555ff);
	loreList.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
public void initGui() {
	loreList = new GuiLoreList(mc, width/2, height/2, height/4, 3*height/4, width/4, 25, width, height, this);
	for(LoreListEntry entry : loreList.getLoreList())
		buttonList.add(entry.getFormatButton());
	buttonList.add(doneButton = new GuiButton(1, width/2 - 100, 3*height/4 + 20, 90, 20, "§2Done"));
	buttonList.add(cancelButton = new GuiButton(2, width/2 + 10, 3*height/4 + 20, 90, 20, "§4Cancel"));
	loreList.getLoreList().get(0).getTextField().setFocused(true);
}

@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
	for (LoreListEntry entry : loreList.getLoreList())
		entry.getTextField().textboxKeyTyped(typedChar, keyCode);
	super.keyTyped(typedChar, keyCode);
}

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
	for (LoreListEntry entry : loreList.getLoreList())
		entry.getTextField().mouseClicked(mouseX, mouseY, mouseButton);
	super.mouseClicked(mouseX, mouseY, mouseButton);
}

@Override
public void updateScreen() {
	for (LoreListEntry entry : loreList.getLoreList())
		entry.getTextField().updateCursorCounter();
	super.updateScreen();
}

@Override
protected void updateServer() {
	for (LoreListEntry entry : loreList.getLoreList())
		loreMessage.add(entry.getTextField().getText());
	ModPacketHandler.INSTANCE.sendToServer(new EditLoreMessage(loreMessage));
}

}

 

GuiLoreList, my GuiScrollingList :

package com.franckyi.itemeditor.client.gui.child;

import java.util.ArrayList;
import java.util.List;

import com.franckyi.itemeditor.ItemEditorMod;
import com.franckyi.itemeditor.api.gui.GuiFormatButton;
import com.franckyi.itemeditor.helper.ModHelper;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.fml.client.GuiScrollingList;

public class GuiLoreList extends GuiScrollingList {

private GuiScreen parent;
private List<LoreListEntry> loreList = new ArrayList<LoreListEntry>();

public GuiLoreList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight,
		int screenWidth, int screenHeight, GuiScreen parent) {
	super(client, width, height, top, bottom, left, entryHeight, screenWidth, screenHeight);
	this.parent = parent;
	NBTTagList lores = ModHelper.clientStack.getOrCreateSubCompound("display").getTagList("Lore", NBT.TAG_STRING);
	for(int i = 0; i < ItemEditorMod.config.loreLineNumber; i++){
		if(lores.hasNoTags() || i >= lores.tagCount())
			loreList.add(new LoreListEntry(i));
		else
			loreList.add(new LoreListEntry(i, lores.getStringTagAt(i)));
	}
}

@Override
protected int getSize() {
	return loreList.size();
}

@Override
protected void elementClicked(int index, boolean doubleClick) {	}

@Override
protected boolean isSelected(int index) {
	return false;
}

@Override
protected void drawBackground() { }

@Override
protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer, Tessellator tess) {
	LoreListEntry entry = loreList.get(slotIdx);
	parent.drawString(parent.mc.fontRendererObj, "Line " + (entry.index + 1), left + 10, slotTop + 7, 0xffffff);
	entry.textField.xPosition = left + 50;
	entry.textField.yPosition = slotTop;
	entry.textField.width = listWidth - 100;
	entry.textField.drawTextBox();
	entry.formatButton.xPosition = entryRight - 30;
	entry.formatButton.yPosition = slotTop;
	entry.formatButton.visible = (entry.formatButton.yPosition > this.top && entry.formatButton.yPosition + 20 < this.bottom);
	entry.formatButton.enabled = entry.formatButton.visible;
}

public List<LoreListEntry> getLoreList(){
	return loreList;
}

public class LoreListEntry {

	private int index;
	private GuiTextField textField;
	private GuiFormatButton formatButton;

	public LoreListEntry(int index){
		this.index = index;
		this.textField = new GuiTextField((index+1)*10, parent.mc.fontRendererObj, 0, 0, 0, 20);
		this.formatButton = new GuiFormatButton((index+1)*20, 0, 0, textField);
	}

	public LoreListEntry(int index, String text) {
		this(index);
		this.textField.setText(text);
	}

	public GuiTextField getTextField() {
		return textField;
	}

	public GuiButton getFormatButton() {
		return formatButton;
	}

}

}

 

 

Posted

If I recall correctly, I don't think you would need to this.drawDefaultBackground(); in the drawScreen method if your GUI does directly extend from GuiScreen (because it already draws it, so you would have a darker background, because you summed the dark ones). Maybe that's why your buttons appear darker ?

Squirrel ! Squirrel ! Squirrel !

Posted

I'll test that but I'm not sure this is the issue, as all buttons out of the list render correctly. It's something with the list, probably.

EDIT : I'll test that in 30mins.

Posted

Okay, I just had to increase the zLevel of the button.

 

Now, (totally out of the subject, but I don't want to open another thread...)

I want to add a texture on the button. In my button class (extends GuiButton), I've done that :

        @Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
	super.drawButton(mc, mouseX, mouseY);
	mc.getTextureManager().bindTexture(new ResourceLocation(ModReference.MODID, "textures/gui/formatbuttonicon.png"));
	this.drawTexturedModalRect(this.xPosition + 2, this.yPosition + 2, 0, 0, 16, 16);	
}

But the texture doesn't appear. It's a 16*16 texture located in

assets/modid/textures/gui/formatbuttonicon.png

folder.

 

Posted
Gui#drawTexturedModalRect

assumes you are using a 256x256 image. Use

Gui#drawModalRectWithCustomSizedTexture

with the last 2 parameters as the image size.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Ok so, I'm using

Gui#drawModalRectWithCustomSizedTexture(xPosInGui, yPosInGui, xPosInImg, yPosInImg, xSizeInGui, ySizeInGui, xSizeInImg, ySizeInImg)

.

The texture works. But I want it to cover the button, and not to be behind it. How can I do that ?

 

EDIT : Found how to do that. I created a custom

drawModalRectWithCustomSizedTexture

method from the original one, and added a zLevel parameter. And that works.

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

    • Hey! I noticed you're trying to register your alexandrite item and possibly set its resource location manually with setId(...). I wanted to help clarify a few things that might simplify your code and avoid errors. ✅ The issue: You're using setId(...) inside the item registration like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties().useItemDescriptionPrefix() .setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "alexandrite"))))); But: Item.Properties does not have a setId(...) method — this line will either fail or do nothing meaningful. useItemDescriptionPrefix() is mostly used for translation keys (like "item.modid.name") but isn't needed unless you have a very specific reason. 🛠 The fix: You only need to register your item like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); Forge automatically handles the ResourceLocation (modid:alexandrite) based on the name passed into .register(...), so there’s no need to manually assign it. 📝 For the texture: Make sure you have this file in your resources: src/main/resources/assets/tutorialmod/models/item/alexandrite.json { "parent": "item/generated", "textures": { "layer0": "tutorialmod:item/alexandrite" } } And your texture PNG goes here: src/main/resources/assets/tutorialmod/textures/item/alexandrite.png 🌍 For the name in-game: Add this to your en_us.json under: src/main/resources/assets/tutorialmod/lang/en_us.json { "item.tutorialmod.alexandrite": "Alexandrite" }   Note: if im wrong about the issues you are encountering, i apologize.
    • 🛠️ Fix for Transparent or Clipping Item Render Issues When Held in First Person (Forge 1.20+) Hey everyone! I recently ran into a frustrating bug while making a custom item (a rocket) for my Forge mod, and I’m sharing the fix because it’s a bit obscure — and it worked wonders. 💥 The Problem: My item rendered semi-transparent and see-through — but only in first person. It also clipped through nearby blocks when held, unlike default items like swords or leads. The texture file was confirmed to be fully opaque (alpha 255), so the issue wasn’t the PNG itself. Interestingly, when no texture was present and the default purple-black checkerboard appeared, the clipping issue disappeared. ✅ The Fix: I ended up resolving it by randomly trying something I found on a Forge forum post about block rendering. I added this property to my item's model JSON — even though it's typically only used for blocks: { "parent": "item/generated", "textures": { "layer0": "farbeyond:item/rocket_item" }, "render_type": "minecraft:cutout" } Boom. That single line forced the item to render using a proper opaque (cutout) layer, removing all the unwanted transparency and clipping behavior in first person. 🙌 Credit: I originally found the "render_type" trick mentioned here, in a block rendering context: 👉 https://forums.minecraftforge.net/topic/149644-1201-help-with-transparent-blocks/ Even though it was meant for blocks, I thought, why not try it on an item? And it worked! Big thanks to the poster — this fix wouldn’t have happened without that tip. Hopefully this helps anyone else stuck on a weird rendering bug like I was. This isn’t a common item solution, so feel free to share it further. I’d love to know if it works for you too.
    • Use Java 21 instead of Java 24   Also make a test without modernfix
    • Ive been on this world for 2 days now, my computer blue screens pretty often so maybe that has something to do with it. maybe just incompatible mods like a lot of people so im hoping someone more knowledgeable can help me find what i need to get rid of. thank you! paste bin
    • Should probably say that i am running minecraft 1.21.1 and with quite a lot of mods (many of which im unsure should even be on the server side)
  • Topics

×
×
  • Create New...

Important Information

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