Jump to content

Armor Flight!


snipermine

Recommended Posts

Not tried this in 1.5.x yet, but in 1.4.7 you could call "player.capabilities.allowFlying = true;" in the on armor update method for the armor, this does have the draw back of not being deactivated when it is removed, so alternatively you can create a player tick handler as follows:


import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class PlayerTickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer) tickData[0]);

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER);
}

@Override
public String getLabel()
{
	return "My Tick Handler";
}



private void playerTick(EntityPlayer player)
{
	//think 0 is helmet, haven't got the setup to try this yet
	player.capabilities.allowFlying = 
			(player.inventory.armorInventory[0] == myHelmet || player.capabilities.isCreativeMode);
}

}

 

then reference this in your common proxy as


import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class CommonProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.SERVER);
}
}

 

and in the client proxy as


import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class ClientProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.CLIENT);
}
}

 

finally in your main mod file (the one with all the annotations (@)) call

proxy.registerHandlers();

 

hope i helped

Link to comment
Share on other sites

Not tried this in 1.5.x yet, but in 1.4.7 you could call "player.capabilities.allowFlying = true;" in the on armor update method for the armor, this does have the draw back of not being deactivated when it is removed, so alternatively you can create a player tick handler as follows:


import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class PlayerTickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer) tickData[0]);

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER);
}

@Override
public String getLabel()
{
	return "My Tick Handler";
}



private void playerTick(EntityPlayer player)
{
	//think 0 is helmet, haven't got the setup to try this yet
	player.capabilities.allowFlying = 
			(player.inventory.armorInventory[0] == myHelmet || player.capabilities.isCreativeMode);
}

}

 

then reference this in your common proxy as


import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class CommonProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.SERVER);
}
}

 

and in the client proxy as


import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class ClientProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.CLIENT);
}
}

 

finally in your main mod file (the one with all the annotations (@)) call

proxy.registerHandlers();

 

hope i helped

I tried it and it wont work

Link to comment
Share on other sites

finally got to a point where i could do some testing on this. I got it to work pretty much first time so nut sure what you're doing wrong, Here's my code: (just make sure you understand what it's doing, far too many people just copy and paste without thinking about it)

 

Main file

@Mod(modid="TestMod", name="TestMod", version = "0.0.0")
@NetworkMod(serverSideRequired=false, clientSideRequired=true)
public class TestMod
{
@Instance("Testmod")
public static TestMod instance;

@SidedProxy(clientSide="mods.testmod.code.client.ClientProxy", serverSide="mods.testmod.code.common.CommonProxy")
public static CommonProxy proxy;

@PreInit
public static void preInit(FMLPreInitializationEvent evt)
{

}

public static Item modHat;

@Init
public static void init(FMLInitializationEvent evt)
{
	modHat = new ItemModArmor(9001, ItemModArmor.ModArmor, 0, 0)
	.setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("modHat");

	LanguageRegistry.addName(modHat, "Mod Hat");

	proxy.registerHandlers();
}

@PostInit
public static void postInit(FMLPostInitializationEvent evt)
{

}
}

 

ItemModArmor

public class ItemModArmor extends ItemArmor
{
public static final EnumArmorMaterial ModArmor = EnumHelper
		.addArmorMaterial("ModArmor", 9001, new int[]{1,2,3,4}, 42);


public ItemModArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial, int par3, int par4)
{
	super(par1, par2EnumArmorMaterial, par3, par4);
}

}

 

PlayerTickHandler

public class PlayerTickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer)tickData[0]);
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{

}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER);
}

@Override
public String getLabel()
{
	return "My_Tick_Handler";
}

private void playerTick(EntityPlayer player)
{
	if (player.inventory.armorInventory[3] != null)
	{
		if (player.inventory.armorInventory[3].getItem() instanceof ItemModArmor)
		{
			player.capabilities.allowFlying = true;

		} 
	}
	else if (!player.capabilities.isCreativeMode)
	{
		player.capabilities.allowFlying = false;
	}

	player.fallDistance = 0F; // does not seem to be working not worked out why yet.
}

}

 

Proxys

public class CommonProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.SERVER);
}
}

 

public class ClientProxy extends CommonProxy
{
@Override
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.CLIENT);
}

}

 

Think that's all of it, didn't bother with textures but the flying works.

if you figure out the fall damage tell me how

 

 

[EDIT]

upon further testing it seems that this method is not working 100% correctly, as it seems that there is some desynchronization between the client and server, meaning that when the player takes damage he will move back to where the server thinks they are. Not sure how to fix this atm but i'll get back to you

Link to comment
Share on other sites

You know there is an easier way to do this right?

 

package O3Bubbles09.testmod.armor;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IArmorTextureProvider;

public class ArmorFlyingArmor extends ItemArmor implements
        IArmorTextureProvider {

    public ArmorFlyingArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial,
            int par3, int par4) {
        super(par1, par2EnumArmorMaterial, par3, par4);
    }

    public void onArmorTickUpdate(World world, EntityPlayer player,
            ItemStack itemStack) {
        
        if(!world.isRemote) {
            player.capabilities.allowFlying = true;
        }
        super.onArmorTickUpdate(world, player, itemStack);
    }
    
    public String getArmorTextureFile(ItemStack itemstack) {
        return null;
    }

}

Link to comment
Share on other sites

I thought of that (see my first reply to this topic), but that doesn't remove the ability once the armor has been removed, so doesn't really have the desired effect.

 

Does work better than my method though, so if a workaround for this exists then use this. (but the if(!world.isRemote) is not required as both the client and server need to know the player can fly for it to work properly)

 

[EDIT]

a possible work around would exist if multiple pieces of armor were being worn, as you could check the armor inventory before enabling the flight, and then deactivate if a piece is missing, however i'm not sure how this would respond on death or some more peculiar case when all the pieces are removed simultaneously

Link to comment
Share on other sites

A tick Handler, like you wanted to do it previously, would be the better solution. Did you try to register in the ClientProxy the TickHandler for both sides (client and server)? So having two registrations for it in the client proxy (since on the client, the CommonProxy stuff is not called, unless you add super.registerHandlers(), which should not be done).

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

on the tick handler I don't think the problem is with the client. The client shows the player flying fine until the server sends its "idea" of the player to the client when events such as damage happen occur, as these happen on the server. (at least that's how i understand it, i've not looked into it too far so i could be wrong). I will try what you said and probably ad some debug lines to see if i can figure out why it's acting weirdly.

 

[EDIT]

well that worked! Thanks, even though it wasn't my problem... haha.

if someone could explain to me why that was necessary that would be super.

Link to comment
Share on other sites

on the tick handler I don't think the problem is with the client. The client shows the player flying fine until the server sends its "idea" of the player to the client when events such as damage happen occur, as these happen on the server. (at least that's how i understand it, i've not looked into it too far so i could be wrong). I will try what you said and probably ad some debug lines to see if i can figure out why it's acting weirdly.

 

Yes, because, following your previous code, the ticks don't happen on the (internal) server-side. They need to happen on the client both, client-sided and server-sided. On a dedicated server, they only need to happen server-sided.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

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.