Skip to content

Commit

Permalink
ToolActions go byebye kinda
Browse files Browse the repository at this point in the history
Yeah

Signed-off-by: Siuolplex <lmeitrodt@gmail.com>
  • Loading branch information
Siuolplex committed Jul 16, 2024
1 parent 10d2e76 commit b1cb7fa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dependencies.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neoforge=21.0.78-beta
neoforge=21.0.98-beta
7 changes: 4 additions & 3 deletions src/main/java/org/violetmoon/zeta/event/play/ZBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.ItemAbility;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.event.bus.IZetaPlayEvent;

Expand All @@ -20,8 +21,8 @@ interface EntityPlace extends ZBlock {
BlockState getPlacedBlock();
}

/*interface BlockToolModification extends ZBlock {
ToolAction getToolAction();
interface BlockToolModification extends ZBlock {
ItemAbility getItemAbility();
void setFinalState(@Nullable BlockState finalState);
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.neoforged.neoforge.common.ToolAction;
import net.neoforged.neoforge.common.ToolActions;
import net.neoforged.neoforge.common.ItemAbilities;
import net.neoforged.neoforge.common.ItemAbility;
import org.apache.commons.lang3.tuple.Pair;
import org.violetmoon.zeta.advancement.modifier.WaxModifier;
import org.violetmoon.zeta.event.bus.LoadEvent;
Expand All @@ -39,31 +39,31 @@ public final class ToolInteractionHandler {
private static final Map<Block, Block> cleanToWaxMap = HashBiMap.create();
private static final List<BooleanPropertyWaxableBlock> booleanPropertySet = new ArrayList<>();

private static final Map<ToolAction, Map<Block, Block>> interactionMaps = new HashMap<>();
private static final Map<ItemAbility, Map<Block, Block>> interactionMaps = new HashMap<>();

private static final Multimap<ZetaModule, Pair<Block, Block>> waxingByModule = HashMultimap.create();

public static void registerWaxedBlock(ZetaModule module, Block clean, Block waxed) {
cleanToWaxMap.put(clean, waxed);
registerInteraction(ToolActions.AXE_WAX_OFF, waxed, clean);
registerInteraction(ItemAbilities.AXE_WAX_OFF, waxed, clean);

waxingByModule.put(module, Pair.of(clean, waxed));
}

public static void registerWaxedBlockBooleanProperty(ZetaModule module, Block block, BooleanProperty property) {
BooleanPropertyWaxableBlock booleanPropertyWaxableBlock =
new BooleanPropertyWaxableBlock(module, block, property, ToolActions.AXE_WAX_OFF);
new BooleanPropertyWaxableBlock(module, block, property, ItemAbilities.AXE_WAX_OFF);

booleanPropertySet.add(booleanPropertyWaxableBlock);

waxingByModule.put(module, Pair.of(block, block));
}

public static void registerInteraction(ToolAction action, Block in, Block out) {
if(!interactionMaps.containsKey(action))
interactionMaps.put(action, new HashMap<>());
public static void registerInteraction(ItemAbility ability, Block in, Block out) {
if(!interactionMaps.containsKey(ability))
interactionMaps.put(ability, new HashMap<>());

Map<Block, Block> map = interactionMaps.get(action);
Map<Block, Block> map = interactionMaps.get(ability);
map.put(in, out);
}

Expand All @@ -87,8 +87,8 @@ public static void addModifiers(ZCommonSetup event) {
}

@PlayEvent
public static void toolActionEvent(ZBlock.BlockToolModification event) {
ToolAction action = event.getToolAction();
public static void itemAbilityEvent(ZBlock.BlockToolModification event) {
ItemAbility action = event.getItemAbility();

if(interactionMaps.containsKey(action)) {
Map<Block, Block> map = interactionMaps.get(action);
Expand All @@ -102,7 +102,7 @@ public static void toolActionEvent(ZBlock.BlockToolModification event) {
}

for (BooleanPropertyWaxableBlock waxableBlock : booleanPropertySet) {
if (waxableBlock.action == action) {
if (waxableBlock.itemAbility == action) {
BlockState state = event.getState();
Block block = state.getBlock();

Expand Down Expand Up @@ -178,13 +178,13 @@ public static class BooleanPropertyWaxableBlock {
public ZetaModule module;
public Block block;
public BooleanProperty property;
public ToolAction action;
public ItemAbility itemAbility;

private BooleanPropertyWaxableBlock(ZetaModule module, Block block, BooleanProperty property, ToolAction action) {
private BooleanPropertyWaxableBlock(ZetaModule module, Block block, BooleanProperty property, ItemAbility action) {
this.module = module;
this.block = block;
this.property = property;
this.action = action;
this.itemAbility = action;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.ItemAbility;
import net.neoforged.neoforge.event.level.BlockEvent;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.event.play.ZBlock;
Expand Down Expand Up @@ -58,22 +59,22 @@ public BlockState getPlacedBlock() {
}
}

/*public static class BlockToolModification extends ForgeZBlock implements ZBlock.BlockToolModification {
public static class BlockToolModification extends ForgeZBlock implements ZBlock.BlockToolModification {
private final BlockEvent.BlockToolModificationEvent e;

public BlockToolModification(BlockEvent.BlockToolModificationEvent e) {
super(e);
this.e = e;
}

//@Override
//public ToolAction getToolAction() {
return e.getToolAction();
@Override
public ItemAbility getItemAbility() {
return e.getItemAbility();
}

@Override
public void setFinalState(@Nullable BlockState finalState) {
e.setFinalState(finalState);
}
}*/
}
}

0 comments on commit b1cb7fa

Please sign in to comment.