@@ -115,7 +115,7 @@ public boolean onUseItemOnBlock(ItemStack itemstack, @Nullable Player player, Wo
115115 int times = 0 ;
116116 for (int addx = -1 ; addx < 2 ; addx ++){
117117 for (int addz = -1 ; addz < 2 ; addz ++){
118- if (Objects . requireNonNull ( player . getHeldItem ()) .getMetadata () < 192 ) {
118+ if (itemstack .getMetadata () < 192 ) {
119119 int id = world .getBlockId (blockX + addx , blockY , blockZ + addz );
120120 int j1 ;
121121 if (id == Blocks .DIRT .id ()) {
@@ -128,8 +128,8 @@ public boolean onUseItemOnBlock(ItemStack itemstack, @Nullable Player player, Wo
128128 if ((world .getBlockId (blockX + addx , blockY +1 , blockZ + addz ) == 0 ||
129129 !world .getBlock (blockX + addx , blockY +1 , blockZ + addz ).blocksLight ())){
130130 world .setBlockWithNotify (blockX + addx , blockY , blockZ + addz , j1 );
131- if (player .getGamemode ().consumeBlocks ()) {
132- player . getHeldItem () .damageItem (1 , player );
131+ if (player == null || player .getGamemode ().consumeBlocks ()) {
132+ itemstack .damageItem (1 , player );
133133 }
134134 }
135135 }
@@ -143,8 +143,8 @@ else if (id == Blocks.DIRT_SCORCHED.id()) {
143143 if ((world .getBlockId (blockX + addx , blockY +1 , blockZ + addz ) == 0 ||
144144 !world .getBlock (blockX + addx , blockY +1 , blockZ + addz ).blocksLight ())){
145145 world .setBlockWithNotify (blockX + addx , blockY , blockZ + addz , j1 );
146- if (player .getGamemode ().consumeBlocks ()) {
147- player . getHeldItem () .damageItem (1 , player );
146+ if (player == null || player .getGamemode ().consumeBlocks ()) {
147+ itemstack .damageItem (1 , player );
148148 }
149149 }
150150 }
@@ -155,7 +155,7 @@ else if (id == Blocks.DIRT_SCORCHED.id()) {
155155 else if (Blocks .blocksList [id ] != null && Blocks .blocksList [id ].hasTag (BlockTags .GROWS_FLOWERS )) {
156156 if (!world .isClientSide ) {
157157 if (player == null || player .getGamemode ().consumeBlocks ()) {
158- player . getHeldItem () .damageItem (1 , player );
158+ itemstack .damageItem (1 , player );
159159 }
160160
161161 label169 :
@@ -216,7 +216,7 @@ else if (id == Blocks.CROPS_WHEAT.id()){
216216 if (!world .isClientSide ) {
217217 world .setBlockMetadataWithNotify (blockX + addx , blockY , blockZ + addz , 7 );
218218 if (player == null || player .getGamemode ().consumeBlocks ()) {
219- player . getHeldItem () .damageItem (1 , player );
219+ itemstack .damageItem (1 , player );
220220 }
221221 }
222222
@@ -232,7 +232,7 @@ else if (id == Blocks.CROPS_PUMPKIN.id()){
232232 if (!world .isClientSide ) {
233233 world .setBlockWithNotify (blockX + addx , blockY , blockZ + addz , Blocks .PUMPKIN .id ());
234234 if (player == null || player .getGamemode ().consumeBlocks ()) {
235- player . getHeldItem () .damageItem (1 , player );
235+ itemstack .damageItem (1 , player );
236236 }
237237 }
238238
@@ -248,7 +248,7 @@ else if (id == FeaturesBlocks.fluxCropws.id()){
248248 if (!world .isClientSide ) {
249249 world .setBlockMetadataWithNotify (blockX + addx , blockY , blockZ + addz , 7 );
250250 if (player == null || player .getGamemode ().consumeBlocks ()) {
251- player . getHeldItem () .damageItem (1 , player );
251+ itemstack .damageItem (1 , player );
252252 }
253253 }
254254
@@ -270,7 +270,7 @@ else if (id == Blocks.LEAVES_CACAO.id()){
270270
271271 world .setBlockMetadataWithNotify (blockX + addx , blockY , blockZ + addz , setGrowthRate (meta , 4 ));
272272 if (player == null || player .getGamemode ().consumeBlocks ()) {
273- player . getHeldItem () .damageItem (1 , player );
273+ itemstack .damageItem (1 , player );
274274 }
275275 }
276276
@@ -291,7 +291,7 @@ else if (id == Blocks.LEAVES_CHERRY_FLOWERING.id()){
291291
292292 world .setBlockMetadataWithNotify (blockX + addx , blockY , blockZ + addz , setGrowthRate (meta , 1 ));
293293 if (player == null || player .getGamemode ().consumeBlocks ()) {
294- player . getHeldItem () .damageItem (1 , player );
294+ itemstack .damageItem (1 , player );
295295 }
296296 }
297297
@@ -311,7 +311,7 @@ else if (id == Blocks.CACTUS.id()){
311311 world .setBlockWithNotify (blockX + addx , blockY + l , blockZ + addz , Blocks .CACTUS .id ());
312312 }
313313 if (player == null || player .getGamemode ().consumeBlocks ()) {
314- player . getHeldItem () .damageItem (1 , player );
314+ itemstack .damageItem (1 , player );
315315 }
316316 }
317317
@@ -329,7 +329,7 @@ else if (id == Blocks.SUGARCANE.id()){
329329 world .setBlockWithNotify (blockX + addx , blockY + l , blockZ + addz , Blocks .SUGARCANE .id ());
330330 }
331331 if (player == null || player .getGamemode ().consumeBlocks ()) {
332- player . getHeldItem () .damageItem (1 , player );
332+ itemstack .damageItem (1 , player );
333333 }
334334 }
335335
@@ -341,8 +341,8 @@ else if (id == Blocks.SUGARCANE.id()){
341341 else if (world .getBlockLogic (blockX + addx , blockY , blockZ + addz , BlockLogicFlowerStackable .class ) != null ){
342342 Random rand = world .rand ;
343343 if (!world .isClientSide ) {
344- if (player .getGamemode ().consumeBlocks ()) {
345- player . getHeldItem () .damageItem (1 , player );
344+ if (player == null || player .getGamemode ().consumeBlocks ()) {
345+ itemstack .damageItem (1 , player );
346346 }
347347
348348 label38 :
@@ -373,8 +373,8 @@ else if (world.getBlockLogic(blockX + addx, blockY, blockZ + addz, BlockLogicFlo
373373
374374 else if (world .getBlockLogic (blockX + addx , blockY , blockZ + addz , BlockLogicMoss .class ) != null ){
375375 if (!world .isClientSide ) {
376- if (player .getGamemode ().consumeBlocks ()) {
377- player . getHeldItem () .damageItem (1 , player );
376+ if (player == null || player .getGamemode ().consumeBlocks ()) {
377+ itemstack .damageItem (1 , player );
378378 }
379379
380380 for (j1 = 0 ; j1 < 32 ; ++j1 ) {
@@ -423,8 +423,8 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
423423 if (!((WorldFeature )treeSmall ).place (world , world .rand , blockX + addx , blockY , blockZ + addz ) && !((WorldFeature )treeBig ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
424424 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_OAK .id ());
425425 }
426- if (player .getGamemode ().consumeBlocks ()) {
427- player . getHeldItem () .damageItem (1 , player );
426+ if (player == null || player .getGamemode ().consumeBlocks ()) {
427+ itemstack .damageItem (1 , player );
428428 }
429429 }
430430
@@ -439,8 +439,8 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
439439 if (!((WorldFeature )treeSmall ).place (world , world .rand , blockX + addx , blockY , blockZ + addz ) && !((WorldFeature )treeBig ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
440440 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_BIRCH .id ());
441441 }
442- if (player .getGamemode ().consumeBlocks ()) {
443- player . getHeldItem () .damageItem (1 , player );
442+ if (player == null || player .getGamemode ().consumeBlocks ()) {
443+ itemstack .damageItem (1 , player );
444444 }
445445 }
446446
@@ -455,8 +455,8 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
455455 if (!((WorldFeature )treeSmall ).place (world , world .rand , blockX + addx , blockY , blockZ + addz ) && !((WorldFeature )treeBig ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
456456 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_CACAO .id ());
457457 }
458- if (player .getGamemode ().consumeBlocks ()) {
459- player . getHeldItem () .damageItem (1 , player );
458+ if (player == null || player .getGamemode ().consumeBlocks ()) {
459+ itemstack .damageItem (1 , player );
460460 }
461461 }
462462
@@ -471,8 +471,8 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
471471 if (!((WorldFeature )treeSmall ).place (world , world .rand , blockX + addx , blockY , blockZ + addz ) && !((WorldFeature )treeBig ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
472472 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_CHERRY .id ());
473473 }
474- if (player .getGamemode ().consumeBlocks ()) {
475- player . getHeldItem () .damageItem (1 , player );
474+ if (player == null || player .getGamemode ().consumeBlocks ()) {
475+ itemstack .damageItem (1 , player );
476476 }
477477 }
478478 times ++;
@@ -485,14 +485,19 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
485485 if (!((WorldFeature )tree ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
486486 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_EUCALYPTUS .id ());
487487 }
488+ if (player == null || player .getGamemode ().consumeBlocks ()) {
489+ itemstack .damageItem (1 , player );
490+ }
488491
489492 times ++;
490493 }
491494
492495 else if (world .getBlockId (blockX + addx , blockY , blockZ + addz ) == Blocks .SAPLING_PALM .id ()){
493496 boolean big = world .getBlockId (blockX + addx , blockY - 1 , blockZ + addz ) != Blocks .SAND .id ();
494497 (new WorldFeatureTreePalm (Blocks .LOG_PALM , Blocks .LEAVES_PALM , big , true , false )).place (world , world .rand , blockX + addx , blockY , blockZ + addz );
495-
498+ if (player == null || player .getGamemode ().consumeBlocks ()) {
499+ itemstack .damageItem (1 , player );
500+ }
496501 times ++;
497502 }
498503
@@ -503,6 +508,9 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
503508 if (!((WorldFeature )treeSmall ).place (world , world .rand , blockX + addx , blockY , blockZ + addz ) && !((WorldFeature )treeBig ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
504509 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_PINE .id ());
505510 }
511+ if (player == null || player .getGamemode ().consumeBlocks ()) {
512+ itemstack .damageItem (1 , player );
513+ }
506514 times ++;
507515 }
508516
@@ -513,6 +521,9 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
513521 if (!((WorldFeature )treeSmall ).place (world , world .rand , blockX + addx , blockY , blockZ + addz ) && !((WorldFeature )treeBig ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
514522 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_OAK_RETRO .id ());
515523 }
524+ if (player == null || player .getGamemode ().consumeBlocks ()) {
525+ itemstack .damageItem (1 , player );
526+ }
516527 times ++;
517528 }
518529
@@ -522,6 +533,9 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
522533 if (!((WorldFeature )tree ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
523534 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_SHRUB .id ());
524535 }
536+ if (player == null || player .getGamemode ().consumeBlocks ()) {
537+ itemstack .damageItem (1 , player );
538+ }
525539 times ++;
526540 }
527541
@@ -532,6 +546,9 @@ else if (world.getBlockId(blockX + addx, blockY, blockZ + addz) == Blocks.SAPLIN
532546 if (!((WorldFeature )treeFeature ).place (world , world .rand , blockX + addx , blockY , blockZ + addz )) {
533547 world .setBlock (blockX + addx , blockY , blockZ + addz , Blocks .SAPLING_THORN .id ());
534548 }
549+ if (player == null || player .getGamemode ().consumeBlocks ()) {
550+ itemstack .damageItem (1 , player );
551+ }
535552 }
536553 times ++;
537554 }
0 commit comments