ItemInWorldManager
Survival interaction handler: block break/place and creative resync emit S23 corrections and S38 list updates.
Updated 2026-09-12
Packets Referenced (2)
Related Vanilla Internals
Deep Analysis
Server-side per-player survival, creative, adventure and spectator interaction controller. Validates dig timing, block harvesting, item use and block activation from NetHandlerPlayServer. Sends corrections and progress animations plus gamemode broadcasts to other players.
Key Methods in Depth (8)
Change gamemode and broadcast to all players
setGameType changes the owned player's gamemode and broadcasts it to the whole server. It stores the new WorldSettings.GameType in gameType for later survivalOrAdventure and isCreative checks. It calls type.configurePlayerCapabilities on thisPlayerMP.capabilities to set fly, edit, and damage flags. It calls thisPlayerMP.sendPlayerAbilities to push those flags to the owner, updating its own client permissions. It then broadcasts S38PacketPlayerListItem with Action UPDATE_GAME_MODE and an array containing thisPlayerMP via sendPacketToAllPlayers. Every connected client receives S38 and updates the tab-list gamemode icon plus adventure interaction rules for that player. The owner also gets the broadcast in addition to the direct abilities packet. No block or inventory change happens here.
public void setGameType(WorldSettings.GameType type)
{
this.gameType = type;
type.configurePlayerCapabilities(this.thisPlayerMP.capabilities);
this.thisPlayerMP.sendPlayerAbilities();
this.thisPlayerMP.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.UPDATE_GAME_MODE, new EntityPlayerMP[] {this.thisPlayerMP}));
}
Storing gameType updates local mode used by dig and use guards. configurePlayerCapabilities maps survival, creative, adventure, and spectator to capability booleans. sendPlayerAbilities pushes those flags to the owner client. Broadcasting S38 UPDATE_GAME_MODE informs all other clients of the new mode for rendering and permissions.
Begin survival dig or instant creative break
onBlockClicked starts block breaking when the client sends a dig-start packet. In creative it tries extinguishFire first to put out fire without breaking, and if not fire it calls tryHarvestBlock for instant removal. In survival and adventure it loads the target Block and enforces adventure canDestroy rules via isAllowEdit and held stack canDestroy, returning early for spectator or disallowed tools. It extinguishes fire at the position, snapshots initialDamage from curblockDamage, and queries getPlayerRelativeBlockHardness for dig speed. It notifies the block via onBlockClicked for doors and special handling. If hardness is at least 1.0 it calls tryHarvestBlock immediately for instant crops or soft blocks. Otherwise it sets isDestroyingBlock true, records field_180240_f position, and calls theWorld.sendBlockBreakProgress with staged crack 0 to 10. That call emits S25PacketBlockBreakAnim to watching clients so all see the crack overlay grow.
public void onBlockClicked(BlockPos pos, EnumFacing side)
{
if (this.isCreative())
{
if (!this.theWorld.extinguishFire((EntityPlayer)null, pos, side))
{
this.tryHarvestBlock(pos);
}
}
else
{
Block block = this.theWorld.getBlockState(pos).getBlock();
The isCreative branch handles instant break versus fire extinguish without progress packets. The else branch loads the server block for survival hardness and adventure checks. Adventure validation returns early when the held item cannot destroy the block. Later code sets isDestroyingBlock and sends S25 crack progress to trackers.
Tick ongoing dig progress and finish harvest
updateBlockRemoving ticks every server tick to advance survival digging and emit S25 progress. It increments curblockDamage as the tick counter for both pending-finish and active-dig paths. If receivedFinishDiggingPacket is true meaning stop-dig arrived early, it computes elapsed ticks, loads the Block at field_180241_i, and clears the flag if now air. It multiplies getPlayerRelativeBlockHardness by elapsed plus one to get fraction f and scales to 0 to 10 stage j. If j differs from durabilityRemainingOnBlock it calls theWorld.sendBlockBreakProgress with player ID, position, and stage, which sends S25PacketBlockBreakAnim to trackers. When f reaches 1.0 it clears the flag and calls tryHarvestBlock to remove and loot the block. Else if isDestroyingBlock is active it performs similar progress for field_180240_f, sending -1 reset and clearing the flag if the block turned to air. Stage caching avoids spamming S25 every tick when unchanged.
public void updateBlockRemoving()
{
++this.curblockDamage;
if (this.receivedFinishDiggingPacket)
{
int i = this.curblockDamage - this.initialBlockDamage;
Block block = this.theWorld.getBlockState(this.field_180241_i).getBlock();
if (block.getMaterial() == Material.air)
{
this.receivedFinishDiggingPacket = false;
}
else
{
float f = block.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.worldObj, this.field_180241_i) * (float)(i + 1);
int j = (int)(f * 10.0F);
if (j != this.durabilityRemainingOnBlock)
{
this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.field_180241_i, j);
this.durabilityRemainingOnBlock = j;
}
if (f >= 1.0F)
{
this.receivedFinishDiggingPacket = false;
this.tryHarvestBlock(this.field_180241_i);
}
}
}
else if (this.isDestroyingBlock)
{
Block block1 = this.theWorld.getBlockState(this.field_180240_f).getBlock();
Incrementing curblockDamage drives both dig paths forward each tick. The receivedFinishDiggingPacket branch finishes blocks whose stop packet arrived before hardness completed. Computing f from hardness times elapsed gives break fraction scaled to S25 stage 0 to 10. sendBlockBreakProgress emits S25 only when the stage changed to limit traffic. Reaching 1.0 harvests the block while the isDestroyingBlock branch maintains live crack for held dig.
Handle stop-digging packet mid-break
blockRemoving handles the stop-digging C07 packet when it arrives mid-break. It first verifies pos equals field_180240_f so stale or moved targets are ignored. It computes elapsed ticks as curblockDamage minus initialDamage and loads the server Block. If material is air it does nothing because onUpdate or harvest already cleared it. It multiplies getPlayerRelativeBlockHardness by elapsed plus one to estimate break fraction f. If f is at least 0.7 it treats the dig as complete: clears isDestroyingBlock, sends progress -1 via sendBlockBreakProgress to erase crack via S25, and calls tryHarvestBlock to remove and drop loot. If below 0.7 and receivedFinishDiggingPacket is not already set, it parks the request by clearing isDestroyingBlock, setting receivedFinishDiggingPacket true, and copying position and initial damage into field_180241_i and initialBlockDamage. updateBlockRemoving will then finish it over subsequent ticks with staged S25 updates.
public void blockRemoving(BlockPos pos)
{
if (pos.equals(this.field_180240_f))
{
int i = this.curblockDamage - this.initialDamage;
Block block = this.theWorld.getBlockState(pos).getBlock();
if (block.getMaterial() != Material.air)
{
float f = block.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.worldObj, pos) * (float)(i + 1);
if (f >= 0.7F)
{
this.isDestroyingBlock = false;
this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), pos, -1);
this.tryHarvestBlock(pos);
}
else if (!this.receivedFinishDiggingPacket)
{
this.isDestroyingBlock = false;
this.receivedFinishDiggingPacket = true;
this.field_180241_i = pos;
this.initialBlockDamage = this.initialDamage;
}
}
}
}
The pos equality guard ensures only the active dig target can be finished. Elapsed ticks times hardness estimates how far digging progressed. The 0.7 threshold allows slightly early stops to succeed while sending S25 -1 to clear crack. Parking below threshold defers harvest to updateBlockRemoving with staged S25. Air targets are ignored as already broken.
Abort dig and clear crack overlay
cancelDestroyingBlock aborts an in-progress survival dig when the client sends abort or switches target. It unconditionally sets isDestroyingBlock false to stop updateBlockRemoving from advancing crack stages. It calls theWorld.sendBlockBreakProgress with the breaker entity ID, field_180240_f position, and -1 stage. WorldServer forwards that as S25PacketBlockBreakAnim with destroy stage -1 to all clients tracking the position. Receivers clear the crack overlay for that breaker ID. No block removal, loot, or tool damage occurs on cancel. The curblockDamage counter is left for the next onBlockClicked to re-baseline via initialDamage. Duplicate cancels simply resend -1 which clients treat as idempotent clear.
/**
* Stops the block breaking process
*/
public void cancelDestroyingBlock()
{
this.isDestroyingBlock = false;
this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.field_180240_f, -1);
}
/**
Clearing isDestroyingBlock halts tick progress in updateBlockRemoving. Sending break progress -1 emits S25 telling trackers to remove the crack. The breaker ID plus position key the overlay so other diggers are unaffected. No harvest or drops follow because cancellation is visual-only.
Remove block, drop loot and correct creative client
tryHarvestBlock removes the block, plays break effects, and corrects the client as needed. It first blocks creative sword use from breaking blocks to preserve attack semantics. It loads IBlockState and TileEntity, then enforces adventure and spectator rules with isAllowEdit and canDestroy checks. It plays AuxSFX 2001 break particles and sound at the position via playAuxSFXAtEntity for nearby clients. It calls removeBlock which fires onBlockHarvested and setBlockToAir plus onBlockDestroyedByPlayer. In creative it sends S23PacketBlockChange with world and position directly to the breaker via playerNetServerHandler so the client matches instant server removal. In survival it damages the held stack, destroys it at zero size, and if both removed and harvestable calls harvestBlock to drop items and XP. The boolean return reports whether setBlockToAir succeeded.
this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
boolean flag1 = this.removeBlock(pos);
if (this.isCreative())
{
this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(this.theWorld, pos));
}
else
{
ItemStack itemstack1 = this.thisPlayerMP.getCurrentEquippedItem();
boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate.getBlock());
Playing AuxSFX 2001 broadcasts break particles and sound to nearby clients. removeBlock performs the actual setBlockToAir with harvest callbacks. The creative branch sends S23PacketBlockChange to the breaker to force client chunk match after instant break. The survival branch inspects the held stack and harvest permission to decide drops and tool damage.
Apply right-click item use with creative restore
tryUseItem applies right-click item use from NetHandlerPlayServer C08 handling. It immediately returns false for spectator mode to block consumables, throws, and placements. It snapshots stackSize and metadata before calling stack.useItemRightClick with world and player for potions, food, buckets, or projectiles. If the returned stack differs by identity, size, max use duration, or metadata, it writes the result into the current hotbar slot. In creative it restores stackSize and item damage so blocks and items are infinite while still triggering effects. If size reached zero it clears the slot to null to remove consumed items. If the player is not in a use animation it calls sendContainerToPlayer to resync the inventory container, correcting any client-server drift. True signals the interaction was consumed while false lets the caller try block activation instead. No block-change packet is sent here beyond container sync.
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
if (this.gameType == WorldSettings.GameType.SPECTATOR)
{
return false;
}
else
{
int i = stack.stackSize;
int j = stack.getMetadata();
ItemStack itemstack = stack.useItemRightClick(worldIn, player);
if (itemstack != stack || itemstack != null && (itemstack.stackSize != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getMetadata() != j))
{
player.inventory.mainInventory[player.inventory.currentItem] = itemstack;
if (this.isCreative())
{
itemstack.stackSize = i;
if (itemstack.isItemStackDamageable())
{
itemstack.setItemDamage(j);
}
}
The spectator guard blocks all right-click use for observers. Snapshotting size and metadata detects consumption or transformation from useItemRightClick. Writing the result into mainInventory keeps server inventory authoritative. Creative restore plus damage reset preserves infinite items while still firing use effects.
Activate block or place held item
activateBlockOrUseItem handles right-click on a block position, choosing block activation versus item placement. Spectators only open chest and inventory GUIs via displayGUIChest without editing, returning false for other blocks. For players it first tries onBlockActivated when not sneaking or when empty-handed, letting doors, chests, furnaces, and levers consume the click with true. If that fails and stack is null it returns false to end the interaction. In creative it records metadata and size, calls stack.onItemUse for placement, then restores damage and size for infinite blocks before returning the result. In survival it directly returns stack.onItemUse which places blocks, consumes items, and triggers TileEntity updates. Block changes from placement flow through WorldServer mark-and-notify as S22 and S23 packets rather than from this method. Deduplication with NetHandlerPlayServer position and face validation prevents ghost blocks.
else
{
if (!player.isSneaking() || player.getHeldItem() == null)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, side, offsetX, offsetY, offsetZ))
{
return true;
}
}
if (stack == null)
{
return false;
}
else if (this.isCreative())
{
int j = stack.getMetadata();
int i = stack.stackSize;
boolean flag = stack.onItemUse(player, worldIn, pos, side, offsetX, offsetY, offsetZ);
stack.setItemDamage(j);
stack.stackSize = i;
return flag;
}
else
{
return stack.onItemUse(player, worldIn, pos, side, offsetX, offsetY, offsetZ);
}
}
}
The sneaking check lets players place blocks instead of opening GUIs when holding items. onBlockActivated gives the target block first chance to consume the click. Null stack returns false after failed activation to stop further work. Creative placement restores metadata and size after onItemUse while survival delegates directly for consumption.
Packet Usage
| Packet | Dir | Trigger |
|---|---|---|
| C07/C08 | handled | NetHandlerPlayServer dig and block-place drive these methods |
| S25 | sent | sendBlockBreakProgress in dig start, tick and cancel |
| S23 | sent | tryHarvestBlock creative correction to breaker |
| S38 | sent | setGameType UPDATE_GAME_MODE broadcast |
Internal State
Related Vanilla Internals
Full Source
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
Deobfuscated MCP 1.8.9 source of ItemInWorldManager from Marcelektro/MavenMCP-1.8.9 (net/minecraft/server/management/ItemInWorldManager.java), stored verbatim.