mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Changelings can only fly whilst disguised if they're disguised as something that can fly
This commit is contained in:
parent
c115acf69d
commit
18bbce8c0e
6 changed files with 70 additions and 6 deletions
|
@ -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);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package com.minelittlepony.unicopia.player;
|
package com.minelittlepony.unicopia.player;
|
||||||
|
|
||||||
public interface IGravity {
|
public interface IGravity extends IFlyingPredicate {
|
||||||
boolean isFlying();
|
boolean isFlying();
|
||||||
|
|
||||||
float getFlightExperience();
|
float getFlightExperience();
|
||||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemFood;
|
import net.minecraft.item.ItemFood;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPlayer>, ITransmittable, IPageOwner {
|
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);
|
void beforeUpdate(EntityPlayer entity);
|
||||||
|
|
||||||
static EntityPlayer getPlayerFromServer(UUID playerId) {
|
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) {
|
if (e instanceof EntityPlayer) {
|
||||||
return (EntityPlayer)e;
|
return (EntityPlayer)e;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.player;
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.mixin.MixinEntity;
|
import com.minelittlepony.unicopia.mixin.MixinEntity;
|
||||||
|
import com.minelittlepony.unicopia.spell.IMagicEffect;
|
||||||
import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable;
|
import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -35,13 +36,28 @@ class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, IGravity, InbtS
|
||||||
this.player = player;
|
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
|
@Override
|
||||||
public void onUpdate(EntityPlayer entity) {
|
public void onUpdate(EntityPlayer entity) {
|
||||||
|
|
||||||
entity.capabilities.allowFlying = entity.capabilities.isCreativeMode || player.getPlayerSpecies().canFly();
|
entity.capabilities.allowFlying = checkCanFly(player);
|
||||||
|
|
||||||
if (!entity.capabilities.isCreativeMode) {
|
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;
|
isFlying = entity.capabilities.isFlying && !entity.capabilities.isCreativeMode;
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.minelittlepony.unicopia.player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.UConfig;
|
import com.minelittlepony.unicopia.UConfig;
|
||||||
import com.minelittlepony.unicopia.forgebullshit.FBS;
|
import com.minelittlepony.unicopia.forgebullshit.FBS;
|
||||||
|
@ -66,6 +68,7 @@ public class PlayerSpeciesList {
|
||||||
throw new IllegalArgumentException("entity");
|
throw new IllegalArgumentException("entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public IPlayer getPlayer(EntityPlayer player) {
|
public IPlayer getPlayer(EntityPlayer player) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -74,6 +77,7 @@ public class PlayerSpeciesList {
|
||||||
return FBS.of(player).getPlayer();
|
return FBS.of(player).getPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public IPlayer getPlayer(UUID playerId) {
|
public IPlayer getPlayer(UUID playerId) {
|
||||||
return getPlayer(IPlayer.getPlayerFromServer(playerId));
|
return getPlayer(IPlayer.getPlayerFromServer(playerId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,22 +7,25 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.UClient;
|
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.IOwned;
|
||||||
import com.minelittlepony.unicopia.player.IPlayer;
|
import com.minelittlepony.unicopia.player.IPlayer;
|
||||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityFlying;
|
||||||
import net.minecraft.entity.EntityList;
|
import net.minecraft.entity.EntityList;
|
||||||
import net.minecraft.entity.EntityLiving;
|
import net.minecraft.entity.EntityLiving;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
public class SpellDisguise extends AbstractSpell {
|
public class SpellDisguise extends AbstractSpell implements IFlyingPredicate {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private String entityId = "";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue