diff --git a/common/src/main/java/io/github/flemmli97/flan/event/ItemInteractEvents.java b/common/src/main/java/io/github/flemmli97/flan/event/ItemInteractEvents.java index 5e326c7..6dbc38c 100644 --- a/common/src/main/java/io/github/flemmli97/flan/event/ItemInteractEvents.java +++ b/common/src/main/java/io/github/flemmli97/flan/event/ItemInteractEvents.java @@ -10,7 +10,6 @@ import io.github.flemmli97.flan.claim.Claim; import io.github.flemmli97.flan.claim.ClaimStorage; import io.github.flemmli97.flan.claim.PermHelper; import io.github.flemmli97.flan.config.ConfigHandler; -import io.github.flemmli97.flan.mixin.IItemAccessor; import io.github.flemmli97.flan.platform.integration.permissions.PermissionNodeHandler; import io.github.flemmli97.flan.player.EnumDisplayType; import io.github.flemmli97.flan.player.EnumEditMode; @@ -22,6 +21,7 @@ import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -37,6 +37,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; import java.util.Set; @@ -65,7 +66,7 @@ public class ItemInteractEvents { ClaimStorage storage = ClaimStorage.get((ServerLevel) world); BlockPos pos = player.blockPosition(); - BlockHitResult hitResult = IItemAccessor.getRaycast(world, player, ClipContext.Fluid.SOURCE_ONLY); + BlockHitResult hitResult = getPlayerHitResult(world, player, ClipContext.Fluid.SOURCE_ONLY); if (hitResult.getType() == HitResult.Type.BLOCK) { pos = new BlockPlaceContext(player, hand, stack, hitResult).getClickedPos(); } @@ -264,4 +265,21 @@ public class ItemInteractEvents { } else player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("inspectNoClaim"), ChatFormatting.RED), false); } + + /** + * From {@link Item#getPlayerPOVHitResult} + */ + protected static BlockHitResult getPlayerHitResult(Level level, Player player, ClipContext.Fluid fluidMode) { + float xRot = player.getXRot(); + float yRot = player.getYRot(); + Vec3 eye = player.getEyePosition(); + float h = Mth.cos(-yRot * Mth.DEG_TO_RAD - Mth.PI); + float i = Mth.sin(-yRot * Mth.DEG_TO_RAD - Mth.PI); + float j = -Mth.cos(-xRot * Mth.DEG_TO_RAD); + float k = Mth.sin(-xRot * Mth.DEG_TO_RAD); + float l = i * j; + float n = h * j; + Vec3 vec32 = eye.add(l * 5.0D, k * 5.0D, n * 5.0D); + return level.clip(new ClipContext(eye, vec32, net.minecraft.world.level.ClipContext.Block.OUTLINE, fluidMode, player)); + } } diff --git a/common/src/main/java/io/github/flemmli97/flan/mixin/IItemAccessor.java b/common/src/main/java/io/github/flemmli97/flan/mixin/IItemAccessor.java deleted file mode 100644 index 7efb584..0000000 --- a/common/src/main/java/io/github/flemmli97/flan/mixin/IItemAccessor.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.github.flemmli97.flan.mixin; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.ClipContext; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.BlockHitResult; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(Item.class) -public interface IItemAccessor { - - @Invoker("getPlayerPOVHitResult") - static BlockHitResult getRaycast(Level world, Player player, ClipContext.Fluid fluidHandling) { - throw new IllegalStateException(); - } -} diff --git a/common/src/main/resources/flan.mixins.json b/common/src/main/resources/flan.mixins.json index 059761a..2e929e3 100644 --- a/common/src/main/resources/flan.mixins.json +++ b/common/src/main/resources/flan.mixins.json @@ -18,7 +18,6 @@ "ItemEntityMixin", "EndermanPickupMixin", "EndermanPlaceMixin", - "IItemAccessor", "IHungerAccessor", "FrostWalkerMixin", "LightningFireEntityMixin",