diff --git a/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java b/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java index d2b8f3d6..f548e6e0 100644 --- a/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java +++ b/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java @@ -4,10 +4,13 @@ import java.util.function.Predicate; import com.minelittlepony.unicopia.entity.CloudEntity; import com.minelittlepony.unicopia.entity.Ponylike; +import com.minelittlepony.unicopia.gas.Gas; + import net.minecraft.entity.Entity; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; public interface EquinePredicates { Predicate IS_CLOUD = e -> e instanceof CloudEntity; @@ -20,7 +23,11 @@ public interface EquinePredicates { Predicate PLAYER_CHANGELING = IS_PLAYER.and(entity -> Ponylike.of(entity).getSpecies() == Race.CHANGELING); Predicate PLAYER_PEGASUS = IS_PLAYER.and(entity -> ((PlayerEntity)entity).abilities.creativeMode || RACE_INTERACT_WITH_CLOUDS.test(entity)); - Predicate ITEM_INTERACT_WITH_CLOUDS = IS_VALID_ITEM.and(RACE_INTERACT_WITH_CLOUDS); + Predicate ITEM_INTERACT_WITH_CLOUDS = IS_VALID_ITEM.and(RACE_INTERACT_WITH_CLOUDS.or(e -> { + return CloudEntity.getFeatherEnchantStrength(((ItemEntity)e).getStack()) > 0 + || (((ItemEntity)e).getStack().getItem() instanceof BlockItem + && ((BlockItem)((ItemEntity)e).getStack().getItem()).getBlock() instanceof Gas); + })); Predicate ENTITY_INTERACT_WITH_CLOUDS = PLAYER_PEGASUS.or(ITEM_INTERACT_WITH_CLOUDS); Predicate ENTITY_WALK_ON_CLOUDS = entity -> entity instanceof LivingEntity && CloudEntity.getFeatherEnchantStrength((LivingEntity)entity) > 0; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java index 80ed424a..d6317756 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java @@ -4,6 +4,7 @@ import java.util.Map; import javax.annotation.Nullable; +import com.google.common.collect.Streams; import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.ability.PegasusCloudInteractionAbility.ICloudEntity; @@ -584,12 +585,17 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate } public static int getFeatherEnchantStrength(LivingEntity entity) { - for (ItemStack stack : entity.getArmorItems()) { - if (stack != null) { - Map enchantments = EnchantmentHelper.getEnchantments(stack); - if (enchantments.containsKey(Enchantments.FEATHER_FALLING)) { - return enchantments.get(Enchantments.FEATHER_FALLING); - } + return Streams.stream(entity.getArmorItems()) + .map(CloudEntity::getFeatherEnchantStrength).filter(i -> i > 0) + .findFirst() + .orElse(0); + } + + public static int getFeatherEnchantStrength(ItemStack stack) { + if (stack != null && !stack.isEmpty()) { + Map enchantments = EnchantmentHelper.getEnchantments(stack); + if (enchantments.containsKey(Enchantments.FEATHER_FALLING)) { + return enchantments.get(Enchantments.FEATHER_FALLING); } } return 0;