4545import net .minecraft .world .item .context .UseOnContext ;
4646import net .minecraft .world .level .Level ;
4747import net .minecraft .world .level .block .Block ;
48- import net .minecraft .world .level .block .CampfireBlock ;
4948import net .minecraft .world .level .block .LevelEvent ;
5049import net .minecraft .world .level .block .RotatedPillarBlock ;
5150import net .minecraft .world .level .block .state .BlockState ;
@@ -95,7 +94,7 @@ public InteractionResult onItemUse(IModule<ModuleFarmingUnit> module, UseOnConte
9594 () -> useAxeAOE (context , lazyClickedState , energyContainer , diameter , ItemAbilities .AXE_WAX_OFF , SoundEvents .AXE_WAX_OFF , LevelEvent .PARTICLES_WAX_OFF ),
9695 //Then as a shovel
9796 () -> flattenAOE (context , lazyClickedState , energyContainer , diameter ),
98- () -> dowseCampfire (context , lazyClickedState , energyContainer ),
97+ () -> douseBlock (context , lazyClickedState , energyContainer , diameter ),
9998 //Finally, as a hoe
10099 () -> tillAOE (context , lazyClickedState , energyContainer , diameter )
101100 );
@@ -153,33 +152,14 @@ public String getSerializedName() {
153152 }
154153 }
155154
156- private InteractionResult dowseCampfire (UseOnContext context , Lazy <BlockState > lazyClickedState , IEnergyContainer energyContainer ) {
157- long energy = energyContainer .getEnergy ();
158- long energyUsage = MekanismConfig .gear .mekaToolEnergyUsageShovel .get ();
159- if (energy < energyUsage ) {
160- //Fail if we don't have enough energy or using the item failed
161- return InteractionResult .FAIL ;
162- }
163- BlockState clickedState = lazyClickedState .get ();
164- if (clickedState .getBlock () instanceof CampfireBlock && clickedState .getValue (CampfireBlock .LIT )) {
165- Level world = context .getLevel ();
166- BlockPos pos = context .getClickedPos ();
167- if (!world .isClientSide ()) {
168- world .levelEvent (null , LevelEvent .SOUND_EXTINGUISH_FIRE , pos , 0 );
169- }
170- CampfireBlock .dowse (context .getPlayer (), world , pos , clickedState );
171- if (!world .isClientSide ()) {
172- world .setBlock (pos , clickedState .setValue (CampfireBlock .LIT , Boolean .FALSE ), Block .UPDATE_ALL_IMMEDIATE );
173- energyContainer .extract (energyUsage , Action .EXECUTE , AutomationType .MANUAL );
174- }
175- return InteractionResult .sidedSuccess (world .isClientSide );
176- }
177- return InteractionResult .PASS ;
155+ private InteractionResult douseBlock (UseOnContext context , Lazy <BlockState > lazyClickedState , IEnergyContainer energyContainer , int diameter ) {
156+ return useAOE (context , lazyClickedState , energyContainer , diameter , ItemAbilities .SHOVEL_DOUSE , null , LevelEvent .SOUND_EXTINGUISH_FIRE ,
157+ MekanismConfig .gear .mekaToolEnergyUsageShovel .get (), new SimpleToolAOEData ());
178158 }
179159
180160 private InteractionResult tillAOE (UseOnContext context , Lazy <BlockState > lazyClickedState , IEnergyContainer energyContainer , int diameter ) {
181161 return useAOE (context , lazyClickedState , energyContainer , diameter , ItemAbilities .HOE_TILL , SoundEvents .HOE_TILL , -1 ,
182- MekanismConfig .gear .mekaToolEnergyUsageHoe .get (), new HoeToolAOEData ());
162+ MekanismConfig .gear .mekaToolEnergyUsageHoe .get (), new SimpleToolAOEData ());
183163 }
184164
185165 private InteractionResult flattenAOE (UseOnContext context , Lazy <BlockState > lazyClickedState , IEnergyContainer energyContainer , int diameter ) {
@@ -199,7 +179,7 @@ private InteractionResult useAxeAOE(UseOnContext context, Lazy<BlockState> lazyC
199179 }
200180
201181 private InteractionResult useAOE (UseOnContext context , Lazy <BlockState > lazyClickedState , IEnergyContainer energyContainer , int diameter , ItemAbility action ,
202- SoundEvent sound , int particle , long energyUsage , IToolAOEData toolAOEData ) {
182+ @ Nullable SoundEvent sound , int particle , long energyUsage , IToolAOEData toolAOEData ) {
203183 long energy = energyContainer .getEnergy ();
204184 if (energy < energyUsage ) {
205185 //Fail if we don't have enough energy or using the item failed
@@ -228,7 +208,9 @@ private InteractionResult useAOE(UseOnContext context, Lazy<BlockState> lazyClic
228208 CriteriaTriggers .ITEM_USED_ON_BLOCK .trigger (player , pos , context .getItemInHand ());
229209 }
230210 world .setBlock (pos , modifiedState , Block .UPDATE_ALL_IMMEDIATE );
231- world .playSound (null , pos , sound , SoundSource .BLOCKS , 1.0F , 1.0F );
211+ if (sound != null ) {
212+ world .playSound (null , pos , sound , SoundSource .BLOCKS , 1.0F , 1.0F );
213+ }
232214 if (particle != -1 ) {
233215 world .levelEvent (null , particle , pos , 0 );
234216 }
@@ -265,7 +247,9 @@ private InteractionResult useAOE(UseOnContext context, Lazy<BlockState> lazyClic
265247 state .getToolModifiedState (adjustedContext , action , false );
266248 //Replace the block. Note it just directly sets it (in the same way the normal tools do).
267249 world .setBlock (newPos , modifiedState , Block .UPDATE_ALL_IMMEDIATE );
268- world .playSound (null , newPos , sound , SoundSource .BLOCKS , 1.0F , 1.0F );
250+ if (sound != null ) {
251+ world .playSound (null , newPos , sound , SoundSource .BLOCKS , 1.0F , 1.0F );
252+ }
269253 if (particle != -1 ) {
270254 world .levelEvent (null , particle , newPos , 0 );
271255 }
@@ -302,7 +286,7 @@ public Vec3 getLightningPos(BlockPos pos) {
302286 }
303287 }
304288
305- private static class HoeToolAOEData extends FlatToolAOEData {
289+ private static class SimpleToolAOEData extends FlatToolAOEData {
306290
307291 @ Override
308292 public boolean isValid (Level level , BlockPos pos , BlockState state ) {
0 commit comments