From 27b4417b2896a7286cbb9c31ac20d55d2f6fb0ae Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Wed, 8 Nov 2023 19:11:38 +0000 Subject: [PATCH] Change PlayerGetter's method to getPlayer() --- .../base/handler/ToolInteractionHandler.java | 21 ++++++++++++------- .../building/module/ShearVinesModule.java | 2 +- .../tools/module/AncientTomesModule.java | 2 +- .../content/tools/module/SeedPouchModule.java | 2 +- .../module/AutomaticRecipeUnlockModule.java | 2 +- .../module/DoubleDoorOpeningModule.java | 2 +- .../module/DyeableItemFramesModule.java | 2 +- .../tweaks/module/EnhancedLaddersModule.java | 2 +- .../module/ReplaceScaffoldingModule.java | 2 +- .../tweaks/module/ShulkerPackingModule.java | 2 +- .../tweaks/module/SignEditingModule.java | 2 +- .../tweaks/module/SimpleHarvestModule.java | 2 +- .../zeta/event/bus/helpers/PlayerGetter.java | 10 ++++++--- 13 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/vazkii/quark/base/handler/ToolInteractionHandler.java b/src/main/java/vazkii/quark/base/handler/ToolInteractionHandler.java index 2dd9dd8e66..37df6b988b 100644 --- a/src/main/java/vazkii/quark/base/handler/ToolInteractionHandler.java +++ b/src/main/java/vazkii/quark/base/handler/ToolInteractionHandler.java @@ -1,8 +1,17 @@ package vazkii.quark.base.handler; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang3.tuple.Pair; + import com.google.common.collect.HashBiMap; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; + import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; @@ -16,19 +25,15 @@ import net.minecraft.world.level.block.state.properties.Property; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.ToolActions; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import org.apache.commons.lang3.tuple.Pair; import vazkii.quark.base.handler.advancement.QuarkAdvancementHandler; import vazkii.quark.base.handler.advancement.mod.WaxModifier; +import vazkii.zeta.event.ZCommonSetup; import vazkii.zeta.event.ZRightClickBlock; +import vazkii.zeta.event.bus.LoadEvent; import vazkii.zeta.event.bus.PlayEvent; import vazkii.zeta.module.ZetaModule; -import vazkii.zeta.event.ZCommonSetup; -import vazkii.zeta.event.bus.LoadEvent; - -import java.util.*; public final class ToolInteractionHandler { @@ -102,9 +107,9 @@ public static void itemUse(ZRightClickBlock event) { if(!world.isClientSide) world.setBlockAndUpdate(pos, copyState(state, alternate)); - world.levelEvent(event.getEntity(), LevelEvent.PARTICLES_AND_SOUND_WAX_ON, pos, 0); + world.levelEvent(event.getPlayer(), LevelEvent.PARTICLES_AND_SOUND_WAX_ON, pos, 0); - if(!event.getEntity().getAbilities().instabuild) + if(!event.getPlayer().getAbilities().instabuild) stack.setCount(stack.getCount() - 1); event.setCanceled(true); diff --git a/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java b/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java index de5123f89d..df1155b096 100644 --- a/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java +++ b/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java @@ -68,7 +68,7 @@ public void onRightClick(ZRightClickBlock event) { testState = world.getBlockState(testPos); } - Player player = event.getEntity(); + Player player = event.getPlayer(); world.playSound(player, pos, SoundEvents.SHEEP_SHEAR, SoundSource.PLAYERS, 0.5F, 1F); if(!player.getAbilities().instabuild) MiscUtil.damageStack(player, event.getHand(), stack, 1); diff --git a/src/main/java/vazkii/quark/content/tools/module/AncientTomesModule.java b/src/main/java/vazkii/quark/content/tools/module/AncientTomesModule.java index a5a2638cba..786343b471 100644 --- a/src/main/java/vazkii/quark/content/tools/module/AncientTomesModule.java +++ b/src/main/java/vazkii/quark/content/tools/module/AncientTomesModule.java @@ -307,7 +307,7 @@ public void onAnvilUse(ZAnvilRepair event) { @PlayEvent public void onGetSpeed(ZPlayer.BreakSpeed event) { if(deepslateTweak) { - Player player = event.getEntity(); + Player player = event.getPlayer(); ItemStack stack = player.getMainHandItem(); BlockState state = event.getState(); diff --git a/src/main/java/vazkii/quark/content/tools/module/SeedPouchModule.java b/src/main/java/vazkii/quark/content/tools/module/SeedPouchModule.java index bfe5157152..ad8969f362 100644 --- a/src/main/java/vazkii/quark/content/tools/module/SeedPouchModule.java +++ b/src/main/java/vazkii/quark/content/tools/module/SeedPouchModule.java @@ -50,7 +50,7 @@ public final void setup(ZCommonSetup event) { @PlayEvent public void onItemPickup(ZEntityItemPickup event) { - Player player = event.getEntity(); + Player player = event.getPlayer(); ItemStack stack = event.getItem().getItem(); ItemStack main = player.getMainHandItem(); diff --git a/src/main/java/vazkii/quark/content/tweaks/module/AutomaticRecipeUnlockModule.java b/src/main/java/vazkii/quark/content/tweaks/module/AutomaticRecipeUnlockModule.java index 22d693434b..9fc296721f 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/AutomaticRecipeUnlockModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/AutomaticRecipeUnlockModule.java @@ -51,7 +51,7 @@ public final void configChanged(ZConfigChanged event) { @PlayEvent public void onPlayerLoggedIn(ZPlayer.LoggedIn event) { - Player player = event.getEntity(); + Player player = event.getPlayer(); if(player instanceof ServerPlayer spe) { MinecraftServer server = spe.getServer(); diff --git a/src/main/java/vazkii/quark/content/tweaks/module/DoubleDoorOpeningModule.java b/src/main/java/vazkii/quark/content/tweaks/module/DoubleDoorOpeningModule.java index 7d35aca468..b006143574 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/DoubleDoorOpeningModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/DoubleDoorOpeningModule.java @@ -123,7 +123,7 @@ private boolean tryOpen(Level level, Player player, BlockState state, BlockPos o public static class Client extends DoubleDoorOpeningModule { @PlayEvent public void onPlayerInteract(ZRightClickBlock.Low event) { - Player player = event.getEntity(); + Player player = event.getPlayer(); if(!event.getLevel().isClientSide || player.isDiscrete() || event.isCanceled() || event.getResult() == ZResult.DENY || event.getUseBlock() == ZResult.DENY || handling) return; diff --git a/src/main/java/vazkii/quark/content/tweaks/module/DyeableItemFramesModule.java b/src/main/java/vazkii/quark/content/tweaks/module/DyeableItemFramesModule.java index 1b85ac9523..9911bf173b 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/DyeableItemFramesModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/DyeableItemFramesModule.java @@ -61,7 +61,7 @@ public final void register(ZRegister event) { @PlayEvent public void onUse(ZRightClickBlock event) { - Player player = event.getEntity(); + Player player = event.getPlayer(); InteractionHand hand = event.getHand(); ItemStack stack = player.getItemInHand(hand); diff --git a/src/main/java/vazkii/quark/content/tweaks/module/EnhancedLaddersModule.java b/src/main/java/vazkii/quark/content/tweaks/module/EnhancedLaddersModule.java index 59fde40440..d31997f1c1 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/EnhancedLaddersModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/EnhancedLaddersModule.java @@ -138,7 +138,7 @@ public void onInteract(ZRightClickBlock event) { if(!allowDroppingDown) return; - Player player = event.getEntity(); + Player player = event.getPlayer(); InteractionHand hand = event.getHand(); ItemStack stack = player.getItemInHand(hand); diff --git a/src/main/java/vazkii/quark/content/tweaks/module/ReplaceScaffoldingModule.java b/src/main/java/vazkii/quark/content/tweaks/module/ReplaceScaffoldingModule.java index 0433995468..53abfba50e 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/ReplaceScaffoldingModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/ReplaceScaffoldingModule.java @@ -40,7 +40,7 @@ public void onInteract(ZRightClickBlock event) { Level world = event.getLevel(); BlockPos pos = event.getPos(); BlockState state = world.getBlockState(pos); - Player player = event.getEntity(); + Player player = event.getPlayer(); if(state.getBlock() == Blocks.SCAFFOLDING && !player.isDiscrete()) { Direction dir = event.getFace(); ItemStack stack = event.getItemStack(); diff --git a/src/main/java/vazkii/quark/content/tweaks/module/ShulkerPackingModule.java b/src/main/java/vazkii/quark/content/tweaks/module/ShulkerPackingModule.java index 97cd91c871..8cb9a8e917 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/ShulkerPackingModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/ShulkerPackingModule.java @@ -34,7 +34,7 @@ public class ShulkerPackingModule extends ZetaModule { @PlayEvent // It's like fedex but eldritch public void callFedEnd(ZRightClickBlock event) { BlockPos pos = event.getHitVec().getBlockPos(); - Player player = event.getEntity(); + Player player = event.getPlayer(); if (player.isShiftKeyDown()) { ItemStack mainHand = player.getMainHandItem(); diff --git a/src/main/java/vazkii/quark/content/tweaks/module/SignEditingModule.java b/src/main/java/vazkii/quark/content/tweaks/module/SignEditingModule.java index 37043aa40b..56c73f92a8 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/SignEditingModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/SignEditingModule.java @@ -41,7 +41,7 @@ public void onInteract(ZRightClickBlock event) { return; BlockEntity tile = event.getLevel().getBlockEntity(event.getPos()); - Player player = event.getEntity(); + Player player = event.getPlayer(); ItemStack stack = player.getMainHandItem(); if(player instanceof ServerPlayer serverPlayer diff --git a/src/main/java/vazkii/quark/content/tweaks/module/SimpleHarvestModule.java b/src/main/java/vazkii/quark/content/tweaks/module/SimpleHarvestModule.java index 6f810098a8..4c28c23f8a 100644 --- a/src/main/java/vazkii/quark/content/tweaks/module/SimpleHarvestModule.java +++ b/src/main/java/vazkii/quark/content/tweaks/module/SimpleHarvestModule.java @@ -218,7 +218,7 @@ public void onClick(ZRightClickBlock event) { if (isHarvesting) return; isHarvesting = true; - if (click(event.getEntity(), event.getHand(), event.getPos(), event.getHitVec())) { + if (click(event.getPlayer(), event.getHand(), event.getPos(), event.getHitVec())) { event.setCanceled(true); event.setCancellationResult(InteractionResult.sidedSuccess(event.getLevel().isClientSide)); } diff --git a/src/main/java/vazkii/zeta/event/bus/helpers/PlayerGetter.java b/src/main/java/vazkii/zeta/event/bus/helpers/PlayerGetter.java index 485b8daa7e..d8a503e6df 100644 --- a/src/main/java/vazkii/zeta/event/bus/helpers/PlayerGetter.java +++ b/src/main/java/vazkii/zeta/event/bus/helpers/PlayerGetter.java @@ -1,8 +1,12 @@ package vazkii.zeta.event.bus.helpers; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; //fixme Move this into a lifelong home & make other interfaces use this more -public interface PlayerGetter { // TODO rename to getPlayer to prevent overload with LivingGetter - Player getEntity(); -} +public interface PlayerGetter extends LivingGetter { + default Player getPlayer() { + LivingEntity living = getEntity(); + return living instanceof Player p ? p : null; + } +} \ No newline at end of file