Jump to content

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


Recommended Posts

Posted

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));
	}
}

 

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • ⚠️ DON'T CLICK THIS LINK OR ANYTHING RELATED TO THIS, IT HAS MALWARE IN THE LINK AND IT'S LIKELY A SCAM. ⚠️
    • ⚠️ DON'T CLICK THIS LINK OR ANYTHING RELATED TO THIS, IT HAS MALWARE IN THE LINK AND IT'S LIKELY A SCAM. ⚠️
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Whats...App : +.1 .4 7.4.3 5.3.7 7..1.9 Website : https://       digitalhackrecovery.com     Mail:            digitalhackrecovery         @techie.       com 
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Wh.ats.Ap.p : +1 .4 .7  4 3. 5  3  .7 7.1.9 Website : https://     digitalhackrecovery.   com Mail:       digitalhackrecovery     @         techie.                     com  
    • Ran it one more time just to check, and there's no errors this time on the log??? Log : https://mclo.gs/LnuaAiu I tried allocating more memory to the modpack, around 8000MB and it's still the same; stopping at "LOAD_REGISTRIES". Are some of the mods clashing, maybe? I have no clue what to do LOL
  • Topics

×
×
  • Create New...

Important Information

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