Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Lighting glitch with Hovering Text


HappyKiller1O1
 Share

Recommended Posts

Hey so, I made my gui and all that fancy stuff. But, when ever I display hovering text, this happens:

 

http://i.imgur.com/l8NZpKU.png

 

I really don't know what's causing this. I would really appreciate some help!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Make sure you are enabling/disabling all GL states to state they should be (were before drawing).

I'd need code to tell you exacly where (it's all about order).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Here's my Gui class:

 

public class GuiShopBlock extends GuiScreen {

public static final ResourceLocation texture = new ResourceLocation(MR.TNAME + "textures/gui/crew_shop.png");
private static final ResourceLocation crewShopPurchase = new ResourceLocation(MR.TNAME + "textures/gui/crew_shop_purchase.png");

private int xSize;
private int ySize;

private int itemPrice;

RenderItem renderedItem;

Item item;

GuiSlider slider;
GuiButton buy;
GuiButton exit;
GuiButton prev;
GuiButton next;
GuiButton exitGui;

private boolean canDisplayPurchase;

public GuiShopBlock() { //ADD THE REST OF THE PAGES
	this.xSize = 176;
	this.ySize = 166;

	renderedItem = new RenderItem();

	canDisplayPurchase = false;
	itemPrice = 0;
	item = null;
}

public void initGui() {
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        
	buttonList.clear();

	slider = new GuiSlider(0, k + 48, l + 40, 72, 14, "Quantity: ", "", 1, 64, 1, false, true);
	buy = new GuiButton(1, k + 49, l + 79, 26, 14, "Buy");
	exit = new GuiButton(2, k + 92, l + 79, 26, 14, "Exit");
	prev = new GuiButton(3, k + 6, l + 145, 30, 18, "Prev");
	next = new GuiButton(4, k + 139, l + 145, 30, 18, "Next");
	exitGui = new GuiButton(5, k + 72, l + 145, 30, 18, "Exit");

	buttonList.add(slider);
	buttonList.add(buy);
	buttonList.add(exit);
	buttonList.add(prev);
	buttonList.add(next);
	buttonList.add(exitGui);

	slider.visible = false;
	buy.visible = false;
	exit.visible = false;
	prev.enabled = false;
}

public void actionPerformed(GuiButton button) {
	int cost = (int)(slider.getValueInt() * itemPrice);
	int userID = this.mc.thePlayer.getEntityId();
	World world = FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld();
	EntityPlayer player = (EntityPlayer)world.getEntityByID(userID);
	ExtendedPlayer ep = ExtendedPlayer.get(player);

	switch(button.id) {
		case 0:
			break;
		case 1:
			if(canPlayerBuy(cost)) {
				//System.out.println(ep.getCrewCoinAmount());
				ep.modifyCrewCoins(-cost);
				PacketRegistry.network.sendTo(new PacketCoinChangeClient(player, ep.getCrewCoinAmount()), (EntityPlayerMP)player);
				ItemStack stack = new ItemStack(this.item, slider.getValueInt(), 0);

				//System.out.println(this.item);

				if(stack != null) {
					EntityItem item = new EntityItem(world, player.posX, player.posY, player.posZ, stack);

					if(!world.isRemote) {
						world.spawnEntityInWorld(item);
					}
				}

				//System.out.println(ep.getCrewCoinAmount());
				//System.out.println(cost);
				//System.out.println(slider.getValueInt());
				closePurchase();
			}else {
				EventsClientForge.purchaseError();
			}

			break;
		case 2:
			closePurchase();
			break;
	}
}

public void drawScreen(int x, int y, float f) {
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;

	mc.getTextureManager().bindTexture(texture);

	this.drawTexturedModalRect(k, l, 0, 0, xSize, ySize);

	this.renderItemOnGui(Items.emerald, 0, 0);
	this.renderItemOnGui(Items.diamond, 100, 0);

	this.renderItemOnGui(Items.gold_ingot, 0, 25);
	this.renderItemOnGui(Items.iron_ingot, 100, 25);

	this.renderItemOnGui(Items.quartz, 0, 50);
	this.renderItemOnGui(Items.redstone, 100, 50);

	this.drawString(mc.fontRenderer, "Crew Shop", k + 60, l + 8, 0xFFFFFF);
	this.drawString(mc.fontRenderer, "Welcome to the Crew Shop!", k + 20, l + 100, 0xFFFFFF);
	this.drawString(mc.fontRenderer, "To purchase an something,", k + 18, l + 114, 0xFFFFFF);
	this.drawString(mc.fontRenderer, "please click an item above.", k + 20, l + 124, 0xFFFFFF);

	if(this.canDisplayPurchase) {
		this.drawPurchaseOverlay();
	}

	this.drawToolTips(x, y);

	super.drawScreen(x, y, f);
}

public void drawToolTips(int mouseX, int mouseY) {
    int boxX = (this.width - this.xSize) / 2 + 25;
    int boxY = (this.height - this.ySize) / 2 + 25;

	int defaultX = 16;
	int defaultY = 16;

	/* Left Side */
	if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
		List list = new ArrayList();
		defaultTooltip(list, ItemPrices.EMERALD, "Emerald");
		this.drawTooltipText(list, mouseX, mouseY, fontRendererObj);
	}

	if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY + 25 && mouseY < boxY + 25 + defaultY) {
		List list = new ArrayList();
		defaultTooltip(list, ItemPrices.GOLD_INGOT, "Gold Ingot");
		this.drawTooltipText(list, mouseX, mouseY, fontRendererObj);
	}

	if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY + 50 && mouseY < boxY + 50 + defaultY) {
		List list = new ArrayList();
		defaultTooltip(list, ItemPrices.QUARTZ, "Quartz");
		this.drawTooltipText(list, mouseX, mouseY, fontRendererObj);
	}

	/* Right Side */
	if(mouseX > boxX + 100 && mouseX < boxX + 100 + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
		List list = new ArrayList();
		defaultTooltip(list, ItemPrices.DIAMOND, "Diamond");
		this.drawTooltipText(list, mouseX, mouseY, fontRendererObj);
	}

	if(mouseX > boxX + 100 && mouseX < boxX + 100 + defaultX && mouseY > boxY + 25 && mouseY < boxY + 25 + defaultY) {
		List list = new ArrayList();
		defaultTooltip(list, ItemPrices.IRON_INGOT, "Iron Ingot");
		this.drawTooltipText(list, mouseX, mouseY, fontRendererObj);
	}

	if(mouseX > boxX + 100 && mouseX < boxX + 100 + defaultX && mouseY > boxY + 50 && mouseY < boxY + 50 + defaultY) {
		List list = new ArrayList();
		defaultTooltip(list, ItemPrices.REDSTONE, "Redstone");
		this.drawTooltipText(list, mouseX, mouseY, fontRendererObj);
	}
}

public void mouseClicked(int mouseX, int mouseY, int which) {
    int boxX = (this.width - this.xSize) / 2 + 25;
    int boxY = (this.height - this.ySize) / 2 + 25;

	int defaultX = 16;
	int defaultY = 16;

	if(!this.canDisplayPurchase) {

		/* Left Side */
		if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
			openPurchase(ItemPrices.EMERALD, Items.emerald);
		}

		if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY + 25 && mouseY < boxY + 25 + defaultY) {
			openPurchase(ItemPrices.GOLD_INGOT, Items.gold_ingot);
		}

		if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY + 50 && mouseY < boxY + 50 + defaultY) {
			openPurchase(ItemPrices.QUARTZ, Items.quartz);
		}

		/* Right Side */
		if(mouseX > boxX + 100 && mouseX < boxX + 100 + defaultX && mouseY > boxY && mouseY < boxY + defaultY) {
			openPurchase(ItemPrices.DIAMOND, Items.diamond);
		}

		if(mouseX > boxX + 100 && mouseX < boxX + 100 + defaultX && mouseY > boxY + 25 && mouseY < boxY + 25 + defaultY) {
			openPurchase(ItemPrices.IRON_INGOT, Items.iron_ingot);
		}

		if(mouseX > boxX + 100 && mouseX < boxX + 100 + defaultX && mouseY > boxY + 50 && mouseY < boxY + 50 + defaultY) {
			openPurchase(ItemPrices.REDSTONE, Items.redstone);
		}
	}

	super.mouseClicked(mouseX, mouseY, which);
}

public void renderItemOnGui(Item item, int mulX, int mulY) {
        int k = (this.width - this.xSize) / 2 + 25;
        int l = (this.height - this.ySize) / 2 + 25;
        
	GL11.glPushMatrix();

	RenderHelper.enableGUIStandardItemLighting();
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glEnable(GL11.GL_COLOR_MATERIAL);
        GL11.glEnable(GL11.GL_LIGHTING);
        
        //GL11.glScalef(2.00F, 2.00F, 2.00F);
        
        renderedItem.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), new ItemStack(item), k + mulX, l + mulY);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDepthMask(true);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        RenderHelper.disableStandardItemLighting();
        
        GL11.glPopMatrix();
}

private void drawPurchaseOverlay() {
	//GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

	int xSize = 80;
	int ySize = 62;

        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;

	mc.getTextureManager().bindTexture(crewShopPurchase);

	this.drawTexturedModalRect(k + 44, l + 34, 0, 0, this.xSize, this.ySize);

	this.renderItemOnGui(this.item, 50, 36);

	//this.drawCenteredString(mc.fontRenderer, "Purchase Item", k + 84, l + 40, 0xFFFFFF);

	//RenderHelper.enableGUIStandardItemLighting();
        //GL11.glDisable(GL11.GL_LIGHTING);
        //GL11.glEnable(GL12.GL_RESCALE_NORMAL);
       //GL11.glEnable(GL11.GL_COLOR_MATERIAL);
        //GL11.glEnable(GL11.GL_LIGHTING);
        
        //GL11.glScalef(2.00F, 2.00F, 2.00F);
        
        //renderedItem.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), new ItemStack(itemForRender), k + 25, l + 25);
        //GL11.glDisable(GL11.GL_LIGHTING);
        //GL11.glDepthMask(true);
        //GL11.glEnable(GL11.GL_DEPTH_TEST);
        
        //GL11.glPopMatrix();
}

private void openPurchase(int itemPrice, Item itemToDrop) {
	this.canDisplayPurchase = true;
	slider.visible = true;
	buy.visible = true;
	exit.visible = true;
	this.itemPrice = itemPrice;
	this.item = itemToDrop;
	slider.maxValue = item.getItemStackLimit();
	slider.updateSlider();
	next.enabled = false;
	exitGui.enabled = false;
}

public void closePurchase() {
	canDisplayPurchase = false;
	slider.visible = false;
	buy.visible = false;
	exit.visible = false;
	slider.setValue(1D);
	slider.maxValue = 64;
	slider.updateSlider();
	this.item = null;
	next.enabled = true;
	exitGui.enabled = true;
}

private void drawTooltipText(List list, int mouseX, int mouseY, FontRenderer fr) {
	if(!this.canDisplayPurchase) {
		this.drawHoveringText(list, mouseX, mouseY, fr);
	}else {
		return;
	}
}

private void defaultTooltip(List list, int itemP, String itemN) {
	list.add(EnumChatFormatting.YELLOW + itemN);
	list.add(EnumChatFormatting.AQUA + "Price: " + getCost(itemP));
}

private boolean canPlayerBuy(int cost) {
	if(ExtendedPlayer.get(this.mc.thePlayer).getCrewCoinAmount() >= cost) {
		return true;
	}else {
		return false;
	}
}

private String getCost(int itemPrice) {
	if(ExtendedPlayer.get(this.mc.thePlayer).getCrewCoinAmount() >= itemPrice) {
		return EnumChatFormatting.GREEN.toString() + itemPrice;
	}else {
		return EnumChatFormatting.RED.toString() + itemPrice;
	}
}

public void keyTyped(char character, int par1) {
	if(character == Keyboard.KEY_E) {
		this.mc.displayGuiScreen((GuiScreen)null);
	}

	super.keyTyped(character, par1);
}

public boolean doesGuiPauseGame() {
	return false;
}
}

 

It's a bit messy because I am still testing some things within it. I mainly just call "this.drawHoveringText()" from the GuiScreen class. Maybe they did something wrong?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Well... that worked. I feel like the more difficult side of things when it comes to mod creation I understand and overcome. But the simplistic things I overlook and have to post a thread on it. xD Thanks to both of you. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Here is my configuration: % java -version java version "18.0.2" 2022-07-19 Java(TM) SE Runtime Environment (build 18.0.2+9-61) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing) forge-1.19-41.1.0-mdk on macOS Monterey 12.5 I ran the command: ./gradlew genEclipseRuns and was hoping it will generate the Eclipse project files for me. The run log is at https://gist.github.com/arun-gupta/06b983a6976b4c0a0f510d0dc225ddd3 and the generated directory structure is at https://gist.github.com/arun-gupta/3f5bfc70ec5d3d903b0f97d42840abda. In previous versions (1.12-ish), it used to generate an eclipse directory but 1.19 does not seem to have it. I tried opening the top-level forge directory but Eclipse does not recognize it as a project as well. How do I open this project in Eclipse now?  
    • I didn't put in credentials, I used it only for testing installing forge. But still the problem mentioned above.
    • I am trying to use Forge 1.18.2, I have checked my firewall, redownloaded Forge, deleted the fml.toml file (which keeps reappearing) and looked at countless help pages. I am just trying to download and use forge so that I can play with my friends and it will not download. It tells me there may be an issue with the Java runtime config and that the exit code is one, and I have copied the exit code.   
    • Okay, i think i understand but im getting issues, i create another packet to sync entity to another players like this package com.naim.belloto.networking.packet; import com.naim.belloto.networking.handler.ClientSyncHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; import java.util.Objects; import java.util.function.Supplier; public class ClientSyncPacket { public ClientSyncPacket() { } public ClientSyncPacket(FriendlyByteBuf buf) { } public void toBytes(FriendlyByteBuf buf) { } public boolean handle(Supplier<NetworkEvent.Context> ctx) { NetworkEvent.Context context = ctx.get(); context.enqueueWork(() -> { assert Minecraft.getInstance().player != null; int idplayer = Minecraft.getInstance().player.getId(); DistExecutor.unsafeCallWhenOn(Dist.CLIENT,() -> () -> ClientSyncHandler.handlePacket(ctx, idplayer)); }); return true; } } And in the handler: public class ClientSyncHandler { public static boolean handlePacket(Supplier<NetworkEvent.Context> ctx, int idPlayer) { Minecraft.getInstance().level.getEntity(idPlayer); return true; } } But is not working :// 
  • Topics

×
×
  • Create New...

Important Information

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