Jump to content

Odd display coloring issues


UberAffe

Recommended Posts

I have some hud "mana bar" type things that I am displaying but there are some odd things going on.

1. If I do not have an item in my hand all the bars go black

2. The colors don't look like they do when I pull the values from here

 

This is my hud overlay class

public class CustomHud{

private static LuxinBarRenderer[] bar_Lux;

public CustomHud(){
	Minecraft mc = Minecraft.getMinecraft();
	Collection<ILuxin> luxin = LuxinReg.RegisteredLuxin.values();
	bar_Lux = new LuxinBarRenderer[luxin.size()];
	int index = 0;
	for(ILuxin lux : luxin)
	{
		bar_Lux[index] = new LuxinBarRenderer(lux.GetName(), mc, index, lux.GetColor());
		index++;
	}
}

@SubscribeEvent(receiveCanceled=false)
public void onEvent(RenderGameOverlayEvent.Pre event) {
	renderHud();
}

public void renderHud()
{
	for( LuxinBarRenderer rend : bar_Lux)
		rend.RenderLuxinBar();
}
}

 

This is the LuxinBarRenderer class

public class LuxinBarRenderer {

private final static int BAR_WIDTH = 81;
private final static int BAR_HEIGHT = 9;
private final static int BAR_SPACING = 3;

private String lux;
private Minecraft mc;
private int iteration;
private int[] RGB;

public LuxinBarRenderer(String lux, Minecraft mc, int iteration, int[] RGB)
{
	this.lux = lux;
	this.mc = mc;
	this.iteration = iteration;
	this.RGB = RGB;
}

public void RenderLuxinBar()
{
	EntityPlayerSP player = mc.thePlayer;
	if(player == null)
		return;
	IDrafter drafter = DraftingProvider.get(player);
	if( drafter == null && !(drafter instanceof DefaultDrafter))
		return;
	DefaultDrafter prop = (DefaultDrafter) drafter;
	float avail = prop.GetAvailableLuxin().get(lux);
	float cap = prop.GetMaxLuxin().get(lux);
	float percent = cap / avail;
	GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
	GL11.glPushMatrix();

	GL11.glColor4f((float)RGB[0]/255, (float)RGB[1]/255, (float)RGB[2]/255, .6f);

	int top = BAR_SPACING + (iteration * (BAR_SPACING + BAR_HEIGHT));
	int left = BAR_SPACING;
	GL11.glBegin(GL11.GL_LINE_LOOP);
	{
		GL11.glVertex2i(left, top);
		GL11.glVertex2i(left + BAR_WIDTH, top);
		GL11.glVertex2i(left + BAR_WIDTH, top + BAR_HEIGHT);
		GL11.glVertex2i(left, top + BAR_HEIGHT);
	}
	GL11.glEnd();

	GL11.glColor4f((float)RGB[0]/255, (float)RGB[1]/255, (float)RGB[2]/255, 1f);
	GL11.glBegin(GL11.GL_QUADS);
	{
		int right = left + (int)(new Float(BAR_WIDTH) / percent);
		GL11.glVertex2i(left, top);
		GL11.glVertex2i(left, top + BAR_HEIGHT);
		GL11.glVertex2i(right, top + BAR_HEIGHT);
		GL11.glVertex2i(right, top);			
	}
	GL11.glEnd();
	GL11.glPopMatrix();
	GL11.glPopAttrib();
}
}

 

Any idea what would be cause these issues?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

So I started a new world and the bars were displaying properly.

I created one of my items and then only the luxin type that was used to create that item displayed properly and all of the others changed hue.

 

I then killed a chicken with my item, got 2 feathers and all of the bars display correctly again.

If I throw one or both of the feathers out of my inventory all but that one bar get messed up.

Picking up the feathers fixes the display.

 

I am so confused...

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

When you render, you change GL states - just make sure you are getting back at proper state after rendering.

 

1. When using RenderGameOveralyEvent you ALWAYS need to pick event.type (otherwise you render multiple times per frame) - I suggest: ElementType.ALL.

 

2. RenderGameOveralyEvent has 2 subs - Pre and Post - Pre can be used to cancel renderings of vanilla/other mods, Post should/can be used for your stuff.

Post rendering also (usually) guarantees that you "can't" really messup other renderings since you do it at the end - still - you will probably need to re-set GL attrubutes - to know which to what - see where this event is called and what attrisbs were there before (or you know - just print them).

 

3. Are you sure problem is code in question? (just make sure).

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

Link to comment
Share on other sites

1. So you mean surround all that with an

if(event.type == ElementType.ALL)
{
   //my code
}

 

2. Alright, I'll switch that to post.

 

3. I really have no idea but I cant think of anywhere else in my code that might be causing this. The only other part of my code this touchs is ILuxin#GetColor which for all instances is a single line method that looks like this

public int[] GetColor(){return new int[]{255,0,0,255};}

 

So after applying 1,2 The bars are staying the correct color but when I scroll through the hotbar any time I come across an item the bars completely disappear for a short time(1.5 - 2 seconds). I Also tried removing my receiveCanceled=false but that didn't change anything.

 

is that something that might be getting caused by using ElementType.All?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

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

    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
  • Topics

×
×
  • Create New...

Important Information

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