调整火炮开火逻辑
This commit is contained in:
parent
6079faa766
commit
73fbb55a68
3 changed files with 44 additions and 9 deletions
|
@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
|
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
|
||||||
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
|
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
|
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) {
|
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
|
|
||||||
if (stack.getItem() instanceof ArtilleryIndicator indicator) {
|
if (stack.getItem() instanceof ArtilleryIndicator indicator) {
|
||||||
if (indicator.addCannon(stack, getStringUUID())) {
|
if (indicator.addCannon(stack, getStringUUID())) {
|
||||||
if (player instanceof ServerPlayer serverPlayer) {
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
@ -155,15 +155,28 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() instanceof CannonShellItem) {
|
if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {
|
||||||
if (this.entityData.get(COOL_DOWN) == 0) {
|
if (this.stack.getItem() instanceof CannonShellItem) {
|
||||||
var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
|
var weaponType = this.stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
|
||||||
setWeaponIndex(0, weaponType);
|
setWeaponIndex(0, weaponType);
|
||||||
vehicleShoot(player, 0);
|
vehicleShoot(player, 0);
|
||||||
}
|
}
|
||||||
return InteractionResult.SUCCESS;
|
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 (player.getMainHandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
|
||||||
if (setTarget(player.getMainHandItem())) {
|
if (setTarget(player.getMainHandItem())) {
|
||||||
player.swing(InteractionHand.MAIN_HAND);
|
player.swing(InteractionHand.MAIN_HAND);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
|
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
|
||||||
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
|
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
|
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.minecraft.world.phys.Vec3;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import net.neoforged.neoforge.event.EventHooks;
|
import net.neoforged.neoforge.event.EventHooks;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -158,15 +160,29 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() instanceof CannonShellItem) {
|
if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {
|
||||||
if (this.entityData.get(COOL_DOWN) == 0) {
|
if (this.stack.getItem() instanceof CannonShellItem) {
|
||||||
var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
|
var weaponType = this.stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1;
|
||||||
setWeaponIndex(0, weaponType);
|
setWeaponIndex(0, weaponType);
|
||||||
vehicleShoot(player, 0);
|
vehicleShoot(player, 0);
|
||||||
}
|
}
|
||||||
return InteractionResult.SUCCESS;
|
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 (player.getMainHandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
|
||||||
if (setTarget(player.getMainHandItem())) {
|
if (setTarget(player.getMainHandItem())) {
|
||||||
player.swing(InteractionHand.MAIN_HAND);
|
player.swing(InteractionHand.MAIN_HAND);
|
||||||
|
|
|
@ -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);
|
this.stack = mainHandItem.copyWithCount(1);
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
mainHandItem.shrink(1);
|
mainHandItem.shrink(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fire(player);
|
fire(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue