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