EntityPlayerMP .java

net.minecraft.entity.player.EntityPlayerMP (class, 1298 lines): members: addSelfToInternalCraftingInventory, respawnInvulnerabilityTicks, wasHungry.

net.minecraft.entity.playerclass1,298 linescommonextends EntityPlayer45.5 KB

Implements

API Surface (70)

void readEntityFromNBT(NBTTagCompound tagCompund)
void writeEntityToNBT(NBTTagCompound tagCompound)
void addExperienceLevel(int levels)
void removeExperienceLevel(int levels)
void addSelfToInternalCraftingInventory()
void sendEnterCombat()
void sendEndCombat()
void onUpdate()
void onUpdateEntity()
void updateBiomesExplored()
void onDeath(DamageSource cause)
boolean attackEntityFrom(DamageSource source, float amount)
boolean canAttackPlayer(EntityPlayer other)
void travelToDimension(int dimensionId)
boolean isSpectatedByPlayer(EntityPlayerMP player)
void onItemPickup(Entity p_71001_1_, int p_71001_2_)
EntityPlayer.EnumStatus trySleep(BlockPos bedLocation)
void wakeUpPlayer(boolean immediately, boolean updateWorldFlag, boolean setSpawn)
void mountEntity(Entity entityIn)
void updateFallState(double y, boolean onGroundIn, Block blockIn, BlockPos pos)
void handleFalling(double p_71122_1_, boolean p_71122_3_)
void openEditSign(TileEntitySign signTile)
void displayGui(IInteractionObject guiOwner)
void displayGUIChest(IInventory chestInventory)
void displayVillagerTradeGui(IMerchant villager)
void displayGUIHorse(EntityHorse horse, IInventory horseInventory)
void displayGUIBook(ItemStack bookStack)
void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
void sendContainerToPlayer(Container p_71120_1_)
void updateCraftingInventory(Container containerToSend, List<ItemStack> itemsList)
void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue)
void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_)
void closeScreen()
void updateHeldItem()
void closeContainer()
void setEntityActionState(float p_110430_1_, float p_110430_2_, boolean p_110430_3_, boolean sneaking)
void addStat(StatBase stat, int amount)
void func_175145_a(StatBase p_175145_1_)
void mountEntityAndWakeUp()
void setPlayerHealthUpdated()
void addChatComponentMessage(IChatComponent chatComponent)
void onItemUseFinish()
void setItemInUse(ItemStack stack, int duration)
void clonePlayer(EntityPlayer oldPlayer, boolean respawnFromEnd)
void onNewPotionEffect(PotionEffect id)
void onChangedPotionEffect(PotionEffect id, boolean p_70695_2_)
void onFinishedPotionEffect(PotionEffect effect)
void setPositionAndUpdate(double x, double y, double z)
void onCriticalHit(Entity entityHit)
void onEnchantmentCritical(Entity entityHit)
void sendPlayerAbilities()
WorldServer getServerForPlayer()
void setGameType(WorldSettings.GameType gameType)
boolean isSpectator()
void addChatMessage(IChatComponent component)
boolean canCommandSenderUseCommand(int permLevel, String commandName)
String getPlayerIP()
void handleClientSettings(C15PacketClientSettings packetIn)
EntityPlayer.EnumChatVisibility getChatVisibility()
void loadResourcePack(String url, String hash)
BlockPos getPosition()
void markPlayerActive()
StatisticsFile getStatFile()
void removeEntity(Entity p_152339_1_)
void updatePotionMetadata()
Entity getSpectatingEntity()
void setSpectatingEntity(Entity entityToSpectate)
void attackTargetEntityWithCurrentItem(Entity targetEntity)
long getLastActiveTime()
IChatComponent getTabListDisplayName()

Fields & Constants (24)

logger
translator
playerNetServerHandler
mcServer
theItemInWorldManager
managedPosX
managedPosZ
loadedChunks
destroyedItemsNetCache
statsFile
combinedHealth
lastHealth
lastFoodLevel
wasHungry
lastExperience
respawnInvulnerabilityTicks
chatVisibility
chatColours
playerLastActiveTime
spectatingEntity
currentWindowId
isChangingQuantityOnly
ping
playerConqueredTheEnd

String literals (17)

"playerGameType"
"Ticking player"
"Player being ticked"
"showDeathMessages"
"keepInventory"
"fall"
"container.isLocked"
"random.door_close"
"minecraft:container"
"minecraft:villager"
"MC|TrList"
"EntityHorse"
"MC|BOpen"
"seed"
"tell"
"help"
"trigger"

Code Graph: Dependencies (80)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EntityPlayerMP.java1298 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.player;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Sets;
5
import com.mojang.authlib.GameProfile;
6
import io.netty.buffer.Unpooled;
7
import java.util.Arrays;
8
import java.util.Iterator;
9
import java.util.List;
10
import java.util.Set;
11
import net.minecraft.block.Block;
12
import net.minecraft.block.BlockFence;
13
import net.minecraft.block.BlockFenceGate;
14
import net.minecraft.block.BlockWall;
15
import net.minecraft.block.material.Material;
16
import net.minecraft.crash.CrashReport;
17
import net.minecraft.crash.CrashReportCategory;
18
import net.minecraft.entity.Entity;
19
import net.minecraft.entity.EntityList;
20
import net.minecraft.entity.EntityLivingBase;
21
import net.minecraft.entity.IMerchant;
22
import net.minecraft.entity.passive.EntityHorse;
23
import net.minecraft.entity.projectile.EntityArrow;
24
import net.minecraft.init.Items;
25
import net.minecraft.inventory.Container;
26
import net.minecraft.inventory.ContainerChest;
27
import net.minecraft.inventory.ContainerHorseInventory;
28
import net.minecraft.inventory.ContainerMerchant;
29
import net.minecraft.inventory.ICrafting;
30
import net.minecraft.inventory.IInventory;
31
import net.minecraft.inventory.SlotCrafting;
32
import net.minecraft.item.EnumAction;
33
import net.minecraft.item.Item;
34
import net.minecraft.item.ItemMapBase;
35
import net.minecraft.item.ItemStack;
36
import net.minecraft.nbt.NBTTagCompound;
37
import net.minecraft.network.NetHandlerPlayServer;
38
import net.minecraft.network.Packet;
39
import net.minecraft.network.PacketBuffer;
40
import net.minecraft.network.play.client.C15PacketClientSettings;
41
import net.minecraft.network.play.server.S02PacketChat;
42
import net.minecraft.network.play.server.S06PacketUpdateHealth;
43
import net.minecraft.network.play.server.S0APacketUseBed;
44
import net.minecraft.network.play.server.S0BPacketAnimation;
45
import net.minecraft.network.play.server.S13PacketDestroyEntities;
46
import net.minecraft.network.play.server.S19PacketEntityStatus;
47
import net.minecraft.network.play.server.S1BPacketEntityAttach;
48
import net.minecraft.network.play.server.S1DPacketEntityEffect;
49
import net.minecraft.network.play.server.S1EPacketRemoveEntityEffect;
50
import net.minecraft.network.play.server.S1FPacketSetExperience;
51
import net.minecraft.network.play.server.S21PacketChunkData;
52
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
53
import net.minecraft.network.play.server.S29PacketSoundEffect;
54
import net.minecraft.network.play.server.S2BPacketChangeGameState;
55
import net.minecraft.network.play.server.S2DPacketOpenWindow;
56
import net.minecraft.network.play.server.S2EPacketCloseWindow;
57
import net.minecraft.network.play.server.S2FPacketSetSlot;
58
import net.minecraft.network.play.server.S30PacketWindowItems;
59
import net.minecraft.network.play.server.S31PacketWindowProperty;
60
import net.minecraft.network.play.server.S36PacketSignEditorOpen;
61
import net.minecraft.network.play.server.S39PacketPlayerAbilities;
62
import net.minecraft.network.play.server.S3FPacketCustomPayload;
63
import net.minecraft.network.play.server.S42PacketCombatEvent;
64
import net.minecraft.network.play.server.S43PacketCamera;
65
import net.minecraft.network.play.server.S48PacketResourcePackSend;
66
import net.minecraft.potion.PotionEffect;
67
import net.minecraft.scoreboard.IScoreObjectiveCriteria;
68
import net.minecraft.scoreboard.Score;
69
import net.minecraft.scoreboard.ScoreObjective;
70
import net.minecraft.scoreboard.Team;
71
import net.minecraft.server.MinecraftServer;
72
import net.minecraft.server.management.ItemInWorldManager;
73
import net.minecraft.server.management.UserListOpsEntry;
74
import net.minecraft.stats.AchievementList;
75
import net.minecraft.stats.StatBase;
76
import net.minecraft.stats.StatList;
77
import net.minecraft.stats.StatisticsFile;
78
import net.minecraft.tileentity.TileEntity;
79
import net.minecraft.tileentity.TileEntitySign;
80
import net.minecraft.util.BlockPos;
81
import net.minecraft.util.ChatComponentTranslation;
82
import net.minecraft.util.DamageSource;
83
import net.minecraft.util.EntityDamageSource;
84
import net.minecraft.util.IChatComponent;
85
import net.minecraft.util.JsonSerializableSet;
86
import net.minecraft.util.MathHelper;
87
import net.minecraft.util.ReportedException;
88
import net.minecraft.village.MerchantRecipeList;
89
import net.minecraft.world.ChunkCoordIntPair;
90
import net.minecraft.world.IInteractionObject;
91
import net.minecraft.world.ILockableContainer;
92
import net.minecraft.world.WorldServer;
93
import net.minecraft.world.WorldSettings;
94
import net.minecraft.world.biome.BiomeGenBase;
95
import net.minecraft.world.chunk.Chunk;
96
import org.apache.logging.log4j.LogManager;
97
import org.apache.logging.log4j.Logger;
98
99
public class EntityPlayerMP extends EntityPlayer implements ICrafting
100
{
101
    private static final Logger logger = LogManager.getLogger();
102
    private String translator = "en_US";
103
104
    /**
105
     * The NetServerHandler assigned to this player by the ServerConfigurationManager.
106
     */
107
    public NetHandlerPlayServer playerNetServerHandler;
108
109
    /** Reference to the MinecraftServer object. */
110
    public final MinecraftServer mcServer;
111
112
    /** The ItemInWorldManager belonging to this player */
113
    public final ItemInWorldManager theItemInWorldManager;
114
115
    /** player X position as seen by PlayerManager */
116
    public double managedPosX;
117
118
    /** player Z position as seen by PlayerManager */
119
    public double managedPosZ;
120
    public final List<ChunkCoordIntPair> loadedChunks = Lists.<ChunkCoordIntPair>newLinkedList();
121
    private final List<Integer> destroyedItemsNetCache = Lists.<Integer>newLinkedList();
122
    private final StatisticsFile statsFile;
123
124
    /**
125
     * the total health of the player, includes actual health and absorption health. Updated every tick.
126
     */
127
    private float combinedHealth = Float.MIN_VALUE;
128
129
    /** amount of health the client was last set to */
130
    private float lastHealth = -1.0E8F;
131
132
    /** set to foodStats.GetFoodLevel */
133
    private int lastFoodLevel = -99999999;
134
135
    /** set to foodStats.getSaturationLevel() == 0.0F each tick */
136
    private boolean wasHungry = true;
137
138
    /** Amount of experience the client was last set to */
139
    private int lastExperience = -99999999;
140
    private int respawnInvulnerabilityTicks = 60;
141
    private EntityPlayer.EnumChatVisibility chatVisibility;
142
    private boolean chatColours = true;
143
    private long playerLastActiveTime = System.currentTimeMillis();
144
145
    /** The entity the player is currently spectating through. */
146
    private Entity spectatingEntity = null;
147
148
    /**
149
     * The currently in use window ID. Incremented every time a window is opened.
150
     */
151
    private int currentWindowId;
152
153
    /**
154
     * set to true when player is moving quantity of items from one inventory to another(crafting) but item in either
155
     * slot is not changed
156
     */
157
    public boolean isChangingQuantityOnly;
158
    public int ping;
159
160
    /**
161
     * Set when a player beats the ender dragon, used to respawn the player at the spawn point while retaining inventory
162
     * and XP
163
     */
164
    public boolean playerConqueredTheEnd;
165
166
    public EntityPlayerMP(MinecraftServer server, WorldServer worldIn, GameProfile profile, ItemInWorldManager interactionManager)
167
    {
168
        super(worldIn, profile);
169
        interactionManager.thisPlayerMP = this;
170
        this.theItemInWorldManager = interactionManager;
171
        BlockPos blockpos = worldIn.getSpawnPoint();
172
173
        if (!worldIn.provider.getHasNoSky() && worldIn.getWorldInfo().getGameType() != WorldSettings.GameType.ADVENTURE)
174
        {
175
            int i = Math.max(5, server.getSpawnProtectionSize() - 6);
176
            int j = MathHelper.floor_double(worldIn.getWorldBorder().getClosestDistance((double)blockpos.getX(), (double)blockpos.getZ()));
177
178
            if (j < i)
179
            {
180
                i = j;
181
            }
182
183
            if (j <= 1)
184
            {
185
                i = 1;
186
            }
187
188
            blockpos = worldIn.getTopSolidOrLiquidBlock(blockpos.add(this.rand.nextInt(i * 2) - i, 0, this.rand.nextInt(i * 2) - i));
189
        }
190
191
        this.mcServer = server;
192
        this.statsFile = server.getConfigurationManager().getPlayerStatsFile(this);
193
        this.stepHeight = 0.0F;
194
        this.moveToBlockPosAndAngles(blockpos, 0.0F, 0.0F);
195
196
        while (!worldIn.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty() && this.posY < 255.0D)
197
        {
198
            this.setPosition(this.posX, this.posY + 1.0D, this.posZ);
199
        }
200
    }
201
202
    /**
203
     * (abstract) Protected helper method to read subclass entity data from NBT.
204
     */
205
    public void readEntityFromNBT(NBTTagCompound tagCompund)
206
    {
207
        super.readEntityFromNBT(tagCompund);
208
209
        if (tagCompund.hasKey("playerGameType", 99))
210
        {
211
            if (MinecraftServer.getServer().getForceGamemode())
212
            {
213
                this.theItemInWorldManager.setGameType(MinecraftServer.getServer().getGameType());
214
            }
215
            else
216
            {
217
                this.theItemInWorldManager.setGameType(WorldSettings.GameType.getByID(tagCompund.getInteger("playerGameType")));
218
            }
219
        }
220
    }
221
222
    /**
223
     * (abstract) Protected helper method to write subclass entity data to NBT.
224
     */
225
    public void writeEntityToNBT(NBTTagCompound tagCompound)
226
    {
227
        super.writeEntityToNBT(tagCompound);
228
        tagCompound.setInteger("playerGameType", this.theItemInWorldManager.getGameType().getID());
229
    }
230
231
    /**
232
     * Add experience levels to this player.
233
     */
234
    public void addExperienceLevel(int levels)
235
    {
236
        super.addExperienceLevel(levels);
237
        this.lastExperience = -1;
238
    }
239
240
    public void removeExperienceLevel(int levels)
241
    {
242
        super.removeExperienceLevel(levels);
243
        this.lastExperience = -1;
244
    }
245
246
    public void addSelfToInternalCraftingInventory()
247
    {
248
        this.openContainer.onCraftGuiOpened(this);
249
    }
250
251
    /**
252
     * Sends an ENTER_COMBAT packet to the client
253
     */
254
    public void sendEnterCombat()
255
    {
256
        super.sendEnterCombat();
257
        this.playerNetServerHandler.sendPacket(new S42PacketCombatEvent(this.getCombatTracker(), S42PacketCombatEvent.Event.ENTER_COMBAT));
258
    }
259
260
    /**
261
     * Sends an END_COMBAT packet to the client
262
     */
263
    public void sendEndCombat()
264
    {
265
        super.sendEndCombat();
266
        this.playerNetServerHandler.sendPacket(new S42PacketCombatEvent(this.getCombatTracker(), S42PacketCombatEvent.Event.END_COMBAT));
267
    }
268
269
    /**
270
     * Called to update the entity's position/logic.
271
     */
272
    public void onUpdate()
273
    {
274
        this.theItemInWorldManager.updateBlockRemoving();
275
        --this.respawnInvulnerabilityTicks;
276
277
        if (this.hurtResistantTime > 0)
278
        {
279
            --this.hurtResistantTime;
280
        }
281
282
        this.openContainer.detectAndSendChanges();
283
284
        if (!this.worldObj.isRemote && !this.openContainer.canInteractWith(this))
285
        {
286
            this.closeScreen();
287
            this.openContainer = this.inventoryContainer;
288
        }
289
290
        while (!this.destroyedItemsNetCache.isEmpty())
291
        {
292
            int i = Math.min(this.destroyedItemsNetCache.size(), Integer.MAX_VALUE);
293
            int[] aint = new int[i];
294
            Iterator<Integer> iterator = this.destroyedItemsNetCache.iterator();
295
            int j = 0;
296
297
            while (iterator.hasNext() && j < i)
298
            {
299
                aint[j++] = ((Integer)iterator.next()).intValue();
300
                iterator.remove();
301
            }
302
303
            this.playerNetServerHandler.sendPacket(new S13PacketDestroyEntities(aint));
304
        }
305
306
        if (!this.loadedChunks.isEmpty())
307
        {
308
            List<Chunk> list = Lists.<Chunk>newArrayList();
309
            Iterator<ChunkCoordIntPair> iterator1 = this.loadedChunks.iterator();
310
            List<TileEntity> list1 = Lists.<TileEntity>newArrayList();
311
312
            while (iterator1.hasNext() && ((List)list).size() < 10)
313
            {
314
                ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator1.next();
315
316
                if (chunkcoordintpair != null)
317
                {
318
                    if (this.worldObj.isBlockLoaded(new BlockPos(chunkcoordintpair.chunkXPos << 4, 0, chunkcoordintpair.chunkZPos << 4)))
319
                    {
320
                        Chunk chunk = this.worldObj.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
321
322
                        if (chunk.isPopulated())
323
                        {
324
                            list.add(chunk);
325
                            list1.addAll(((WorldServer)this.worldObj).getTileEntitiesIn(chunkcoordintpair.chunkXPos * 16, 0, chunkcoordintpair.chunkZPos * 16, chunkcoordintpair.chunkXPos * 16 + 16, 256, chunkcoordintpair.chunkZPos * 16 + 16));
326
                            iterator1.remove();
327
                        }
328
                    }
329
                }
330
                else
331
                {
332
                    iterator1.remove();
333
                }
334
            }
335
336
            if (!list.isEmpty())
337
            {
338
                if (list.size() == 1)
339
                {
340
                    this.playerNetServerHandler.sendPacket(new S21PacketChunkData((Chunk)list.get(0), true, 65535));
341
                }
342
                else
343
                {
344
                    this.playerNetServerHandler.sendPacket(new S26PacketMapChunkBulk(list));
345
                }
346
347
                for (TileEntity tileentity : list1)
348
                {
349
                    this.sendTileEntityUpdate(tileentity);
350
                }
351
352
                for (Chunk chunk1 : list)
353
                {
354
                    this.getServerForPlayer().getEntityTracker().func_85172_a(this, chunk1);
355
                }
356
            }
357
        }
358
359
        Entity entity = this.getSpectatingEntity();
360
361
        if (entity != this)
362
        {
363
            if (!entity.isEntityAlive())
364
            {
365
                this.setSpectatingEntity(this);
366
            }
367
            else
368
            {
369
                this.setPositionAndRotation(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
370
                this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this);
371
372
                if (this.isSneaking())
373
                {
374
                    this.setSpectatingEntity(this);
375
                }
376
            }
377
        }
378
    }
379
380
    public void onUpdateEntity()
381
    {
382
        try
383
        {
384
            super.onUpdate();
385
386
            for (int i = 0; i < this.inventory.getSizeInventory(); ++i)
387
            {
388
                ItemStack itemstack = this.inventory.getStackInSlot(i);
389
390
                if (itemstack != null && itemstack.getItem().isMap())
391
                {
392
                    Packet packet = ((ItemMapBase)itemstack.getItem()).createMapDataPacket(itemstack, this.worldObj, this);
393
394
                    if (packet != null)
395
                    {
396
                        this.playerNetServerHandler.sendPacket(packet);
397
                    }
398
                }
399
            }
400
401
            if (this.getHealth() != this.lastHealth || this.lastFoodLevel != this.foodStats.getFoodLevel() || this.foodStats.getSaturationLevel() == 0.0F != this.wasHungry)
402
            {
403
                this.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(this.getHealth(), this.foodStats.getFoodLevel(), this.foodStats.getSaturationLevel()));
404
                this.lastHealth = this.getHealth();
405
                this.lastFoodLevel = this.foodStats.getFoodLevel();
406
                this.wasHungry = this.foodStats.getSaturationLevel() == 0.0F;
407
            }
408
409
            if (this.getHealth() + this.getAbsorptionAmount() != this.combinedHealth)
410
            {
411
                this.combinedHealth = this.getHealth() + this.getAbsorptionAmount();
412
413
                for (ScoreObjective scoreobjective : this.getWorldScoreboard().getObjectivesFromCriteria(IScoreObjectiveCriteria.health))
414
                {
415
                    this.getWorldScoreboard().getValueFromObjective(this.getName(), scoreobjective).func_96651_a(Arrays.<EntityPlayer>asList(new EntityPlayer[] {this}));
416
                }
417
            }
418
419
            if (this.experienceTotal != this.lastExperience)
420
            {
421
                this.lastExperience = this.experienceTotal;
422
                this.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(this.experience, this.experienceTotal, this.experienceLevel));
423
            }
424
425
            if (this.ticksExisted % 20 * 5 == 0 && !this.getStatFile().hasAchievementUnlocked(AchievementList.exploreAllBiomes))
426
            {
427
                this.updateBiomesExplored();
428
            }
429
        }
430
        catch (Throwable throwable)
431
        {
432
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Ticking player");
433
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Player being ticked");
434
            this.addEntityCrashInfo(crashreportcategory);
435
            throw new ReportedException(crashreport);
436
        }
437
    }
438
439
    /**
440
     * Updates all biomes that have been explored by this player and triggers Adventuring Time if player qualifies.
441
     */
442
    protected void updateBiomesExplored()
443
    {
444
        BiomeGenBase biomegenbase = this.worldObj.getBiomeGenForCoords(new BlockPos(MathHelper.floor_double(this.posX), 0, MathHelper.floor_double(this.posZ)));
445
        String s = biomegenbase.biomeName;
446
        JsonSerializableSet jsonserializableset = (JsonSerializableSet)this.getStatFile().func_150870_b(AchievementList.exploreAllBiomes);
447
448
        if (jsonserializableset == null)
449
        {
450
            jsonserializableset = (JsonSerializableSet)this.getStatFile().func_150872_a(AchievementList.exploreAllBiomes, new JsonSerializableSet());
451
        }
452
453
        jsonserializableset.add(s);
454
455
        if (this.getStatFile().canUnlockAchievement(AchievementList.exploreAllBiomes) && jsonserializableset.size() >= BiomeGenBase.explorationBiomesList.size())
456
        {
457
            Set<BiomeGenBase> set = Sets.newHashSet(BiomeGenBase.explorationBiomesList);
458
459
            for (String s1 : jsonserializableset)
460
            {
461
                Iterator<BiomeGenBase> iterator = set.iterator();
462
463
                while (iterator.hasNext())
464
                {
465
                    BiomeGenBase biomegenbase1 = (BiomeGenBase)iterator.next();
466
467
                    if (biomegenbase1.biomeName.equals(s1))
468
                    {
469
                        iterator.remove();
470
                    }
471
                }
472
473
                if (set.isEmpty())
474
                {
475
                    break;
476
                }
477
            }
478
479
            if (set.isEmpty())
480
            {
481
                this.triggerAchievement(AchievementList.exploreAllBiomes);
482
            }
483
        }
484
    }
485
486
    /**
487
     * Called when the mob's health reaches 0.
488
     */
489
    public void onDeath(DamageSource cause)
490
    {
491
        if (this.worldObj.getGameRules().getBoolean("showDeathMessages"))
492
        {
493
            Team team = this.getTeam();
494
495
            if (team != null && team.getDeathMessageVisibility() != Team.EnumVisible.ALWAYS)
496
            {
497
                if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OTHER_TEAMS)
498
                {
499
                    this.mcServer.getConfigurationManager().sendMessageToAllTeamMembers(this, this.getCombatTracker().getDeathMessage());
500
                }
501
                else if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OWN_TEAM)
502
                {
503
                    this.mcServer.getConfigurationManager().sendMessageToTeamOrEvryPlayer(this, this.getCombatTracker().getDeathMessage());
504
                }
505
            }
506
            else
507
            {
508
                this.mcServer.getConfigurationManager().sendChatMsg(this.getCombatTracker().getDeathMessage());
509
            }
510
        }
511
512
        if (!this.worldObj.getGameRules().getBoolean("keepInventory"))
513
        {
514
            this.inventory.dropAllItems();
515
        }
516
517
        for (ScoreObjective scoreobjective : this.worldObj.getScoreboard().getObjectivesFromCriteria(IScoreObjectiveCriteria.deathCount))
518
        {
519
            Score score = this.getWorldScoreboard().getValueFromObjective(this.getName(), scoreobjective);
520
            score.func_96648_a();
521
        }
522
523
        EntityLivingBase entitylivingbase = this.getAttackingEntity();
524
525
        if (entitylivingbase != null)
526
        {
527
            EntityList.EntityEggInfo entitylist$entityegginfo = (EntityList.EntityEggInfo)EntityList.entityEggs.get(Integer.valueOf(EntityList.getEntityID(entitylivingbase)));
528
529
            if (entitylist$entityegginfo != null)
530
            {
531
                this.triggerAchievement(entitylist$entityegginfo.field_151513_e);
532
            }
533
534
            entitylivingbase.addToPlayerScore(this, this.scoreValue);
535
        }
536
537
        this.triggerAchievement(StatList.deathsStat);
538
        this.func_175145_a(StatList.timeSinceDeathStat);
539
        this.getCombatTracker().reset();
540
    }
541
542
    /**
543
     * Called when the entity is attacked.
544
     */
545
    public boolean attackEntityFrom(DamageSource source, float amount)
546
    {
547
        if (this.isEntityInvulnerable(source))
548
        {
549
            return false;
550
        }
551
        else
552
        {
553
            boolean flag = this.mcServer.isDedicatedServer() && this.canPlayersAttack() && "fall".equals(source.damageType);
554
555
            if (!flag && this.respawnInvulnerabilityTicks > 0 && source != DamageSource.outOfWorld)
556
            {
557
                return false;
558
            }
559
            else
560
            {
561
                if (source instanceof EntityDamageSource)
562
                {
563
                    Entity entity = source.getEntity();
564
565
                    if (entity instanceof EntityPlayer && !this.canAttackPlayer((EntityPlayer)entity))
566
                    {
567
                        return false;
568
                    }
569
570
                    if (entity instanceof EntityArrow)
571
                    {
572
                        EntityArrow entityarrow = (EntityArrow)entity;
573
574
                        if (entityarrow.shootingEntity instanceof EntityPlayer && !this.canAttackPlayer((EntityPlayer)entityarrow.shootingEntity))
575
                        {
576
                            return false;
577
                        }
578
                    }
579
                }
580
581
                return super.attackEntityFrom(source, amount);
582
            }
583
        }
584
    }
585
586
    public boolean canAttackPlayer(EntityPlayer other)
587
    {
588
        return !this.canPlayersAttack() ? false : super.canAttackPlayer(other);
589
    }
590
591
    /**
592
     * Returns if other players can attack this player
593
     */
594
    private boolean canPlayersAttack()
595
    {
596
        return this.mcServer.isPVPEnabled();
597
    }
598
599
    /**
600
     * Teleports the entity to another dimension. Params: Dimension number to teleport to
601
     */
602
    public void travelToDimension(int dimensionId)
603
    {
604
        if (this.dimension == 1 && dimensionId == 1)
605
        {
606
            this.triggerAchievement(AchievementList.theEnd2);
607
            this.worldObj.removeEntity(this);
608
            this.playerConqueredTheEnd = true;
609
            this.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(4, 0.0F));
610
        }
611
        else
612
        {
613
            if (this.dimension == 0 && dimensionId == 1)
614
            {
615
                this.triggerAchievement(AchievementList.theEnd);
616
                BlockPos blockpos = this.mcServer.worldServerForDimension(dimensionId).getSpawnCoordinate();
617
618
                if (blockpos != null)
619
                {
620
                    this.playerNetServerHandler.setPlayerLocation((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ(), 0.0F, 0.0F);
621
                }
622
623
                dimensionId = 1;
624
            }
625
            else
626
            {
627
                this.triggerAchievement(AchievementList.portal);
628
            }
629
630
            this.mcServer.getConfigurationManager().transferPlayerToDimension(this, dimensionId);
631
            this.lastExperience = -1;
632
            this.lastHealth = -1.0F;
633
            this.lastFoodLevel = -1;
634
        }
635
    }
636
637
    public boolean isSpectatedByPlayer(EntityPlayerMP player)
638
    {
639
        return player.isSpectator() ? this.getSpectatingEntity() == this : (this.isSpectator() ? false : super.isSpectatedByPlayer(player));
640
    }
641
642
    private void sendTileEntityUpdate(TileEntity p_147097_1_)
643
    {
644
        if (p_147097_1_ != null)
645
        {
646
            Packet packet = p_147097_1_.getDescriptionPacket();
647
648
            if (packet != null)
649
            {
650
                this.playerNetServerHandler.sendPacket(packet);
651
            }
652
        }
653
    }
654
655
    /**
656
     * Called whenever an item is picked up from walking over it. Args: pickedUpEntity, stackSize
657
     */
658
    public void onItemPickup(Entity p_71001_1_, int p_71001_2_)
659
    {
660
        super.onItemPickup(p_71001_1_, p_71001_2_);
661
        this.openContainer.detectAndSendChanges();
662
    }
663
664
    public EntityPlayer.EnumStatus trySleep(BlockPos bedLocation)
665
    {
666
        EntityPlayer.EnumStatus entityplayer$enumstatus = super.trySleep(bedLocation);
667
668
        if (entityplayer$enumstatus == EntityPlayer.EnumStatus.OK)
669
        {
670
            Packet packet = new S0APacketUseBed(this, bedLocation);
671
            this.getServerForPlayer().getEntityTracker().sendToAllTrackingEntity(this, packet);
672
            this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
673
            this.playerNetServerHandler.sendPacket(packet);
674
        }
675
676
        return entityplayer$enumstatus;
677
    }
678
679
    /**
680
     * Wake up the player if they're sleeping.
681
     */
682
    public void wakeUpPlayer(boolean immediately, boolean updateWorldFlag, boolean setSpawn)
683
    {
684
        if (this.isPlayerSleeping())
685
        {
686
            this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(this, 2));
687
        }
688
689
        super.wakeUpPlayer(immediately, updateWorldFlag, setSpawn);
690
691
        if (this.playerNetServerHandler != null)
692
        {
693
            this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
694
        }
695
    }
696
697
    /**
698
     * Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
699
     */
700
    public void mountEntity(Entity entityIn)
701
    {
702
        Entity entity = this.ridingEntity;
703
        super.mountEntity(entityIn);
704
705
        if (entityIn != entity)
706
        {
707
            this.playerNetServerHandler.sendPacket(new S1BPacketEntityAttach(0, this, this.ridingEntity));
708
            this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
709
        }
710
    }
711
712
    protected void updateFallState(double y, boolean onGroundIn, Block blockIn, BlockPos pos)
713
    {
714
    }
715
716
    /**
717
     * process player falling based on movement packet
718
     */
719
    public void handleFalling(double p_71122_1_, boolean p_71122_3_)
720
    {
721
        int i = MathHelper.floor_double(this.posX);
722
        int j = MathHelper.floor_double(this.posY - 0.20000000298023224D);
723
        int k = MathHelper.floor_double(this.posZ);
724
        BlockPos blockpos = new BlockPos(i, j, k);
725
        Block block = this.worldObj.getBlockState(blockpos).getBlock();
726
727
        if (block.getMaterial() == Material.air)
728
        {
729
            Block block1 = this.worldObj.getBlockState(blockpos.down()).getBlock();
730
731
            if (block1 instanceof BlockFence || block1 instanceof BlockWall || block1 instanceof BlockFenceGate)
732
            {
733
                blockpos = blockpos.down();
734
                block = this.worldObj.getBlockState(blockpos).getBlock();
735
            }
736
        }
737
738
        super.updateFallState(p_71122_1_, p_71122_3_, block, blockpos);
739
    }
740
741
    public void openEditSign(TileEntitySign signTile)
742
    {
743
        signTile.setPlayer(this);
744
        this.playerNetServerHandler.sendPacket(new S36PacketSignEditorOpen(signTile.getPos()));
745
    }
746
747
    /**
748
     * get the next window id to use
749
     */
750
    private void getNextWindowId()
751
    {
752
        this.currentWindowId = this.currentWindowId % 100 + 1;
753
    }
754
755
    public void displayGui(IInteractionObject guiOwner)
756
    {
757
        this.getNextWindowId();
758
        this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, guiOwner.getGuiID(), guiOwner.getDisplayName()));
759
        this.openContainer = guiOwner.createContainer(this.inventory, this);
760
        this.openContainer.windowId = this.currentWindowId;
761
        this.openContainer.onCraftGuiOpened(this);
762
    }
763
764
    /**
765
     * Displays the GUI for interacting with a chest inventory. Args: chestInventory
766
     */
767
    public void displayGUIChest(IInventory chestInventory)
768
    {
769
        if (this.openContainer != this.inventoryContainer)
770
        {
771
            this.closeScreen();
772
        }
773
774
        if (chestInventory instanceof ILockableContainer)
775
        {
776
            ILockableContainer ilockablecontainer = (ILockableContainer)chestInventory;
777
778
            if (ilockablecontainer.isLocked() && !this.canOpen(ilockablecontainer.getLockCode()) && !this.isSpectator())
779
            {
780
                this.playerNetServerHandler.sendPacket(new S02PacketChat(new ChatComponentTranslation("container.isLocked", new Object[] {chestInventory.getDisplayName()}), (byte)2));
781
                this.playerNetServerHandler.sendPacket(new S29PacketSoundEffect("random.door_close", this.posX, this.posY, this.posZ, 1.0F, 1.0F));
782
                return;
783
            }
784
        }
785
786
        this.getNextWindowId();
787
788
        if (chestInventory instanceof IInteractionObject)
789
        {
790
            this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getDisplayName(), chestInventory.getSizeInventory()));
791
            this.openContainer = ((IInteractionObject)chestInventory).createContainer(this.inventory, this);
792
        }
793
        else
794
        {
795
            this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:container", chestInventory.getDisplayName(), chestInventory.getSizeInventory()));
796
            this.openContainer = new ContainerChest(this.inventory, chestInventory, this);
797
        }
798
799
        this.openContainer.windowId = this.currentWindowId;
800
        this.openContainer.onCraftGuiOpened(this);
801
    }
802
803
    public void displayVillagerTradeGui(IMerchant villager)
804
    {
805
        this.getNextWindowId();
806
        this.openContainer = new ContainerMerchant(this.inventory, villager, this.worldObj);
807
        this.openContainer.windowId = this.currentWindowId;
808
        this.openContainer.onCraftGuiOpened(this);
809
        IInventory iinventory = ((ContainerMerchant)this.openContainer).getMerchantInventory();
810
        IChatComponent ichatcomponent = villager.getDisplayName();
811
        this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:villager", ichatcomponent, iinventory.getSizeInventory()));
812
        MerchantRecipeList merchantrecipelist = villager.getRecipes(this);
813
814
        if (merchantrecipelist != null)
815
        {
816
            PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
817
            packetbuffer.writeInt(this.currentWindowId);
818
            merchantrecipelist.writeToBuf(packetbuffer);
819
            this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer));
820
        }
821
    }
822
823
    public void displayGUIHorse(EntityHorse horse, IInventory horseInventory)
824
    {
825
        if (this.openContainer != this.inventoryContainer)
826
        {
827
            this.closeScreen();
828
        }
829
830
        this.getNextWindowId();
831
        this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "EntityHorse", horseInventory.getDisplayName(), horseInventory.getSizeInventory(), horse.getEntityId()));
832
        this.openContainer = new ContainerHorseInventory(this.inventory, horseInventory, horse, this);
833
        this.openContainer.windowId = this.currentWindowId;
834
        this.openContainer.onCraftGuiOpened(this);
835
    }
836
837
    /**
838
     * Displays the GUI for interacting with a book.
839
     */
840
    public void displayGUIBook(ItemStack bookStack)
841
    {
842
        Item item = bookStack.getItem();
843
844
        if (item == Items.written_book)
845
        {
846
            this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|BOpen", new PacketBuffer(Unpooled.buffer())));
847
        }
848
    }
849
850
    /**
851
     * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
852
     * contents of that slot. Args: Container, slot number, slot contents
853
     */
854
    public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
855
    {
856
        if (!(containerToSend.getSlot(slotInd) instanceof SlotCrafting))
857
        {
858
            if (!this.isChangingQuantityOnly)
859
            {
860
                this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(containerToSend.windowId, slotInd, stack));
861
            }
862
        }
863
    }
864
865
    public void sendContainerToPlayer(Container p_71120_1_)
866
    {
867
        this.updateCraftingInventory(p_71120_1_, p_71120_1_.getInventory());
868
    }
869
870
    /**
871
     * update the crafting window inventory with the items in the list
872
     */
873
    public void updateCraftingInventory(Container containerToSend, List<ItemStack> itemsList)
874
    {
875
        this.playerNetServerHandler.sendPacket(new S30PacketWindowItems(containerToSend.windowId, itemsList));
876
        this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(-1, -1, this.inventory.getItemStack()));
877
    }
878
879
    /**
880
     * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
881
     * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
882
     * value. Both are truncated to shorts in non-local SMP.
883
     */
884
    public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue)
885
    {
886
        this.playerNetServerHandler.sendPacket(new S31PacketWindowProperty(containerIn.windowId, varToUpdate, newValue));
887
    }
888
889
    public void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_)
890
    {
891
        for (int i = 0; i < p_175173_2_.getFieldCount(); ++i)
892
        {
893
            this.playerNetServerHandler.sendPacket(new S31PacketWindowProperty(p_175173_1_.windowId, i, p_175173_2_.getField(i)));
894
        }
895
    }
896
897
    /**
898
     * set current crafting inventory back to the 2x2 square
899
     */
900
    public void closeScreen()
901
    {
902
        this.playerNetServerHandler.sendPacket(new S2EPacketCloseWindow(this.openContainer.windowId));
903
        this.closeContainer();
904
    }
905
906
    /**
907
     * updates item held by mouse
908
     */
909
    public void updateHeldItem()
910
    {
911
        if (!this.isChangingQuantityOnly)
912
        {
913
            this.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(-1, -1, this.inventory.getItemStack()));
914
        }
915
    }
916
917
    /**
918
     * Closes the container the player currently has open.
919
     */
920
    public void closeContainer()
921
    {
922
        this.openContainer.onContainerClosed(this);
923
        this.openContainer = this.inventoryContainer;
924
    }
925
926
    public void setEntityActionState(float p_110430_1_, float p_110430_2_, boolean p_110430_3_, boolean sneaking)
927
    {
928
        if (this.ridingEntity != null)
929
        {
930
            if (p_110430_1_ >= -1.0F && p_110430_1_ <= 1.0F)
931
            {
932
                this.moveStrafing = p_110430_1_;
933
            }
934
935
            if (p_110430_2_ >= -1.0F && p_110430_2_ <= 1.0F)
936
            {
937
                this.moveForward = p_110430_2_;
938
            }
939
940
            this.isJumping = p_110430_3_;
941
            this.setSneaking(sneaking);
942
        }
943
    }
944
945
    /**
946
     * Adds a value to a statistic field.
947
     */
948
    public void addStat(StatBase stat, int amount)
949
    {
950
        if (stat != null)
951
        {
952
            this.statsFile.increaseStat(this, stat, amount);
953
954
            for (ScoreObjective scoreobjective : this.getWorldScoreboard().getObjectivesFromCriteria(stat.getCriteria()))
955
            {
956
                this.getWorldScoreboard().getValueFromObjective(this.getName(), scoreobjective).increseScore(amount);
957
            }
958
959
            if (this.statsFile.func_150879_e())
960
            {
961
                this.statsFile.func_150876_a(this);
962
            }
963
        }
964
    }
965
966
    public void func_175145_a(StatBase p_175145_1_)
967
    {
968
        if (p_175145_1_ != null)
969
        {
970
            this.statsFile.unlockAchievement(this, p_175145_1_, 0);
971
972
            for (ScoreObjective scoreobjective : this.getWorldScoreboard().getObjectivesFromCriteria(p_175145_1_.getCriteria()))
973
            {
974
                this.getWorldScoreboard().getValueFromObjective(this.getName(), scoreobjective).setScorePoints(0);
975
            }
976
977
            if (this.statsFile.func_150879_e())
978
            {
979
                this.statsFile.func_150876_a(this);
980
            }
981
        }
982
    }
983
984
    public void mountEntityAndWakeUp()
985
    {
986
        if (this.riddenByEntity != null)
987
        {
988
            this.riddenByEntity.mountEntity(this);
989
        }
990
991
        if (this.sleeping)
992
        {
993
            this.wakeUpPlayer(true, false, false);
994
        }
995
    }
996
997
    /**
998
     * this function is called when a players inventory is sent to him, lastHealth is updated on any dimension
999
     * transitions, then reset.
1000
     */
1001
    public void setPlayerHealthUpdated()
1002
    {
1003
        this.lastHealth = -1.0E8F;
1004
    }
1005
1006
    public void addChatComponentMessage(IChatComponent chatComponent)
1007
    {
1008
        this.playerNetServerHandler.sendPacket(new S02PacketChat(chatComponent));
1009
    }
1010
1011
    /**
1012
     * Used for when item use count runs out, ie: eating completed
1013
     */
1014
    protected void onItemUseFinish()
1015
    {
1016
        this.playerNetServerHandler.sendPacket(new S19PacketEntityStatus(this, (byte)9));
1017
        super.onItemUseFinish();
1018
    }
1019
1020
    /**
1021
     * sets the itemInUse when the use item button is clicked. Args: itemstack, int maxItemUseDuration
1022
     */
1023
    public void setItemInUse(ItemStack stack, int duration)
1024
    {
1025
        super.setItemInUse(stack, duration);
1026
1027
        if (stack != null && stack.getItem() != null && stack.getItem().getItemUseAction(stack) == EnumAction.EAT)
1028
        {
1029
            this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(this, 3));
1030
        }
1031
    }
1032
1033
    /**
1034
     * Copies the values from the given player into this player if boolean par2 is true. Always clones Ender Chest
1035
     * Inventory.
1036
     */
1037
    public void clonePlayer(EntityPlayer oldPlayer, boolean respawnFromEnd)
1038
    {
1039
        super.clonePlayer(oldPlayer, respawnFromEnd);
1040
        this.lastExperience = -1;
1041
        this.lastHealth = -1.0F;
1042
        this.lastFoodLevel = -1;
1043
        this.destroyedItemsNetCache.addAll(((EntityPlayerMP)oldPlayer).destroyedItemsNetCache);
1044
    }
1045
1046
    protected void onNewPotionEffect(PotionEffect id)
1047
    {
1048
        super.onNewPotionEffect(id);
1049
        this.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.getEntityId(), id));
1050
    }
1051
1052
    protected void onChangedPotionEffect(PotionEffect id, boolean p_70695_2_)
1053
    {
1054
        super.onChangedPotionEffect(id, p_70695_2_);
1055
        this.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.getEntityId(), id));
1056
    }
1057
1058
    protected void onFinishedPotionEffect(PotionEffect effect)
1059
    {
1060
        super.onFinishedPotionEffect(effect);
1061
        this.playerNetServerHandler.sendPacket(new S1EPacketRemoveEntityEffect(this.getEntityId(), effect));
1062
    }
1063
1064
    /**
1065
     * Sets the position of the entity and updates the 'last' variables
1066
     */
1067
    public void setPositionAndUpdate(double x, double y, double z)
1068
    {
1069
        this.playerNetServerHandler.setPlayerLocation(x, y, z, this.rotationYaw, this.rotationPitch);
1070
    }
1071
1072
    /**
1073
     * Called when the player performs a critical hit on the Entity. Args: entity that was hit critically
1074
     */
1075
    public void onCriticalHit(Entity entityHit)
1076
    {
1077
        this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(entityHit, 4));
1078
    }
1079
1080
    public void onEnchantmentCritical(Entity entityHit)
1081
    {
1082
        this.getServerForPlayer().getEntityTracker().func_151248_b(this, new S0BPacketAnimation(entityHit, 5));
1083
    }
1084
1085
    /**
1086
     * Sends the player's abilities to the server (if there is one).
1087
     */
1088
    public void sendPlayerAbilities()
1089
    {
1090
        if (this.playerNetServerHandler != null)
1091
        {
1092
            this.playerNetServerHandler.sendPacket(new S39PacketPlayerAbilities(this.capabilities));
1093
            this.updatePotionMetadata();
1094
        }
1095
    }
1096
1097
    public WorldServer getServerForPlayer()
1098
    {
1099
        return (WorldServer)this.worldObj;
1100
    }
1101
1102
    /**
1103
     * Sets the player's game mode and sends it to them.
1104
     */
1105
    public void setGameType(WorldSettings.GameType gameType)
1106
    {
1107
        this.theItemInWorldManager.setGameType(gameType);
1108
        this.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(3, (float)gameType.getID()));
1109
1110
        if (gameType == WorldSettings.GameType.SPECTATOR)
1111
        {
1112
            this.mountEntity((Entity)null);
1113
        }
1114
        else
1115
        {
1116
            this.setSpectatingEntity(this);
1117
        }
1118
1119
        this.sendPlayerAbilities();
1120
        this.markPotionsDirty();
1121
    }
1122
1123
    /**
1124
     * Returns true if the player is in spectator mode.
1125
     */
1126
    public boolean isSpectator()
1127
    {
1128
        return this.theItemInWorldManager.getGameType() == WorldSettings.GameType.SPECTATOR;
1129
    }
1130
1131
    /**
1132
     * Send a chat message to the CommandSender
1133
     */
1134
    public void addChatMessage(IChatComponent component)
1135
    {
1136
        this.playerNetServerHandler.sendPacket(new S02PacketChat(component));
1137
    }
1138
1139
    /**
1140
     * Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
1141
     */
1142
    public boolean canCommandSenderUseCommand(int permLevel, String commandName)
1143
    {
1144
        if ("seed".equals(commandName) && !this.mcServer.isDedicatedServer())
1145
        {
1146
            return true;
1147
        }
1148
        else if (!"tell".equals(commandName) && !"help".equals(commandName) && !"me".equals(commandName) && !"trigger".equals(commandName))
1149
        {
1150
            if (this.mcServer.getConfigurationManager().canSendCommands(this.getGameProfile()))
1151
            {
1152
                UserListOpsEntry userlistopsentry = (UserListOpsEntry)this.mcServer.getConfigurationManager().getOppedPlayers().getEntry(this.getGameProfile());
1153
                return userlistopsentry != null ? userlistopsentry.getPermissionLevel() >= permLevel : this.mcServer.getOpPermissionLevel() >= permLevel;
1154
            }
1155
            else
1156
            {
1157
                return false;
1158
            }
1159
        }
1160
        else
1161
        {
1162
            return true;
1163
        }
1164
    }
1165
1166
    /**
1167
     * Gets the player's IP address. Used in /banip.
1168
     */
1169
    public String getPlayerIP()
1170
    {
1171
        String s = this.playerNetServerHandler.netManager.getRemoteAddress().toString();
1172
        s = s.substring(s.indexOf("/") + 1);
1173
        s = s.substring(0, s.indexOf(":"));
1174
        return s;
1175
    }
1176
1177
    public void handleClientSettings(C15PacketClientSettings packetIn)
1178
    {
1179
        this.translator = packetIn.getLang();
1180
        this.chatVisibility = packetIn.getChatVisibility();
1181
        this.chatColours = packetIn.isColorsEnabled();
1182
        this.getDataWatcher().updateObject(10, Byte.valueOf((byte)packetIn.getModelPartFlags()));
1183
    }
1184
1185
    public EntityPlayer.EnumChatVisibility getChatVisibility()
1186
    {
1187
        return this.chatVisibility;
1188
    }
1189
1190
    public void loadResourcePack(String url, String hash)
1191
    {
1192
        this.playerNetServerHandler.sendPacket(new S48PacketResourcePackSend(url, hash));
1193
    }
1194
1195
    /**
1196
     * Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
1197
     * the coordinates 0, 0, 0
1198
     */
1199
    public BlockPos getPosition()
1200
    {
1201
        return new BlockPos(this.posX, this.posY + 0.5D, this.posZ);
1202
    }
1203
1204
    public void markPlayerActive()
1205
    {
1206
        this.playerLastActiveTime = MinecraftServer.getCurrentTimeMillis();
1207
    }
1208
1209
    /**
1210
     * Gets the stats file for reading achievements
1211
     */
1212
    public StatisticsFile getStatFile()
1213
    {
1214
        return this.statsFile;
1215
    }
1216
1217
    /**
1218
     * Sends a packet to the player to remove an entity.
1219
     */
1220
    public void removeEntity(Entity p_152339_1_)
1221
    {
1222
        if (p_152339_1_ instanceof EntityPlayer)
1223
        {
1224
            this.playerNetServerHandler.sendPacket(new S13PacketDestroyEntities(new int[] {p_152339_1_.getEntityId()}));
1225
        }
1226
        else
1227
        {
1228
            this.destroyedItemsNetCache.add(Integer.valueOf(p_152339_1_.getEntityId()));
1229
        }
1230
    }
1231
1232
    /**
1233
     * Clears potion metadata values if the entity has no potion effects. Otherwise, updates potion effect color,
1234
     * ambience, and invisibility metadata values
1235
     */
1236
    protected void updatePotionMetadata()
1237
    {
1238
        if (this.isSpectator())
1239
        {
1240
            this.resetPotionEffectMetadata();
1241
            this.setInvisible(true);
1242
        }
1243
        else
1244
        {
1245
            super.updatePotionMetadata();
1246
        }
1247
1248
        this.getServerForPlayer().getEntityTracker().func_180245_a(this);
1249
    }
1250
1251
    public Entity getSpectatingEntity()
1252
    {
1253
        return (Entity)(this.spectatingEntity == null ? this : this.spectatingEntity);
1254
    }
1255
1256
    public void setSpectatingEntity(Entity entityToSpectate)
1257
    {
1258
        Entity entity = this.getSpectatingEntity();
1259
        this.spectatingEntity = (Entity)(entityToSpectate == null ? this : entityToSpectate);
1260
1261
        if (entity != this.spectatingEntity)
1262
        {
1263
            this.playerNetServerHandler.sendPacket(new S43PacketCamera(this.spectatingEntity));
1264
            this.setPositionAndUpdate(this.spectatingEntity.posX, this.spectatingEntity.posY, this.spectatingEntity.posZ);
1265
        }
1266
    }
1267
1268
    /**
1269
     * Attacks for the player the targeted entity with the currently equipped item.  The equipped item has hitEntity
1270
     * called on it. Args: targetEntity
1271
     */
1272
    public void attackTargetEntityWithCurrentItem(Entity targetEntity)
1273
    {
1274
        if (this.theItemInWorldManager.getGameType() == WorldSettings.GameType.SPECTATOR)
1275
        {
1276
            this.setSpectatingEntity(targetEntity);
1277
        }
1278
        else
1279
        {
1280
            super.attackTargetEntityWithCurrentItem(targetEntity);
1281
        }
1282
    }
1283
1284
    public long getLastActiveTime()
1285
    {
1286
        return this.playerLastActiveTime;
1287
    }
1288
1289
    /**
1290
     * Returns null which indicates the tab list should just display the player's name, return a different value to
1291
     * display the specified text instead of the player's name
1292
     */
1293
    public IChatComponent getTabListDisplayName()
1294
    {
1295
        return null;
1296
    }
1297
}
1298

Deobfuscated MCP 1.8.9 source of EntityPlayerMP from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/player/EntityPlayerMP.java), stored verbatim.