修复部分崩溃问题

This commit is contained in:
Light_Quanta 2025-04-08 07:39:00 +08:00
parent bd7fda211c
commit b2ca631f08
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 10 additions and 12 deletions

View file

@ -87,7 +87,6 @@ public class ClickHandler {
if (player.isSpectator()) return; if (player.isSpectator()) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
final var tag = NBTTool.getTag(stack);
int button = event.getButton(); int button = event.getButton();
@ -122,15 +121,14 @@ public class ClickHandler {
handleWeaponFirePress(player, stack); handleWeaponFirePress(player, stack);
} }
var data = GunData.from(stack);
if (button == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) { if (button == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
handleWeaponZoomPress(player, data); handleWeaponZoomPress(player, stack);
switchZoom = false; switchZoom = false;
return; return;
} }
if (button == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) { if (button == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) {
handleWeaponZoomPress(player, data); handleWeaponZoomPress(player, stack);
switchZoom = !switchZoom; switchZoom = !switchZoom;
} }
} }
@ -194,7 +192,6 @@ public class ClickHandler {
if (player.isSpectator()) return; if (player.isSpectator()) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
final var tag = NBTTool.getTag(stack);
int key = event.getKey(); int key = event.getKey();
if (event.getAction() == GLFW.GLFW_PRESS) { if (event.getAction() == GLFW.GLFW_PRESS) {
@ -258,7 +255,7 @@ public class ClickHandler {
PacketDistributor.sendToServer(new SensitivityMessage(false)); PacketDistributor.sendToServer(new SensitivityMessage(false));
} }
if (stack.is(ModTags.Items.GUN) if (stack.getItem() instanceof GunItem
|| stack.is(ModItems.MONITOR.get()) || stack.is(ModItems.MONITOR.get())
|| (player.getVehicle() instanceof ArmedVehicleEntity iVehicle && iVehicle.isDriver(player)) || (player.getVehicle() instanceof ArmedVehicleEntity iVehicle && iVehicle.isDriver(player))
|| (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) { || (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) {
@ -266,15 +263,14 @@ public class ClickHandler {
handleWeaponFirePress(player, stack); handleWeaponFirePress(player, stack);
} }
var data = GunData.from(stack);
if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) { if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
handleWeaponZoomPress(player, data); handleWeaponZoomPress(player, stack);
switchZoom = false; switchZoom = false;
return; return;
} }
if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) { if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) {
handleWeaponZoomPress(player, data); handleWeaponZoomPress(player, stack);
switchZoom = !switchZoom; switchZoom = !switchZoom;
} }
} }
@ -333,7 +329,6 @@ public class ClickHandler {
&& !notInGame() && !notInGame()
) { ) {
var data = GunData.from(stack); var data = GunData.from(stack);
var tag = data.tag();
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
if (!gunItem.useBackpackAmmo(stack) && data.ammo() <= 0 && data.reload.time() == 0) { if (!gunItem.useBackpackAmmo(stack) && data.ammo() <= 0 && data.reload.time() == 0) {
@ -365,7 +360,7 @@ public class ClickHandler {
ClientEventHandler.customRpm = 0; ClientEventHandler.customRpm = 0;
} }
public static void handleWeaponZoomPress(Player player, GunData data) { public static void handleWeaponZoomPress(Player player, ItemStack stack) {
PacketDistributor.sendToServer(new ZoomMessage(0)); PacketDistributor.sendToServer(new ZoomMessage(0));
if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player))) { if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player))) {
@ -373,6 +368,9 @@ public class ClickHandler {
return; return;
} }
if (!(stack.getItem() instanceof GunItem)) return;
var data = GunData.from(stack);
ClientEventHandler.zoom = true; ClientEventHandler.zoom = true;
int level = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP); int level = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP);
if (level > 0) { if (level > 0) {

View file

@ -19,6 +19,6 @@ public class SwarmDroneModel extends GeoModel<SwarmDroneEntity> {
@Override @Override
public ResourceLocation getTextureResource(SwarmDroneEntity entity) { public ResourceLocation getTextureResource(SwarmDroneEntity entity) {
return Mod.loc("textures/entity/swamDrone.png"); return Mod.loc("textures/entity/swarm_drone.png");
} }
} }

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB