diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 79b6c27e5..55cb889d3 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -8,10 +8,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.network.ModVariables; -import com.atsuishio.superbwarfare.network.message.LaserShootMessage; -import com.atsuishio.superbwarfare.network.message.LungeMineAttackMessage; -import com.atsuishio.superbwarfare.network.message.ShootMessage; -import com.atsuishio.superbwarfare.network.message.VehicleFireMessage; +import com.atsuishio.superbwarfare.network.message.*; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -31,6 +28,7 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.npc.AbstractVillager; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ClipContext; @@ -54,6 +52,7 @@ import net.minecraftforge.registries.ForgeRegistries; import org.lwjgl.glfw.GLFW; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; @@ -146,6 +145,7 @@ public class ClientEventHandler { public static Entity entity; public static int dismountCountdown = 0; + public static int aimVillagerCountdown = 0; @SubscribeEvent public static void handleWeaponTurn(RenderHandEvent event) { @@ -208,6 +208,21 @@ public class ClientEventHandler { } } + if (notInGame() && !ClickHandler.switchZoom) { + zoom = false; + } + + isProne(player); + beamShoot(player, stack); + handleLungeAttack(player, stack); + + if (event.phase == TickEvent.Phase.END) { + handleVariableDecrease(); + aimAtVillager(player); + } + } + + private static void handleVariableDecrease() { if (miniGunRot > 0) { miniGunRot--; } @@ -216,13 +231,9 @@ public class ClientEventHandler { dismountCountdown--; } - if (notInGame() && !ClickHandler.switchZoom) { - zoom = false; + if (aimVillagerCountdown > 0) { + aimVillagerCountdown--; } - - isProne(player); - beamShoot(player, stack); - handleLungeAttack(player, stack); } public static boolean isProne(Player player) { @@ -1370,4 +1381,21 @@ public class ClientEventHandler { shells[i].setRotY((float) (randomShell[2] * shellIndexTime[i])); } } + + public static void aimAtVillager(Player player) { + if (aimVillagerCountdown > 0) return; + + if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom) { + Entity entity = TraceTool.findLookingEntity(player, 10); + if (entity instanceof AbstractVillager villager) { + List entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120); + for (var e : entities) { + if (e == player) { + ModUtils.PACKET_HANDLER.sendToServer(new AimVillagerMessage(villager.getId())); + aimVillagerCountdown = 80; + } + } + } + } + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java index b330b5303..e7509c365 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java @@ -6,9 +6,10 @@ import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.network.ModVariables; -import com.atsuishio.superbwarfare.network.message.AimVillagerMessage; import com.atsuishio.superbwarfare.network.message.SimulationDistanceMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.GunsTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; @@ -16,9 +17,7 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.npc.AbstractVillager; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.event.AnvilUpdateEvent; @@ -28,8 +27,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.network.PacketDistributor; -import java.util.List; - @Mod.EventBusSubscriber public class PlayerEventHandler { @@ -88,7 +85,7 @@ public class PlayerEventHandler { handlePlayerSprint(player); handleSpecialWeaponAmmo(player); handleBocekPulling(player); - aimAtVillager(player); + } handleGround(player); @@ -98,20 +95,6 @@ public class PlayerEventHandler { } } - public static void aimAtVillager(Player player) { - if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom) { - Entity entity = TraceTool.findLookingEntity(player, 10); - if (entity instanceof AbstractVillager villager) { - List entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120); - for (var e : entities) { - if (e == player) { - ModUtils.PACKET_HANDLER.sendToServer(new AimVillagerMessage(villager.getId())); - } - } - } - } - } - private static void handleBreath(Player player) { if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).breath) { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {