Jump to content

Remove Name Tag Mod


DrOlive

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
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 tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
  • Topics

×
×
  • Create New...

Important Information

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