调整火炮开火逻辑

This commit is contained in:
Atsuishio 2025-07-12 00:13:55 +08:00 committed by Light_Quanta
parent 6079faa766
commit 73fbb55a68
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 44 additions and 9 deletions

View file

@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
@ -136,7 +137,6 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
ItemStack stack = player.getMainHandItem();
if (stack.getItem() instanceof ArtilleryIndicator indicator) {
if (indicator.addCannon(stack, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
@ -155,15 +155,28 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
}
}
if (stack.getItem() instanceof CannonShellItem) {
if (this.entityData.get(COOL_DOWN) == 0) {
var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {
if (this.stack.getItem() instanceof CannonShellItem) {
var weaponType = this.stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
setWeaponIndex(0, weaponType);
vehicleShoot(player, 0);
}
return InteractionResult.SUCCESS;
}
if (stack.getItem() instanceof CannonShellItem) {
if (this.entityData.get(COOL_DOWN) == 0 && this.stack.isEmpty()) {
this.stack = stack.copyWithCount(1);
if (!player.isCreative()) {
stack.shrink(1);
}
if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_RELOAD.get(), 2, 1);
}
}
return InteractionResult.SUCCESS;
}
if (player.getMainHandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
if (setTarget(player.getMainHandItem())) {
player.swing(InteractionHand.MAIN_HAND);

View file

@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
@ -48,6 +49,7 @@ import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -158,15 +160,29 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
}
}
if (stack.getItem() instanceof CannonShellItem) {
if (this.entityData.get(COOL_DOWN) == 0) {
var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {
if (this.stack.getItem() instanceof CannonShellItem) {
var weaponType = this.stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
setWeaponIndex(0, weaponType);
vehicleShoot(player, 0);
}
return InteractionResult.SUCCESS;
}
if (stack.getItem() instanceof CannonShellItem) {
var itemHandler = this.getCapability(Capabilities.ItemHandler.ENTITY);
if (itemHandler != null && this.entityData.get(COOL_DOWN) == 0 && (stack.getItem() == this.stack.getItem() || this.stack.isEmpty())) {
itemHandler.insertItem(0, stack.copyWithCount(1), false);
if (!player.isCreative()) {
stack.shrink(1);
}
if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_RELOAD.get(), 2, 1);
}
}
return InteractionResult.SUCCESS;
}
if (player.getMainHandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
if (setTarget(player.getMainHandItem())) {
player.swing(InteractionHand.MAIN_HAND);

View file

@ -153,12 +153,18 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
}
}
if (mainHandItem.getItem() instanceof MortarShell && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0) {
if (mainHandItem.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {
if (this.stack.getItem() instanceof MortarShell) {
fire(player);
}
return InteractionResult.SUCCESS;
}
if (mainHandItem.getItem() instanceof MortarShell && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0 && stack.isEmpty()) {
this.stack = mainHandItem.copyWithCount(1);
if (!player.isCreative()) {
mainHandItem.shrink(1);
}
fire(player);
}