Bumping your topic a thousand times telling people 'it doesn't work' won't help us at all. Please realize that the only guy who can fix this is YOU and you only, this is your problem not ours. We can merely help you and if you want that then give us some more information about what doesn't work and why it doesn't work.
I can't TELL what's wrong. If I could, then this topic wouldn't exist! Plus, I've posted my code. Even though it may be sloppy, since you're such an expert and I'm such a noob, then why haven't you figured it out yet? Anway, since I'm a nice person, here is my code:
So you can't identify the problem, but you want to fix it? That means that you don't know how to debug your code, you can't solve your own problems, you want other people to do it for you and you're not being a nice person right now. (Neither am I but I don't care).
Conclusion: I don't want to help you
A: I don't know if you've heard me say this, but it isn't my code that's the problem. My game only crashed with the first method Bendonnelly1 gave me, which you fixed by giving me that other way to do it. The only problem is that I can't fly! Everything you've given me does not work. You should be able to look at my code, tell me what to put, and tell me where to put it!
B: I've been waiting for a decent answer from you guys for a while now, and am growing agitated.
C: Frankly, I don't care if you help or not, because I bet I can get a clearer answer from coolAlias or Bendonnelly21.
There's a field in the player entity which enables/disables flight.
Item's are updated regularly when in the inventory and there's a field in the player class for which item is currently held in hand.
That's one way to do it.
Another way would be to use a tick handler and if the player is holding the correct item, allow flight.
There's a field in the player entity which enables/disables flight.
Item's are updated regularly when in the inventory and there's a field in the player class for which item is currently held in hand.
That's one way to do it.
Another way would be to use a tick handler and if the player is holding the correct item, allow flight.
I have tried both of your methods and neither one works.
I have tried both of your methods and neither one works.
The method works,
your implementation of them however is flawed somehow then
there are probably other ways to do this as well, but those two I have done in the past and I can't think of other methods on the spot now.
Anyways seen from a logical standpoint both ways should still work in the recent updates.
Is the problem related to the field for player flight not working?
Take a look into how the creative command gives flight then, that should give a clue.
But we did just change the field on the flight speed variables when we did add flying from having armor equipped.
Edit:
I can see you have tried a few times, so I'll just do it like this:
So is it solved? Does this all work? Also can someone link me to a good TickHandler/EventHandler tutorial? Thanks
I'd say it's solved
Personally, I prefer EventHandler because it gives you so much more control over timing as well as more parameters to work with. It's very simple to make one:
Step 1: Create EventHandler class - yes, it's this simple
public class EventHandler
{
}
Step 2: Register your event handler class to EVENT_BUS either in 'load' or 'postInit' methods in your main mod
@EventHandler
public void load(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
Step 3: Look through MinecraftForge event types for ones you want to use and add them to your EventHandler
// in your EventHandler class - the name of the method doesn't matter; the Event type parameter is what's important
@ForgeSubscribe
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
// This event has an Entity variable, access it like this:
event.entity;
// do something to player every update tick:
if (event.entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entity;
ItemStack heldItem = player.getHeldItem();
if (heldItem != null && heldItem.itemID == Item.arrow.itemID) {
player.capabilities.allowFlying = true;
}
else {
player.capabilities.allowFlying = player.capabilities.isCreativeMode ? true : false;
}
}
If you're ever curious what variables the Event stores, type ' event. ' in Eclipse and it will bring up a menu of all the methods and variables. Or go to the implementation by ctrl-clicking on the class name.
There are lots of event types. Here are some examples:
ArrowNockEvent
EntityConstructing
EntityJoinWorldEvent
LivingDropsEvent
LivingFallEvent
LivingJumpEvent
LivingHurtEvent
Every time one of these things happens in the game, it is posted as an event. If you made a method in EventHandler for that Event Type, it is effectively 'listening' in and will be called whenever that event is posted.
A template for whatever event method you want to make. Name it whatever you want, but use the correct Event Type from above.
@ForgeSubscribe
public void methodName(EventType event)
{
// do whatever you want here
}
If you need a more in-depth explanation, I just finished a tutorial on it here.
....Your tutorials... Beautiful... Thank you so much. You should put all your tutorials in one post though. It makes it easier to find them without going through multiple pages. Thanks again
I'd say it's solved
Personally, I prefer EventHandler because it gives you so much more control over timing as well as more parameters to work with. It's very simple to make one:
Step 1: Create EventHandler class - yes, it's this simple
public class EventHandler
{
}
Step 2: Register your event handler class to EVENT_BUS either in 'load' or 'postInit' methods in your main mod
@EventHandler
public void load(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
Step 3: Look through MinecraftForge event types for ones you want to use and add them to your EventHandler
// in your EventHandler class - the name of the method doesn't matter; the Event type parameter is what's important
@ForgeSubscribe
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
// This event has an Entity variable, access it like this:
event.entity;
// do something to player every update tick:
if (event.entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entity;
ItemStack heldItem = player.getHeldItem();
if (heldItem != null && heldItem.itemID == Item.arrow.itemID) {
player.capabilities.allowFlying = true;
}
else {
player.capabilities.allowFlying = player.capabilities.isCreativeMode ? true : false;
}
}
If you're ever curious what variables the Event stores, type ' event. ' in Eclipse and it will bring up a menu of all the methods and variables. Or go to the implementation by ctrl-clicking on the class name.
There are lots of event types. Here are some examples:
ArrowNockEvent
EntityConstructing
EntityJoinWorldEvent
LivingDropsEvent
LivingFallEvent
LivingJumpEvent
LivingHurtEvent
Every time one of these things happens in the game, it is posted as an event. If you made a method in EventHandler for that Event Type, it is effectively 'listening' in and will be called whenever that event is posted.
A template for whatever event method you want to make. Name it whatever you want, but use the correct Event Type from above.
@ForgeSubscribe
public void methodName(EventType event)
{
// do whatever you want here
}
If you need a more in-depth explanation, I just finished a tutorial on it here.
Well, I'd say it's not. I haven't figured it out yet. I don't have an event handler, only a tick handler. Please look back at my code and see if I'm doing something wrong. Thanks.
Well, I'd say it's not. I haven't figured it out yet. I don't have an event handler, only a tick handler. Please look back at my code and see if I'm doing something wrong. Thanks.
Oh sorry then. I thought Mazetar's reply fixed it for you? If not, are you sure your TickHandler method is being called? I know someone mentioned println before, but try putting this in your onPlayerTick method:
System.out.println("[TICK HANDLER] Player tick");
See if it prints a bunch of times to the console when you play the game. If so, did you try Mazetar's code instead of yours? Last I saw you were using something like
if (boots.getItem() == DarkMagicMod.smolderingboots)
I don't think the Item class handles '==' operator very well, and it's also less processor-heavy to just check the integer 'itemID' like Mazetar did above:
Try that if you haven't already and then re-post your code (yes, I know you've posted it a bajillion times already, but we need the latest version of it to help you).
Well if 'printing it didn't do anything' then that means your method isn't being called, so no matter what you put in there nothing will happen.
Did you register your tick handler class from your main mod?
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
TickRegistry.registerTickHandler(new YourTickHandler(), Side.SERVER);
}
Well if 'printing it didn't do anything' then that means your method isn't being called, so no matter what you put in there nothing will happen.
Did you register your tick handler class from your main mod?
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
TickRegistry.registerTickHandler(new YourTickHandler(), Side.SERVER);
}
Yes. I've already said that on this topic... *sigh* I'll never find the answer...
Well if 'printing it didn't do anything' then that means your method isn't being called, so no matter what you put in there nothing will happen.
Did you register your tick handler class from your main mod?
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
TickRegistry.registerTickHandler(new YourTickHandler(), Side.SERVER);
}
Everything else in there works... My particles spawn, and I have the potion effects.
Try removing these two lines, or at least putting them somewhere else besides between your 'if (armor checks)' statement and its bracket. Anyways, as they are, these lines don't do anything.
System.out.println("(TICK HANDLER) Player tick");
player.capabilities.allowFlying = true;
Does your console ever print that line? I'm willing to bet you it doesn't. That should tell you where to look for your problem, in the preceding 'if' statements. So let's continue our debugging experience so you can learn how to figure this stuff out on your own.
Since your if statement checking that armor ids are matching isn't working, adding println beforehand to check your variables will show you what the problem is:
ItemStack boots = player.getCurrentArmor(0);
if (boots != null) {
System.out.println("[TICK] Current boots id = " + boots.itemID);
System.out.println("[TICK] Divine boots id = " + DarkMagicMod.divineboots.itemID);
}
ItemStack legs = player.getCurrentArmor(1);
if (legs != null) {
System.out.println("[TICK] Current legs id = " + legs.itemID);
System.out.println("[TICK] Divine legs id = " + DarkMagicMod.divinelegs.itemID);
}
ItemStack chest = player.getCurrentArmor(2);
if (chest != null) {
System.out.println("[TICK] Current chest id = " + chest.itemID);
System.out.println("[TICK] Divine chest id = " + DarkMagicMod.divinechest.itemID);
}
ItemStack helm = player.getCurrentArmor(3);
if (helm != null) {
System.out.println("[TICK] Current helm id = " + helm.itemID);
System.out.println("[TICK] Divine helm id = " + DarkMagicMod.divinehelm.itemID);
}
Try that and see if you can figure out the answer for yourself. Using println is a powerful debugging tool that, when used properly, will allow you to figure out the problem much more quickly on your own than anyone on the forums can. It will save everyone a lot of time. So please use it.
If you still need the answer, here it is:
This is from vanilla ItemArmor:
/**
* Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots
*/
public final int armorType;
Now look at the values you use to get your armor pieces
Try removing these two lines, or at least putting them somewhere else besides between your 'if (armor checks)' statement and its bracket. Anyways, as they are, these lines don't do anything.
B: I've been waiting for a decent answer from you guys for a while now, and am growing agitated.
C: Frankly, I don't care if you help or not, because I bet I can get a clearer answer from coolAlias or Bendonnelly21.
Item's are updated regularly when in the inventory and there's a field in the player class for which item is currently held in hand.
That's one way to do it.
Another way would be to use a tick handler and if the player is holding the correct item, allow flight.
The method works,
your implementation of them however is flawed somehow then
there are probably other ways to do this as well, but those two I have done in the past and I can't think of other methods on the spot now.
Anyways seen from a logical standpoint both ways should still work in the recent updates.
Is the problem related to the field for player flight not working?
Take a look into how the creative command gives flight then, that should give a clue.
But we did just change the field on the flight speed variables when we did add flying from having armor equipped.
Edit:
I can see you have tried a few times, so I'll just do it like this:
That's from our TickHandler.
Youtube Channel : http://www.youtube.com/user/ZCProductions211
I'd say it's solved
Personally, I prefer EventHandler because it gives you so much more control over timing as well as more parameters to work with. It's very simple to make one:
Step 1: Create EventHandler class - yes, it's this simple
Step 2: Register your event handler class to EVENT_BUS either in 'load' or 'postInit' methods in your main mod
Step 3: Look through MinecraftForge event types for ones you want to use and add them to your EventHandler
If you're ever curious what variables the Event stores, type ' event. ' in Eclipse and it will bring up a menu of all the methods and variables. Or go to the implementation by ctrl-clicking on the class name.
There are lots of event types. Here are some examples:
ArrowNockEvent
EntityConstructing
EntityJoinWorldEvent
LivingDropsEvent
LivingFallEvent
LivingJumpEvent
LivingHurtEvent
Every time one of these things happens in the game, it is posted as an event. If you made a method in EventHandler for that Event Type, it is effectively 'listening' in and will be called whenever that event is posted.
A template for whatever event method you want to make. Name it whatever you want, but use the correct Event Type from above.
If you need a more in-depth explanation, I just finished a tutorial on it here.
Oh sorry then. I thought Mazetar's reply fixed it for you? If not, are you sure your TickHandler method is being called? I know someone mentioned println before, but try putting this in your onPlayerTick method:
See if it prints a bunch of times to the console when you play the game. If so, did you try Mazetar's code instead of yours? Last I saw you were using something like
I don't think the Item class handles '==' operator very well, and it's also less processor-heavy to just check the integer 'itemID' like Mazetar did above:
Try that if you haven't already and then re-post your code (yes, I know you've posted it a bajillion times already, but we need the latest version of it to help you).
Here it is again:
Did you register your tick handler class from your main mod?
Your code is really messy with brackets all over the place it's hard to tell where one 'if' statement begins or ends.
You could use a tickhandler, on r-click set a variable inside the tick handler.
Then if it's false then remove flying, else keep flying on.
aka. on tick:
if it's true
then if is holding item
let fly
else (if not holding item)
remove flying
Does your console ever print that line? I'm willing to bet you it doesn't. That should tell you where to look for your problem, in the preceding 'if' statements. So let's continue our debugging experience so you can learn how to figure this stuff out on your own.
Since your if statement checking that armor ids are matching isn't working, adding println beforehand to check your variables will show you what the problem is:
Try that and see if you can figure out the answer for yourself. Using println is a powerful debugging tool that, when used properly, will allow you to figure out the problem much more quickly on your own than anyone on the forums can. It will save everyone a lot of time. So please use it.
If you still need the answer, here it is:
This is from vanilla ItemArmor:
Now look at the values you use to get your armor pieces
Do you see the problem now?