Jump to content

Recommended Posts

Posted

Hey so I was board and decided to work on my mod pack. So after trying to tweak the boat drops and failing I decided to see if I could make a fly mod. However I don't know if what I tried to de will work and I ran in to a problem with my code and I am not sure what eclips is wanting me to do do fix it it says to insert } but I can't find where it wants me to put the }. Anyways, am I on the right track for making a fly mod with what I have done here?

 

package net.boatDrops.mod;

 

import java.util.Random;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraftforge.event.entity.living.LivingEvent;

 

 

 

public class boatDrop  {

 

@SubscribeEvent

public void giveLeather(LivingEvent evt){

 

if (evt.entity instanceof EntityPlayer){

EntityPlayer player = getPlayer();

 

if(!player.capabilities.isCreativeMode){

 

player.capabilities.allowFlying true

 

 

}

 

 

 

 

 

}

 

}

 

private EntityPlayer getPlayer() {

// TODO Auto-generated method stub

return null;

}}

 

Posted

it should be player.capabilities.allowFlying = true. That's basic java (basic programming in general). I'd use a PlayerTickEvent instead

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

it should be player.capabilities.allowFlying = true. That's basic java (basic programming in general). I'd use a PlayerTickEvent instead

 

I made the changes that you told me to make and I have no errors but I still can't fly in survival mode.

Posted

Did you put ; at the end at your statement?

allowFlying means you still have to double jump to enable fly.

 

You can also use player.capabilities.isFlying = true;

which makes you fly directly.

 

Example from one of my mod that works (it's an item that makes you fly when used).

Just remove the lines with DebugTools.debugMessage (it's custom debugging) :

 

public class obsidianWings extends Item
{
public obsidianWings()
{
	super();
	this.setCreativeTab(CreativeTabs.tabMisc);
}

@Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_)
{
	DebugTools.debugMessage(world.isRemote, "obsidianWings used (onItemUse function)");
	fly(player);
	return true;
}

@Override
public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player)
{
	DebugTools.debugMessage(world.isRemote, "obsidianWings used (onItemRightClick function)");
	fly(player);
	return item;
}

void fly(EntityPlayer player)
{
	player.capabilities.isFlying = !player.capabilities.isFlying;
}	

Posted

getPlayer is returning null. Use evt.player in the playertickevent. And how are you registering the event?

 

This is what the code for the fly event looks like(by the way the reason the name is boatDrop is because I was working on a diffrent mod befor trying to make this one and I didn't rename the files.)

package net.boatDrops.mod;

 

import java.util.Random;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

 

 

 

public class boatDrop  {

 

  @SubscribeEvent

  public void giveLeather(PlayerTickEvent evt){

     

      if (evt.player instanceof EntityPlayer){

       

        if(!evt.player.capabilities.isCreativeMode){

           

            evt.player.capabilities.allowFlying = true;

           

       

        }

       

       

       

       

       

      }

     

  }

 

 

  }

 

 

And I have it registered  like this in my main class.

boatDrop eventFly = new boatDrop();

@EventHandler
public void PreInit(FMLPreInitializationEvent preEvent){

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

}

Posted

Register it with FMLCommonHandler.instance().bus().register() since its an FML event. Also, you don't need to check it evt.player is an instance of EntityPlayer since it always is.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

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



×
×
  • Create New...

Important Information

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