mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed null exceptions when ticking players
This commit is contained in:
parent
cc63736466
commit
c36402b4d9
6 changed files with 30 additions and 28 deletions
|
@ -16,7 +16,6 @@ import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
|||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
@ -89,7 +88,7 @@ public class Unicopia {
|
|||
@SubscribeEvent
|
||||
public static void onPlyerTick(TickEvent.PlayerTickEvent event) {
|
||||
if (event.phase == Phase.END) {
|
||||
PlayerSpeciesList.instance().getPlayer(event.player).onEntityUpdate();
|
||||
PlayerSpeciesList.instance().getPlayer(event.player).onUpdate(event.player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ final class DefaultPlayerSpecies implements IPlayer, IAbilityReceiver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onEntityUpdate() {
|
||||
public void onUpdate(EntityPlayer entity) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,11 @@ import com.minelittlepony.unicopia.InbtSerialisable;
|
|||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.spell.ICaster;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
public interface IPlayer extends ICaster<EntityPlayer>, InbtSerialisable {
|
||||
public interface IPlayer extends ICaster<EntityPlayer>, InbtSerialisable, IUpdatable {
|
||||
Race getPlayerSpecies();
|
||||
|
||||
void setPlayerSpecies(Race race);
|
||||
|
@ -20,13 +21,20 @@ public interface IPlayer extends ICaster<EntityPlayer>, InbtSerialisable {
|
|||
|
||||
boolean isClientPlayer();
|
||||
|
||||
void onEntityUpdate();
|
||||
|
||||
default void onEntityEat() {
|
||||
|
||||
}
|
||||
|
||||
static EntityPlayer getPlayerEntity(UUID playerId) {
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(playerId);
|
||||
EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(playerId);
|
||||
|
||||
if (player == null) {
|
||||
Entity e = FMLCommonHandler.instance().getMinecraftServerInstance().getEntityFromUuid(playerId);
|
||||
if (e instanceof EntityPlayer) {
|
||||
return (EntityPlayer)e;
|
||||
}
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,16 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
private Race playerSpecies = Race.HUMAN;
|
||||
|
||||
private UUID playerId;
|
||||
|
||||
private final PlayerAbilityDelegate powers = new PlayerAbilityDelegate(this);
|
||||
|
||||
private final PlayerGravityDelegate gravity = new PlayerGravityDelegate(this);
|
||||
|
||||
private IMagicEffect effect;
|
||||
|
||||
private EntityPlayer entity;
|
||||
|
||||
PlayerCapabilities(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,10 +37,6 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
@Override
|
||||
public void setPlayerSpecies(Race race) {
|
||||
if (race == playerSpecies) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerSpecies = race;
|
||||
|
||||
EntityPlayer self = getOwner();
|
||||
|
@ -53,7 +49,7 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
@Override
|
||||
public void sendCapabilities() {
|
||||
PlayerSpeciesList.instance().sendCapabilities(playerId);
|
||||
PlayerSpeciesList.instance().sendCapabilities(getOwner().getGameProfile().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,26 +60,26 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
@Override
|
||||
public boolean isClientPlayer() {
|
||||
return UClient.isClientSide() &&
|
||||
Minecraft.getMinecraft().player.getGameProfile().getId().equals(playerId);
|
||||
Minecraft.getMinecraft().player.getGameProfile().getId().equals(getOwner().getGameProfile().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityUpdate() {
|
||||
EntityPlayer player = getOwner();
|
||||
public void onUpdate(EntityPlayer entity) {
|
||||
this.entity = entity;
|
||||
|
||||
powers.onUpdate(player);
|
||||
gravity.onUpdate(player);
|
||||
powers.onUpdate(entity);
|
||||
gravity.onUpdate(entity);
|
||||
|
||||
if (!getPlayerSpecies().canCast()) {
|
||||
effect = null;
|
||||
}
|
||||
|
||||
if (effect != null) {
|
||||
if (player.getEntityWorld().isRemote && player.getEntityWorld().getWorldTime() % 10 == 0) {
|
||||
effect.render(player);
|
||||
if (entity.getEntityWorld().isRemote && entity.getEntityWorld().getWorldTime() % 10 == 0) {
|
||||
effect.render(entity);
|
||||
}
|
||||
|
||||
if (!effect.update(player)) {
|
||||
if (!effect.update(entity)) {
|
||||
effect = null;
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +96,6 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
compound.setUniqueId("playerId", playerId);
|
||||
compound.setString("playerSpecies", playerSpecies.name());
|
||||
compound.setTag("powers", powers.toNBT());
|
||||
compound.setTag("gravity", gravity.toNBT());
|
||||
|
@ -113,7 +108,6 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
playerId = compound.getUniqueId("playerId");
|
||||
playerSpecies = Race.fromName(compound.getString("playerSpecies"));
|
||||
powers.readFromNBT(compound.getCompoundTag("powers"));
|
||||
gravity.readFromNBT(compound.getCompoundTag("gravity"));
|
||||
|
@ -139,6 +133,6 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
@Override
|
||||
public EntityPlayer getOwner() {
|
||||
return IPlayer.getPlayerEntity(playerId);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ class PlayerGravityDelegate implements IUpdatable, InbtSerialisable {
|
|||
ticksSinceLanding++;
|
||||
}
|
||||
|
||||
entity.capabilities.allowFlying = entity.capabilities.isFlying = false;
|
||||
entity.capabilities.allowFlying = player.getPlayerSpecies().canFly();
|
||||
entity.capabilities.isFlying = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PlayerSpeciesList {
|
|||
}
|
||||
|
||||
public void sendCapabilities(UUID playerId) {
|
||||
Unicopia.channel.send(new MsgPlayerCapabilities(getPlayer(playerId).getPlayerSpecies(), playerId), Target.SERVER_AND_CLIENTS);
|
||||
Unicopia.channel.send(new MsgPlayerCapabilities(getPlayer(playerId).getPlayerSpecies(), playerId), playerId);
|
||||
}
|
||||
|
||||
public void handleSpeciesChange(UUID playerId, Race race) {
|
||||
|
|
Loading…
Reference in a new issue