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

Remove Name Tag Mod


DrOlive
 Share

Recommended Posts

Hey Minecraft Forge Modders! I've been trying to make a quick simple mod that allows players to remove their name tag so no other players can see it, but I can't seem to find out how to go about doing this. If somebody could help me do this it would be great! I'm not asking for a full written out code for me, just some pointers to help get me going. Thanks!

Link to comment
Share on other sites

Ok so if I were to have a key binding class like this:

package drolive.nonametags;

import java.util.EnumSet;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

class NoNameTagsKeyBind extends KeyHandler {

private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);

public NoNameTagsKeyBind(KeyBinding[] keyBindings, boolean[] repeatings) {
	super(keyBindings, repeatings);
}

@Override
public String getLabel() {
	return "Hide";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {



}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

}

@Override
public EnumSet<TickType> ticks() {
	return null;
}

}

How would I cancel RenderLivingEvent.Specials.Pre? Would I have to make another class for my key binding or what?

Link to comment
Share on other sites

Ok I made a class for my key binding

package drolive.nonametags;

import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import net.minecraftforge.event.Event;

public class NoNameTagsKeyBindHide {

public void Pre(Specials.Pre event){
	if (event.isCancelable()) {
        event.setCanceled(true);
}
}
}

but how do I make it so when you press the key it cancels Pre, then if you press it again it doesn't cancel it?

Link to comment
Share on other sites

I have my keybindings class and my keybindinghide class without any errors and it show up in the game's control menu, but when I press it in game, nothing happens!

Main Keybinding class:

package drolive.nonametags;

import java.util.EnumSet;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

class NoNameTagsKeyBind extends KeyHandler {

public static boolean cancelPre = false;

private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);

public NoNameTagsKeyBind(KeyBinding[] keyBindings, boolean[] repeatings) {
	super(keyBindings, repeatings);
}

@Override
public String getLabel() {
	return "Hide";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {

	if (cancelPre == false){
		cancelPre = true;
	}
	else cancelPre = false;

}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

}

@Override
public EnumSet<TickType> ticks() {
	return null;
}

}

 

My class for the "hide" keybinding:

package drolive.nonametags;

import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import net.minecraftforge.event.Event;

public class NoNameTagsKeyBindHide {

public void Pre(Specials.Pre event){
	if (event.isCancelable() && NoNameTagsKeyBind.cancelPre == true){
		System.out.println("You are now Hiding!");
        event.setCanceled(true);}
        else if (event.isCancelable() && NoNameTagsKeyBind.cancelPre == false) {
        	event.setCanceled(false);
        	System.out.println("You are not Hiding!");
        }	
   }
}

And yes I did register the key binding in my main class. Anybody know why nothing's happening?

Link to comment
Share on other sites

Oh and also here is my main class:

package drolive.nonametags;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.settings.KeyBinding;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid="NoNameTags", name="NoNameTags", version="0.0.1")
@NetworkMod(clientSideRequired=false, serverSideRequired=false)

public class NoNameTags {

    @Instance("NoNameTags")
    public static NoNameTags instance;
    
    @SidedProxy(clientSide="drolive.nonametags.client.ClientProxy", serverSide="drolive.nonametags.CommonProxy")
    public static CommonProxy proxy;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    }
    
    @EventHandler
    public void load(FMLInitializationEvent event) {
            proxy.registerRenderers();
            
            KeyBinding[] key = {new KeyBinding("Hide", Keyboard.KEY_H)};
            boolean[] repeat = {false};
            KeyBindingRegistry.registerKeyBinding(new NoNameTagsKeyBind(key, repeat));
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {
    }
}

Link to comment
Share on other sites

Yeah I registered the event and everything, but when I load a world it says "You are not hiding!" and it never says anything else no matter how many times I press h.

I feel like my NoNameTagsKeyBindHide class isn't checking if cancelPre changes, but how would I do that?

 

My main class:

package drolive.nonametags;

import java.util.EnumSet;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid="NoNameTags", name="NoNameTags", version="0.0.1")
@NetworkMod(clientSideRequired=false, serverSideRequired=false)

public class NoNameTags {

    @Instance("NoNameTags")
    public static NoNameTags instance;
    
    @SidedProxy(clientSide="drolive.nonametags.client.ClientProxy", serverSide="drolive.nonametags.CommonProxy")
    public static CommonProxy proxy;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    }
    
    @EventHandler
    public void load(FMLInitializationEvent event) {
            proxy.registerRenderers();
            KeyBinding[] key = {new KeyBinding("Hide", Keyboard.KEY_H)};
            boolean[] repeat = {true};
            KeyBindingRegistry.registerKeyBinding(new NoNameTagsKeyBind(key, repeat));
            MinecraftForge.EVENT_BUS.register(new NoNameTagsKeyBindHide());
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {
    }
}

 

My keybind class:

package drolive.nonametags;

import java.util.EnumSet;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

class NoNameTagsKeyBind extends KeyHandler {

private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);

public static boolean cancelPre = false;

public NoNameTagsKeyBind(KeyBinding[] keyBindings, boolean[] repeatings) {
	super(keyBindings, repeatings);
}

@Override
public String getLabel() {
	return "Hide";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {

	cancelPre = (!cancelPre);

}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

}

@Override
public EnumSet<TickType> ticks() {
	return null;
}

}

My keybind hide class:

package drolive.nonametags;

import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import net.minecraftforge.event.Event;
import net.minecraftforge.event.ForgeSubscribe;

public class NoNameTagsKeyBindHide {

public int makeItStop = 0;

@ForgeSubscribe(receiveCanceled=true)
public void Pre(Specials.Pre event){
	if (NoNameTagsKeyBind.cancelPre == true && makeItStop == 1){
		event.setCanceled(true);
		System.out.println("You are now hiding!");
		makeItStop = makeItStop - 1;
        }
    else if (NoNameTagsKeyBind.cancelPre == false && makeItStop == 0) {
    	event.setCanceled(false);
        System.out.println("You are not hiding!");
        makeItStop = makeItStop + 1;
        }	
   }
}

Note: I added the int makeItStop because before when I would load a world, it would spam the console with never ending "You are not hiding!"

Link to comment
Share on other sites

Am I supposed to call the boolean in a different way?

what other way would there be

 

if(NoNameTagsKeyBind.cancelPre == true) ?

if(NoNameTagsKeyBind.cancelPre != false) ?

if(NoNameTagsKeyBind.cancelPre) ?

if(NoNameTagsKeyBind.cancelPre || false) ?

 

 

...all those do the same thing ...

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

*main class*
boolean[] repeat = {true};

Set to false to stop the repeating keybind. ;)

 

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
	if(tickEnd)//so it doesn't fire twice
	cancelPre = (!cancelPre);

}

Link to comment
Share on other sites

*main class*
boolean[] repeat = {true};

Set to false to stop the repeating keybind. ;)

 

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
	if(tickEnd)//so it doesn't fire twice
	cancelPre = (!cancelPre);

}

I tried all this and it still repeats if I dont use makeItStop. And it still wont work in game. :(

Link to comment
Share on other sites

Nevermind it doesn't stop repeating without makeItStop...

Also I tried it in a LAN world and it said "You are now hiding!" but it didn't remove the name tag, know why?

Main Class:

package drolive.nonametags;

import java.util.EnumSet;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid="NoNameTags", name="NoNameTags", version="0.0.1")
@NetworkMod(clientSideRequired=false, serverSideRequired=false)

public class NoNameTags {

    @Instance("NoNameTags")
    public static NoNameTags instance;
    
    @SidedProxy(clientSide="drolive.nonametags.client.ClientProxy", serverSide="drolive.nonametags.CommonProxy")
    public static CommonProxy proxy;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    }
    
    @EventHandler
    public void load(FMLInitializationEvent event) {
            proxy.registerRenderers();
            KeyBinding[] key = {new KeyBinding("Hide", Keyboard.KEY_H)};
            boolean[] repeat = {false};
            KeyBindingRegistry.registerKeyBinding(new NoNameTagsKeyBind(key, repeat));
            MinecraftForge.EVENT_BUS.register(new NoNameTagsKeyBindHide());
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {
    }
}

Key Bind class:

package drolive.nonametags;

import java.util.EnumSet;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

class NoNameTagsKeyBind extends KeyHandler {

private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);

public static boolean cancelPre;

public NoNameTagsKeyBind(KeyBinding[] keyBindings, boolean[] repeatings) {
	super(keyBindings, repeatings);
}

@Override
public String getLabel() {
	return "Hide";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
	if(tickEnd){
	cancelPre = !cancelPre;
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

}

@Override
public EnumSet<TickType> ticks() {
	return tickTypes;
}

}

KeyBindHide class:

package drolive.nonametags;

import net.minecraft.src.ModLoader;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import net.minecraftforge.event.Event;
import net.minecraftforge.event.ForgeSubscribe;

public class NoNameTagsKeyBindHide {

public int makeItStop = 0;

@ForgeSubscribe(receiveCanceled=true)
public void Pre(Specials.Pre event){
	if (NoNameTagsKeyBind.cancelPre == true && makeItStop == 1){
		event.setCanceled(true);
		ModLoader.getMinecraftInstance().thePlayer.addChatMessage("You are now hiding!");
		makeItStop = makeItStop - 1;
        }
    else if (NoNameTagsKeyBind.cancelPre == false && makeItStop == 0) {
    	event.setCanceled(false);
    	ModLoader.getMinecraftInstance().thePlayer.addChatMessage("You are not hiding!");
        makeItStop = makeItStop + 1;
        }	
   }
}

Link to comment
Share on other sites

Nevermind it doesn't stop repeating without makeItStop...

Of course, my fixes only stop repeats from the input key, not from the event. The event will continue fire endlessly while there is living entities to render (that is, until world is closed).

For now, we have it so cancelPre boolean is only changed once each time you press the key.

We should add so only players have their name tags removed, right ?

So let's do only

if(event.entity instanceof EntityPlayer)
{
event.setCanceled(true);
}

Oh by the way, stop using ModLoader.

Link to comment
Share on other sites

I did just what you said but when I press the key in game, nothing happens, it wont even print a text. I also tried using it like this, but still no luck:

if(NoNameTagsKeyBind.cancelPre == true && event.entity instanceof EntityPlayer)

Is this where I'm supposed to put the code?

package drolive.nonametags;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.src.ModLoader;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials;
import net.minecraftforge.event.Event;
import net.minecraftforge.event.ForgeSubscribe;

public class NoNameTagsKeyBindHide {

@ForgeSubscribe(receiveCanceled=true)
public void Pre(Specials.Pre event){
	if(event.entity instanceof EntityPlayer){
        event.setCanceled(true);
        }

Link to comment
Share on other sites

Well I got it to cancel the event by using isCanceled(), but it turns out that cancelling Specials.Pre only makes everyone else's names disappear, not the player's who used the command... How would I make it so only the player's disappears from everyone else's view?

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

    • Those three errors are what is making the IRCE return null and kicking them. Not sure what more the debug log will give but at least you know for sure the issue is happening when those three functions try to run. So process of deduction.
    • [Info: 2022-01-23 01:21:36.6133870: Xal.lib(0)] XAL: <<< Xal::Auth::InMemoryXboxTokenCache::GetTokenInternal (000085C2AB6FB370) [Info: 2022-01-23 01:21:36.6159390: Xal.lib(0)] XAL: [op 285139008] Refresh Xtoken running with user: true. [Info: 2022-01-23 01:21:36.6166694: Xal.lib(0)] XAL: [op 285139008] Operation RefreshXtoken is starting [Info: 2022-01-23 01:21:36.6176117: Xal.lib(0)] XAL: [op 285139008]     with CV '9/gCxFwybu+GIYtd.14.95' [Info: 2022-01-23 01:21:36.6179699: Xal.lib(0)] XAL: [op 285139008] RefreshXtoken token fetch started. [Info: 2022-01-23 01:21:36.6560585: NetQueue.cpp(601)] NetQueue: No connection available for https://sentry.io/api/2703928/store/ [Error: 2022-01-23 01:21:36.6562804: SentryAPI.cpp(124)] 0 No network connection available [Info: 2022-01-23 01:21:36.6565318: NetQueue.cpp(601)] NetQueue: No connection available for xsts.auth.xboxlive.com [Error: 2022-01-23 01:21:36.8822268: Xal.lib(0)] XAL: Http request 0C18B300 failed with 0x89235006, system error code 0, message:  [Warning: 2022-01-23 01:21:36.8868846: Xal.lib(0)] XAL: [op 285139008] Operation RefreshXtoken failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8885727: Xal.lib(0)] XAL: [op 295548488] Operation GetXtoken failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8968640: Xal.lib(0)] XAL: [op 258947712] Operation GetTokenAndSignature failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8993100: Xal.lib(0)] XAL: GetTokenAndSignature for presence heartbeat failed with Network error (0x89235106)
    • Did you ever find a resolution?  I know that io.netty.util.IllegalReferenceCountException: refCnt: 0 is used as a way to check/validate functions.  I have yet to understand where there is "0" count. We don't have the issue ever on Val 3 only issue that arrises there is.. lets not go there. Anyway I was curious if you had any info in your research, thanks again!
    • I added it like this main private void doClientStuff(final FMLClientSetupEvent event) { event.enqueueWork(() -> { OverlayRegistry.registerOverlayBelow(ForgeIngameGui.FOOD_LEVEL_ELEMENT , "Mana", new ManaOverlay()); }); } But it's not working.   I feel that you don't understand about main... I'll try to find it.
    • Mc Version: 1.17.1 Forge: 37.1.1 Eclipse: 2021-06 new BlockItem(BlockInit.COMPRESSED_SOULS_BLOCK.get(), new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))   When I hover over the line, eclipse says that the constructer BlockItem(Block, Item) is not defined
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.