fudge OpEntityPos to eye height when cast on a player and fix spellbook in offhand only scrolling in empty mainhand
This commit is contained in:
parent
ed7bfc5450
commit
db850be39f
3 changed files with 12 additions and 11 deletions
|
@ -7,7 +7,7 @@ import at.petrak.hex.common.network.MsgShiftScrollSyn;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -22,21 +22,20 @@ public class ShiftScrollListener {
|
|||
// yes, this does work if you remap your sneak key
|
||||
if (player.isShiftKeyDown()) {
|
||||
InteractionHand hand = null;
|
||||
if (player.getMainHandItem().getItem() != Items.AIR) {
|
||||
if (IsScrollableItem(player.getMainHandItem().getItem())) {
|
||||
hand = InteractionHand.MAIN_HAND;
|
||||
} else if (player.getOffhandItem().getItem() != Items.AIR) {
|
||||
} else if (IsScrollableItem(player.getOffhandItem().getItem())) {
|
||||
hand = InteractionHand.OFF_HAND;
|
||||
}
|
||||
|
||||
if (hand != null) {
|
||||
var item = player.getItemInHand(hand).getItem();
|
||||
if (item instanceof ItemSpellbook) {
|
||||
evt.setCanceled(true);
|
||||
|
||||
HexMessages.getNetwork().sendToServer(new MsgShiftScrollSyn(hand, evt.getScrollDelta()));
|
||||
}
|
||||
evt.setCanceled(true);
|
||||
HexMessages.getNetwork().sendToServer(new MsgShiftScrollSyn(hand, evt.getScrollDelta()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean IsScrollableItem(Item item) {
|
||||
return item instanceof ItemSpellbook;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,15 @@ import at.petrak.hex.common.casting.SpellDatum
|
|||
import at.petrak.hex.common.casting.SpellOperator.Companion.getChecked
|
||||
import at.petrak.hex.common.casting.SpellOperator.Companion.spellListOf
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
|
||||
object OpEntityPos : SimpleOperator {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
|
||||
val e: Entity = args.getChecked(0)
|
||||
return spellListOf(e.position())
|
||||
// If this is a player, "expected behavior" is to get the *eye* position so raycasts don't immediately
|
||||
// hit the ground.
|
||||
return spellListOf(if (e is Player) e.eyePosition else e.position())
|
||||
}
|
||||
}
|
|
@ -37,7 +37,6 @@ public record MsgShiftScrollSyn(InteractionHand hand, double scrollDelta) {
|
|||
|
||||
if (stack.getItem() instanceof ItemSpellbook) {
|
||||
spellbook(sender, stack);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue