Posted July 28, 201312 yr 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!
July 28, 201312 yr Author I can't figure out how to cancel an event in forge without directly altering it's class, I've been trying to figure this out all morning.
July 28, 201312 yr event.setCanceled(true); how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
July 28, 201312 yr Author 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?
July 28, 201312 yr Author 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?
July 28, 201312 yr You can store a boolean for the key pressed. public boolean alreadyPressed = false; *in your method* if(!alreadyPressed) { *cancel event } else { *uncancel event* }
July 29, 201312 yr Author 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?
July 29, 201312 yr Author 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) { } }
July 29, 201312 yr You didn't register your event. MinecraftForge.EVENT_BUS.register(new eventClazz()); With your event class having an @ForgeSubscribe(receiveCanceled=true) above the method.
July 29, 201312 yr Author 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!"
July 29, 201312 yr if(NoNameTagsKeyBind.cancelPre){ //do stuff ? } how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
July 29, 201312 yr Author if(NoNameTagsKeyBind.cancelPre){ //do stuff ? } Am I supposed to call the boolean in a different way?
July 29, 201312 yr 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-
July 29, 201312 yr Author Yes I know I was just trying to make sense of what you said before. Is the problem that it's not constantly checking if cancelPre is true or false?
July 29, 201312 yr *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); }
July 29, 201312 yr Author *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.
July 29, 201312 yr In your keybinding, you set this field. private EnumSet tickTypes = EnumSet.of(TickType.CLIENT); You should use it here: @Override public EnumSet<TickType> ticks() { return null; } instead of null.
July 29, 201312 yr Author Yeah I know I just noticed that... can't believe I never realized it! And I also got it to stop repeating, thanks so much!
July 29, 201312 yr Author 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; } } }
July 29, 201312 yr 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.
July 30, 201312 yr Author 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); }
July 30, 201312 yr Author 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?
July 30, 201312 yr it should be the same how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
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.