Skip to content

Commit

Permalink
Change PlayerGetter's method to getPlayer()
Browse files Browse the repository at this point in the history
  • Loading branch information
Vazkii committed Nov 8, 2023
1 parent 0b41740 commit 27b4417
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/vazkii/zeta/event/bus/helpers/PlayerGetter.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 27b4417

Please sign in to comment.