6666import net .minecraft .world .phys .shapes .VoxelShape ;
6767import net .neoforged .neoforge .client .model .data .ModelData ;
6868import net .neoforged .neoforge .client .model .data .ModelProperty ;
69- import net .neoforged .neoforge .items .wrapper .PlayerInvWrapper ;
7069import org .jetbrains .annotations .Nullable ;
7170
7271/**
@@ -253,7 +252,11 @@ public ItemStack getCamouflageStack() {
253252 /**
254253 * Set the camouflage directly. The camouflage block should be consumed from the player before calling this.
255254 */
256- private void setCamouflage (Player player , @ Nullable BlockState newCamouflage ) {
255+ private void setCamouflage (@ Nullable BlockState newCamouflage ) {
256+ if (level .isClientSide ) {
257+ throw new IllegalStateException ("Cannot call setCamouflage on the client" );
258+ }
259+
257260 boolean hadCamouflage = hasCamouflage ();
258261
259262 if (camouflage != null ) {
@@ -267,16 +270,14 @@ private void setCamouflage(Player player, @Nullable BlockState newCamouflage) {
267270 if (newCamouflage == null ) {
268271 var group = camouflage .getSoundType ();
269272 var sound = group .getBreakSound ();
270- level .playSound (player , worldPosition , sound , SoundSource .BLOCKS , (group .getVolume () + 1.0F ) / 4.0F , group .getPitch () * 0.8F );
273+ level .playSound (null , worldPosition , sound , SoundSource .BLOCKS , (group .getVolume () + 1.0F ) / 4.0F , group .getPitch () * 0.8F );
271274 }
272275
273276 // Remove camouflage
274277 camouflage = null ;
275278 setChanged ();
276- if (!level .isClientSide ()) {
277- sync ();
278- rebuildCollisionShape ();
279- }
279+ sync ();
280+ rebuildCollisionShape ();
280281 }
281282
282283 camouflage = newCamouflage ;
@@ -285,13 +286,11 @@ private void setCamouflage(Player player, @Nullable BlockState newCamouflage) {
285286 // Play a cool sound
286287 var group = newCamouflage .getSoundType ();
287288 var sound = group .getPlaceSound ();
288- level .playSound (player , worldPosition , sound , SoundSource .BLOCKS , (group .getVolume () + 1.0F ) / 4.0F , group .getPitch () * 0.8F );
289+ level .playSound (null , worldPosition , sound , SoundSource .BLOCKS , (group .getVolume () + 1.0F ) / 4.0F , group .getPitch () * 0.8F );
289290
290291 setChanged ();
291- if (!level .isClientSide ()) {
292- sync ();
293- rebuildCollisionShape ();
294- }
292+ sync ();
293+ rebuildCollisionShape ();
295294 }
296295
297296 if (hadCamouflage != hasCamouflage ()) {
@@ -310,7 +309,9 @@ public boolean tryRemoveCamouflage(Player player, InteractionHand hand) {
310309 return false ;
311310 }
312311
313- setCamouflage (player , null );
312+ if (!player .level ().isClientSide ) {
313+ setCamouflage (null );
314+ }
314315
315316 return true ;
316317 }
@@ -340,11 +341,16 @@ public boolean tryApplyCamouflage(Player player, InteractionHand hand) {
340341 return true ;
341342 }
342343
344+ // Item capabilities shouldn't be messed with (and in some cases cannot - leading to inconsistent behavior) on the client side
345+ if (player .level ().isClientSide ) {
346+ return true ;
347+ }
348+
343349 boolean itemChanged = camouflage == null || newCamouflage .getBlock () != camouflage .getBlock ();
344350
345351 if (!player .getAbilities ().instabuild && itemChanged ) {
346352 var itemToUse = newCamouflage .getBlock ().asItem ();
347- var extracted = TransferHelper .extractMatching (new PlayerInvWrapper ( player .getInventory ()) , s -> s .is (itemToUse ), 1 );
353+ var extracted = TransferHelper .extractMatching (player .getInventory (), s -> s .is (itemToUse ), 1 , true );
348354
349355 if (extracted .isEmpty ()) {
350356 player .displayClientMessage (MITooltips .line (MIText .ConfigCardNoCamouflageInInventory )
@@ -353,7 +359,7 @@ public boolean tryApplyCamouflage(Player player, InteractionHand hand) {
353359 }
354360 }
355361
356- setCamouflage (player , newCamouflage );
362+ setCamouflage (newCamouflage );
357363 return true ;
358364 }
359365
0 commit comments