Jump to content

Recommended Posts

Posted (edited)

I have made an overlay gui with some information of the player but when you hover over an entity it dissapears.

InfoOverlay.class:

package com.ptsmods.morecommands.miscellaneous;

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

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.EnumSkyBlock;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class InfoOverlay extends Gui {

	private Minecraft mc;
	
	public InfoOverlay() {
		this.mc = Minecraft.getMinecraft();
		this.zLevel = Float.MAX_VALUE;
		try {
			Reference.loadInfoOverlayConfig();
		} catch (IOException e) {
			e.printStackTrace();
		}
		drawStrings(parseInfoOverlayConfig(Reference.getInfoOverlayConfig()).toArray(new String[0]));
	}
	
	private void drawString(String string, int row) {
		int defaultHeight = 2;
		int defaultWidth = 2;
		if (Reference.setVariables.containsKey("defaultHeight") && Reference.isInteger(Reference.setVariables.get("defaultHeight"))) defaultHeight = Integer.parseInt(Reference.setVariables.get("defaultHeight"));
		if (Reference.setVariables.containsKey("defaultWidth") && Reference.isInteger(Reference.setVariables.get("defaultWidth"))) defaultWidth = Integer.parseInt(Reference.setVariables.get("defaultWidth"));
		drawString(this.mc.fontRenderer, string, defaultWidth, row*10 + defaultHeight, Integer.parseInt("FFFFFF", 16));
	}
	
	private void drawStrings(String... strings) {
		for (int x = 0; x < strings.length; x++) {
			drawString(strings[x], x);
		}
	}
	
	private TextFormatting getRandomColor() {
		if (Reference.Random.randInt(101) == 0) {
			Reference.lastColor = Reference.getRandomColor("WHITE");
		}
		return Reference.lastColor;
	}
	
    private List<String> parseInfoOverlayConfig(List<String> config) {
    	Minecraft mc = Minecraft.getMinecraft();
    	List<String> output = new ArrayList<String>();
    	Reference.setVariables = new HashMap<String, String>();
    	try {
	    	for (String line : config) {
	    		if (line.startsWith("var ")) {
	    			if (line.split(" ").length == 4) Reference.setVariables.put(line.split(" ")[1], line.split(" ")[3]);
	    		} else {
	    			line = line.replaceAll("\\{playerName\\}", mc.player.getName())
		    		.replaceAll("\\{x\\}", String.format("%f", mc.player.getPositionVector().x))
		    		.replaceAll("\\{y\\}", String.format("%f", mc.player.getPositionVector().y))
		    		.replaceAll("\\{z\\}", String.format("%f", mc.player.getPositionVector().z))
		    		.replaceAll("\\{chunkX\\}", "" + mc.player.chunkCoordX)
		    		.replaceAll("\\{chunkY\\}", "" + mc.player.chunkCoordY)
		    		.replaceAll("\\{chunkZ\\}", "" + mc.player.chunkCoordZ)
		    		.replaceAll("\\{yaw\\}", "" + MathHelper.wrapDegrees(mc.player.rotationYaw))
		    		.replaceAll("\\{pitch\\}", "" + MathHelper.wrapDegrees(mc.player.rotationPitch))
		    		.replaceAll("\\{biome\\}", mc.world.getBiome(mc.player.getPosition()).getBiomeName())
		    		.replaceAll("\\{difficulty\\}", mc.world.getWorldInfo().getDifficulty().name())
		    		.replaceAll("\\{blocksPerSec\\}", String.format("%f", Reference.blocksPerSecond))
		    		.replaceAll("\\{toggleKey\\}", Reference.getKeyBindingByName("toggleOverlay").getDisplayName())
		    		.replaceAll("\\{configFile\\}", new File("config/MoreCommands/infoOverlay.txt").getAbsolutePath().replaceAll("\\\\", "\\\\\\\\")) // replacing 1 backslash with 2 so backslashes actually show
		    		.replaceAll("\\{facing\\}", Reference.getLookDirectionFromLookVec(mc.player.getLookVec()))
		    		.replaceAll("\\{time\\}", Reference.parseTime(FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(mc.player.dimension).getWorldTime() % 24000L, false))
		    		.replaceAll("\\{UUID\\}", mc.player.getUniqueID().toString())
		    		.replaceAll("\\{holding\\}", Reference.getLocalizedName(mc.player.getHeldItemMainhand().getItem()))
		    		.replaceAll("\\{rainbow\\}", "" + getRandomColor())
		    		.replaceAll("\\{easterEgg\\}", ":O, you found the easter egg!")
		    		.replaceAll("\\{xp\\}", "" + mc.player.experienceTotal)
		    		.replaceAll("\\{xpLevel\\}", "" + mc.player.experienceLevel)
		    		.replaceAll("\\{gamemode\\}", FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(mc.player.getName()).interactionManager.getGameType().getName())
		    		.replaceAll("\\{fps\\}", "" + mc.getDebugFPS())
		    		.replaceAll("\\{blockLight\\}", "" + mc.world.getChunkFromBlockCoords(mc.player.getPosition()).getLightFor(EnumSkyBlock.BLOCK, mc.player.getPosition()))
		    		.replaceAll("\\{skyLight\\}", "" + mc.world.getChunkFromBlockCoords(mc.player.getPosition()).getLightFor(EnumSkyBlock.SKY, mc.player.getPosition()))
	    			.replaceAll("\\{lookingAtX\\}", "" + mc.objectMouseOver.getBlockPos().getX())
	    			.replaceAll("\\{lookingAtY\\}", "" + mc.objectMouseOver.getBlockPos().getY())
	    			.replaceAll("\\{lookingAtZ\\}", "" + mc.objectMouseOver.getBlockPos().getZ())
	    			.replaceAll("\\{lookingAt\\}", "" + Reference.getLocalizedName(mc.world.getBlockState(mc.objectMouseOver.getBlockPos()).getBlock()))
	    			.replaceAll("\\{isSingleplayer\\}", "" + FMLCommonHandler.instance().getMinecraftServerInstance().isSinglePlayer());
		    		if (line.equals("") || !line.split("//")[0].equals("")) output.add(line.split("//")[0]);
	    		}
	    	}
    	} catch (NullPointerException e) {}
    	return output;
    }
}

How I render it (in ClientEventHandler.class):

@SubscribeEvent
public void onRenderGui(RenderGameOverlayEvent.Post event) {
	if (event.getType() == ElementType.EXPERIENCE && Reference.isInfoOverlayEnabled()) new InfoOverlay();
}

 

Edited by PlanetTeamSpeak
Added how I render it

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

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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