Skip to content

Commit 6f7c187

Browse files
committed
Make use of new douse item ability, and allow the farming unit to douse in an AOE
1 parent f1906dc commit 6f7c187

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

gradle/wrapper/gradle-wrapper.jar

51 Bytes
Binary file not shown.

src/main/java/mekanism/common/content/gear/mekatool/ModuleFarmingUnit.java

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import net.minecraft.world.item.context.UseOnContext;
4646
import net.minecraft.world.level.Level;
4747
import net.minecraft.world.level.block.Block;
48-
import net.minecraft.world.level.block.CampfireBlock;
4948
import net.minecraft.world.level.block.LevelEvent;
5049
import net.minecraft.world.level.block.RotatedPillarBlock;
5150
import 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) {

src/tools/java/mekanism/tools/common/item/ItemMekanismPaxel.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import net.minecraft.world.item.context.UseOnContext;
2929
import net.minecraft.world.level.Level;
3030
import net.minecraft.world.level.block.Block;
31-
import net.minecraft.world.level.block.CampfireBlock;
3231
import net.minecraft.world.level.block.LevelEvent;
3332
import net.minecraft.world.level.block.state.BlockState;
3433
import net.minecraft.world.level.gameevent.GameEvent;
@@ -96,13 +95,12 @@ public InteractionResult useOn(UseOnContext context) {
9695
//We can flatten the item as a shovel
9796
world.playSound(player, blockpos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
9897
resultToSet = foundResult;
99-
} else if (blockstate.getBlock() instanceof CampfireBlock && blockstate.getValue(CampfireBlock.LIT)) {
98+
} else {
99+
resultToSet = blockstate.getToolModifiedState(context, ItemAbilities.SHOVEL_DOUSE, false);
100100
//We can use the paxel as a shovel to extinguish a campfire
101-
if (!world.isClientSide) {
101+
if (resultToSet != null && !world.isClientSide) {
102102
world.levelEvent(null, LevelEvent.SOUND_EXTINGUISH_FIRE, blockpos, 0);
103103
}
104-
CampfireBlock.dowse(player, world, blockpos, blockstate);
105-
resultToSet = blockstate.setValue(CampfireBlock.LIT, false);
106104
}
107105
if (resultToSet == null) {
108106
return InteractionResult.PASS;

0 commit comments

Comments
 (0)