From 47002b3b3c553eece5be0b56b5d34e8876a5bd81 Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Thu, 25 Jan 2024 12:16:48 +0100 Subject: [PATCH] simple harvest event refactor --- .../quark/api/event/SimpleHarvestEvent.java | 98 +++++++++---------- .../tweaks/module/SimpleHarvestModule.java | 7 -- 2 files changed, 49 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/violetmoon/quark/api/event/SimpleHarvestEvent.java b/src/main/java/org/violetmoon/quark/api/event/SimpleHarvestEvent.java index abbc07a94b..de7acfe821 100644 --- a/src/main/java/org/violetmoon/quark/api/event/SimpleHarvestEvent.java +++ b/src/main/java/org/violetmoon/quark/api/event/SimpleHarvestEvent.java @@ -2,10 +2,14 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.eventbus.api.Cancelable; import net.minecraftforge.eventbus.api.Event; +import org.jetbrains.annotations.Nullable; +import org.violetmoon.quark.content.tweaks.module.SimpleHarvestModule; /** * Used primarily for double crops which need extra checks before they are considered ready. @@ -15,62 +19,58 @@ @Cancelable public class SimpleHarvestEvent extends Event { - public final BlockState blockState; - public final BlockPos pos; - public final InteractionHand hand; - public final Player player; - public final Source type; - private BlockPos newTarget; - private ActionType action; + public final BlockState blockState; + public final BlockPos pos; + public final Level level; + public final @Nullable InteractionHand hand; + public final @Nullable Entity entity; + private BlockPos newTarget; + private ActionType action; - public SimpleHarvestEvent(BlockState blockState, BlockPos pos, InteractionHand hand, - Player player, boolean isHoe, ActionType actionType) { - this.blockState = blockState; - this.pos = pos; - this.hand = hand; - this.player = player; - this.newTarget = pos; - this.type = isHoe ? Source.HOE : Source.RIGHT_CLICK; - this.action = actionType; - } + //Note that entity could be a player or villager + public SimpleHarvestEvent(BlockState blockState, BlockPos pos, Level level, @Nullable InteractionHand hand, + @Nullable Entity entity, ActionType originalActionType) { + this.blockState = blockState; + this.pos = pos; + this.hand = hand; + this.level = level; + this.entity = entity; + this.newTarget = pos; + this.action = originalActionType; + } - /** - * Used for double crops and the like. Pass a new position which should be broken instead - * - * @param pos new target position - */ - public void setTargetPos(BlockPos pos) { - this.newTarget = pos; - } + /** + * Used for double crops and the like. Pass a new position which should be broken instead + * + * @param pos new target position + */ + public void setTargetPos(BlockPos pos) { + this.newTarget = pos; + } - public Source getInteractionSource() { - return type; - } + @Override + public void setCanceled(boolean cancel) { + if (cancel) + action = ActionType.NONE; + super.setCanceled(cancel); + } - @Override - public void setCanceled(boolean cancel) { - if(cancel) - action = ActionType.NONE; - super.setCanceled(cancel); - } + //Click will work just for players! + public enum ActionType { + NONE, CLICK, HARVEST; + } - public enum ActionType { - NONE, CLICK, HARVEST; - } + public ActionType getAction() { + return action; + } - public ActionType getAction() { - return action; - } + public void setAction(ActionType action) { + this.action = action; + } - public void setAction(ActionType action) { - this.action = action; - } + public BlockPos getTargetPos() { + return newTarget; + } - public BlockPos getTargetPos() { - return newTarget; - } - public enum Source { - RIGHT_CLICK, HOE - } } diff --git a/src/main/java/org/violetmoon/quark/content/tweaks/module/SimpleHarvestModule.java b/src/main/java/org/violetmoon/quark/content/tweaks/module/SimpleHarvestModule.java index 7509855730..1897f1e4e5 100644 --- a/src/main/java/org/violetmoon/quark/content/tweaks/module/SimpleHarvestModule.java +++ b/src/main/java/org/violetmoon/quark/content/tweaks/module/SimpleHarvestModule.java @@ -196,13 +196,6 @@ private static boolean harvestAndReplant(Level level, BlockPos pos, BlockState i }else{ // is this needed? isnt enchantent level handled intenrally? copy = entity.getItemInHand(hand).copy(); - - //TODO: I'm pretty sure all this is unnecessary and can be removed - int fortune = Quark.ZETA.itemExtensions.get(copy).getEnchantmentLevelZeta(copy, Enchantments.BLOCK_FORTUNE); - - Map enchMap = EnchantmentHelper.getEnchantments(copy); - enchMap.put(Enchantments.BLOCK_FORTUNE, fortune); - EnchantmentHelper.setEnchantments(enchMap, copy); } MutableBoolean hasTaken = new MutableBoolean(false);