Changelings can only fly whilst disguised if they're disguised as something that can fly

This commit is contained in:
Sollace 2019-02-09 20:15:15 +02:00
parent c115acf69d
commit 18bbce8c0e
6 changed files with 70 additions and 6 deletions

View file

@ -0,0 +1,10 @@
package com.minelittlepony.unicopia.player;
/**
* Predicate for abilities to control whether a player can fly.
*
* This overrides what the race specifies.
*/
public interface IFlyingPredicate {
boolean checkCanFly(IPlayer player);
}

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.player;
public interface IGravity {
public interface IGravity extends IFlyingPredicate {
boolean isFlying();
float getFlightExperience();

View file

@ -14,6 +14,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.common.FMLCommonHandler;
public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPlayer>, ITransmittable, IPageOwner {
@ -63,7 +64,13 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
void beforeUpdate(EntityPlayer entity);
static EntityPlayer getPlayerFromServer(UUID playerId) {
Entity e = FMLCommonHandler.instance().getMinecraftServerInstance().getEntityFromUuid(playerId);
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server == null) {
return UClient.instance().getPlayerByUUID(playerId);
}
Entity e = server.getEntityFromUuid(playerId);
if (e instanceof EntityPlayer) {
return (EntityPlayer)e;

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.player;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.mixin.MixinEntity;
import com.minelittlepony.unicopia.spell.IMagicEffect;
import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable;
import net.minecraft.block.Block;
@ -35,13 +36,28 @@ class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, IGravity, InbtS
this.player = player;
}
public boolean checkCanFly(IPlayer player) {
if (player.getOwner().capabilities.isCreativeMode) {
return true;
}
if (player.hasEffect()) {
IMagicEffect effect = player.getEffect();
if (!effect.getDead() && effect instanceof IFlyingPredicate) {
return ((IFlyingPredicate)effect).checkCanFly(player);
}
}
return player.getPlayerSpecies().canFly();
}
@Override
public void onUpdate(EntityPlayer entity) {
entity.capabilities.allowFlying = entity.capabilities.isCreativeMode || player.getPlayerSpecies().canFly();
entity.capabilities.allowFlying = checkCanFly(player);
if (!entity.capabilities.isCreativeMode) {
entity.capabilities.isFlying |= entity.capabilities.allowFlying && isFlying && !entity.onGround;
entity.capabilities.isFlying |= entity.capabilities.allowFlying && isFlying && !entity.onGround && !entity.isWet();
}
isFlying = entity.capabilities.isFlying && !entity.capabilities.isCreativeMode;

View file

@ -2,6 +2,8 @@ package com.minelittlepony.unicopia.player;
import java.util.UUID;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UConfig;
import com.minelittlepony.unicopia.forgebullshit.FBS;
@ -66,6 +68,7 @@ public class PlayerSpeciesList {
throw new IllegalArgumentException("entity");
}
@Nullable
public IPlayer getPlayer(EntityPlayer player) {
if (player == null) {
return null;
@ -74,6 +77,7 @@ public class PlayerSpeciesList {
return FBS.of(player).getPlayer();
}
@Nullable
public IPlayer getPlayer(UUID playerId) {
return getPlayer(IPlayer.getPlayerFromServer(playerId));
}

View file

@ -7,22 +7,25 @@ import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.mixin.MixinEntity;
import com.minelittlepony.unicopia.player.IFlyingPredicate;
import com.minelittlepony.unicopia.player.IOwned;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.passive.EntityAmbientCreature;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class SpellDisguise extends AbstractSpell {
public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
@Nonnull
private String entityId = "";
@ -302,4 +305,28 @@ public class SpellDisguise extends AbstractSpell {
}
}
}
@Override
public boolean checkCanFly(IPlayer player) {
if (!player.getPlayerSpecies().canFly()) {
return false;
}
if (entity != null) {
if (entity instanceof EntityFlying
|| entity instanceof net.minecraft.entity.passive.EntityFlying
|| entity instanceof EntityDragon
|| entity instanceof EntityAmbientCreature) {
return true;
}
if (entity instanceof IOwned) {
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(IOwned.<UUID>cast(entity).getOwner());
return iplayer != null && iplayer.getPlayerSpecies().canFly();
}
}
return false;
}
}