SHARE
TWEET

Untitled

a guest Aug 18th, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.minecraft.client.entity;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.audio.MovingSoundMinecartRiding;
  5. import net.minecraft.client.audio.PositionedSoundRecord;
  6. import net.minecraft.client.gui.GuiCommandBlock;
  7. import net.minecraft.client.gui.GuiEnchantment;
  8. import net.minecraft.client.gui.GuiHopper;
  9. import net.minecraft.client.gui.GuiMerchant;
  10. import net.minecraft.client.gui.GuiRepair;
  11. import net.minecraft.client.gui.GuiScreen;
  12. import net.minecraft.client.gui.GuiScreenBook;
  13. import net.minecraft.client.gui.inventory.GuiBeacon;
  14. import net.minecraft.client.gui.inventory.GuiBrewingStand;
  15. import net.minecraft.client.gui.inventory.GuiChest;
  16. import net.minecraft.client.gui.inventory.GuiCrafting;
  17. import net.minecraft.client.gui.inventory.GuiDispenser;
  18. import net.minecraft.client.gui.inventory.GuiEditSign;
  19. import net.minecraft.client.gui.inventory.GuiFurnace;
  20. import net.minecraft.client.gui.inventory.GuiScreenHorseInventory;
  21. import net.minecraft.client.network.NetHandlerPlayClient;
  22. import net.minecraft.command.server.CommandBlockLogic;
  23. import net.minecraft.entity.Entity;
  24. import net.minecraft.entity.IMerchant;
  25. import net.minecraft.entity.item.EntityItem;
  26. import net.minecraft.entity.item.EntityMinecart;
  27. import net.minecraft.entity.passive.EntityHorse;
  28. import net.minecraft.init.Items;
  29. import net.minecraft.inventory.IInventory;
  30. import net.minecraft.item.Item;
  31. import net.minecraft.item.ItemStack;
  32. import net.minecraft.network.play.client.C01PacketChatMessage;
  33. import net.minecraft.network.play.client.C03PacketPlayer;
  34. import net.minecraft.network.play.client.C07PacketPlayerDigging;
  35. import net.minecraft.network.play.client.C0APacketAnimation;
  36. import net.minecraft.network.play.client.C0BPacketEntityAction;
  37. import net.minecraft.network.play.client.C0CPacketInput;
  38. import net.minecraft.network.play.client.C0DPacketCloseWindow;
  39. import net.minecraft.network.play.client.C13PacketPlayerAbilities;
  40. import net.minecraft.network.play.client.C16PacketClientStatus;
  41. import net.minecraft.potion.Potion;
  42. import net.minecraft.stats.StatBase;
  43. import net.minecraft.stats.StatFileWriter;
  44. import net.minecraft.tileentity.TileEntitySign;
  45. import net.minecraft.util.BlockPos;
  46. import net.minecraft.util.DamageSource;
  47. import net.minecraft.util.EnumFacing;
  48. import net.minecraft.util.EnumParticleTypes;
  49. import net.minecraft.util.IChatComponent;
  50. import net.minecraft.util.MovementInput;
  51. import net.minecraft.util.ResourceLocation;
  52. import net.minecraft.world.IInteractionObject;
  53. import net.minecraft.world.World;
  54.  
  55. public class EntityPlayerSP extends AbstractClientPlayer
  56. {
  57.     public final NetHandlerPlayClient sendQueue;
  58.     private final StatFileWriter statWriter;
  59.  
  60.     /**
  61.      * The last X position which was transmitted to the server, used to determine when the X position changes and needs
  62.      * to be re-trasmitted
  63.      */
  64.     private double lastReportedPosX;
  65.  
  66.     /**
  67.      * The last Y position which was transmitted to the server, used to determine when the Y position changes and needs
  68.      * to be re-transmitted
  69.      */
  70.     private double lastReportedPosY;
  71.  
  72.     /**
  73.      * The last Z position which was transmitted to the server, used to determine when the Z position changes and needs
  74.      * to be re-transmitted
  75.      */
  76.     private double lastReportedPosZ;
  77.  
  78.     /**
  79.      * The last yaw value which was transmitted to the server, used to determine when the yaw changes and needs to be
  80.      * re-transmitted
  81.      */
  82.     private float lastReportedYaw;
  83.  
  84.     /**
  85.      * The last pitch value which was transmitted to the server, used to determine when the pitch changes and needs to
  86.      * be re-transmitted
  87.      */
  88.     private float lastReportedPitch;
  89.  
  90.     /** the last sneaking state sent to the server */
  91.     private boolean serverSneakState;
  92.  
  93.     /** the last sprinting state sent to the server */
  94.     private boolean serverSprintState;
  95.  
  96.     /**
  97.      * Reset to 0 every time position is sent to the server, used to send periodic updates every 20 ticks even when the
  98.      * player is not moving.
  99.      */
  100.     private int positionUpdateTicks;
  101.     private boolean hasValidHealth;
  102.     private String clientBrand;
  103.     public MovementInput movementInput;
  104.     protected Minecraft mc;
  105.  
  106.     /**
  107.      * Used to tell if the player pressed forward twice. If this is at 0 and it's pressed (And they are allowed to
  108.      * sprint, aka enough food on the ground etc) it sets this to 7. If it's pressed and it's greater than 0 enable
  109.      * sprinting.
  110.      */
  111.     protected int sprintToggleTimer;
  112.  
  113.     /** Ticks left before sprinting is disabled. */
  114.     public int sprintingTicksLeft;
  115.     public float renderArmYaw;
  116.     public float renderArmPitch;
  117.     public float prevRenderArmYaw;
  118.     public float prevRenderArmPitch;
  119.     private int horseJumpPowerCounter;
  120.     private float horseJumpPower;
  121.  
  122.     /** The amount of time an entity has been in a Portal */
  123.     public float timeInPortal;
  124.  
  125.     /** The amount of time an entity has been in a Portal the previous tick */
  126.     public float prevTimeInPortal;
  127.  
  128.     public EntityPlayerSP(Minecraft mcIn, World worldIn, NetHandlerPlayClient netHandler, StatFileWriter statFile)
  129.     {
  130.         super(worldIn, netHandler.getGameProfile());
  131.         this.sendQueue = netHandler;
  132.         this.statWriter = statFile;
  133.         this.mc = mcIn;
  134.         this.dimension = 0;
  135.     }
  136.  
  137.     /**
  138.      * Called when the entity is attacked.
  139.      */
  140.     public boolean attackEntityFrom(DamageSource source, float amount)
  141.     {
  142.         return false;
  143.     }
  144.  
  145.     /**
  146.      * Heal living entity (param: amount of half-hearts)
  147.      */
  148.     public void heal(float healAmount)
  149.     {
  150.     }
  151.  
  152.     /**
  153.      * Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
  154.      */
  155.     public void mountEntity(Entity entityIn)
  156.     {
  157.         super.mountEntity(entityIn);
  158.  
  159.         if (entityIn instanceof EntityMinecart)
  160.         {
  161.             this.mc.getSoundHandler().playSound(new MovingSoundMinecartRiding(this, (EntityMinecart)entityIn));
  162.         }
  163.     }
  164.  
  165.     /**
  166.      * Called to update the entity's position/logic.
  167.      */
  168.     public void onUpdate()
  169.     {
  170.         if (this.worldObj.isBlockLoaded(new BlockPos(this.posX, 0.0D, this.posZ)))
  171.         {
  172.             super.onUpdate();
  173.  
  174.             if (this.isRiding())
  175.             {
  176.                 this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
  177.                 this.sendQueue.addToSendQueue(new C0CPacketInput(this.moveStrafing, this.moveForward, this.movementInput.jump, this.movementInput.sneak));
  178.             }
  179.             else
  180.             {
  181.                 this.onUpdateWalkingPlayer();
  182.             }
  183.         }
  184.     }
  185.  
  186.     /**
  187.      * called every tick when the player is on foot. Performs all the things that normally happen during movement.
  188.      */
  189.     public void onUpdateWalkingPlayer()
  190.     {
  191.         boolean flag = this.isSprinting();
  192.  
  193.         if (flag != this.serverSprintState)
  194.         {
  195.             if (flag)
  196.             {
  197.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SPRINTING));
  198.             }
  199.             else
  200.             {
  201.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SPRINTING));
  202.             }
  203.  
  204.             this.serverSprintState = flag;
  205.         }
  206.  
  207.         boolean flag1 = this.isSneaking();
  208.  
  209.         if (flag1 != this.serverSneakState)
  210.         {
  211.             if (flag1)
  212.             {
  213.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SNEAKING));
  214.             }
  215.             else
  216.             {
  217.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SNEAKING));
  218.             }
  219.  
  220.             this.serverSneakState = flag1;
  221.         }
  222.  
  223.         if (this.isCurrentViewEntity())
  224.         {
  225.             double d0 = this.posX - this.lastReportedPosX;
  226.             double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY;
  227.             double d2 = this.posZ - this.lastReportedPosZ;
  228.             double d3 = (double)(this.rotationYaw - this.lastReportedYaw);
  229.             double d4 = (double)(this.rotationPitch - this.lastReportedPitch);
  230.             boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
  231.             boolean flag3 = d3 != 0.0D || d4 != 0.0D;
  232.  
  233.             if (this.ridingEntity == null)
  234.             {
  235.                 if (flag2 && flag3)
  236.                 {
  237.                     this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround));
  238.                 }
  239.                 else if (flag2)
  240.                 {
  241.                     this.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround));
  242.                 }
  243.                 else if (flag3)
  244.                 {
  245.                     this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
  246.                 }
  247.                 else
  248.                 {
  249.                     this.sendQueue.addToSendQueue(new C03PacketPlayer(this.onGround));
  250.                 }
  251.             }
  252.             else
  253.             {
  254.                 this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.motionX, -999.0D, this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));
  255.                 flag2 = false;
  256.             }
  257.  
  258.             ++this.positionUpdateTicks;
  259.  
  260.             if (flag2)
  261.             {
  262.                 this.lastReportedPosX = this.posX;
  263.                 this.lastReportedPosY = this.getEntityBoundingBox().minY;
  264.                 this.lastReportedPosZ = this.posZ;
  265.                 this.positionUpdateTicks = 0;
  266.             }
  267.  
  268.             if (flag3)
  269.             {
  270.                 this.lastReportedYaw = this.rotationYaw;
  271.                 this.lastReportedPitch = this.rotationPitch;
  272.             }
  273.         }
  274.     }
  275.  
  276.     /**
  277.      * Called when player presses the drop item key
  278.      */
  279.     public EntityItem dropOneItem(boolean dropAll)
  280.     {
  281.         C07PacketPlayerDigging.Action c07packetplayerdigging$action = dropAll ? C07PacketPlayerDigging.Action.DROP_ALL_ITEMS : C07PacketPlayerDigging.Action.DROP_ITEM;
  282.         this.sendQueue.addToSendQueue(new C07PacketPlayerDigging(c07packetplayerdigging$action, BlockPos.ORIGIN, EnumFacing.DOWN));
  283.         return null;
  284.     }
  285.  
  286.     /**
  287.      * Joins the passed in entity item with the world. Args: entityItem
  288.      */
  289.     protected void joinEntityItemWithWorld(EntityItem itemIn)
  290.     {
  291.     }
  292.  
  293.     /**
  294.      * Sends a chat message from the player. Args: chatMessage
  295.      */
  296.     public void sendChatMessage(String message)
  297.     {
  298.         this.sendQueue.addToSendQueue(new C01PacketChatMessage(message));
  299.     }
  300.  
  301.     /**
  302.      * Swings the item the player is holding.
  303.      */
  304.     public void swingItem()
  305.     {
  306.         super.swingItem();
  307.         this.sendQueue.addToSendQueue(new C0APacketAnimation());
  308.     }
  309.  
  310.     public void respawnPlayer()
  311.     {
  312.         this.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
  313.     }
  314.  
  315.     /**
  316.      * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
  317.      * second with the reduced value. Args: damageAmount
  318.      */
  319.     protected void damageEntity(DamageSource damageSrc, float damageAmount)
  320.     {
  321.         if (!this.isEntityInvulnerable(damageSrc))
  322.         {
  323.             this.setHealth(this.getHealth() - damageAmount);
  324.         }
  325.     }
  326.  
  327.     /**
  328.      * set current crafting inventory back to the 2x2 square
  329.      */
  330.     public void closeScreen()
  331.     {
  332.         this.sendQueue.addToSendQueue(new C0DPacketCloseWindow(this.openContainer.windowId));
  333.         this.closeScreenAndDropStack();
  334.     }
  335.  
  336.     public void closeScreenAndDropStack()
  337.     {
  338.         this.inventory.setItemStack((ItemStack)null);
  339.         super.closeScreen();
  340.         this.mc.displayGuiScreen((GuiScreen)null);
  341.     }
  342.  
  343.     /**
  344.      * Updates health locally.
  345.      */
  346.     public void setPlayerSPHealth(float health)
  347.     {
  348.         if (this.hasValidHealth)
  349.         {
  350.             float f = this.getHealth() - health;
  351.  
  352.             if (f <= 0.0F)
  353.             {
  354.                 this.setHealth(health);
  355.  
  356.                 if (f < 0.0F)
  357.                 {
  358.                     this.hurtResistantTime = this.maxHurtResistantTime / 2;
  359.                 }
  360.             }
  361.             else
  362.             {
  363.                 this.lastDamage = f;
  364.                 this.setHealth(this.getHealth());
  365.                 this.hurtResistantTime = this.maxHurtResistantTime;
  366.                 this.damageEntity(DamageSource.generic, f);
  367.                 this.hurtTime = this.maxHurtTime = 10;
  368.             }
  369.         }
  370.         else
  371.         {
  372.             this.setHealth(health);
  373.             this.hasValidHealth = true;
  374.         }
  375.     }
  376.  
  377.     /**
  378.      * Adds a value to a statistic field.
  379.      */
  380.     public void addStat(StatBase stat, int amount)
  381.     {
  382.         if (stat != null)
  383.         {
  384.             if (stat.isIndependent)
  385.             {
  386.                 super.addStat(stat, amount);
  387.             }
  388.         }
  389.     }
  390.  
  391.     /**
  392.      * Sends the player's abilities to the server (if there is one).
  393.      */
  394.     public void sendPlayerAbilities()
  395.     {
  396.         this.sendQueue.addToSendQueue(new C13PacketPlayerAbilities(this.capabilities));
  397.     }
  398.  
  399.     /**
  400.      * returns true if this is an EntityPlayerSP, or the logged in player.
  401.      */
  402.     public boolean isUser()
  403.     {
  404.         return true;
  405.     }
  406.  
  407.     protected void sendHorseJump()
  408.     {
  409.         this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.RIDING_JUMP, (int)(this.getHorseJumpPower() * 100.0F)));
  410.     }
  411.  
  412.     public void sendHorseInventory()
  413.     {
  414.         this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.OPEN_INVENTORY));
  415.     }
  416.  
  417.     public void setClientBrand(String brand)
  418.     {
  419.         this.clientBrand = brand;
  420.     }
  421.  
  422.     public String getClientBrand()
  423.     {
  424.         return this.clientBrand;
  425.     }
  426.  
  427.     public StatFileWriter getStatFileWriter()
  428.     {
  429.         return this.statWriter;
  430.     }
  431.  
  432.     public void addChatComponentMessage(IChatComponent chatComponent)
  433.     {
  434.         this.mc.ingameGUI.getChatGUI().printChatMessage(chatComponent);
  435.     }
  436.  
  437.     protected boolean pushOutOfBlocks(double x, double y, double z)
  438.     {
  439.         if (this.noClip)
  440.         {
  441.             return false;
  442.         }
  443.         else
  444.         {
  445.             BlockPos blockpos = new BlockPos(x, y, z);
  446.             double d0 = x - (double)blockpos.getX();
  447.             double d1 = z - (double)blockpos.getZ();
  448.  
  449.             if (!this.isOpenBlockSpace(blockpos))
  450.             {
  451.                 int i = -1;
  452.                 double d2 = 9999.0D;
  453.  
  454.                 if (this.isOpenBlockSpace(blockpos.west()) && d0 < d2)
  455.                 {
  456.                     d2 = d0;
  457.                     i = 0;
  458.                 }
  459.  
  460.                 if (this.isOpenBlockSpace(blockpos.east()) && 1.0D - d0 < d2)
  461.                 {
  462.                     d2 = 1.0D - d0;
  463.                     i = 1;
  464.                 }
  465.  
  466.                 if (this.isOpenBlockSpace(blockpos.north()) && d1 < d2)
  467.                 {
  468.                     d2 = d1;
  469.                     i = 4;
  470.                 }
  471.  
  472.                 if (this.isOpenBlockSpace(blockpos.south()) && 1.0D - d1 < d2)
  473.                 {
  474.                     d2 = 1.0D - d1;
  475.                     i = 5;
  476.                 }
  477.  
  478.                 float f = 0.1F;
  479.  
  480.                 if (i == 0)
  481.                 {
  482.                     this.motionX = (double)(-f);
  483.                 }
  484.  
  485.                 if (i == 1)
  486.                 {
  487.                     this.motionX = (double)f;
  488.                 }
  489.  
  490.                 if (i == 4)
  491.                 {
  492.                     this.motionZ = (double)(-f);
  493.                 }
  494.  
  495.                 if (i == 5)
  496.                 {
  497.                     this.motionZ = (double)f;
  498.                 }
  499.             }
  500.  
  501.             return false;
  502.         }
  503.     }
  504.  
  505.     /**
  506.      * Returns true if the block at the given BlockPos and the block above it are NOT full cubes.
  507.      */
  508.     private boolean isOpenBlockSpace(BlockPos pos)
  509.     {
  510.         return !this.worldObj.getBlockState(pos).getBlock().isNormalCube() && !this.worldObj.getBlockState(pos.up()).getBlock().isNormalCube();
  511.     }
  512.  
  513.     /**
  514.      * Set sprinting switch for Entity.
  515.      */
  516.     public void setSprinting(boolean sprinting)
  517.     {
  518.         super.setSprinting(sprinting);
  519.         this.sprintingTicksLeft = sprinting ? 600 : 0;
  520.     }
  521.  
  522.     /**
  523.      * Sets the current XP, total XP, and level number.
  524.      */
  525.     public void setXPStats(float currentXP, int maxXP, int level)
  526.     {
  527.         this.experience = currentXP;
  528.         this.experienceTotal = maxXP;
  529.         this.experienceLevel = level;
  530.     }
  531.  
  532.     /**
  533.      * Send a chat message to the CommandSender
  534.      */
  535.     public void addChatMessage(IChatComponent component)
  536.     {
  537.         this.mc.ingameGUI.getChatGUI().printChatMessage(component);
  538.     }
  539.  
  540.     /**
  541.      * Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
  542.      */
  543.     public boolean canCommandSenderUseCommand(int permLevel, String commandName)
  544.     {
  545.         return permLevel <= 0;
  546.     }
  547.  
  548.     /**
  549.      * Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
  550.      * the coordinates 0, 0, 0
  551.      */
  552.     public BlockPos getPosition()
  553.     {
  554.         return new BlockPos(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D);
  555.     }
  556.  
  557.     public void playSound(String name, float volume, float pitch)
  558.     {
  559.         this.worldObj.playSound(this.posX, this.posY, this.posZ, name, volume, pitch, false);
  560.     }
  561.  
  562.     /**
  563.      * Returns whether the entity is in a server world
  564.      */
  565.     public boolean isServerWorld()
  566.     {
  567.         return true;
  568.     }
  569.  
  570.     public boolean isRidingHorse()
  571.     {
  572.         return this.ridingEntity != null && this.ridingEntity instanceof EntityHorse && ((EntityHorse)this.ridingEntity).isHorseSaddled();
  573.     }
  574.  
  575.     public float getHorseJumpPower()
  576.     {
  577.         return this.horseJumpPower;
  578.     }
  579.  
  580.     public void openEditSign(TileEntitySign signTile)
  581.     {
  582.         this.mc.displayGuiScreen(new GuiEditSign(signTile));
  583.     }
  584.  
  585.     public void openEditCommandBlock(CommandBlockLogic cmdBlockLogic)
  586.     {
  587.         this.mc.displayGuiScreen(new GuiCommandBlock(cmdBlockLogic));
  588.     }
  589.  
  590.     /**
  591.      * Displays the GUI for interacting with a book.
  592.      */
  593.     public void displayGUIBook(ItemStack bookStack)
  594.     {
  595.         Item item = bookStack.getItem();
  596.  
  597.         if (item == Items.writable_book)
  598.         {
  599.             this.mc.displayGuiScreen(new GuiScreenBook(this, bookStack, true));
  600.         }
  601.     }
  602.  
  603.     /**
  604.      * Displays the GUI for interacting with a chest inventory. Args: chestInventory
  605.      */
  606.     public void displayGUIChest(IInventory chestInventory)
  607.     {
  608.         String s = chestInventory instanceof IInteractionObject ? ((IInteractionObject)chestInventory).getGuiID() : "minecraft:container";
  609.  
  610.         if ("minecraft:chest".equals(s))
  611.         {
  612.             this.mc.displayGuiScreen(new GuiChest(this.inventory, chestInventory));
  613.         }
  614.         else if ("minecraft:hopper".equals(s))
  615.         {
  616.             this.mc.displayGuiScreen(new GuiHopper(this.inventory, chestInventory));
  617.         }
  618.         else if ("minecraft:furnace".equals(s))
  619.         {
  620.             this.mc.displayGuiScreen(new GuiFurnace(this.inventory, chestInventory));
  621.         }
  622.         else if ("minecraft:brewing_stand".equals(s))
  623.         {
  624.             this.mc.displayGuiScreen(new GuiBrewingStand(this.inventory, chestInventory));
  625.         }
  626.         else if ("minecraft:beacon".equals(s))
  627.         {
  628.             this.mc.displayGuiScreen(new GuiBeacon(this.inventory, chestInventory));
  629.         }
  630.         else if (!"minecraft:dispenser".equals(s) && !"minecraft:dropper".equals(s))
  631.         {
  632.             this.mc.displayGuiScreen(new GuiChest(this.inventory, chestInventory));
  633.         }
  634.         else
  635.         {
  636.             this.mc.displayGuiScreen(new GuiDispenser(this.inventory, chestInventory));
  637.         }
  638.     }
  639.  
  640.     public void displayGUIHorse(EntityHorse horse, IInventory horseInventory)
  641.     {
  642.         this.mc.displayGuiScreen(new GuiScreenHorseInventory(this.inventory, horseInventory, horse));
  643.     }
  644.  
  645.     public void displayGui(IInteractionObject guiOwner)
  646.     {
  647.         String s = guiOwner.getGuiID();
  648.  
  649.         if ("minecraft:crafting_table".equals(s))
  650.         {
  651.             this.mc.displayGuiScreen(new GuiCrafting(this.inventory, this.worldObj));
  652.         }
  653.         else if ("minecraft:enchanting_table".equals(s))
  654.         {
  655.             this.mc.displayGuiScreen(new GuiEnchantment(this.inventory, this.worldObj, guiOwner));
  656.         }
  657.         else if ("minecraft:anvil".equals(s))
  658.         {
  659.             this.mc.displayGuiScreen(new GuiRepair(this.inventory, this.worldObj));
  660.         }
  661.     }
  662.  
  663.     public void displayVillagerTradeGui(IMerchant villager)
  664.     {
  665.         this.mc.displayGuiScreen(new GuiMerchant(this.inventory, villager, this.worldObj));
  666.     }
  667.  
  668.     /**
  669.      * Called when the player performs a critical hit on the Entity. Args: entity that was hit critically
  670.      */
  671.     public void onCriticalHit(Entity entityHit)
  672.     {
  673.         this.mc.effectRenderer.emitParticleAtEntity(entityHit, EnumParticleTypes.CRIT);
  674.     }
  675.  
  676.     public void onEnchantmentCritical(Entity entityHit)
  677.     {
  678.         this.mc.effectRenderer.emitParticleAtEntity(entityHit, EnumParticleTypes.CRIT_MAGIC);
  679.     }
  680.  
  681.     /**
  682.      * Returns if this entity is sneaking.
  683.      */
  684.     public boolean isSneaking()
  685.     {
  686.         boolean flag = this.movementInput != null ? this.movementInput.sneak : false;
  687.         return flag && !this.sleeping;
  688.     }
  689.  
  690.     public void updateEntityActionState()
  691.     {
  692.         super.updateEntityActionState();
  693.  
  694.         if (this.isCurrentViewEntity())
  695.         {
  696.             this.moveStrafing = this.movementInput.moveStrafe;
  697.             this.moveForward = this.movementInput.moveForward;
  698.             this.isJumping = this.movementInput.jump;
  699.             this.prevRenderArmYaw = this.renderArmYaw;
  700.             this.prevRenderArmPitch = this.renderArmPitch;
  701.             this.renderArmPitch = (float)((double)this.renderArmPitch + (double)(this.rotationPitch - this.renderArmPitch) * 0.5D);
  702.             this.renderArmYaw = (float)((double)this.renderArmYaw + (double)(this.rotationYaw - this.renderArmYaw) * 0.5D);
  703.         }
  704.     }
  705.  
  706.     protected boolean isCurrentViewEntity()
  707.     {
  708.         return this.mc.getRenderViewEntity() == this;
  709.     }
  710.  
  711.     /**
  712.      * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
  713.      * use this to react to sunlight and start to burn.
  714.      */
  715.     public void onLivingUpdate()
  716.     {
  717.         if (this.sprintingTicksLeft > 0)
  718.         {
  719.             --this.sprintingTicksLeft;
  720.  
  721.             if (this.sprintingTicksLeft == 0)
  722.             {
  723.                 this.setSprinting(false);
  724.             }
  725.         }
  726.  
  727.         if (this.sprintToggleTimer > 0)
  728.         {
  729.             --this.sprintToggleTimer;
  730.         }
  731.  
  732.         this.prevTimeInPortal = this.timeInPortal;
  733.  
  734.         if (this.inPortal)
  735.         {
  736.             if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame())
  737.             {
  738.                 this.mc.displayGuiScreen((GuiScreen)null);
  739.             }
  740.  
  741.             if (this.timeInPortal == 0.0F)
  742.             {
  743.                 this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
  744.             }
  745.  
  746.             this.timeInPortal += 0.0125F;
  747.  
  748.             if (this.timeInPortal >= 1.0F)
  749.             {
  750.                 this.timeInPortal = 1.0F;
  751.             }
  752.  
  753.             this.inPortal = false;
  754.         }
  755.         else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60)
  756.         {
  757.             this.timeInPortal += 0.006666667F;
  758.  
  759.             if (this.timeInPortal > 1.0F)
  760.             {
  761.                 this.timeInPortal = 1.0F;
  762.             }
  763.         }
  764.         else
  765.         {
  766.             if (this.timeInPortal > 0.0F)
  767.             {
  768.                 this.timeInPortal -= 0.05F;
  769.             }
  770.  
  771.             if (this.timeInPortal < 0.0F)
  772.             {
  773.                 this.timeInPortal = 0.0F;
  774.             }
  775.         }
  776.  
  777.         if (this.timeUntilPortal > 0)
  778.         {
  779.             --this.timeUntilPortal;
  780.         }
  781.  
  782.         boolean flag = this.movementInput.jump;
  783.         boolean flag1 = this.movementInput.sneak;
  784.         float f = 0.8F;
  785.         boolean flag2 = this.movementInput.moveForward >= f;
  786.         this.movementInput.updatePlayerMoveState();
  787.  
  788.         if (this.isUsingItem() && !this.isRiding())
  789.         {
  790.             this.movementInput.moveStrafe *= 0.2F;
  791.             this.movementInput.moveForward *= 0.2F;
  792.             this.sprintToggleTimer = 0;
  793.         }
  794.  
  795.         this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
  796.         this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
  797.         this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
  798.         this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
  799.         boolean flag3 = (float)this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
  800.  
  801.         if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness))
  802.         {
  803.             if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown())
  804.             {
  805.                 this.sprintToggleTimer = 7;
  806.             }
  807.             else
  808.             {
  809.                 this.setSprinting(true);
  810.             }
  811.         }
  812.  
  813.         if (!this.isSprinting() && this.movementInput.moveForward >= f && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown())
  814.         {
  815.             this.setSprinting(true);
  816.         }
  817.  
  818.         if (this.isSprinting() && (this.movementInput.moveForward < f || this.isCollidedHorizontally || !flag3))
  819.         {
  820.             this.setSprinting(false);
  821.         }
  822.  
  823.         if (this.capabilities.allowFlying)
  824.         {
  825.             if (this.mc.playerController.isSpectatorMode())
  826.             {
  827.                 if (!this.capabilities.isFlying)
  828.                 {
  829.                     this.capabilities.isFlying = true;
  830.                     this.sendPlayerAbilities();
  831.                 }
  832.             }
  833.             else if (!flag && this.movementInput.jump)
  834.             {
  835.                 if (this.flyToggleTimer == 0)
  836.                 {
  837.                     this.flyToggleTimer = 7;
  838.                 }
  839.                 else
  840.                 {
  841.                     this.capabilities.isFlying = !this.capabilities.isFlying;
  842.                     this.sendPlayerAbilities();
  843.                     this.flyToggleTimer = 0;
  844.                 }
  845.             }
  846.         }
  847.  
  848.         if (this.capabilities.isFlying && this.isCurrentViewEntity())
  849.         {
  850.             if (this.movementInput.sneak)
  851.             {
  852.                 this.motionY -= (double)(this.capabilities.getFlySpeed() * 3.0F);
  853.             }
  854.  
  855.             if (this.movementInput.jump)
  856.             {
  857.                 this.motionY += (double)(this.capabilities.getFlySpeed() * 3.0F);
  858.             }
  859.         }
  860.  
  861.         if (this.isRidingHorse())
  862.         {
  863.             if (this.horseJumpPowerCounter < 0)
  864.             {
  865.                 ++this.horseJumpPowerCounter;
  866.  
  867.                 if (this.horseJumpPowerCounter == 0)
  868.                 {
  869.                     this.horseJumpPower = 0.0F;
  870.                 }
  871.             }
  872.  
  873.             if (flag && !this.movementInput.jump)
  874.             {
  875.                 this.horseJumpPowerCounter = -10;
  876.                 this.sendHorseJump();
  877.             }
  878.             else if (!flag && this.movementInput.jump)
  879.             {
  880.                 this.horseJumpPowerCounter = 0;
  881.                 this.horseJumpPower = 0.0F;
  882.             }
  883.             else if (flag)
  884.             {
  885.                 ++this.horseJumpPowerCounter;
  886.  
  887.                 if (this.horseJumpPowerCounter < 10)
  888.                 {
  889.                     this.horseJumpPower = (float)this.horseJumpPowerCounter * 0.1F;
  890.                 }
  891.                 else
  892.                 {
  893.                     this.horseJumpPower = 0.8F + 2.0F / (float)(this.horseJumpPowerCounter - 9) * 0.1F;
  894.                 }
  895.             }
  896.         }
  897.         else
  898.         {
  899.             this.horseJumpPower = 0.0F;
  900.         }
  901.  
  902.         super.onLivingUpdate();
  903.  
  904.         if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode())
  905.         {
  906.             this.capabilities.isFlying = false;
  907.             this.sendPlayerAbilities();
  908.         }
  909.     }
  910. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top