Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] player.isElytraFlying() is not being set to true when flying with custom elytra code
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
Rosy162

[1.12.2] player.isElytraFlying() is not being set to true when flying with custom elytra code

By Rosy162, November 14, 2020 in Modder Support

  • Start new topic

Recommended Posts

Rosy162    0

Rosy162

Rosy162    0

  • Tree Puncher
  • Rosy162
  • Members
  • 0
  • 3 posts
Posted November 14, 2020

ok so i have a very specific issue that i dont know how to solve. im trying to make a mod which uses the baubles api that allows you to place the elytra in the baubles (body) slot. ive got pretty much everything to work but in EntityLivingBase, the method updateElytra() is checking if the chestplate slot has the elytra and if it doesnt it sets the player.isElytraFlying() method to false, regardless of if you are actually flying with the elytra. this is causing issues minecraft uses this method to decide when to calculate the elytra damage and so on... when im flying with the elytra in the baubles slot, player.isElytraFlying() is returning true and false repeatedly because of this method. i need it to always return true when you are flying but idk how to do that. hopefully someone smarter than me can help .-. sorry if im being stupid. here is the code for my custom elytra item:

 

 

@Mod.EventBusSubscriber
public class BaubleItemElytra extends ItemElytra implements IBauble {
	private static boolean render = true;
	public Method setFlagMethod;
	public BaubleItemElytra() {
		super();
		this.setUnlocalizedName("elytra");
		try {
          	// this method is what is used to make the player fly, it is private so i get it here ._.
			try {
				setFlagMethod = Entity.class.getDeclaredMethod("setFlag", int.class, boolean.class);
			} catch (Exception e) {
				setFlagMethod = Entity.class.getDeclaredMethod("func_70052_a", int.class, boolean.class);
			}
			setFlagMethod.setAccessible(true);
		} catch (NoSuchMethodException e) {}
	}
	@Override
	public BaubleType getBaubleType(ItemStack stack) {
		return BaubleType.BODY;
	}
  	//register item
	@SubscribeEvent
	public static void register(RegistryEvent.Register<Item> event) {
		event.getRegistry().register((new BaubleItemElytra().setRegistryName("minecraft", "elytra")));
	}
  	//registers the elytra render once,
  	//BaubleLayerElytra is just the same as the vanilla LayerElytra but it checks for the bauble slot
	@SubscribeEvent
	public static void onPlayerRender(RenderPlayerEvent.Pre event) {
		if (render) {
			event.getRenderer().addLayer(new BaubleLayerElytra(event.getRenderer()));
			render = false; 
		}
	}
  	//cant equip if you have elytra equipped already
	@Override
	public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
		return !slotHasElytra((EntityPlayer)player);
	}
	@Override
	public void onEquipped(ItemStack itemstack, EntityLivingBase player) {
		player.playSound(SoundEvents.ITEM_ARMOR_EQIIP_ELYTRA, .75F, 1.9f);
		//chatMessage(player, "equipped");
	}
	@Override
	public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
		//chatMessage(player, "unequipped");
		setFlying(player, false);
		player.playSound(SoundEvents.ITEM_ARMOR_EQIIP_ELYTRA, .75F, 1.8f);
	}
	public static boolean slotHasElytra(EntityPlayer player) {
		return player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() instanceof ItemElytra;
	}
	@Override
	public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
		//unequips elytra in bauble if elytra is in chestplate slot
		if (slotHasElytra((EntityPlayer)player)) {
			((EntityPlayer)player).addItemStackToInventory(itemstack.copy());
			BaublesApi.getBaublesHandler((EntityPlayer)player).setStackInSlot(5, ItemStack.EMPTY);;
		}
      
		boolean flag = player.isElytraFlying();
		//chatMessage(player, "check flying:" + player.isElytraFlying());
		if (flag && !player.onGround && !player.isRiding() && isUsable(itemstack)) {
			flag = true;
			if ((player.getTicksElytraFlying() + 1) % 20 == 0) {
				//itemstack.damageItem(1, player);
			}
		} else {
			flag = false;
          	//if you press jump in the right conditions you fly
			if (Minecraft.getMinecraft().gameSettings.keyBindJump.isPressed() && !player.isElytraFlying() && isUsable(itemstack) && player.motionY < 0.0D && !player.isInLava() && !player.isInWater() && !player.onGround) {
				flag = true;
			}
		}
		if (flag != player.isElytraFlying()) {
			setFlying(player, flag);
			//chatMessage(player, "flying set to: " + flag);
		}
	}
  	//sets the player to the flying state
	public void setFlying(EntityLivingBase player, boolean fly) {
		try { setFlagMethod.invoke(player, 7, fly); } 
		catch (Exception e) {}
	}
	private void chatMessage(EntityLivingBase player, String text) {
		((EntityPlayer)player).sendMessage(new TextComponentString(text));
	}
  	//right clicking puts it in the bauble body slot if its empty, if its full it puts it in the chestplate
	@Override
	public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
		player.playSound(SoundEvents.ITEM_ARMOR_EQIIP_ELYTRA, .75F, 1.9f);
		if (!world.isRemote) {
			IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
			ItemStack stack = baubles.getStackInSlot(5);
			if ((stack == null || stack.isEmpty()) && baubles.isItemValidForSlot(5, player.getHeldItem(hand), player)) {
				baubles.setStackInSlot(5, player.getHeldItem(hand).copy());
				if (!player.capabilities.isCreativeMode) {
					player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
				}
				//onEquipped(player.getHeldItem(hand), player);
			} else {
				super.onItemRightClick(world, player, hand);
			}	
		}
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
	}
}

 

Share this post


Link to post
Share on other sites

ChampionAsh5357    162

ChampionAsh5357

ChampionAsh5357    162

  • World Shaper
  • ChampionAsh5357
  • Members
  • 162
  • 1021 posts
Posted November 14, 2020

The supported versions are in the blue banner above. Please update to one of those versions mentioned to receive support.

Share this post


Link to post
Share on other sites

diesieben07    7616

diesieben07

diesieben07    7616

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7616
  • 55209 posts
Posted November 14, 2020

1.12 is no longer supported on this forum.

Please update to a modern version of Minecraft to receive support.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Leronus
      1.12.2 Custom Furnace Issues

      By Leronus · Posted 2 minutes ago

      1.12.2.... I know it's unsupported ;-;
    • loordgek
      1.12.2 Custom Furnace Issues

      By loordgek · Posted 11 minutes ago

      Leronus what version are you modding ?  
    • FrannDzs
      Add ferritecore code to forge

      By FrannDzs · Posted 13 minutes ago

      hi, good afternoon, i was looking at this mod and apparently it seems to do a good job, could you double check? if so, it would be a substantial improvement. Links: FerriteCore/summary.md at master · malte0811/FerriteCore (github.com) FerriteCore - Mods - Minecraft - CurseForge
    • domi0908
      fix hitbox red baby mobs version forge

      By domi0908 · Posted 40 minutes ago

    • Leronus
      1.12.2 Custom Furnace Issues

      By Leronus · Posted 42 minutes ago

      Please share your code.... Having the exact same issues you mentioned but even with those answers I can't figure it out...
  • Topics

    • Will11690
      10
      1.12.2 Custom Furnace Issues

      By Will11690
      Started September 10, 2018

    • FrannDzs
      0
      Add ferritecore code to forge

      By FrannDzs
      Started 13 minutes ago

    • domi0908
      0
      fix hitbox red baby mobs version forge

      By domi0908
      Started 40 minutes ago

    • BBoi69
      7
      My modpack takes years to load

      By BBoi69
      Started 7 hours ago

    • domi0908
      2
      fix hitboxes red baby mobs please

      By domi0908
      Started 53 minutes ago

  • Who's Online (See full list)

    • awesomeJVR
    • BoulouU
    • FrannDzs
    • domi0908
    • loordgek
    • vemerion
    • squidlex
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] player.isElytraFlying() is not being set to true when flying with custom elytra code
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community