PlayerControllerMP

Client interaction controller: attackEntity/interact send C02, clickBlock sends C07, windowClick sends C0E, slot sync sends C10.

net/minecraft/client/multiplayer/PlayerControllerMP.java

Updated 2026-09-12

Deep Analysis

Client interaction controller translating clicks/keys to server C packets with prediction. No tick entity itself; driven by Minecraft loop via updateController. Validates creative/adventure/spectator/border locally, plays sounds/particles, then sends authoritative request. Paired with NetHandlerPlayClient and EntityPlayerSP.

Key Methods in Depth (8)

clickBlock

Starts block hit; creative instant vs survival progress init.

clickBlock first enforces adventure and spectator rules, returning false for spectators and for adventure players without allowEdit or whose held item cannot destroy the target block. It then enforces world border containment on the block position, refusing clicks outside the border. In creative mode it queues C07 START_DESTROY_BLOCK with position and face, calls clickBlockCreative for instant local break, and sets blockHitDelay to 5 to throttle repeats. In survival it aborts any prior target with C07 ABORT_DESTROY_BLOCK to the old currentBlock when switching positions, then queues C07 START_DESTROY_BLOCK for the new location. It calls onBlockClicked for zero-damage starts, instantly breaks when relative hardness reaches 1.0, else initializes isHittingBlock, currentBlock, currentItemHittingBlock, curBlockDamageMP zero and crack overlay. The server validates reach, hardness and timing, so nuker cheats that spam START without STOP are detected here.

        if (!this.mc.theWorld.getWorldBorder().contains(loc))
        {
            return false;
        }
        else
        {
            if (this.currentGameType.isCreative())
            {
                this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
                clickBlockCreative(this.mc, this, loc, face);
                this.blockHitDelay = 5;
            }
            else if (!this.isHittingBlock || !this.isHittingPosition(loc))
            {
                if (this.isHittingBlock)
                {
                    this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
                }

                this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
                Block block1 = this.mc.theWorld.getBlockState(loc).getBlock();
                boolean flag = block1.getMaterial() != Material.air;

The border contains check runs before any packet, so out-of-border clicks never reach the server. The creative branch shows the START_DESTROY plus instant client break plus 5-tick delay pattern, explaining creative nuker speed limits. The survival branch first sends ABORT for the stale currentBlock when retargeting, keeping server crack state consistent. The final START_DESTROY carries the new loc and face the server validates for reach and hardness, and suppressing ABORT leaves ghost cracks server-side.

onPlayerDamageBlock

Accumulates crack progress and finishes block.

onPlayerDamageBlock first calls syncCurrentPlayItem so any hotbar change emits C09 before mining packets, keeping server held-item in sync. It honors blockHitDelay by decrementing and returning true to swallow clicks during the 5-tick cooldown after place or break. In creative with border containment it re-sends C07 START_DESTROY_BLOCK and instantly breaks via clickBlockCreative, re-arming the delay. If isHittingPosition confirms the same block and held item, it returns false on air to clear isHittingBlock, else adds getPlayerRelativeBlockHardness to curBlockDamageMP for progressive cracking. Every 4 stepSoundTickCounter ticks it plays the block step sound locally at the block center for feedback. When curBlockDamageMP reaches 1.0 it clears isHittingBlock, sends C07 STOP_DESTROY_BLOCK, calls onPlayerDestroyBlock for local removal, zeroes damage and re-arms delay. Otherwise it falls through to clickBlock to start a new target, so holding mouse produces START, progress, STOP sequencing.

                this.curBlockDamageMP += block.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, posBlock);

                if (this.stepSoundTickCounter % 4.0F == 0.0F)
                {
                    this.mc.getSoundHandler().playSound(new PositionedSoundRecord(new ResourceLocation(block.stepSound.getStepSound()), (block.stepSound.getVolume() + 1.0F) / 8.0F, block.stepSound.getFrequency() * 0.5F, (float)posBlock.getX() + 0.5F, (float)posBlock.getY() + 0.5F, (float)posBlock.getZ() + 0.5F));
                }

                ++this.stepSoundTickCounter;

                if (this.curBlockDamageMP >= 1.0F)
                {
                    this.isHittingBlock = false;
                    this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
                    this.onPlayerDestroyBlock(posBlock, directionFacing);
                    this.curBlockDamageMP = 0.0F;
                    this.stepSoundTickCounter = 0.0F;
                    this.blockHitDelay = 5;
                }

                this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);

The hardness accumulation line advances crack progress per tick based on tool, haste and block strength, so speed-mine cheats inflate this value locally but the server recomputes it. The step-sound block plays every fourth tick purely client-side with no packet, giving audio feedback during digging. The 1.0 threshold branch sends STOP_DESTROY_BLOCK with exact pos and face, which is the only packet the server accepts as a legitimate break. sendBlockBreakProgress updates the local crack overlay from 0 to 9, and forging STOP without real progress is the core fast-break detection signal.

onPlayerRightClick

Block activate or ItemBlock place with prediction.

onPlayerRightClick first syncs the hotbar via syncCurrentPlayItem so the server sees the correct held item for placement. It computes hitVec offsets f, f1, f2 as fractional positions inside the block for precise face placement and tile orientation. It rejects clicks outside the world border with no packet, preventing border-bypass builds. In non-spectator it tries onBlockActivated for doors, chests and levers when not sneaking with an item, setting flag true to indicate activation consumed the click. It validates ItemBlock.canPlaceBlockOnSide before sending, returning false early on illegal placement to save bandwidth. It always queues C08PacketPlayerBlockPlacement with hitPos, face index, current item and f offsets, even for pure activation, because the server re-decides activation versus place. Locally it applies onItemUse with creative restore of damage and count versus survival consume, or returns true for pure activation. Spectators send C08 but skip local world changes, so the server must ignore their placements.

            if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
            {
                IBlockState iblockstate = worldIn.getBlockState(hitPos);

                if ((!player.isSneaking() || player.getHeldItem() == null) && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
                {
                    flag = true;
                }

                if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock)
                {
                    ItemBlock itemblock = (ItemBlock)heldStack.getItem();

                    if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack))
                    {
                        return false;
                    }
                }
            }

            this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));

            if (!flag && this.currentGameType != WorldSettings.GameType.SPECTATOR)

The onBlockActivated call predicts door or chest opening locally so the GUI feels instant, with flag recording whether activation succeeded. The canPlaceBlockOnSide check mirrors server placement rules for ItemBlock, aborting without a packet on illegal faces. The C08 line packs block position, face index, held stack and fractional hit offsets the server uses to orient slabs, stairs and pistons. Sending C08 even when flag is true lets the server confirm activation, and spamming C08 with crafted offsets is the scaffold and ghost-block vector.

sendUseItem

Air right-click (food, bow, etc).

sendUseItem blocks all use in SPECTATOR mode with an immediate false and no packet, enforcing spectator intangibility. It syncs the hotbar via syncCurrentPlayItem so the following C08 references the correct slot. It queues C08PacketPlayerBlockPlacement constructed from the current inventory item with the air-use constructor that uses -1 position internally. It records the pre-use stackSize, then calls useItemRightClick locally to predict food eating, bow drawing, potion throwing or snowball spawning. If the returned stack differs by identity or count it writes the result into mainInventory, clears to null on zero, and returns true to indicate consumption. If nothing changed it returns false, meaning the item had no right-click action. The server separately validates cooldowns, food hunger and projectile spawn on C08 receipt, so no-use-delay or fast-eat cheats forge timing around this packet.

    public boolean sendUseItem(EntityPlayer playerIn, World worldIn, ItemStack itemStackIn)
    {
        if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
        {
            return false;
        }
        else
        {
            this.syncCurrentPlayItem();
            this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(playerIn.inventory.getCurrentItem()));
            int i = itemStackIn.stackSize;
            ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);

            if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i)
            {
                playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;

                if (itemstack.stackSize == 0)
                {
                    playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
                }

                return true;
            }
            else
            {
                return false;
            }
        }
    }

The spectator early-return shows air-use is entirely disabled for that mode with no network traffic. syncCurrentPlayItem emits C09 first when needed so the C08 that follows is attributed to the right hotbar slot. The C08 air-use constructor signals right-click-air rather than block-place, which the server maps to food, bows and throwables. The stackSize comparison detects consumption locally for instant inventory feedback, while the server authoritative consume arrives later, so desync here causes ghost food or infinite snowballs if C08 is replayed.

attackEntity/interactWithEntitySendPacket

Left-click attack vs right-click interact.

attackEntity syncs the hotbar, queues C02PacketUseEntity with Action.ATTACK for the target entity ID, then applies attackTargetEntityWithCurrentItem locally only when not in spectator. interactWithEntitySendPacket syncs the hotbar, queues C02 with Action.INTERACT, and applies playerIn.interactWith locally only for non-spectators. isPlayerRightClickingOnEntity computes a hitVec offset from entity position, queues C02 with the Vec3 interact-at variant for armor stands and villagers, and applies interactAt locally for non-spectators. All three share netClientHandler as the sink and always send the C02 even in spectator, letting the server decide to ignore effects while still logging the attempt. The server validates distance, line of sight and cooldown, applying damage or leash or trade effects. Suppressing C02 creates silent aura where damage happens without animation, while spamming C02 with forged IDs is the reach and kill-aura vector. Local prediction keeps hits feeling instant pending S19, S0B or S06 confirmations.

    public void attackEntity(EntityPlayer playerIn, Entity targetEntity)
    {
        this.syncCurrentPlayItem();
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.ATTACK));

        if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
        {
            playerIn.attackTargetEntityWithCurrentItem(targetEntity);
        }
    }

    /**
     * Send packet to server - player is interacting with another entity (left click)
     */
    public boolean interactWithEntitySendPacket(EntityPlayer playerIn, Entity targetEntity)
    {
        this.syncCurrentPlayItem();
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.INTERACT));
        return this.currentGameType != WorldSettings.GameType.SPECTATOR && playerIn.interactWith(targetEntity);
    }

syncCurrentPlayItem before each C02 guarantees the server uses the current weapon for damage calculation rather than a stale slot. The ATTACK constructor carries only the entity ID, while the INTERACT and Vec3 variants add interaction coordinates for precise armor-stand handling. The spectator conditionals show packets are still sent but local effects are skipped, so the server is the final arbiter. Forging ATTACK with distant IDs is reach, and omitting the paired C0A swing is the no-swing signature.

windowClick/sendEnchantPacket

Container click and enchant button.

windowClick obtains the next short transaction ID from openContainer.getNextTransactionID, applies slotClick locally for instant GUI movement with mouseButton and mode, then queues C0EPacketClickWindow with windowId, slotId, button, mode, resulting ItemStack and transaction ID. The server replays the click against its authoritative Container, validates the transaction, and corrects with S2F or S30 on mismatch. sendEnchantPacket queues C11PacketEnchantItem with windowID and button for the enchantment table selection, where the server rolls levels and applies S31 progress. sendSlotPacket and sendPacketDropItem queue C10 creative actions for set or drop slot, gated on isCreative to prevent survival item spawning. Racing C0E clicks against C0D close or spamming transaction IDs is the classic inventory-dupe and chest-stealer pattern. The local slotClick prediction is why containers feel instant despite round-trip validation.

    public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityPlayer playerIn)
    {
        short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
        ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn);
        this.netClientHandler.addToSendQueue(new C0EPacketClickWindow(windowId, slotId, mouseButtonClicked, mode, itemstack, short1));
        return itemstack;
    }

    /**
     * GuiEnchantment uses this during multiplayer to tell PlayerControllerMP to send a packet indicating the
     * enchantment action the player has taken.
     *  
     * @param windowID The ID of the current window
     * @param button The button id (enchantment selected)
     */
    public void sendEnchantPacket(int windowID, int button)
    {
        this.netClientHandler.addToSendQueue(new C11PacketEnchantItem(windowID, button));
    }

getNextTransactionID allocates the short the server will echo or reject in S32 confirm, linking each C0E to a server settlement. slotClick mutates the client Container immediately for responsive dragging, with the result stack echoed in the C0E for server comparison. The C0E constructor packs window, slot, button, mode and transaction together so the server can replay the exact click. The C11 line carries only window and enchant button, with the actual level cost decided server-side, so forged C11 buttons attempt free-enchant exploits.

syncCurrentPlayItem

Hotbar change notifier called before most actions.

syncCurrentPlayItem reads the live hotbar index from mc.thePlayer.inventory.currentItem each call and compares it to the cached currentPlayerItem field. On mismatch it copies the new index into the cache and queues C09PacketHeldItemChange with that slot on netClientHandler. It is invoked at the top of updateController, click handling, damage, right-click, use-item, attack and interact paths, making it the universal pre-action hotbar sync. Because it only sends on change, scrolling without acting emits a single C09, while acting without scrolling emits none. The server applies the slot switch before processing the following C07, C08 or C02, so weapon or block identity is correct. Blocking C09 while switching items causes ghost-block or wrong-weapon hits where client and server disagree. The cache also drives isHittingPosition validation for mining continuity.

    private void syncCurrentPlayItem()
    {
        int i = this.mc.thePlayer.inventory.currentItem;

        if (i != this.currentPlayerItem)
        {
            this.currentPlayerItem = i;
            this.netClientHandler.addToSendQueue(new C09PacketHeldItemChange(this.currentPlayerItem));
        }
    }

The inventory.currentItem read captures the live hotbar slot after number-key or wheel input. The inequality against currentPlayerItem filters redundant sends so idle ticks produce no C09. The C09 constructor carries just the slot index the server equips before handling the next action packet. If this sync is skipped the server applies C07 or C08 with the previous slot, which is the slot-desync behind far-place or wrong-tool anomalies.

resetBlockRemoving/onStoppedUsingItem

Abort mining and stop use.

resetBlockRemoving checks isHittingBlock and on true queues C07 ABORT_DESTROY_BLOCK with currentBlock and DOWN face, clears isHittingBlock and curBlockDamageMP, and clears the crack overlay via sendBlockBreakProgress with -1. It is called when the mouse is released, the target changes, or the held item switches via isHittingPosition mismatch. onStoppedUsingItem syncs the hotbar, queues C07 RELEASE_USE_ITEM with ORIGIN and DOWN placeholders, and calls stopUsingItem locally to end bow draw or food eat. Both use the C07 channel with distinct actions so the server can separate mining abort from use release. For bow release the server spawns the arrow based on draw duration, while for food it cancels eating progress. Omitting ABORT leaves server crack progress running, and omitting RELEASE allows fast-bow or no-slow exploits that the server times via packet intervals.

    public void resetBlockRemoving()
    {
        if (this.isHittingBlock)
        {
            this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, EnumFacing.DOWN));
            this.isHittingBlock = false;
            this.curBlockDamageMP = 0.0F;
            this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, -1);
        }
    }

    public boolean onPlayerDamageBlock(BlockPos posBlock, EnumFacing directionFacing)

The isHittingBlock guard ensures ABORT is only sent when a dig was actually in progress, avoiding spurious server resets. The C07 ABORT carries the stale currentBlock so the server can clear crack state for that exact position. Clearing curBlockDamageMP and sending progress -1 removes the local crack overlay in step with the server. onStoppedUsingItem mirrors this with RELEASE_USE_ITEM for bows and food, so blocking either ABORT or RELEASE desyncs server progress timers used by anti-cheat.

Packet Usage

PacketDirTrigger
C02sentAttack/interact entity.
C07sentStart/stop/abort mining, drop handled by SP.
C08sentRight-click block or air use.
C09sentHotbar slot change before actions.
C0EsentInventory slot click.
C10sentCreative set/drop slot.
C11sentEnchant button.

Internal State

netClientHandlerNetHandlerPlayClient queue for all C packets
currentBlock/isHittingBlockMining target and active flag; abort on change
curBlockDamageMP/stepSoundTickCounterAccumulated hardness 0-1 and step-sound cadence
blockHitDelay5-tick cooldown after place/destroy
currentGameType/currentPlayerItemSurvival/creative/spectator rules and cached hotbar for C09
currentItemHittingBlockItem used at hit start; abort if swapped via isHittingPosition

Related Vanilla Internals

Full Source

PlayerControllerMP.java637 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.multiplayer;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.state.IBlockState;
6
import net.minecraft.client.Minecraft;
7
import net.minecraft.client.audio.PositionedSoundRecord;
8
import net.minecraft.client.entity.EntityPlayerSP;
9
import net.minecraft.client.network.NetHandlerPlayClient;
10
import net.minecraft.entity.Entity;
11
import net.minecraft.entity.passive.EntityHorse;
12
import net.minecraft.entity.player.EntityPlayer;
13
import net.minecraft.item.ItemBlock;
14
import net.minecraft.item.ItemStack;
15
import net.minecraft.item.ItemSword;
16
import net.minecraft.network.play.client.C02PacketUseEntity;
17
import net.minecraft.network.play.client.C07PacketPlayerDigging;
18
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
19
import net.minecraft.network.play.client.C09PacketHeldItemChange;
20
import net.minecraft.network.play.client.C0EPacketClickWindow;
21
import net.minecraft.network.play.client.C10PacketCreativeInventoryAction;
22
import net.minecraft.network.play.client.C11PacketEnchantItem;
23
import net.minecraft.stats.StatFileWriter;
24
import net.minecraft.util.BlockPos;
25
import net.minecraft.util.EnumFacing;
26
import net.minecraft.util.MovingObjectPosition;
27
import net.minecraft.util.ResourceLocation;
28
import net.minecraft.util.Vec3;
29
import net.minecraft.world.World;
30
import net.minecraft.world.WorldSettings;
31
32
public class PlayerControllerMP
33
{
34
    /** The Minecraft instance. */
35
    private final Minecraft mc;
36
    private final NetHandlerPlayClient netClientHandler;
37
    private BlockPos currentBlock = new BlockPos(-1, -1, -1);
38
39
    /** The Item currently being used to destroy a block */
40
    private ItemStack currentItemHittingBlock;
41
42
    /** Current block damage (MP) */
43
    private float curBlockDamageMP;
44
45
    /**
46
     * Tick counter, when it hits 4 it resets back to 0 and plays the step sound
47
     */
48
    private float stepSoundTickCounter;
49
50
    /**
51
     * Delays the first damage on the block after the first click on the block
52
     */
53
    private int blockHitDelay;
54
55
    /** Tells if the player is hitting a block */
56
    private boolean isHittingBlock;
57
58
    /** Current game type for the player */
59
    private WorldSettings.GameType currentGameType = WorldSettings.GameType.SURVIVAL;
60
61
    /** Index of the current item held by the player in the inventory hotbar */
62
    private int currentPlayerItem;
63
64
    public PlayerControllerMP(Minecraft mcIn, NetHandlerPlayClient netHandler)
65
    {
66
        this.mc = mcIn;
67
        this.netClientHandler = netHandler;
68
    }
69
70
    public static void clickBlockCreative(Minecraft mcIn, PlayerControllerMP playerController, BlockPos pos, EnumFacing facing)
71
    {
72
        if (!mcIn.theWorld.extinguishFire(mcIn.thePlayer, pos, facing))
73
        {
74
            playerController.onPlayerDestroyBlock(pos, facing);
75
        }
76
    }
77
78
    /**
79
     * Sets player capabilities depending on current gametype. params: player
80
     *  
81
     * @param player The player's instance
82
     */
83
    public void setPlayerCapabilities(EntityPlayer player)
84
    {
85
        this.currentGameType.configurePlayerCapabilities(player.capabilities);
86
    }
87
88
    /**
89
     * None
90
     */
91
    public boolean isSpectator()
92
    {
93
        return this.currentGameType == WorldSettings.GameType.SPECTATOR;
94
    }
95
96
    /**
97
     * Sets the game type for the player.
98
     *  
99
     * @param type The GameType to set
100
     */
101
    public void setGameType(WorldSettings.GameType type)
102
    {
103
        this.currentGameType = type;
104
        this.currentGameType.configurePlayerCapabilities(this.mc.thePlayer.capabilities);
105
    }
106
107
    /**
108
     * Flips the player around.
109
     */
110
    public void flipPlayer(EntityPlayer playerIn)
111
    {
112
        playerIn.rotationYaw = -180.0F;
113
    }
114
115
    public boolean shouldDrawHUD()
116
    {
117
        return this.currentGameType.isSurvivalOrAdventure();
118
    }
119
120
    /**
121
     * Called when a player completes the destruction of a block
122
     */
123
    public boolean onPlayerDestroyBlock(BlockPos pos, EnumFacing side)
124
    {
125
        if (this.currentGameType.isAdventure())
126
        {
127
            if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
128
            {
129
                return false;
130
            }
131
132
            if (!this.mc.thePlayer.isAllowEdit())
133
            {
134
                Block block = this.mc.theWorld.getBlockState(pos).getBlock();
135
                ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();
136
137
                if (itemstack == null)
138
                {
139
                    return false;
140
                }
141
142
                if (!itemstack.canDestroy(block))
143
                {
144
                    return false;
145
                }
146
            }
147
        }
148
149
        if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItem() != null && this.mc.thePlayer.getHeldItem().getItem() instanceof ItemSword)
150
        {
151
            return false;
152
        }
153
        else
154
        {
155
            World world = this.mc.theWorld;
156
            IBlockState iblockstate = world.getBlockState(pos);
157
            Block block1 = iblockstate.getBlock();
158
159
            if (block1.getMaterial() == Material.air)
160
            {
161
                return false;
162
            }
163
            else
164
            {
165
                world.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
166
                boolean flag = world.setBlockToAir(pos);
167
168
                if (flag)
169
                {
170
                    block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
171
                }
172
173
                this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
174
175
                if (!this.currentGameType.isCreative())
176
                {
177
                    ItemStack itemstack1 = this.mc.thePlayer.getCurrentEquippedItem();
178
179
                    if (itemstack1 != null)
180
                    {
181
                        itemstack1.onBlockDestroyed(world, block1, pos, this.mc.thePlayer);
182
183
                        if (itemstack1.stackSize == 0)
184
                        {
185
                            this.mc.thePlayer.destroyCurrentEquippedItem();
186
                        }
187
                    }
188
                }
189
190
                return flag;
191
            }
192
        }
193
    }
194
195
    /**
196
     * Called when the player is hitting a block with an item.
197
     */
198
    public boolean clickBlock(BlockPos loc, EnumFacing face)
199
    {
200
        if (this.currentGameType.isAdventure())
201
        {
202
            if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
203
            {
204
                return false;
205
            }
206
207
            if (!this.mc.thePlayer.isAllowEdit())
208
            {
209
                Block block = this.mc.theWorld.getBlockState(loc).getBlock();
210
                ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();
211
212
                if (itemstack == null)
213
                {
214
                    return false;
215
                }
216
217
                if (!itemstack.canDestroy(block))
218
                {
219
                    return false;
220
                }
221
            }
222
        }
223
224
        if (!this.mc.theWorld.getWorldBorder().contains(loc))
225
        {
226
            return false;
227
        }
228
        else
229
        {
230
            if (this.currentGameType.isCreative())
231
            {
232
                this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
233
                clickBlockCreative(this.mc, this, loc, face);
234
                this.blockHitDelay = 5;
235
            }
236
            else if (!this.isHittingBlock || !this.isHittingPosition(loc))
237
            {
238
                if (this.isHittingBlock)
239
                {
240
                    this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
241
                }
242
243
                this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
244
                Block block1 = this.mc.theWorld.getBlockState(loc).getBlock();
245
                boolean flag = block1.getMaterial() != Material.air;
246
247
                if (flag && this.curBlockDamageMP == 0.0F)
248
                {
249
                    block1.onBlockClicked(this.mc.theWorld, loc, this.mc.thePlayer);
250
                }
251
252
                if (flag && block1.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, loc) >= 1.0F)
253
                {
254
                    this.onPlayerDestroyBlock(loc, face);
255
                }
256
                else
257
                {
258
                    this.isHittingBlock = true;
259
                    this.currentBlock = loc;
260
                    this.currentItemHittingBlock = this.mc.thePlayer.getHeldItem();
261
                    this.curBlockDamageMP = 0.0F;
262
                    this.stepSoundTickCounter = 0.0F;
263
                    this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
264
                }
265
            }
266
267
            return true;
268
        }
269
    }
270
271
    /**
272
     * Resets current block damage and isHittingBlock
273
     */
274
    public void resetBlockRemoving()
275
    {
276
        if (this.isHittingBlock)
277
        {
278
            this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, EnumFacing.DOWN));
279
            this.isHittingBlock = false;
280
            this.curBlockDamageMP = 0.0F;
281
            this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, -1);
282
        }
283
    }
284
285
    public boolean onPlayerDamageBlock(BlockPos posBlock, EnumFacing directionFacing)
286
    {
287
        this.syncCurrentPlayItem();
288
289
        if (this.blockHitDelay > 0)
290
        {
291
            --this.blockHitDelay;
292
            return true;
293
        }
294
        else if (this.currentGameType.isCreative() && this.mc.theWorld.getWorldBorder().contains(posBlock))
295
        {
296
            this.blockHitDelay = 5;
297
            this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, posBlock, directionFacing));
298
            clickBlockCreative(this.mc, this, posBlock, directionFacing);
299
            return true;
300
        }
301
        else if (this.isHittingPosition(posBlock))
302
        {
303
            Block block = this.mc.theWorld.getBlockState(posBlock).getBlock();
304
305
            if (block.getMaterial() == Material.air)
306
            {
307
                this.isHittingBlock = false;
308
                return false;
309
            }
310
            else
311
            {
312
                this.curBlockDamageMP += block.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, posBlock);
313
314
                if (this.stepSoundTickCounter % 4.0F == 0.0F)
315
                {
316
                    this.mc.getSoundHandler().playSound(new PositionedSoundRecord(new ResourceLocation(block.stepSound.getStepSound()), (block.stepSound.getVolume() + 1.0F) / 8.0F, block.stepSound.getFrequency() * 0.5F, (float)posBlock.getX() + 0.5F, (float)posBlock.getY() + 0.5F, (float)posBlock.getZ() + 0.5F));
317
                }
318
319
                ++this.stepSoundTickCounter;
320
321
                if (this.curBlockDamageMP >= 1.0F)
322
                {
323
                    this.isHittingBlock = false;
324
                    this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
325
                    this.onPlayerDestroyBlock(posBlock, directionFacing);
326
                    this.curBlockDamageMP = 0.0F;
327
                    this.stepSoundTickCounter = 0.0F;
328
                    this.blockHitDelay = 5;
329
                }
330
331
                this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
332
                return true;
333
            }
334
        }
335
        else
336
        {
337
            return this.clickBlock(posBlock, directionFacing);
338
        }
339
    }
340
341
    /**
342
     * player reach distance = 4F
343
     */
344
    public float getBlockReachDistance()
345
    {
346
        return this.currentGameType.isCreative() ? 5.0F : 4.5F;
347
    }
348
349
    public void updateController()
350
    {
351
        this.syncCurrentPlayItem();
352
353
        if (this.netClientHandler.getNetworkManager().isChannelOpen())
354
        {
355
            this.netClientHandler.getNetworkManager().processReceivedPackets();
356
        }
357
        else
358
        {
359
            this.netClientHandler.getNetworkManager().checkDisconnected();
360
        }
361
    }
362
363
    private boolean isHittingPosition(BlockPos pos)
364
    {
365
        ItemStack itemstack = this.mc.thePlayer.getHeldItem();
366
        boolean flag = this.currentItemHittingBlock == null && itemstack == null;
367
368
        if (this.currentItemHittingBlock != null && itemstack != null)
369
        {
370
            flag = itemstack.getItem() == this.currentItemHittingBlock.getItem() && ItemStack.areItemStackTagsEqual(itemstack, this.currentItemHittingBlock) && (itemstack.isItemStackDamageable() || itemstack.getMetadata() == this.currentItemHittingBlock.getMetadata());
371
        }
372
373
        return pos.equals(this.currentBlock) && flag;
374
    }
375
376
    /**
377
     * Syncs the current player item with the server
378
     */
379
    private void syncCurrentPlayItem()
380
    {
381
        int i = this.mc.thePlayer.inventory.currentItem;
382
383
        if (i != this.currentPlayerItem)
384
        {
385
            this.currentPlayerItem = i;
386
            this.netClientHandler.addToSendQueue(new C09PacketHeldItemChange(this.currentPlayerItem));
387
        }
388
    }
389
390
    public boolean onPlayerRightClick(EntityPlayerSP player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, EnumFacing side, Vec3 hitVec)
391
    {
392
        this.syncCurrentPlayItem();
393
        float f = (float)(hitVec.xCoord - (double)hitPos.getX());
394
        float f1 = (float)(hitVec.yCoord - (double)hitPos.getY());
395
        float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ());
396
        boolean flag = false;
397
398
        if (!this.mc.theWorld.getWorldBorder().contains(hitPos))
399
        {
400
            return false;
401
        }
402
        else
403
        {
404
            if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
405
            {
406
                IBlockState iblockstate = worldIn.getBlockState(hitPos);
407
408
                if ((!player.isSneaking() || player.getHeldItem() == null) && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
409
                {
410
                    flag = true;
411
                }
412
413
                if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock)
414
                {
415
                    ItemBlock itemblock = (ItemBlock)heldStack.getItem();
416
417
                    if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack))
418
                    {
419
                        return false;
420
                    }
421
                }
422
            }
423
424
            this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
425
426
            if (!flag && this.currentGameType != WorldSettings.GameType.SPECTATOR)
427
            {
428
                if (heldStack == null)
429
                {
430
                    return false;
431
                }
432
                else if (this.currentGameType.isCreative())
433
                {
434
                    int i = heldStack.getMetadata();
435
                    int j = heldStack.stackSize;
436
                    boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
437
                    heldStack.setItemDamage(i);
438
                    heldStack.stackSize = j;
439
                    return flag1;
440
                }
441
                else
442
                {
443
                    return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
444
                }
445
            }
446
            else
447
            {
448
                return true;
449
            }
450
        }
451
    }
452
453
    /**
454
     * Notifies the server of things like consuming food, etc...
455
     */
456
    public boolean sendUseItem(EntityPlayer playerIn, World worldIn, ItemStack itemStackIn)
457
    {
458
        if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
459
        {
460
            return false;
461
        }
462
        else
463
        {
464
            this.syncCurrentPlayItem();
465
            this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(playerIn.inventory.getCurrentItem()));
466
            int i = itemStackIn.stackSize;
467
            ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);
468
469
            if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i)
470
            {
471
                playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;
472
473
                if (itemstack.stackSize == 0)
474
                {
475
                    playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
476
                }
477
478
                return true;
479
            }
480
            else
481
            {
482
                return false;
483
            }
484
        }
485
    }
486
487
    public EntityPlayerSP func_178892_a(World worldIn, StatFileWriter statWriter)
488
    {
489
        return new EntityPlayerSP(this.mc, worldIn, this.netClientHandler, statWriter);
490
    }
491
492
    /**
493
     * Attacks an entity
494
     */
495
    public void attackEntity(EntityPlayer playerIn, Entity targetEntity)
496
    {
497
        this.syncCurrentPlayItem();
498
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.ATTACK));
499
500
        if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
501
        {
502
            playerIn.attackTargetEntityWithCurrentItem(targetEntity);
503
        }
504
    }
505
506
    /**
507
     * Send packet to server - player is interacting with another entity (left click)
508
     */
509
    public boolean interactWithEntitySendPacket(EntityPlayer playerIn, Entity targetEntity)
510
    {
511
        this.syncCurrentPlayItem();
512
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.INTERACT));
513
        return this.currentGameType != WorldSettings.GameType.SPECTATOR && playerIn.interactWith(targetEntity);
514
    }
515
516
    /**
517
     * Return true when the player rightclick on an entity
518
     *  
519
     * @param player The player's instance
520
     * @param entityIn The entity clicked
521
     * @param movingObject The object clicked
522
     */
523
    public boolean isPlayerRightClickingOnEntity(EntityPlayer player, Entity entityIn, MovingObjectPosition movingObject)
524
    {
525
        this.syncCurrentPlayItem();
526
        Vec3 vec3 = new Vec3(movingObject.hitVec.xCoord - entityIn.posX, movingObject.hitVec.yCoord - entityIn.posY, movingObject.hitVec.zCoord - entityIn.posZ);
527
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(entityIn, vec3));
528
        return this.currentGameType != WorldSettings.GameType.SPECTATOR && entityIn.interactAt(player, vec3);
529
    }
530
531
    /**
532
     * Handles slot clicks sends a packet to the server.
533
     */
534
    public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityPlayer playerIn)
535
    {
536
        short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
537
        ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn);
538
        this.netClientHandler.addToSendQueue(new C0EPacketClickWindow(windowId, slotId, mouseButtonClicked, mode, itemstack, short1));
539
        return itemstack;
540
    }
541
542
    /**
543
     * GuiEnchantment uses this during multiplayer to tell PlayerControllerMP to send a packet indicating the
544
     * enchantment action the player has taken.
545
     *  
546
     * @param windowID The ID of the current window
547
     * @param button The button id (enchantment selected)
548
     */
549
    public void sendEnchantPacket(int windowID, int button)
550
    {
551
        this.netClientHandler.addToSendQueue(new C11PacketEnchantItem(windowID, button));
552
    }
553
554
    /**
555
     * Used in PlayerControllerMP to update the server with an ItemStack in a slot.
556
     */
557
    public void sendSlotPacket(ItemStack itemStackIn, int slotId)
558
    {
559
        if (this.currentGameType.isCreative())
560
        {
561
            this.netClientHandler.addToSendQueue(new C10PacketCreativeInventoryAction(slotId, itemStackIn));
562
        }
563
    }
564
565
    /**
566
     * Sends a Packet107 to the server to drop the item on the ground
567
     */
568
    public void sendPacketDropItem(ItemStack itemStackIn)
569
    {
570
        if (this.currentGameType.isCreative() && itemStackIn != null)
571
        {
572
            this.netClientHandler.addToSendQueue(new C10PacketCreativeInventoryAction(-1, itemStackIn));
573
        }
574
    }
575
576
    public void onStoppedUsingItem(EntityPlayer playerIn)
577
    {
578
        this.syncCurrentPlayItem();
579
        this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN));
580
        playerIn.stopUsingItem();
581
    }
582
583
    public boolean gameIsSurvivalOrAdventure()
584
    {
585
        return this.currentGameType.isSurvivalOrAdventure();
586
    }
587
588
    /**
589
     * Checks if the player is not creative, used for checking if it should break a block instantly
590
     */
591
    public boolean isNotCreative()
592
    {
593
        return !this.currentGameType.isCreative();
594
    }
595
596
    /**
597
     * returns true if player is in creative mode
598
     */
599
    public boolean isInCreativeMode()
600
    {
601
        return this.currentGameType.isCreative();
602
    }
603
604
    /**
605
     * true for hitting entities far away.
606
     */
607
    public boolean extendedReach()
608
    {
609
        return this.currentGameType.isCreative();
610
    }
611
612
    /**
613
     * Checks if the player is riding a horse, used to chose the GUI to open
614
     */
615
    public boolean isRidingHorse()
616
    {
617
        return this.mc.thePlayer.isRiding() && this.mc.thePlayer.ridingEntity instanceof EntityHorse;
618
    }
619
620
    public boolean isSpectatorMode()
621
    {
622
        return this.currentGameType == WorldSettings.GameType.SPECTATOR;
623
    }
624
625
    public WorldSettings.GameType getCurrentGameType()
626
    {
627
        return this.currentGameType;
628
    }
629
630
    /**
631
     * Return isHittingBlock
632
     */
633
    public boolean getIsHittingBlock()
634
    {
635
        return this.isHittingBlock;
636
    }
637
}

Deobfuscated MCP 1.8.9 source of PlayerControllerMP from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/multiplayer/PlayerControllerMP.java), stored verbatim.