001 package net.minecraft.src;
002
003 import java.io.ByteArrayOutputStream;
004 import java.io.DataOutputStream;
005 import java.io.IOException;
006 import java.util.ArrayList;
007 import java.util.Iterator;
008 import java.util.LinkedList;
009 import java.util.List;
010 import net.minecraft.server.MinecraftServer;
011 import net.minecraftforge.common.ForgeHooks;
012 import net.minecraftforge.common.MinecraftForge;
013 import net.minecraftforge.event.entity.player.PlayerDropsEvent;
014
015 public class EntityPlayerMP extends EntityPlayer implements ICrafting
016 {
017 private StringTranslate translator = new StringTranslate("en_US");
018
019 /**
020 * The NetServerHandler assigned to this player by the ServerConfigurationManager.
021 */
022 public NetServerHandler playerNetServerHandler;
023
024 /** Reference to the MinecraftServer object. */
025 public MinecraftServer mcServer;
026
027 /** The ItemInWorldManager belonging to this player */
028 public ItemInWorldManager theItemInWorldManager;
029
030 /** player X position as seen by PlayerManager */
031 public double managedPosX;
032
033 /** player Z position as seen by PlayerManager */
034 public double managedPosZ;
035
036 /** LinkedList that holds the loaded chunks. */
037 public final List loadedChunks = new LinkedList();
038
039 /** entities added to this list will be packet29'd to the player */
040 public final List destroyedItemsNetCache = new LinkedList();
041
042 /** set to getHealth */
043 private int lastHealth = -99999999;
044
045 /** set to foodStats.GetFoodLevel */
046 private int lastFoodLevel = -99999999;
047
048 /** set to foodStats.getSaturationLevel() == 0.0F each tick */
049 private boolean wasHungry = true;
050
051 /** Amount of experience the client was last set to */
052 private int lastExperience = -99999999;
053
054 /** de-increments onUpdate, attackEntityFrom is ignored if this >0 */
055 private int initialInvulnerability = 60;
056
057 /** must be between 3>x>15 (strictly between) */
058 private int renderDistance = 0;
059 private int chatVisibility = 0;
060 private boolean chatColours = true;
061
062 /**
063 * The currently in use window ID. Incremented every time a window is opened.
064 */
065 public int currentWindowId = 0;
066
067 /**
068 * poor mans concurency flag, lets hope the jvm doesn't re-order the setting of this flag wrt the inventory change
069 * on the next line
070 */
071 public boolean playerInventoryBeingManipulated;
072 public int ping;
073
074 /**
075 * Set when a player beats the ender dragon, used to respawn the player at the spawn point while retaining inventory
076 * and XP
077 */
078 public boolean playerConqueredTheEnd = false;
079
080 public EntityPlayerMP(MinecraftServer par1MinecraftServer, World par2World, String par3Str, ItemInWorldManager par4ItemInWorldManager)
081 {
082 super(par2World);
083 par4ItemInWorldManager.thisPlayerMP = this;
084 this.theItemInWorldManager = par4ItemInWorldManager;
085 this.renderDistance = par1MinecraftServer.getConfigurationManager().getViewDistance();
086 ChunkCoordinates var5 = par2World.provider.getRandomizedSpawnPoint();
087 int var6 = var5.posX;
088 int var7 = var5.posZ;
089 int var8 = var5.posY;
090
091 this.setLocationAndAngles((double)var6 + 0.5D, (double)var8, (double)var7 + 0.5D, 0.0F, 0.0F);
092 this.mcServer = par1MinecraftServer;
093 this.stepHeight = 0.0F;
094 this.username = par3Str;
095 this.yOffset = 0.0F;
096 }
097
098 /**
099 * (abstract) Protected helper method to read subclass entity data from NBT.
100 */
101 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
102 {
103 super.readEntityFromNBT(par1NBTTagCompound);
104
105 if (par1NBTTagCompound.hasKey("playerGameType"))
106 {
107 this.theItemInWorldManager.setGameType(EnumGameType.getByID(par1NBTTagCompound.getInteger("playerGameType")));
108 }
109 }
110
111 /**
112 * (abstract) Protected helper method to write subclass entity data to NBT.
113 */
114 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
115 {
116 super.writeEntityToNBT(par1NBTTagCompound);
117 par1NBTTagCompound.setInteger("playerGameType", this.theItemInWorldManager.getGameType().getID());
118 }
119
120 /**
121 * Add experience levels to this player.
122 */
123 public void addExperienceLevel(int par1)
124 {
125 super.addExperienceLevel(par1);
126 this.lastExperience = -1;
127 }
128
129 public void addSelfToInternalCraftingInventory()
130 {
131 this.craftingInventory.addCraftingToCrafters(this);
132 }
133
134 /**
135 * sets the players height back to normal after doing things like sleeping and dieing
136 */
137 protected void resetHeight()
138 {
139 this.yOffset = 0.0F;
140 }
141
142 public float getEyeHeight()
143 {
144 return 1.62F;
145 }
146
147 /**
148 * Called to update the entity's position/logic.
149 */
150 public void onUpdate()
151 {
152 this.theItemInWorldManager.updateBlockRemoving();
153 --this.initialInvulnerability;
154 this.craftingInventory.updateCraftingResults();
155
156 if (!this.loadedChunks.isEmpty())
157 {
158 ArrayList var1 = new ArrayList();
159 Iterator var2 = this.loadedChunks.iterator();
160 ArrayList var3 = new ArrayList();
161
162 while (var2.hasNext() && var1.size() < 5)
163 {
164 ChunkCoordIntPair var4 = (ChunkCoordIntPair)var2.next();
165 var2.remove();
166
167 if (var4 != null && this.worldObj.blockExists(var4.chunkXPos << 4, 0, var4.chunkZPos << 4))
168 {
169 var1.add(this.worldObj.getChunkFromChunkCoords(var4.chunkXPos, var4.chunkZPos));
170 //BugFix: 16 makes it load an extra chunk, which isn't associated with a player, which makes it not unload unless a player walks near it.
171 //ToDo: Find a way to efficiently clean abandoned chunks.
172 //var3.addAll(((WorldServer)this.worldObj).getAllTileEntityInBox(var4.chunkXPos * 16, 0, var4.chunkZPos * 16, var4.chunkXPos * 16 + 16, 256, var4.chunkZPos * 16 + 16));
173 var3.addAll(((WorldServer)this.worldObj).getAllTileEntityInBox(var4.chunkXPos * 16, 0, var4.chunkZPos * 16, var4.chunkXPos * 16 + 15, 256, var4.chunkZPos * 16 + 15));
174
175 }
176 }
177
178 if (!var1.isEmpty())
179 {
180 this.playerNetServerHandler.sendPacketToPlayer(new Packet56MapChunks(var1));
181 Iterator var9 = var3.iterator();
182
183 while (var9.hasNext())
184 {
185 TileEntity var5 = (TileEntity)var9.next();
186 this.sendTileEntityToPlayer(var5);
187 }
188 }
189 }
190
191 if (!this.destroyedItemsNetCache.isEmpty())
192 {
193 int var6 = Math.min(this.destroyedItemsNetCache.size(), 127);
194 int[] var7 = new int[var6];
195 Iterator var8 = this.destroyedItemsNetCache.iterator();
196 int var10 = 0;
197
198 while (var8.hasNext() && var10 < var6)
199 {
200 var7[var10++] = ((Integer)var8.next()).intValue();
201 var8.remove();
202 }
203
204 this.playerNetServerHandler.sendPacketToPlayer(new Packet29DestroyEntity(var7));
205 }
206 }
207
208 public void onUpdateEntity()
209 {
210 super.onUpdate();
211
212 for (int var1 = 0; var1 < this.inventory.getSizeInventory(); ++var1)
213 {
214 ItemStack var2 = this.inventory.getStackInSlot(var1);
215
216 if (var2 != null && Item.itemsList[var2.itemID].isMap() && this.playerNetServerHandler.packetSize() <= 5)
217 {
218 Packet var3 = ((ItemMapBase)Item.itemsList[var2.itemID]).createMapDataPacket(var2, this.worldObj, this);
219
220 if (var3 != null)
221 {
222 this.playerNetServerHandler.sendPacketToPlayer(var3);
223 }
224 }
225 }
226
227 if (this.getHealth() != this.lastHealth || this.lastFoodLevel != this.foodStats.getFoodLevel() || this.foodStats.getSaturationLevel() == 0.0F != this.wasHungry)
228 {
229 this.playerNetServerHandler.sendPacketToPlayer(new Packet8UpdateHealth(this.getHealth(), this.foodStats.getFoodLevel(), this.foodStats.getSaturationLevel()));
230 this.lastHealth = this.getHealth();
231 this.lastFoodLevel = this.foodStats.getFoodLevel();
232 this.wasHungry = this.foodStats.getSaturationLevel() == 0.0F;
233 }
234
235 if (this.experienceTotal != this.lastExperience)
236 {
237 this.lastExperience = this.experienceTotal;
238 this.playerNetServerHandler.sendPacketToPlayer(new Packet43Experience(this.experience, this.experienceTotal, this.experienceLevel));
239 }
240 }
241
242 /**
243 * Called when the mob's health reaches 0.
244 */
245 public void onDeath(DamageSource par1DamageSource)
246 {
247 if (ForgeHooks.onLivingDeath(this, par1DamageSource))
248 {
249 return;
250 }
251
252 this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat(par1DamageSource.getDeathMessage(this)));
253
254 if (!this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory"))
255 {
256 captureDrops = true;
257 capturedDrops.clear();
258
259 this.inventory.dropAllItems();
260
261 captureDrops = false;
262 PlayerDropsEvent event = new PlayerDropsEvent(this, par1DamageSource, capturedDrops, recentlyHit > 0);
263 if (!MinecraftForge.EVENT_BUS.post(event))
264 {
265 for (EntityItem item : capturedDrops)
266 {
267 joinEntityItemWithWorld(item);
268 }
269 }
270 }
271 }
272
273 /**
274 * Called when the entity is attacked.
275 */
276 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
277 {
278 if (this.initialInvulnerability > 0)
279 {
280 return false;
281 }
282 else
283 {
284 if (!this.mcServer.isPVPEnabled() && par1DamageSource instanceof EntityDamageSource)
285 {
286 Entity var3 = par1DamageSource.getEntity();
287
288 if (var3 instanceof EntityPlayer)
289 {
290 return false;
291 }
292
293 if (var3 instanceof EntityArrow)
294 {
295 EntityArrow var4 = (EntityArrow)var3;
296
297 if (var4.shootingEntity instanceof EntityPlayer)
298 {
299 return false;
300 }
301 }
302 }
303
304 return super.attackEntityFrom(par1DamageSource, par2);
305 }
306 }
307
308 /**
309 * returns if pvp is enabled or not
310 */
311 protected boolean isPVPEnabled()
312 {
313 return this.mcServer.isPVPEnabled();
314 }
315
316 /**
317 * Teleports the entity to another dimension. Params: Dimension number to teleport to
318 */
319 public void travelToDimension(int par1)
320 {
321 if (this.dimension == 1 && par1 == 1)
322 {
323 this.triggerAchievement(AchievementList.theEnd2);
324 this.worldObj.setEntityDead(this);
325 this.playerConqueredTheEnd = true;
326 this.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(4, 0));
327 }
328 else
329 {
330 if (this.dimension == 1 && par1 == 0)
331 {
332 this.triggerAchievement(AchievementList.theEnd);
333 ChunkCoordinates var2 = this.mcServer.worldServerForDimension(par1).getEntrancePortalLocation();
334
335 if (var2 != null)
336 {
337 this.playerNetServerHandler.setPlayerLocation((double)var2.posX, (double)var2.posY, (double)var2.posZ, 0.0F, 0.0F);
338 }
339
340 par1 = 1;
341 }
342 else
343 {
344 this.triggerAchievement(AchievementList.portal);
345 }
346
347 this.mcServer.getConfigurationManager().transferPlayerToDimension(this, par1);
348 this.lastExperience = -1;
349 this.lastHealth = -1;
350 this.lastFoodLevel = -1;
351 }
352 }
353
354 /**
355 * called from onUpdate for all tileEntity in specific chunks
356 */
357 private void sendTileEntityToPlayer(TileEntity par1TileEntity)
358 {
359 if (par1TileEntity != null)
360 {
361 Packet var2 = par1TileEntity.getDescriptionPacket();
362
363 if (var2 != null)
364 {
365 this.playerNetServerHandler.sendPacketToPlayer(var2);
366 }
367 }
368 }
369
370 /**
371 * Called whenever an item is picked up from walking over it. Args: pickedUpEntity, stackSize
372 */
373 public void onItemPickup(Entity par1Entity, int par2)
374 {
375 super.onItemPickup(par1Entity, par2);
376 this.craftingInventory.updateCraftingResults();
377 }
378
379 /**
380 * Attempts to have the player sleep in a bed at the specified location.
381 */
382 public EnumStatus sleepInBedAt(int par1, int par2, int par3)
383 {
384 EnumStatus var4 = super.sleepInBedAt(par1, par2, par3);
385
386 if (var4 == EnumStatus.OK)
387 {
388 Packet17Sleep var5 = new Packet17Sleep(this, 0, par1, par2, par3);
389 this.getServerForPlayer().getEntityTracker().sendPacketToAllPlayersTrackingEntity(this, var5);
390 this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
391 this.playerNetServerHandler.sendPacketToPlayer(var5);
392 }
393
394 return var4;
395 }
396
397 /**
398 * Wake up the player if they're sleeping.
399 */
400 public void wakeUpPlayer(boolean par1, boolean par2, boolean par3)
401 {
402 if (this.isPlayerSleeping())
403 {
404 this.getServerForPlayer().getEntityTracker().sendPacketToAllAssociatedPlayers(this, new Packet18Animation(this, 3));
405 }
406
407 super.wakeUpPlayer(par1, par2, par3);
408
409 if (this.playerNetServerHandler != null)
410 {
411 this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
412 }
413 }
414
415 /**
416 * Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
417 */
418 public void mountEntity(Entity par1Entity)
419 {
420 super.mountEntity(par1Entity);
421 this.playerNetServerHandler.sendPacketToPlayer(new Packet39AttachEntity(this, this.ridingEntity));
422 this.playerNetServerHandler.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
423 }
424
425 /**
426 * Takes in the distance the entity has fallen this tick and whether its on the ground to update the fall distance
427 * and deal fall damage if landing on the ground. Args: distanceFallenThisTick, onGround
428 */
429 protected void updateFallState(double par1, boolean par3) {}
430
431 /**
432 * likeUpdateFallState, but called from updateFlyingState, rather than moveEntity
433 */
434 public void updateFlyingState(double par1, boolean par3)
435 {
436 super.updateFallState(par1, par3);
437 }
438
439 public void incrementWindowID()
440 {
441 this.currentWindowId = this.currentWindowId % 100 + 1;
442 }
443
444 /**
445 * Displays the crafting GUI for a workbench.
446 */
447 public void displayGUIWorkbench(int par1, int par2, int par3)
448 {
449 this.incrementWindowID();
450 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 1, "Crafting", 9));
451 this.craftingInventory = new ContainerWorkbench(this.inventory, this.worldObj, par1, par2, par3);
452 this.craftingInventory.windowId = this.currentWindowId;
453 this.craftingInventory.addCraftingToCrafters(this);
454 }
455
456 public void displayGUIEnchantment(int par1, int par2, int par3)
457 {
458 this.incrementWindowID();
459 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 4, "Enchanting", 9));
460 this.craftingInventory = new ContainerEnchantment(this.inventory, this.worldObj, par1, par2, par3);
461 this.craftingInventory.windowId = this.currentWindowId;
462 this.craftingInventory.addCraftingToCrafters(this);
463 }
464
465 /**
466 * Displays the GUI for interacting with an anvil.
467 */
468 public void displayGUIAnvil(int par1, int par2, int par3)
469 {
470 this.incrementWindowID();
471 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 8, "Repairing", 9));
472 this.craftingInventory = new ContainerRepair(this.inventory, this.worldObj, par1, par2, par3, this);
473 this.craftingInventory.windowId = this.currentWindowId;
474 this.craftingInventory.addCraftingToCrafters(this);
475 }
476
477 /**
478 * Displays the GUI for interacting with a chest inventory. Args: chestInventory
479 */
480 public void displayGUIChest(IInventory par1IInventory)
481 {
482 if (this.craftingInventory != this.inventorySlots)
483 {
484 this.closeScreen();
485 }
486
487 this.incrementWindowID();
488 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 0, par1IInventory.getInvName(), par1IInventory.getSizeInventory()));
489 this.craftingInventory = new ContainerChest(this.inventory, par1IInventory);
490 this.craftingInventory.windowId = this.currentWindowId;
491 this.craftingInventory.addCraftingToCrafters(this);
492 }
493
494 /**
495 * Displays the furnace GUI for the passed in furnace entity. Args: tileEntityFurnace
496 */
497 public void displayGUIFurnace(TileEntityFurnace par1TileEntityFurnace)
498 {
499 this.incrementWindowID();
500 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 2, par1TileEntityFurnace.getInvName(), par1TileEntityFurnace.getSizeInventory()));
501 this.craftingInventory = new ContainerFurnace(this.inventory, par1TileEntityFurnace);
502 this.craftingInventory.windowId = this.currentWindowId;
503 this.craftingInventory.addCraftingToCrafters(this);
504 }
505
506 /**
507 * Displays the dipsenser GUI for the passed in dispenser entity. Args: TileEntityDispenser
508 */
509 public void displayGUIDispenser(TileEntityDispenser par1TileEntityDispenser)
510 {
511 this.incrementWindowID();
512 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 3, par1TileEntityDispenser.getInvName(), par1TileEntityDispenser.getSizeInventory()));
513 this.craftingInventory = new ContainerDispenser(this.inventory, par1TileEntityDispenser);
514 this.craftingInventory.windowId = this.currentWindowId;
515 this.craftingInventory.addCraftingToCrafters(this);
516 }
517
518 /**
519 * Displays the GUI for interacting with a brewing stand.
520 */
521 public void displayGUIBrewingStand(TileEntityBrewingStand par1TileEntityBrewingStand)
522 {
523 this.incrementWindowID();
524 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 5, par1TileEntityBrewingStand.getInvName(), par1TileEntityBrewingStand.getSizeInventory()));
525 this.craftingInventory = new ContainerBrewingStand(this.inventory, par1TileEntityBrewingStand);
526 this.craftingInventory.windowId = this.currentWindowId;
527 this.craftingInventory.addCraftingToCrafters(this);
528 }
529
530 /**
531 * Displays the GUI for interacting with a beacon.
532 */
533 public void displayGUIBeacon(TileEntityBeacon par1TileEntityBeacon)
534 {
535 this.incrementWindowID();
536 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 7, par1TileEntityBeacon.getInvName(), par1TileEntityBeacon.getSizeInventory()));
537 this.craftingInventory = new ContainerBeacon(this.inventory, par1TileEntityBeacon);
538 this.craftingInventory.windowId = this.currentWindowId;
539 this.craftingInventory.addCraftingToCrafters(this);
540 }
541
542 public void displayGUIMerchant(IMerchant par1IMerchant)
543 {
544 this.incrementWindowID();
545 this.craftingInventory = new ContainerMerchant(this.inventory, par1IMerchant, this.worldObj);
546 this.craftingInventory.windowId = this.currentWindowId;
547 this.craftingInventory.addCraftingToCrafters(this);
548 InventoryMerchant var2 = ((ContainerMerchant)this.craftingInventory).getMerchantInventory();
549 this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 6, var2.getInvName(), var2.getSizeInventory()));
550 MerchantRecipeList var3 = par1IMerchant.getRecipes(this);
551
552 if (var3 != null)
553 {
554 try
555 {
556 ByteArrayOutputStream var4 = new ByteArrayOutputStream();
557 DataOutputStream var5 = new DataOutputStream(var4);
558 var5.writeInt(this.currentWindowId);
559 var3.writeRecipiesToStream(var5);
560 this.playerNetServerHandler.sendPacketToPlayer(new Packet250CustomPayload("MC|TrList", var4.toByteArray()));
561 }
562 catch (IOException var6)
563 {
564 var6.printStackTrace();
565 }
566 }
567 }
568
569 /**
570 * inform the player of a change in a single slot
571 */
572 public void updateCraftingInventorySlot(Container par1Container, int par2, ItemStack par3ItemStack)
573 {
574 if (!(par1Container.getSlot(par2) instanceof SlotCrafting))
575 {
576 if (!this.playerInventoryBeingManipulated)
577 {
578 this.playerNetServerHandler.sendPacketToPlayer(new Packet103SetSlot(par1Container.windowId, par2, par3ItemStack));
579 }
580 }
581 }
582
583 public void sendContainerToPlayer(Container par1Container)
584 {
585 this.sendContainerAndContentsToPlayer(par1Container, par1Container.getInventory());
586 }
587
588 public void sendContainerAndContentsToPlayer(Container par1Container, List par2List)
589 {
590 this.playerNetServerHandler.sendPacketToPlayer(new Packet104WindowItems(par1Container.windowId, par2List));
591 this.playerNetServerHandler.sendPacketToPlayer(new Packet103SetSlot(-1, -1, this.inventory.getItemStack()));
592 }
593
594 /**
595 * send information about the crafting inventory to the client(currently only for furnace times)
596 */
597 public void updateCraftingInventoryInfo(Container par1Container, int par2, int par3)
598 {
599 this.playerNetServerHandler.sendPacketToPlayer(new Packet105UpdateProgressbar(par1Container.windowId, par2, par3));
600 }
601
602 /**
603 * sets current screen to null (used on escape buttons of GUIs)
604 */
605 public void closeScreen()
606 {
607 this.playerNetServerHandler.sendPacketToPlayer(new Packet101CloseWindow(this.craftingInventory.windowId));
608 this.closeInventory();
609 }
610
611 public void sendInventoryToPlayer()
612 {
613 if (!this.playerInventoryBeingManipulated)
614 {
615 this.playerNetServerHandler.sendPacketToPlayer(new Packet103SetSlot(-1, -1, this.inventory.getItemStack()));
616 }
617 }
618
619 public void closeInventory()
620 {
621 this.craftingInventory.onCraftGuiClosed(this);
622 this.craftingInventory = this.inventorySlots;
623 }
624
625 /**
626 * Adds a value to a statistic field.
627 */
628 public void addStat(StatBase par1StatBase, int par2)
629 {
630 if (par1StatBase != null)
631 {
632 if (!par1StatBase.isIndependent)
633 {
634 while (par2 > 100)
635 {
636 this.playerNetServerHandler.sendPacketToPlayer(new Packet200Statistic(par1StatBase.statId, 100));
637 par2 -= 100;
638 }
639
640 this.playerNetServerHandler.sendPacketToPlayer(new Packet200Statistic(par1StatBase.statId, par2));
641 }
642 }
643 }
644
645 public void mountEntityAndWakeUp()
646 {
647 if (this.ridingEntity != null)
648 {
649 this.mountEntity(this.ridingEntity);
650 }
651
652 if (this.riddenByEntity != null)
653 {
654 this.riddenByEntity.mountEntity(this);
655 }
656
657 if (this.sleeping)
658 {
659 this.wakeUpPlayer(true, false, false);
660 }
661 }
662
663 /**
664 * this function is called when a players inventory is sent to him, lastHealth is updated on any dimension
665 * transitions, then reset.
666 */
667 public void setPlayerHealthUpdated()
668 {
669 this.lastHealth = -99999999;
670 }
671
672 /**
673 * Add a chat message to the player
674 */
675 public void addChatMessage(String par1Str)
676 {
677 StringTranslate var2 = StringTranslate.getInstance();
678 String var3 = var2.translateKey(par1Str);
679 this.playerNetServerHandler.sendPacketToPlayer(new Packet3Chat(var3));
680 }
681
682 /**
683 * Used for when item use count runs out, ie: eating completed
684 */
685 protected void onItemUseFinish()
686 {
687 this.playerNetServerHandler.sendPacketToPlayer(new Packet38EntityStatus(this.entityId, (byte)9));
688 super.onItemUseFinish();
689 }
690
691 /**
692 * sets the itemInUse when the use item button is clicked. Args: itemstack, int maxItemUseDuration
693 */
694 public void setItemInUse(ItemStack par1ItemStack, int par2)
695 {
696 super.setItemInUse(par1ItemStack, par2);
697
698 if (par1ItemStack != null && par1ItemStack.getItem() != null && par1ItemStack.getItem().getItemUseAction(par1ItemStack) == EnumAction.eat)
699 {
700 this.getServerForPlayer().getEntityTracker().sendPacketToAllAssociatedPlayers(this, new Packet18Animation(this, 5));
701 }
702 }
703
704 /**
705 * Copies the values from the given player into this player if boolean par2 is true. Always clones Ender Chest
706 * Inventory.
707 */
708 public void clonePlayer(EntityPlayer par1EntityPlayer, boolean par2)
709 {
710 super.clonePlayer(par1EntityPlayer, par2);
711 this.lastExperience = -1;
712 this.lastHealth = -1;
713 this.lastFoodLevel = -1;
714 this.destroyedItemsNetCache.addAll(((EntityPlayerMP)par1EntityPlayer).destroyedItemsNetCache);
715 }
716
717 protected void onNewPotionEffect(PotionEffect par1PotionEffect)
718 {
719 super.onNewPotionEffect(par1PotionEffect);
720 this.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(this.entityId, par1PotionEffect));
721 }
722
723 protected void onChangedPotionEffect(PotionEffect par1PotionEffect)
724 {
725 super.onChangedPotionEffect(par1PotionEffect);
726 this.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(this.entityId, par1PotionEffect));
727 }
728
729 protected void onFinishedPotionEffect(PotionEffect par1PotionEffect)
730 {
731 super.onFinishedPotionEffect(par1PotionEffect);
732 this.playerNetServerHandler.sendPacketToPlayer(new Packet42RemoveEntityEffect(this.entityId, par1PotionEffect));
733 }
734
735 /**
736 * Move the entity to the coordinates informed, but keep yaw/pitch values.
737 */
738 public void setPositionAndUpdate(double par1, double par3, double par5)
739 {
740 this.playerNetServerHandler.setPlayerLocation(par1, par3, par5, this.rotationYaw, this.rotationPitch);
741 }
742
743 /**
744 * Called when the player performs a critical hit on the Entity. Args: entity that was hit critically
745 */
746 public void onCriticalHit(Entity par1Entity)
747 {
748 this.getServerForPlayer().getEntityTracker().sendPacketToAllAssociatedPlayers(this, new Packet18Animation(par1Entity, 6));
749 }
750
751 public void onEnchantmentCritical(Entity par1Entity)
752 {
753 this.getServerForPlayer().getEntityTracker().sendPacketToAllAssociatedPlayers(this, new Packet18Animation(par1Entity, 7));
754 }
755
756 /**
757 * Sends the player's abilities to the server (if there is one).
758 */
759 public void sendPlayerAbilities()
760 {
761 if (this.playerNetServerHandler != null)
762 {
763 this.playerNetServerHandler.sendPacketToPlayer(new Packet202PlayerAbilities(this.capabilities));
764 }
765 }
766
767 public WorldServer getServerForPlayer()
768 {
769 return (WorldServer)this.worldObj;
770 }
771
772 public void sendGameTypeToPlayer(EnumGameType par1EnumGameType)
773 {
774 this.theItemInWorldManager.setGameType(par1EnumGameType);
775 this.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(3, par1EnumGameType.getID()));
776 }
777
778 public void sendChatToPlayer(String par1Str)
779 {
780 this.playerNetServerHandler.sendPacketToPlayer(new Packet3Chat(par1Str));
781 }
782
783 /**
784 * Returns true if the command sender is allowed to use the given command.
785 */
786 public boolean canCommandSenderUseCommand(int par1, String par2Str)
787 {
788 return "seed".equals(par2Str) && !this.mcServer.isDedicatedServer() ? true : (!"tell".equals(par2Str) && !"help".equals(par2Str) && !"me".equals(par2Str) ? this.mcServer.getConfigurationManager().areCommandsAllowed(this.username) : true);
789 }
790
791 public String func_71114_r()
792 {
793 String var1 = this.playerNetServerHandler.netManager.getSocketAddress().toString();
794 var1 = var1.substring(var1.indexOf("/") + 1);
795 var1 = var1.substring(0, var1.indexOf(":"));
796 return var1;
797 }
798
799 public void updateClientInfo(Packet204ClientInfo par1Packet204ClientInfo)
800 {
801 if (this.translator.getLanguageList().containsKey(par1Packet204ClientInfo.getLanguage()))
802 {
803 this.translator.setLanguage(par1Packet204ClientInfo.getLanguage());
804 }
805
806 int var2 = 256 >> par1Packet204ClientInfo.getRenderDistance();
807
808 if (var2 > 3 && var2 < 15)
809 {
810 this.renderDistance = var2;
811 }
812
813 this.chatVisibility = par1Packet204ClientInfo.getChatVisibility();
814 this.chatColours = par1Packet204ClientInfo.getChatColours();
815
816 if (this.mcServer.isSinglePlayer() && this.mcServer.getServerOwner().equals(this.username))
817 {
818 this.mcServer.setDifficultyForAllWorlds(par1Packet204ClientInfo.getDifficulty());
819 }
820
821 this.func_82239_b(1, !par1Packet204ClientInfo.func_82563_j());
822 }
823
824 public StringTranslate getTranslator()
825 {
826 return this.translator;
827 }
828
829 public int getChatVisibility()
830 {
831 return this.chatVisibility;
832 }
833
834 /**
835 * on recieving this message the client (if permission is given) will download the requested textures
836 */
837 public void requestTexturePackLoad(String par1Str, int par2)
838 {
839 String var3 = par1Str + "\u0000" + par2;
840 this.playerNetServerHandler.sendPacketToPlayer(new Packet250CustomPayload("MC|TPack", var3.getBytes()));
841 }
842
843 /**
844 * Return the coordinates for this player as ChunkCoordinates.
845 */
846 public ChunkCoordinates getPlayerCoordinates()
847 {
848 return new ChunkCoordinates(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY + 0.5D), MathHelper.floor_double(this.posZ));
849 }
850 }