Environmental

Environmental

8M Downloads

Yak pants code breaks step assist

Xetaxheb opened this issue ยท 0 comments

commented

cd6c8f1

There was a fix for a specific other mod put in here but really what needs to happen is not touching it unless the pants are on.
If you're having issues with the height remaining after removal, just store a variable that the player has had step height applied, and check if it's true when running your reset code. Something like (https://github.com/team-abnormals/environmental/blob/1.16.1/src/main/java/com/minecraftabnormals/environmental/common/item/YakPantsItem.java) :


package com.minecraftabnormals.environmental.common.item;

import com.minecraftabnormals.environmental.core.Environmental;
import com.teamabnormals.abnormals_core.core.utils.ItemStackUtils;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.NonNullList;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

@EventBusSubscriber(modid = Environmental.MODID)
public class YakPantsItem extends ArmorItem {

	public YakPantsItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builderIn) {
		super(materialIn, slot, builderIn);
	}
	private boolean stepHeightApplied = false;

	@SubscribeEvent(priority = EventPriority.HIGHEST)
	public static void onLivingUpdate(LivingUpdateEvent event) {
		LivingEntity entity = event.getEntityLiving();
		ItemStack legsStack = entity.getItemStackFromSlot(EquipmentSlotType.LEGS);
		boolean wearingPants = legsStack.getItem() instanceof YakPantsItem;
		if (entity instanceof PlayerEntity) {
			float defaultHeight = 0.6F;
			float upgradedHeight = 1.1F;
			if (wearingPants && entity.stepHeight < upgradedHeight) {
				entity.stepHeight = upgradedHeight;
				this.stepHeightApplied = true;
			} else if (this.stepHeightApplied && entity.stepHeight > defaultHeight) {
				entity.stepHeight = defaultHeight;
				this.stepHeightApplied = false;
			}
		}

		if (wearingPants && entity.getRidingEntity() instanceof LivingEntity) {
			LivingEntity mount = (LivingEntity)entity.getRidingEntity();
			mount.addPotionEffect(new EffectInstance(Effects.REGENERATION, 60));
			mount.addPotionEffect(new EffectInstance(Effects.SPEED, 60, 1));
		}
	}

	@Override
	public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
		ItemStackUtils.fillAfterItemForGroup(this.asItem(), Items.TURTLE_HELMET, group, items);
	}
}