Skip to content

Commit 3e09163

Browse files
committed
Expose various item abilities for Mekanism's configurator for when it is in various modes
1 parent a02920d commit 3e09163

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package mekanism.api;
2+
3+
import net.neoforged.neoforge.common.ItemAbility;
4+
5+
/**
6+
* Common placeholder of all the Item Abilities we create in Mekanism. It is still possible to just recreate the item abilities yourself to avoid referencing this class
7+
*
8+
* @since 10.7.0
9+
*/
10+
public final class MekanismItemAbilities {
11+
12+
/**
13+
* Represents the action of a paxel digging.
14+
*
15+
* @apiNote This is only used by Mekanism: Tools.
16+
*/
17+
public static final ItemAbility PAXEL_DIG = ItemAbility.get("paxel_dig");
18+
19+
/**
20+
* Exposed by wrenches that can currently configure a block.
21+
*
22+
* @apiNote Configuring in this case means something different then {@link #WRENCH_DISMANTLE}, {@link #WRENCH_EMPTY}, or {@link #WRENCH_ROTATE}
23+
*/
24+
public static final ItemAbility WRENCH_CONFIGURE = ItemAbility.get("wrench_configure");
25+
/**
26+
* Exposed by wrenches that can currently configure chemical properties for a block.
27+
*/
28+
public static final ItemAbility WRENCH_CONFIGURE_CHEMICALS = ItemAbility.get("wrench_configure_chemicals");
29+
/**
30+
* Exposed by wrenches that can currently configure energy properties for a block.
31+
*/
32+
public static final ItemAbility WRENCH_CONFIGURE_ENERGY = ItemAbility.get("wrench_configure_energy");
33+
/**
34+
* Exposed by wrenches that can currently configure fluid properties for a block.
35+
*/
36+
public static final ItemAbility WRENCH_CONFIGURE_FLUIDS = ItemAbility.get("wrench_configure_fluids");
37+
/**
38+
* Exposed by wrenches that can currently configure heat properties for a block.
39+
*/
40+
public static final ItemAbility WRENCH_CONFIGURE_HEAT = ItemAbility.get("wrench_configure_heat");
41+
/**
42+
* Exposed by wrenches that can currently configure item properties for a block.
43+
*/
44+
public static final ItemAbility WRENCH_CONFIGURE_ITEMS = ItemAbility.get("wrench_configure_items");
45+
46+
/**
47+
* Exposed by wrenches that can currently dismantle blocks.
48+
*/
49+
public static final ItemAbility WRENCH_DISMANTLE = ItemAbility.get("wrench_dismantle");
50+
/**
51+
* Exposed by wrenches that can currently empty the contents of blocks.
52+
*/
53+
public static final ItemAbility WRENCH_EMPTY = ItemAbility.get("wrench_empty");
54+
/**
55+
* Exposed by wrenches that can currently rotate blocks.
56+
*/
57+
public static final ItemAbility WRENCH_ROTATE = ItemAbility.get("wrench_rotate");
58+
}

src/main/java/mekanism/common/item/ItemConfigurator.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.function.IntFunction;
99
import mekanism.api.IConfigurable;
1010
import mekanism.api.IIncrementalEnum;
11+
import mekanism.api.MekanismItemAbilities;
1112
import mekanism.api.RelativeSide;
1213
import mekanism.api.annotations.NothingNullByDefault;
1314
import mekanism.api.inventory.IInventorySlot;
@@ -61,13 +62,14 @@
6162
import net.minecraft.world.level.LevelReader;
6263
import net.minecraft.world.level.block.Block;
6364
import net.minecraft.world.level.block.entity.BlockEntity;
65+
import net.neoforged.neoforge.common.ItemAbility;
6466
import net.neoforged.neoforge.common.util.Lazy;
6567
import org.jetbrains.annotations.NotNull;
6668
import org.jetbrains.annotations.Nullable;
6769

6870
public class ItemConfigurator extends Item implements IRadialModeItem<ConfiguratorMode>, IItemHUDProvider {
6971

70-
public static final Lazy<RadialData<ConfiguratorMode>> LAZY_RADIAL_DATA = Lazy.of(() ->
72+
private static final Lazy<RadialData<ConfiguratorMode>> LAZY_RADIAL_DATA = Lazy.of(() ->
7173
IRadialDataHelper.INSTANCE.dataForEnum(Mekanism.rl("configurator_mode"), ConfiguratorMode.class));
7274

7375
public ItemConfigurator(Properties properties) {
@@ -88,6 +90,30 @@ public Component getName(@NotNull ItemStack stack) {
8890
return TextComponentUtil.build(EnumColor.AQUA, super.getName(stack));
8991
}
9092

93+
@Override
94+
public boolean canPerformAction(@NotNull ItemStack stack, @NotNull ItemAbility action) {
95+
if (action == MekanismItemAbilities.WRENCH_CONFIGURE) {
96+
return getMode(stack).isConfigurating();
97+
} else if (action == MekanismItemAbilities.WRENCH_CONFIGURE_CHEMICALS) {
98+
return getMode(stack) == ConfiguratorMode.CONFIGURATE_CHEMICALS;
99+
} else if (action == MekanismItemAbilities.WRENCH_CONFIGURE_ENERGY) {
100+
return getMode(stack) == ConfiguratorMode.CONFIGURATE_ENERGY;
101+
} else if (action == MekanismItemAbilities.WRENCH_CONFIGURE_FLUIDS) {
102+
return getMode(stack) == ConfiguratorMode.CONFIGURATE_FLUIDS;
103+
} else if (action == MekanismItemAbilities.WRENCH_CONFIGURE_HEAT) {
104+
return getMode(stack) == ConfiguratorMode.CONFIGURATE_HEAT;
105+
} else if (action == MekanismItemAbilities.WRENCH_CONFIGURE_ITEMS) {
106+
return getMode(stack) == ConfiguratorMode.CONFIGURATE_ITEMS;
107+
} else if (action == MekanismItemAbilities.WRENCH_DISMANTLE) {
108+
return getMode(stack) == ConfiguratorMode.WRENCH;
109+
} else if (action == MekanismItemAbilities.WRENCH_EMPTY) {
110+
return getMode(stack) == ConfiguratorMode.EMPTY;
111+
} else if (action == MekanismItemAbilities.WRENCH_ROTATE) {
112+
return getMode(stack) == ConfiguratorMode.ROTATE;
113+
}
114+
return super.canPerformAction(stack, action);
115+
}
116+
91117
@NotNull
92118
@Override
93119
public InteractionResult useOn(UseOnContext context) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.Set;
77
import javax.annotation.ParametersAreNonnullByDefault;
8+
import mekanism.api.MekanismItemAbilities;
89
import mekanism.tools.common.ToolsTags;
910
import mekanism.tools.common.material.IPaxelMaterial;
1011
import mekanism.tools.common.material.MaterialCreator;
@@ -39,9 +40,8 @@
3940
@ParametersAreNonnullByDefault
4041
public class ItemMekanismPaxel extends DiggerItem {
4142

42-
private static final ItemAbility PAXEL_DIG = ItemAbility.get("paxel_dig");
4343
private static final Set<ItemAbility> PAXEL_ACTIONS = Util.make(Collections.newSetFromMap(new IdentityHashMap<>()), actions -> {
44-
actions.add(PAXEL_DIG);
44+
actions.add(MekanismItemAbilities.PAXEL_DIG);
4545
actions.addAll(ItemAbilities.DEFAULT_PICKAXE_ACTIONS);
4646
actions.addAll(ItemAbilities.DEFAULT_SHOVEL_ACTIONS);
4747
actions.addAll(ItemAbilities.DEFAULT_AXE_ACTIONS);

0 commit comments

Comments
 (0)