Skip to content

Commit

Permalink
consolidated a couple more expect platform methods into AntimatterPla…
Browse files Browse the repository at this point in the history
…tformUtils
  • Loading branch information
Trinsdar committed Jun 13, 2024
1 parent 3ece03a commit 789f04d
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 86 deletions.
18 changes: 0 additions & 18 deletions common/src/main/java/muramasa/antimatter/tool/ToolUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import muramasa.antimatter.material.MaterialTags;
import muramasa.antimatter.registration.ISharedAntimatterObject;
import muramasa.antimatter.tool.IAntimatterArmor;
import muramasa.antimatter.tool.ToolUtils;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.minecraft.network.chat.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import muramasa.antimatter.behaviour.IItemUse;
import muramasa.antimatter.tool.IAntimatterTool;
import muramasa.antimatter.tool.IBasicAntimatterTool;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -42,7 +43,7 @@ public InteractionResult onItemUse(IBasicAntimatterTool instance, UseOnContext c
if (c.getClickedFace() != Direction.DOWN && c.getLevel().isEmptyBlock(c.getClickedPos().above())) {
BlockState blockstate = getToolModifiedState(c.getLevel().getBlockState(c.getClickedPos()), c, "hoe_dig");
if (blockstate == null) return InteractionResult.PASS;
if (BehaviourUtil.onUseHoe(c)) return InteractionResult.PASS;
if (AntimatterPlatformUtils.onUseHoe(c)) return InteractionResult.PASS;
Utils.damageStack(c.getItemInHand(), c.getPlayer());
SoundEvent soundEvent = instance.getAntimatterToolType().getUseSound() == null ? SoundEvents.HOE_TILL : instance.getAntimatterToolType().getUseSound();
c.getLevel().playSound(c.getPlayer(), c.getClickedPos(), soundEvent, SoundSource.BLOCKS, 1.0F, 1.0F);
Expand All @@ -53,7 +54,7 @@ public InteractionResult onItemUse(IBasicAntimatterTool instance, UseOnContext c
}

private BlockState getToolModifiedState(BlockState originalState, UseOnContext context, String action) {
BlockState eventState = BehaviourUtil.onToolUse(originalState, context, action);
BlockState eventState = AntimatterPlatformUtils.onToolUse(originalState, context, action);
return eventState != originalState ? eventState : TILLING_MAP.get(originalState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import muramasa.antimatter.behaviour.IItemUse;
import muramasa.antimatter.tool.IAntimatterTool;
import muramasa.antimatter.tool.IBasicAntimatterTool;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
Expand Down Expand Up @@ -56,7 +57,7 @@ public InteractionResult onItemUse(IBasicAntimatterTool instance, UseOnContext c
}

private BlockState getToolModifiedState(BlockState originalState, UseOnContext context, String action) {
BlockState eventState = BehaviourUtil.onToolUse(originalState, context, action);
BlockState eventState = AntimatterPlatformUtils.onToolUse(originalState, context, action);
if (eventState != originalState) return eventState;
Block stripped = STRIPPING_MAP.get(originalState.getBlock());
if (stripped == null) return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import muramasa.antimatter.behaviour.IItemUse;
import muramasa.antimatter.tool.IBasicAntimatterTool;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -66,7 +67,7 @@ public InteractionResult onItemUse(IBasicAntimatterTool instance, UseOnContext c
}

private BlockState getToolModifiedState(BlockState originalState, UseOnContext context, String action) {
BlockState eventState = BehaviourUtil.onToolUse(originalState, context, action);
BlockState eventState = AntimatterPlatformUtils.onToolUse(originalState, context, action);
if (eventState != originalState) return eventState;
Block flattened = FLATTENING_MAP.get(originalState.getBlock());
if (flattened == null) return null;
Expand All @@ -80,7 +81,7 @@ private BlockState getToolModifiedState(BlockState originalState, UseOnContext c
}

private BlockState getFireModifiedState(BlockState originalState, BlockState changedState, UseOnContext context, String action) {
BlockState eventState = BehaviourUtil.onToolUse(originalState, context, action);
BlockState eventState = AntimatterPlatformUtils.onToolUse(originalState, context, action);
return eventState != originalState ? eventState : changedState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -309,4 +310,14 @@ public static Item.Properties getToolProperties(CreativeModeTab group, boolean r
public static boolean isCorrectTierForDrops(Tier tier, BlockState state){
throw new AssertionError();
}

@ExpectPlatform
public static BlockState onToolUse(BlockState originalState, UseOnContext context, String action){
throw new AssertionError();
}

@ExpectPlatform
public static boolean onUseHoe(UseOnContext context){
throw new AssertionError();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -252,4 +253,13 @@ public static Item.Properties getToolProperties(CreativeModeTab group, boolean r
public static boolean isCorrectTierForDrops(Tier tier, BlockState state){
return TierSortingRegistry.isCorrectTierForDrops(tier, state);
}

//TODO make this use fabric events, if they exist
public static BlockState onToolUse(BlockState originalState, UseOnContext context, String action){
return originalState;
}

public static boolean onUseHoe(UseOnContext context){
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -55,8 +56,10 @@
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.TierSortingRegistry;
import net.minecraftforge.common.ToolAction;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoader;
Expand Down Expand Up @@ -305,4 +308,12 @@ public static Item.Properties getToolProperties(CreativeModeTab group, boolean r
public static boolean isCorrectTierForDrops(Tier tier, BlockState state){
return TierSortingRegistry.isCorrectTierForDrops(tier, state);
}

public static BlockState onToolUse(BlockState originalState, UseOnContext context, String action){
return ForgeEventFactory.onToolUse(originalState, context, ToolAction.get(action), false);
}

public static boolean onUseHoe(UseOnContext context){
return MinecraftForge.EVENT_BUS.post(new UseHoeEvent(context));
}
}

0 comments on commit 789f04d

Please sign in to comment.