So I typically create a new package called handlers. In that package I create a class file, call it whatever you want, maybe ArmorEventHandler.
Make sure you register the class like it says in the tutorial. It will run the onArmorEvent function whenever the SetArmorModel event occurs. BTW, that event by canceling it, causes the armor to simply not be rendered, hence it appears to be invisible.
I really would recommend you mod in at least 1.7.10, as many of the events that are so helpful, did not exist in 1.6.4. Although that isn't the problem here. I think it used a different syntax for this, try:
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
Alright so I registered it in my preInit but the armor still isn't turning invisible, just to clarify, I'm trying to make it so that I'm wearing a certain armor and that armor will turn me invisible and any other armor worn with it
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
The armor adds the potion effect but when I put on other armor they are still visible but even if I try and use a potion of invisibility it still doesn't render the armor invisible
Does anyone know how to make armor disappear along with the player with the invisibility effect?
So if you don't care what type of armor is being worn, you can use this event:
@SubscribeEvent
public void onArmorEvent(SetArmorModel event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer) {
if (((EntityPlayer) event.entity).isInvisible())
event.result = -1;
}
}
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Where should I add this code to? The armor class?
If you've never used events before, then read this:
http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2195105-a-coherent-guide-to-minecraft-forge-events
The code goes in an event handler, not the armor class.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Okay, I kinda understand. But I have one more question, where do you access the EventHandler class/ create Eventhandler class?
So I typically create a new package called handlers. In that package I create a class file, call it whatever you want, maybe ArmorEventHandler.
Make sure you register the class like it says in the tutorial. It will run the onArmorEvent function whenever the SetArmorModel event occurs. BTW, that event by canceling it, causes the armor to simply not be rendered, hence it appears to be invisible.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
It say that SubscribeEvent cannot be resolved to a type.
(Here is my code)
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.client.event.RenderPlayerEvent.SetArmorModel;
public class ArmorHandler {
@SubscribeEvent
public void onArmorEvent(SetArmorModel event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer) {
if (((EntityPlayer) event.entity).isInvisible())
event.result = -1;
}
}
}
You need this import:
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
I think you do a Ctrl + Shift + O shortcut with the cursor on "SubscribeEvent" to get Eclipse to automatically add the import for you.
I always hover the mouse pointer over the item that has the error and select from the recommended fixes.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
When I do that, it says that it cannot be resolved. Do I need to add it to my code?
Yes, add the import I mentioned to your code in the ArmorHandler class file.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
I don't think you understand, the import cannot be resolved.
Error: The import cpw.mods.fml.common.eventhandler.SubscribeEvent cannot be resolved.
Oh, I keep forgetting you are doing 1.6.4.
I really would recommend you mod in at least 1.7.10, as many of the events that are so helpful, did not exist in 1.6.4. Although that isn't the problem here. I think it used a different syntax for this, try:
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
It still isn't working.
There are no errors in the code, but ill put it here:
package handlers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.client.event.RenderPlayerEvent.SetArmorModel;
import cpw.mods.fml.common.Mod.EventHandler;
public class ArmorHandler {
@EventHandler
public void onArmorEvent(SetArmorModel event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer) {
if (((EntityPlayer) event.entity).isInvisible())
event.result = -1;
}
}
}
Also, does it matter where the handler package is(it is currently in my src folder)
Find a basic tutorial on modding. Normally with a package handlers, it would be in the src/main/java/handlers folder.
Also, you can add:
system.println("the SetArmorModel event fired");
inside the if statement to see if it is running. Another way to see, is to debug the mod. Set a breakpoint inside the event.
It is probably never running, maybe you forgot to register it?
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
how do you register it? I'm stumped on that part
In the tutorial, he says: "you can add MinecraftForge.EVENT_BUS.register(new EventHandler()); to the preInit method in your main mod class."
So for yours, in you main mod file, where you have this method, like so:
@EventHandler
public void preInit(FMLPreInitializationEvent event){
MinecraftForge.EVENT_BUS.register(new ArmorHandler());
}
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Okay thanks.
Alright so I registered it in my preInit but the armor still isn't turning invisible, just to clarify, I'm trying to make it so that I'm wearing a certain armor and that armor will turn me invisible and any other armor worn with it
Like I said, the code I gave you will be for any armor, if you have the invisible potion in effect.
So you still need the potion, so I assume you are taking that?
Also add the println or debug it to see if the code is actually running.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
The armor adds the potion effect but when I put on other armor they are still visible but even if I try and use a potion of invisibility it still doesn't render the armor invisible