Jump to content

Recommended Posts

Posted

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!

Posted

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?

Posted

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?

Posted

You can store a boolean for the key pressed.

public boolean alreadyPressed = false;

*in your method*
if(!alreadyPressed)
{
*cancel event
}
else
{
*uncancel event*
}

Posted

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?

Posted

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) {
    }
}

Posted

You didn't register your event.

MinecraftForge.EVENT_BUS.register(new eventClazz());

 

With your event class having an

@ForgeSubscribe(receiveCanceled=true)

above the method.

 

Posted

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

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

Posted

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?

Posted

*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);

}

Posted

*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. :(

Posted

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.

Posted

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

Posted

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.

Posted

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);
        }

Posted

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?

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

    • @Tsuk1 Also, new note, you can use blockbench to make the custom item model for when it is not on the head.   EDIT: Funny story, I am making a mod similar to yours! Mine is called NorseMC.
    • @Nood_dev Could you send a screenshot of your weapon code? Here is the one I made (for a dagger): The specific UUID does not matter, just that it is the same every time, which is why UUID#randomUUID does not work public class DaggerItem extends TieredItem implements Vanishable { protected static final double REACH_MODIFIER = -1.5D; protected final Multimap<Attribute, AttributeModifier> defaultModifiers; protected final UUID BASE_ATTACK_REACH_UUID = UUID.fromString("6fe75b5c-9d1b-4e83-9eea-a1d5a94e8dd5") public DaggerItem(Tier pTier, int pAttackDamageModifier, float pAttackSpeedModifier, Properties pProperties) { super(pTier, pAttackDamageModifier, pAttackSpeedModifier, pProperties); this.attackDamage = (float) pAttackDamageModifier + pTier.getAttackDamageBonus(); ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder(); builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", this.attackDamage, AttributeModifier.Operation.ADDITION)); builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", pAttackSpeedModifier, AttributeModifier.Operation.ADDITION)); // THE ONE YOU WANT: builder.put(ForgeMod.ENTITY_REACH.get(), new AttributeModifier(BASE_ATTACK_REACH_UUID, "Weapon modifier", REACH_MODIFIER, AttributeModifier.Operation.ADDITION)); this.defaultModifiers = builder.build(); } @Override public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot pEquipmentSlot) { return pEquipmentSlot == EquipmentSlot.MAINHAND ? this.defaultModifiers : super.getDefaultAttributeModifiers(pEquipmentSlot); } }
    • https://images.app.goo.gl/1PxFKdxByTgkxvSu6
    • That's what we'll try out. I could never figure out how to recreate the crash, so I'll just have to wait and see.
    • Ok, I updated to the latest version and now the models are visible, the problem now is that the glowing eyes are not rendered nor any texture I render there when using shaders, even using the default Minecraft eyes RenderType, I use entityTranslucent and entityCutout, but it still won't render. Something I noticed when using shaders is that a texture, instead of appearing at the world position, would appear somewhere on the screen, following a curved path, it was strange, I haven't been able to reproduce it again. I thought it could be that since I render the texture in the AFTER ENTITIES stage which is posted after the batches used for entity rendering are finished, maybe that was the reason why the render types were not being drawn correctly, so I tried injecting code before finishing the batches but it still didn't work, plus the model was invisible when using shaders, there was a bug where if I look at the model from above it is visible but if I look at it from below it is invisible. So in summary, models are now visible but glowing eyes and textures are not rendered, that hasn't changed.
  • Topics

×
×
  • Create New...

Important Information

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