From c43de8fed481341dce90f327db05f37b5509b1ad Mon Sep 17 00:00:00 2001 From: jimchen5209 Date: Sun, 7 Jan 2024 13:41:30 +0800 Subject: [PATCH] feat: Add gun aiming and shooting --- .../MixinPlayerDropItem_NetworkHandler.java | 53 +++++ .../MixinPlayerPickupItem_ItemEntity.java | 45 ++++ ...nPlayerSwapItemInHand_NetworkHandler.java} | 28 ++- src/main/kotlin/one/oktw/galaxy/Main.kt | 3 +- ...tUpdateEvent.kt => PlayerDropItemEvent.kt} | 6 +- .../event/type/PlayerPickupItemEvent.kt | 23 +++ .../event/type/PlayerSwapItemInHandEvent.kt | 23 +++ .../kotlin/one/oktw/galaxy/item/event/Gun.kt | 193 ++++++++++++++++++ .../one/oktw/galaxy/item/event/Weapon.kt | 68 ------ src/main/resources/galaxy.mixin.json | 4 +- 10 files changed, 356 insertions(+), 90 deletions(-) create mode 100644 src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerDropItem_NetworkHandler.java create mode 100644 src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerPickupItem_ItemEntity.java rename src/main/java/one/oktw/galaxy/mixin/event/{MixinHotBarSlotUpdate_ScreenHandlerListener.java => MixinPlayerSwapItemInHand_NetworkHandler.java} (59%) rename src/main/kotlin/one/oktw/galaxy/event/type/{HotBarSlotUpdateEvent.kt => PlayerDropItemEvent.kt} (76%) create mode 100644 src/main/kotlin/one/oktw/galaxy/event/type/PlayerPickupItemEvent.kt create mode 100644 src/main/kotlin/one/oktw/galaxy/event/type/PlayerSwapItemInHandEvent.kt create mode 100644 src/main/kotlin/one/oktw/galaxy/item/event/Gun.kt delete mode 100644 src/main/kotlin/one/oktw/galaxy/item/event/Weapon.kt diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerDropItem_NetworkHandler.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerDropItem_NetworkHandler.java new file mode 100644 index 000000000..1b9411bae --- /dev/null +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerDropItem_NetworkHandler.java @@ -0,0 +1,53 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2022 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.mixin.event; + +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import one.oktw.galaxy.Main; +import one.oktw.galaxy.event.type.PlayerDropItemEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ServerPlayNetworkHandler.class) +public class MixinPlayerDropItem_NetworkHandler { + @Shadow + public ServerPlayerEntity player; + + @Inject( + method = "onPlayerAction", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayerEntity;dropSelectedItem(Z)Z", + shift = At.Shift.BEFORE + ), cancellable = true) + private void onPlayerAction(PlayerActionC2SPacket packet, CallbackInfo ci) { + Main main = Main.Companion.getMain(); + if (main != null && main.getEventManager().emit(new PlayerDropItemEvent(player)).getCancel()) { + ci.cancel(); + player.currentScreenHandler.syncState(); + } + } + + +} diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerPickupItem_ItemEntity.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerPickupItem_ItemEntity.java new file mode 100644 index 000000000..ac3ab7b36 --- /dev/null +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerPickupItem_ItemEntity.java @@ -0,0 +1,45 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2022 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.mixin.event; + +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import one.oktw.galaxy.Main; +import one.oktw.galaxy.event.type.PlayerPickupItemEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ItemEntity.class) +public class MixinPlayerPickupItem_ItemEntity { + @Inject( + method = "onPlayerCollision", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/player/PlayerEntity;triggerItemPickedUpByEntityCriteria(Lnet/minecraft/entity/ItemEntity;)V", + shift = At.Shift.AFTER + )) + private void onPlayerCollision(PlayerEntity player, CallbackInfo ci) { + Main main = Main.Companion.getMain(); + if (main == null) return; + main.getEventManager().emit(new PlayerPickupItemEvent((ServerPlayerEntity) player)); + } +} diff --git a/src/main/java/one/oktw/galaxy/mixin/event/MixinHotBarSlotUpdate_ScreenHandlerListener.java b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerSwapItemInHand_NetworkHandler.java similarity index 59% rename from src/main/java/one/oktw/galaxy/mixin/event/MixinHotBarSlotUpdate_ScreenHandlerListener.java rename to src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerSwapItemInHand_NetworkHandler.java index e8d2869b0..40119828e 100644 --- a/src/main/java/one/oktw/galaxy/mixin/event/MixinHotBarSlotUpdate_ScreenHandlerListener.java +++ b/src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerSwapItemInHand_NetworkHandler.java @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2022 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,31 +18,27 @@ package one.oktw.galaxy.mixin.event; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; +import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import one.oktw.galaxy.Main; -import one.oktw.galaxy.event.type.HotBarSlotUpdateEvent; +import one.oktw.galaxy.event.type.PlayerSwapItemInHandEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(targets = {"net/minecraft/server/network/ServerPlayerEntity$2"}) -public class MixinHotBarSlotUpdate_ScreenHandlerListener { - @Shadow(aliases = {"field_29183"}) - private ServerPlayerEntity player; +@Mixin(ServerPlayNetworkHandler.class) +public class MixinPlayerSwapItemInHand_NetworkHandler { + @Shadow + public ServerPlayerEntity player; - @Inject( - method = "onSlotUpdate(Lnet/minecraft/screen/ScreenHandler;ILnet/minecraft/item/ItemStack;)V", - at = @At(value = "RETURN") - ) - private void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack, CallbackInfo ci) { + @Inject(method = "onPlayerAction", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;clearActiveItem()V", shift = At.Shift.AFTER)) + private void onPlayerAction(PlayerActionC2SPacket packet, CallbackInfo ci) { Main main = Main.Companion.getMain(); if (main == null) return; - if (slotId >= 36 && slotId <= 45) { - main.getEventManager().emit(new HotBarSlotUpdateEvent(player, handler, slotId, stack)); - } + main.getEventManager().emit(new PlayerSwapItemInHandEvent(player)); } + } diff --git a/src/main/kotlin/one/oktw/galaxy/Main.kt b/src/main/kotlin/one/oktw/galaxy/Main.kt index b2e64465b..67ca241a2 100644 --- a/src/main/kotlin/one/oktw/galaxy/Main.kt +++ b/src/main/kotlin/one/oktw/galaxy/Main.kt @@ -39,6 +39,7 @@ import one.oktw.galaxy.command.commands.Spawn import one.oktw.galaxy.event.EventManager import one.oktw.galaxy.event.type.ProxyResponseEvent import one.oktw.galaxy.item.event.CustomItemEventHandler +import one.oktw.galaxy.item.event.Gun import one.oktw.galaxy.item.event.Wrench import one.oktw.galaxy.player.Harvest import one.oktw.galaxy.proxy.api.ProxyAPI @@ -99,7 +100,7 @@ class Main : DedicatedServerModInitializer, CoroutineScope { eventManager.register(Elevator()) eventManager.register(AngelBlock()) eventManager.register(CustomItemEventHandler()) -// eventManager.register(Weapon()) + eventManager.register(Gun()) }) ServerLifecycleEvents.SERVER_STOPPING.register { diff --git a/src/main/kotlin/one/oktw/galaxy/event/type/HotBarSlotUpdateEvent.kt b/src/main/kotlin/one/oktw/galaxy/event/type/PlayerDropItemEvent.kt similarity index 76% rename from src/main/kotlin/one/oktw/galaxy/event/type/HotBarSlotUpdateEvent.kt rename to src/main/kotlin/one/oktw/galaxy/event/type/PlayerDropItemEvent.kt index c69f2c13a..033963f10 100644 --- a/src/main/kotlin/one/oktw/galaxy/event/type/HotBarSlotUpdateEvent.kt +++ b/src/main/kotlin/one/oktw/galaxy/event/type/PlayerDropItemEvent.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2022 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -18,8 +18,6 @@ package one.oktw.galaxy.event.type -import net.minecraft.item.ItemStack -import net.minecraft.screen.ScreenHandler import net.minecraft.server.network.ServerPlayerEntity -class HotBarSlotUpdateEvent(val player: ServerPlayerEntity, val handler: ScreenHandler, val slotId: Int, val item: ItemStack) : Event +class PlayerDropItemEvent(val player: ServerPlayerEntity) : CancelableEvent() diff --git a/src/main/kotlin/one/oktw/galaxy/event/type/PlayerPickupItemEvent.kt b/src/main/kotlin/one/oktw/galaxy/event/type/PlayerPickupItemEvent.kt new file mode 100644 index 000000000..ed00f0bba --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/event/type/PlayerPickupItemEvent.kt @@ -0,0 +1,23 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2022 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.event.type + +import net.minecraft.server.network.ServerPlayerEntity + +class PlayerPickupItemEvent(val player: ServerPlayerEntity) : Event diff --git a/src/main/kotlin/one/oktw/galaxy/event/type/PlayerSwapItemInHandEvent.kt b/src/main/kotlin/one/oktw/galaxy/event/type/PlayerSwapItemInHandEvent.kt new file mode 100644 index 000000000..1b3d39c02 --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/event/type/PlayerSwapItemInHandEvent.kt @@ -0,0 +1,23 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2022 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.event.type + +import net.minecraft.server.network.ServerPlayerEntity + +class PlayerSwapItemInHandEvent(val player: ServerPlayerEntity) : Event diff --git a/src/main/kotlin/one/oktw/galaxy/item/event/Gun.kt b/src/main/kotlin/one/oktw/galaxy/item/event/Gun.kt new file mode 100644 index 000000000..f63ad031e --- /dev/null +++ b/src/main/kotlin/one/oktw/galaxy/item/event/Gun.kt @@ -0,0 +1,193 @@ +/* + * OKTW Galaxy Project + * Copyright (C) 2018-2022 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package one.oktw.galaxy.item.event + +import net.minecraft.item.ItemStack +import net.minecraft.particle.ParticleTypes +import net.minecraft.server.MinecraftServer +import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.world.ServerWorld +import net.minecraft.sound.SoundCategory +import net.minecraft.sound.SoundEvents +import net.minecraft.util.Hand +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d +import one.oktw.galaxy.event.annotation.EventListener +import one.oktw.galaxy.event.type.* +import one.oktw.galaxy.item.CustomItemHelper +import one.oktw.galaxy.item.Gun +import one.oktw.galaxy.sound.GalaxySound +import java.lang.Math.random +import kotlin.math.abs +import kotlin.math.roundToInt + +class Gun { + @EventListener(true) + fun onPlayerInteractItem(event: PlayerInteractItemEvent) = shoot(event.player) + + @EventListener(true) + fun onPlayerUseItemOnBlock(event: PlayerUseItemOnBlock) = shoot(event.context.player as ServerPlayerEntity) + + @EventListener(true) + fun onPlayerSneak(event: PlayerSneakEvent) = switchAiming(event.player, true) + + @EventListener(true) + fun onPlayerSneakRelease(event: PlayerSneakReleaseEvent) = switchAiming(event.player, false) + + @EventListener(true) + fun onUpdateSelectedSlot(event: UpdateSelectedSlotEvent) = switchAiming(event.player, event.player.shouldCancelInteraction()) + + @EventListener(true) + fun onSwapItem(event: PlayerSwapItemInHandEvent) = switchAiming(event.player, event.player.shouldCancelInteraction()) + + // cancel aiming before dropping + @EventListener(true) + fun onDropItem(event: PlayerDropItemEvent) = switchAiming(event.player, false) + + @EventListener(true) + fun onPickupItem(event: PlayerPickupItemEvent) = switchAiming(event.player, event.player.shouldCancelInteraction()) + + private fun shoot(player: ServerPlayerEntity) { + val items = getWeaponsFromHands(player) + val gun = items[Hand.MAIN_HAND] ?: items[Hand.OFF_HAND] ?: return + shoot(gun, player, player.world as ServerWorld) + } + + private fun getWeaponsFromHands(player: ServerPlayerEntity): Map = mapOf( + Hand.MAIN_HAND to CustomItemHelper.getItem(player.getStackInHand(Hand.MAIN_HAND)) as? Gun, + Hand.OFF_HAND to CustomItemHelper.getItem(player.getStackInHand(Hand.OFF_HAND)) as? Gun + ) + + private fun switchAiming(player: ServerPlayerEntity, aiming: Boolean) { + val items = getWeaponsFromHands(player) + + val hand = if (items[Hand.MAIN_HAND] != null) Hand.MAIN_HAND else if (items[Hand.OFF_HAND] != null) Hand.OFF_HAND else return + + if (hand == Hand.MAIN_HAND && items[Hand.OFF_HAND] != null) { // turn weapon on offhand aiming off + switchAiming(items[Hand.OFF_HAND]!!, false)?.let { player.setStackInHand(Hand.OFF_HAND, it) } + } + + switchAiming(items[hand]!!, aiming)?.let { player.setStackInHand(hand, it) } + } + + private fun shoot(item: Gun, player: ServerPlayerEntity, world: ServerWorld) { + showTrajectory(item, player, world) + playSound(item, player.server, world, player.blockPos) + } + + private fun switchAiming(item: Gun, aiming: Boolean): ItemStack? { + val newItem = if (aiming) { + when (item) { + Gun.PISTOL_LASOR -> Gun.PISTOL_LASOR_AIMING + Gun.SNIPER -> Gun.SNIPER_AIMING + Gun.RAILGUN -> Gun.RAILGUN_AIMING + else -> item + } as Gun + } else { + when (item) { + Gun.PISTOL_LASOR_AIMING -> Gun.PISTOL_LASOR + Gun.SNIPER_AIMING -> Gun.SNIPER + Gun.RAILGUN_AIMING -> Gun.RAILGUN + else -> item + } as Gun + } + if (item != newItem) { + return newItem.apply { + migrateData(item) + }.createItemStack() + } + return null + } + + private fun showTrajectory(item: Gun, player: ServerPlayerEntity, world: ServerWorld) { + val gun = item.weaponData + var playerLookVec = player.rotationVector + if (!player.shouldCancelInteraction()) playerLookVec = drift(playerLookVec) + val line = playerLookVec.multiply(gun.range) + + val interval = when (maxAxis(vecAbs(line))) { + 0 -> vecAbs(line).x.div(0.3) + 1 -> vecAbs(line).y.div(0.3) + 2 -> vecAbs(line).z.div(0.3) + else -> 10.0 + } + var pos = Vec3d(player.x, player.eyeY, player.z).add(vecDiv(line, interval)) + + for (i in 0..interval.roundToInt()) { + world.spawnParticles(ParticleTypes.ENCHANTED_HIT, pos.x, pos.y, pos.z, 1, 0.0, 0.0, 0.0, 0.0) + pos = pos.add(vecDiv(line, interval)) + } + } + + private fun drift(vec: Vec3d) = vecDiv( + vec.multiply(10.0).add(random(), random(), random()) + .subtract(random(), random(), random()), 10.0 + ) + + private fun playSound(item: Gun, server: MinecraftServer, world: ServerWorld, pos: BlockPos) = when (item) { + Gun.PISTOL, Gun.PISTOL_LASOR, Gun.PISTOL_LASOR_AIMING -> + GalaxySound.playSound( + server, + world, + null, + pos, + GalaxySound.GUN_SHOOT, + SoundCategory.PLAYERS, + 1.0f, + (1 + random() / 10 - random() / 10).toFloat() + ) + Gun.SNIPER, Gun.SNIPER_AIMING -> { + world.playSound( + null, + pos, + SoundEvents.ENTITY_BLAZE_HURT, + SoundCategory.PLAYERS, + 1.0f, + 2.0f + ) + world.playSound( + null, + pos, + SoundEvents.ENTITY_FIREWORK_ROCKET_BLAST, + SoundCategory.PLAYERS, + 1.0f, + 0.0f + ) + world.playSound( + null, + pos, + SoundEvents.BLOCK_PISTON_EXTEND, + SoundCategory.PLAYERS, + 1.0f, + 2.0f + ) + } + else -> Unit // TODO RailGun + } + + private fun vecAbs(vec: Vec3d) = Vec3d(abs(vec.x), abs(vec.y), abs(vec.z)) + + private fun maxAxis(vec: Vec3d) = if (vec.x < vec.y) { + if (vec.y < vec.z) 2 else 1 + } else { + if (vec.x < vec.z) 2 else 0 + } + + private fun vecDiv(vec: Vec3d, value: Double) = Vec3d(vec.x / value, vec.y / value, vec.z / value) +} diff --git a/src/main/kotlin/one/oktw/galaxy/item/event/Weapon.kt b/src/main/kotlin/one/oktw/galaxy/item/event/Weapon.kt deleted file mode 100644 index 5195b8a96..000000000 --- a/src/main/kotlin/one/oktw/galaxy/item/event/Weapon.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * OKTW Galaxy Project - * Copyright (C) 2018-2022 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package one.oktw.galaxy.item.event - -import net.minecraft.server.network.ServerPlayerEntity -import one.oktw.galaxy.event.annotation.EventListener -import one.oktw.galaxy.event.type.* - -class Weapon { - @EventListener(true) - fun onPlayerInteractItem(event: PlayerInteractItemEvent) { -// var hand = Hand.MAIN_HAND -// var weapon = WeaponData.fromItem(event.player.getStackInHand(hand)) -// if (event.packet.hand == Hand.OFF_HAND) { -// if (weapon == null) { -// hand = Hand.OFF_HAND -// weapon = WeaponData.fromItem(event.player.getStackInHand(hand)) -// } -// } -// if (weapon == null) return -// weapon.shoot(event.player, event.player.world as ServerWorld) - } - - @EventListener(true) - fun onPlayerSneak(event: PlayerSneakEvent) = switchAiming(event.player, true) - - @EventListener(true) - fun onPlayerSneakRelease(event: PlayerSneakReleaseEvent) = switchAiming(event.player, false) - - @EventListener(true) - fun onUpdateSelectedSlot(event: UpdateSelectedSlotEvent) = updateInventory(event.player) - - @EventListener(true) - fun onHotBarSlotUpdate(event: HotBarSlotUpdateEvent) = updateInventory(event.player) - - private fun updateInventory(player: ServerPlayerEntity) = switchAiming(player, player.shouldCancelInteraction()) - - private fun switchAiming(player: ServerPlayerEntity, aiming: Boolean) { -// var hand = Hand.MAIN_HAND -// var weapon = WeaponData.fromItem(player.getStackInHand(hand)) -// if (weapon == null) { -// hand = Hand.OFF_HAND -// weapon = WeaponData.fromItem(player.getStackInHand(hand)) ?: return -// } else { -// val offWeapon = WeaponData.fromItem(player.getStackInHand(Hand.OFF_HAND)) -// if (offWeapon != null) { // turn off offhand aim -// player.setStackInHand(Hand.OFF_HAND, offWeapon.switchAiming(false)) -// } -// } -// player.setStackInHand(hand, weapon.switchAiming(aiming)) - } -} diff --git a/src/main/resources/galaxy.mixin.json b/src/main/resources/galaxy.mixin.json index b42110651..4f8306527 100644 --- a/src/main/resources/galaxy.mixin.json +++ b/src/main/resources/galaxy.mixin.json @@ -3,15 +3,17 @@ "package": "one.oktw.galaxy.mixin.event", "compatibilityLevel": "JAVA_16", "mixins": [ - "MixinHotBarSlotUpdate_ScreenHandlerListener", "MixinPlayerAction_NetworkHandler", "MixinPlayerChat_MeCommand", "MixinPlayerChat_NetworkHandler", "MixinPlayerChat_SayCommand", + "MixinPlayerDropItem_NetworkHandler", "MixinPlayerInteractBlock_NetworkHandler", "MixinPlayerInteractItem_NetworkHandler", "MixinPlayerJump_NetworkHandler", + "MixinPlayerPickupItem_ItemEntity", "MixinPlayerSneak_NetworkHandler", + "MixinPlayerSwapItemInHand_NetworkHandler", "MixinPlayerUseItemOnBlock_ItemStack", "MixinUpdateSelectedSlot_NetworkHandler" ],