snipermine Posted April 25, 2013 Share Posted April 25, 2013 Any idea how i can make creative type fly allowed when the user is wearing a full set of armor? Quote Link to comment Share on other sites More sharing options...
snipermine Posted April 25, 2013 Author Share Posted April 25, 2013 Any idea how i can make creative type fly allowed when the user is wearing a full set of armor? Quote Link to comment Share on other sites More sharing options...
snipermine Posted April 25, 2013 Author Share Posted April 25, 2013 Bump! Quote Link to comment Share on other sites More sharing options...
snipermine Posted April 25, 2013 Author Share Posted April 25, 2013 Bump! Quote Link to comment Share on other sites More sharing options...
Yagoki Posted April 25, 2013 Share Posted April 25, 2013 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 Quote github Link to comment Share on other sites More sharing options...
snipermine Posted April 25, 2013 Author Share Posted April 25, 2013 Thanks! Quote Link to comment Share on other sites More sharing options...
snipermine Posted April 26, 2013 Author Share Posted April 26, 2013 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 Quote Link to comment Share on other sites More sharing options...
Yagoki Posted April 26, 2013 Share Posted April 26, 2013 How so? can i see your relevant code (Main mod file, proxies...) [EDIT] have you tried editing the number in the item[] for the armor inventory, i wasn't definite that 0 was correct for the helmet, so that could be the problem Quote github Link to comment Share on other sites More sharing options...
snipermine Posted April 28, 2013 Author Share Posted April 28, 2013 I set the number to 3 because thats the helmet. i did try lots of other ones though Quote Link to comment Share on other sites More sharing options...
Yagoki Posted April 28, 2013 Share Posted April 28, 2013 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 Quote github Link to comment Share on other sites More sharing options...
O3Bubbles09 Posted April 29, 2013 Share Posted April 29, 2013 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; } } Quote Link to comment Share on other sites More sharing options...
Yagoki Posted April 29, 2013 Share Posted April 29, 2013 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 Quote github Link to comment Share on other sites More sharing options...
SanAndreaP Posted April 30, 2013 Share Posted April 30, 2013 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). Quote 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 More sharing options...
Yagoki Posted April 30, 2013 Share Posted April 30, 2013 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. Quote github Link to comment Share on other sites More sharing options...
SanAndreaP Posted April 30, 2013 Share Posted April 30, 2013 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. Quote 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 More sharing options...
Recommended Posts
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.