Cloud blocks and items with feather falling will always collid with cloud blocks

This commit is contained in:
Sollace 2020-04-26 19:51:30 +02:00
parent 91e84e7551
commit 976a07800e
2 changed files with 20 additions and 7 deletions

View file

@ -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<Entity> IS_CLOUD = e -> e instanceof CloudEntity;
@ -20,7 +23,11 @@ public interface EquinePredicates {
Predicate<Entity> PLAYER_CHANGELING = IS_PLAYER.and(entity -> Ponylike.of(entity).getSpecies() == Race.CHANGELING);
Predicate<Entity> PLAYER_PEGASUS = IS_PLAYER.and(entity -> ((PlayerEntity)entity).abilities.creativeMode || RACE_INTERACT_WITH_CLOUDS.test(entity));
Predicate<Entity> ITEM_INTERACT_WITH_CLOUDS = IS_VALID_ITEM.and(RACE_INTERACT_WITH_CLOUDS);
Predicate<Entity> 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> ENTITY_INTERACT_WITH_CLOUDS = PLAYER_PEGASUS.or(ITEM_INTERACT_WITH_CLOUDS);
Predicate<Entity> ENTITY_WALK_ON_CLOUDS = entity -> entity instanceof LivingEntity && CloudEntity.getFeatherEnchantStrength((LivingEntity)entity) > 0;

View file

@ -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<Enchantment, Integer> 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<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
if (enchantments.containsKey(Enchantments.FEATHER_FALLING)) {
return enchantments.get(Enchantments.FEATHER_FALLING);
}
}
return 0;