优化单发装填武器的换弹流程
This commit is contained in:
parent
c2ecc62537
commit
ccc26f58df
12 changed files with 327 additions and 178 deletions
|
@ -39,16 +39,6 @@ public class M870ItemModel extends GeoModel<M870Item> {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) return;
|
||||
|
||||
if (stack.getOrCreateTag().getBoolean("reloading")) {
|
||||
if (stack.getOrCreateTag().getDouble("prepare") == 0) {
|
||||
if (stack.getOrCreateTag().getDouble("loading") > 10 || stack.getOrCreateTag().getDouble("loading") < 2) {
|
||||
shell.setScaleX(0);
|
||||
shell.setScaleY(0);
|
||||
shell.setScaleZ(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double p = player.getPersistentData().getDouble("zoom_pos");
|
||||
double zp = player.getPersistentData().getDouble("zoom_pos_z");
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public class GunEventHandler {
|
|||
handleGunFire(player);
|
||||
handleMiniGunFire(player);
|
||||
handleGunReload(player);
|
||||
handleGunSingleReload(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +64,7 @@ public class GunEventHandler {
|
|||
|
||||
if ((player.getPersistentData().getBoolean("firing") || stack.getOrCreateTag().getInt("burst_fire") > 0)
|
||||
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||
&& !stack.getOrCreateTag().getBoolean("reloading")
|
||||
&& !stack.getOrCreateTag().getBoolean("charging")
|
||||
&& stack.getOrCreateTag().getInt("ammo") > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
|
@ -500,4 +502,256 @@ public class GunEventHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单发装填类的武器换弹流程
|
||||
*/
|
||||
private static void handleGunSingleReload(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
//换弹流程计时器
|
||||
|
||||
if (tag.getDouble("prepare") > 0) {
|
||||
tag.putDouble("prepare", tag.getDouble("prepare") - 1);
|
||||
}
|
||||
if (tag.getDouble("prepare_load") > 0) {
|
||||
tag.putDouble("prepare_load", tag.getDouble("prepare_load") - 1);
|
||||
}
|
||||
if (tag.getDouble("iterative") > 0) {
|
||||
tag.putDouble("iterative", tag.getDouble("iterative") - 1);
|
||||
}
|
||||
if (tag.getDouble("finish") > 0) {
|
||||
tag.putDouble("finish", tag.getDouble("finish") - 1);
|
||||
}
|
||||
|
||||
//一阶段
|
||||
|
||||
if (tag.getBoolean("start_single_reload")) {
|
||||
|
||||
//此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
||||
if (tag.getDouble("prepare_load_time") != 0 && tag.getInt("ammo") == 0) {
|
||||
playGunPrepareLoadReloadSounds(player);
|
||||
tag.putInt("prepare_load",(int)tag.getDouble("prepare_load_time"));
|
||||
player.getCooldowns().addCooldown(stack.getItem(), (int)tag.getDouble("prepare_load_time"));
|
||||
|
||||
} else {
|
||||
playGunPrepareReloadSounds(player);
|
||||
tag.putInt("prepare",(int)tag.getDouble("prepare_time"));
|
||||
player.getCooldowns().addCooldown(stack.getItem(), (int)tag.getDouble("prepare_time"));
|
||||
}
|
||||
|
||||
tag.putBoolean("force_stop", false);
|
||||
tag.putBoolean("stop", false);
|
||||
tag.putInt("reload_stage",1);
|
||||
tag.putBoolean("reloading", true);
|
||||
tag.putBoolean("start_single_reload", false);
|
||||
|
||||
}
|
||||
|
||||
if (stack.getItem() == TargetModItems.M_870.get()) {
|
||||
if (tag.getInt("prepare_load") == 10) {
|
||||
singleLoad(player);
|
||||
}
|
||||
}
|
||||
|
||||
//一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
||||
|
||||
|
||||
if ((tag.getDouble("prepare") == 1 || tag.getDouble("prepare_load") == 1)) {
|
||||
|
||||
//检查备弹
|
||||
var capability = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables());
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN) && capability.shotgunAmmo == 0) {
|
||||
tag.putBoolean("force_stage3_start",true);
|
||||
} else if (stack.is(TargetModTags.Items.SNIPER_RIFLE) && capability.sniperAmmo == 0) {
|
||||
tag.putBoolean("force_stage3_start",true);
|
||||
} else if ((stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG)) && capability.handgunAmmo == 0) {
|
||||
tag.putBoolean("force_stage3_start",true);
|
||||
} else if (stack.is(TargetModTags.Items.RIFLE) && capability.rifleAmmo == 0) {
|
||||
tag.putBoolean("force_stage3_start",true);
|
||||
} else {
|
||||
tag.putInt("reload_stage",2);
|
||||
}
|
||||
}
|
||||
|
||||
//强制停止换弹,进入三阶段
|
||||
if (tag.getBoolean("force_stop")) {
|
||||
tag.putBoolean("stop",true);
|
||||
}
|
||||
|
||||
//二阶段
|
||||
|
||||
if ((tag.getDouble("prepare") == 0 || tag.getDouble("prepare_load") == 0)
|
||||
&& tag.getInt("reload_stage") == 2
|
||||
&& tag.getInt("iterative") == 0
|
||||
&& !tag.getBoolean("stop")
|
||||
&& tag.getInt("ammo") < (int)tag.getDouble("mag")) {
|
||||
|
||||
playGunLoopReloadSounds(player);
|
||||
tag.putDouble("iterative", (int)tag.getDouble("iterative_time"));
|
||||
player.getCooldowns().addCooldown(stack.getItem(), (int)tag.getDouble("iterative_time"));
|
||||
//动画播放nbt
|
||||
if (tag.getDouble("load_index") == 1) {
|
||||
tag.putDouble("load_index", 0);
|
||||
} else {
|
||||
tag.putDouble("load_index", 1);
|
||||
}
|
||||
}
|
||||
|
||||
//装填
|
||||
|
||||
if (stack.getItem() == TargetModItems.M_870.get()) {
|
||||
if (tag.getInt("iterative") == 3) {
|
||||
singleLoad(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == TargetModItems.MARLIN.get()) {
|
||||
if (tag.getInt("iterative") == 3) {
|
||||
singleLoad(player);
|
||||
}
|
||||
}
|
||||
|
||||
//二阶段结束
|
||||
if (tag.getInt("iterative") == 1) {
|
||||
|
||||
//装满结束
|
||||
if (tag.getInt("ammo") >= (int)tag.getDouble("mag")) {
|
||||
tag.putInt("reload_stage",3);
|
||||
}
|
||||
|
||||
//备弹耗尽结束
|
||||
var capability = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables());
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN) && capability.shotgunAmmo == 0) {
|
||||
tag.putInt("reload_stage",3);
|
||||
} else if (stack.is(TargetModTags.Items.SNIPER_RIFLE) && capability.sniperAmmo == 0) {
|
||||
tag.putInt("reload_stage",3);
|
||||
} else if ((stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG)) && capability.handgunAmmo == 0) {
|
||||
tag.putInt("reload_stage",3);
|
||||
} else if (stack.is(TargetModTags.Items.RIFLE) && capability.rifleAmmo == 0) {
|
||||
tag.putInt("reload_stage",3);
|
||||
}
|
||||
|
||||
//强制结束
|
||||
if (tag.getBoolean("stop")) {
|
||||
tag.putInt("reload_stage",3);
|
||||
tag.putBoolean("force_stop", false);
|
||||
tag.putBoolean("stop", false);
|
||||
}
|
||||
}
|
||||
|
||||
//三阶段
|
||||
|
||||
if ((tag.getInt("iterative") == 1 && tag.getInt("reload_stage") == 3) || tag.getBoolean("force_stage3_start")) {
|
||||
tag.putBoolean("force_stage3_start", false);
|
||||
tag.putDouble("finish", (int)tag.getDouble("finish_time"));
|
||||
player.getCooldowns().addCooldown(stack.getItem(), (int)tag.getDouble("finish_time"));
|
||||
playGunEndReloadSounds(player);
|
||||
|
||||
}
|
||||
|
||||
//三阶段结束
|
||||
if (tag.getInt("finish") == 1) {
|
||||
tag.putInt("reload_stage",0);
|
||||
tag.putBoolean("reloading", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void singleLoad(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
tag.putInt("ammo", tag.getInt("ammo") + 1);
|
||||
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.shotgunAmmo = capability.shotgunAmmo - 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
} else if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.sniperAmmo = capability.sniperAmmo - 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
} else if ((stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG))) {
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.handgunAmmo = capability.handgunAmmo - 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
} else if (stack.is(TargetModTags.Items.RIFLE)) {
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = capability.rifleAmmo - 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void playGunPrepareReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_prepare"));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 10f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void playGunPrepareLoadReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_prepare_load"));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 10f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void playGunLoopReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_loop"));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 10f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void playGunEndReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_end"));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 10f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,15 @@ public class LivingEventHandler {
|
|||
oldTags.putBoolean("is_normal_reloading", false);
|
||||
oldTags.putBoolean("is_empty_reloading", false);
|
||||
oldTags.putInt("gun_reloading_time", 0);
|
||||
|
||||
oldTags.putBoolean("force_stop", false);
|
||||
oldTags.putBoolean("stop", false);
|
||||
oldTags.putInt("reload_stage",0);
|
||||
oldTags.putBoolean("reloading", false);
|
||||
oldTags.putDouble("prepare", 0);
|
||||
oldTags.putDouble("prepare_load", 0);
|
||||
oldTags.putDouble("iterative", 0);
|
||||
oldTags.putDouble("finish", 0);
|
||||
}
|
||||
|
||||
if (newStack.getItem() instanceof GunItem) {
|
||||
|
@ -175,6 +184,15 @@ public class LivingEventHandler {
|
|||
newStack.getOrCreateTag().putBoolean("is_empty_reloading", false);
|
||||
newStack.getOrCreateTag().putInt("gun_reloading_time", 0);
|
||||
|
||||
newStack.getOrCreateTag().putBoolean("force_stop", false);
|
||||
newStack.getOrCreateTag().putBoolean("stop", false);
|
||||
newStack.getOrCreateTag().putInt("reload_stage",0);
|
||||
newStack.getOrCreateTag().putBoolean("reloading", false);
|
||||
newStack.getOrCreateTag().putDouble("prepare", 0);
|
||||
newStack.getOrCreateTag().putDouble("prepare_load", 0);
|
||||
newStack.getOrCreateTag().putDouble("iterative", 0);
|
||||
newStack.getOrCreateTag().putDouble("finish", 0);
|
||||
|
||||
double weight = newStack.getOrCreateTag().getDouble("weight");
|
||||
|
||||
if (weight == 0) {
|
||||
|
|
|
@ -177,7 +177,11 @@ public class PlayerEventHandler {
|
|||
private static void handlePrepareZoom(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.is(TargetModTags.Items.GUN) && !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) && !player.isSpectator() && !stack.getOrCreateTag().getBoolean("charging")) {
|
||||
if (stack.is(TargetModTags.Items.GUN)
|
||||
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||
&& !player.isSpectator()
|
||||
&& !stack.getOrCreateTag().getBoolean("charging")
|
||||
&& !stack.getOrCreateTag().getBoolean("reloading")) {
|
||||
if (player.getMainHandItem().getItem() != TargetModItems.MINIGUN.get()) {
|
||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
|
||||
player.setSprinting(false);
|
||||
|
|
|
@ -172,15 +172,15 @@ public class TargetModSounds {
|
|||
public static final RegistryObject<SoundEvent> MARLIN_FIRE_3P = REGISTRY.register("marlin_fire_3p", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_fire_3p")));
|
||||
public static final RegistryObject<SoundEvent> MARLIN_FAR = REGISTRY.register("marlin_far", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_far")));
|
||||
public static final RegistryObject<SoundEvent> MARLIN_VERYFAR = REGISTRY.register("marlin_veryfar", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_veryfar")));
|
||||
public static final RegistryObject<SoundEvent> MARLIN_PREPARE = REGISTRY.register("marlin_prepare", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_prepare")));
|
||||
public static final RegistryObject<SoundEvent> MARLIN_LOOP = REGISTRY.register("marlin_loop", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_loop")));
|
||||
public static final RegistryObject<SoundEvent> MARLIN_START = REGISTRY.register("marlin_start", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_start")));
|
||||
public static final RegistryObject<SoundEvent> MARLIN_END = REGISTRY.register("marlin_end", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "marlin_end")));
|
||||
public static final RegistryObject<SoundEvent> M_870_FIRE_1P = REGISTRY.register("m_870_fire_1p", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_fire_1p")));
|
||||
public static final RegistryObject<SoundEvent> M_870_FIRE_3P = REGISTRY.register("m_870_fire_3p", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_fire_3p")));
|
||||
public static final RegistryObject<SoundEvent> M_870_FAR = REGISTRY.register("m_870_far", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_far")));
|
||||
public static final RegistryObject<SoundEvent> M_870_VERYFAR = REGISTRY.register("m_870_veryfar", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_veryfar")));
|
||||
public static final RegistryObject<SoundEvent> M_870_PREPARE_ALT = REGISTRY.register("m_870_preparealt", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_preparealt")));
|
||||
public static final RegistryObject<SoundEvent> M_870_RELOAD_LOOP = REGISTRY.register("m_870_reloadloop", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_reloadloop")));
|
||||
public static final RegistryObject<SoundEvent> M_870_PREPARE_LOAD = REGISTRY.register("m_870_prepare_load", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_prepare_load")));
|
||||
public static final RegistryObject<SoundEvent> M_870_LOOP = REGISTRY.register("m_870_loop", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_loop")));
|
||||
public static final RegistryObject<SoundEvent> BULLET_SUPPLY = REGISTRY.register("bullet_supply", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "bullet_supply")));
|
||||
public static final RegistryObject<SoundEvent> ADJUST_FOV = REGISTRY.register("adjust_fov", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "adjust_fov")));
|
||||
}
|
||||
|
|
|
@ -94,23 +94,23 @@ public class M870Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.shift"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getBoolean("empty_reload") && stack.getOrCreateTag().getDouble("prepare") > 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && stack.getOrCreateTag().getDouble("prepare_load") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.preparealt"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getBoolean("reloading") && stack.getOrCreateTag().getDouble("prepare") > 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && stack.getOrCreateTag().getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.prepare"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 0 && stack.getOrCreateTag().getDouble("loading") > 0) {
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 0 && stack.getOrCreateTag().getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 1 && stack.getOrCreateTag().getDouble("loading") > 0) {
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 1 && stack.getOrCreateTag().getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload2"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("finish") > 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.finish"));
|
||||
}
|
||||
|
||||
|
@ -158,82 +158,9 @@ public class M870Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
TooltipTool.addShotgunTips(list, stack, 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemstack, world, entity, slot, selected);
|
||||
if (entity instanceof Player player) {
|
||||
var tag = itemstack.getOrCreateTag();
|
||||
double id = tag.getDouble("id");
|
||||
if (player.getMainHandItem().getOrCreateTag().getDouble("id") != tag.getDouble("id")) {
|
||||
tag.putDouble("finish", 0);
|
||||
tag.putBoolean("reloading", false);
|
||||
tag.putDouble("prepare", 0);
|
||||
tag.putDouble("loading", 0);
|
||||
tag.putDouble("force_stop", 0);
|
||||
tag.putDouble("stop", 0);
|
||||
tag.putBoolean("empty_reload", false);
|
||||
}
|
||||
if (tag.getDouble("prepare") > 0) {
|
||||
tag.putDouble("prepare", tag.getDouble("prepare") - 1);
|
||||
}
|
||||
if (tag.getDouble("loading") > 0) {
|
||||
tag.putDouble("loading", tag.getDouble("loading") - 1);
|
||||
}
|
||||
if (tag.getDouble("finish") > 0 && tag.getDouble("loading") == 0) {
|
||||
tag.putDouble("finish", tag.getDouble("finish") - 1);
|
||||
}
|
||||
if (player.getMainHandItem().getOrCreateTag().getDouble("id") != tag.getDouble("id")) {
|
||||
tag.putBoolean("reloading", false);
|
||||
}
|
||||
if (tag.getBoolean("reloading") && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
if (tag.getDouble("prepare") == 10 && tag.getBoolean("empty_reload")) {
|
||||
tag.putInt("ammo", tag.getInt("ammo") + 1);
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.shotgunAmmo = capability.shotgunAmmo - 1;
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
}
|
||||
if (tag.getDouble("prepare") == 0 && tag.getDouble("loading") == 0
|
||||
&& !(tag.getInt("ammo") >= 8 || entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.shotgunAmmo).orElse(0) == 0)) {
|
||||
if (tag.getDouble("force_stop") == 1) {
|
||||
tag.putDouble("stop", 1);
|
||||
} else {
|
||||
tag.putDouble("loading", 16);
|
||||
|
||||
player.getCooldowns().addCooldown(itemstack.getItem(), 16);
|
||||
if (entity instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.M_870_RELOAD_LOOP.get(), 100, 1);
|
||||
}
|
||||
if (tag.getDouble("load_index") == 1) {
|
||||
tag.putDouble("load_index", 0);
|
||||
} else {
|
||||
tag.putDouble("load_index", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tag.getDouble("loading") == 9) {
|
||||
tag.putInt("ammo", tag.getInt("ammo") + 1);
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.shotgunAmmo = capability.shotgunAmmo - 1;
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
}
|
||||
if ((tag.getInt("ammo") >= 8 || entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.shotgunAmmo).orElse(0) == 0)
|
||||
&& tag.getDouble("loading") == 0 || tag.getDouble("stop") == 1) {
|
||||
tag.putDouble("force_stop", 0);
|
||||
tag.putDouble("stop", 0);
|
||||
tag.putDouble("finish", 12);
|
||||
player.getCooldowns().addCooldown(itemstack.getItem(), 12);
|
||||
tag.putBoolean("reloading", false);
|
||||
tag.putBoolean("empty_reload", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SoundEvent> getReloadSound() {
|
||||
return Set.of(TargetModSounds.M_870_PREPARE_ALT.get(), TargetModSounds.M_870_RELOAD_LOOP.get());
|
||||
return Set.of(TargetModSounds.M_870_PREPARE_LOAD.get(), TargetModSounds.M_870_LOOP.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -105,19 +105,19 @@ public class MarlinItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.shift2"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getBoolean("reloading") && stack.getOrCreateTag().getDouble("prepare") > 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && stack.getOrCreateTag().getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.prepare"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 0 && stack.getOrCreateTag().getDouble("loading") > 0) {
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 0 && stack.getOrCreateTag().getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 1 && stack.getOrCreateTag().getDouble("loading") > 0) {
|
||||
if (stack.getOrCreateTag().getDouble("load_index") == 1 && stack.getOrCreateTag().getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload2"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("finish") > 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.finish"));
|
||||
}
|
||||
|
||||
|
@ -168,75 +168,15 @@ public class MarlinItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
@Override
|
||||
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemstack, world, entity, slot, selected);
|
||||
if (entity instanceof Player player) {
|
||||
var tag = itemstack.getOrCreateTag();
|
||||
double id = tag.getDouble("id");
|
||||
if (player.getMainHandItem().getOrCreateTag().getDouble("id") != tag.getDouble("id")) {
|
||||
tag.putDouble("finish", 0);
|
||||
tag.putBoolean("reloading", false);
|
||||
tag.putDouble("prepare", 0);
|
||||
tag.putDouble("loading", 0);
|
||||
tag.putDouble("force_stop", 0);
|
||||
tag.putDouble("stop", 0);
|
||||
}
|
||||
if (tag.getDouble("marlin_animation_time") > 0) {
|
||||
tag.putDouble("marlin_animation_time", tag.getDouble("marlin_animation_time") - 1);
|
||||
}
|
||||
if (tag.getDouble("prepare") > 0) {
|
||||
tag.putDouble("prepare", tag.getDouble("prepare") - 1);
|
||||
}
|
||||
if (tag.getDouble("loading") > 0) {
|
||||
tag.putDouble("loading", tag.getDouble("loading") - 1);
|
||||
}
|
||||
if (tag.getDouble("finish") > 0 && tag.getDouble("loading") == 0) {
|
||||
tag.putDouble("finish", tag.getDouble("finish") - 1);
|
||||
}
|
||||
if (player.getMainHandItem().getOrCreateTag().getDouble("id") != tag.getDouble("id")) {
|
||||
tag.putBoolean("reloading", false);
|
||||
}
|
||||
if (tag.getBoolean("reloading") && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
if (tag.getDouble("prepare") == 0 && tag.getDouble("loading") == 0
|
||||
&& !(tag.getInt("ammo") >= 8 || entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.rifleAmmo).orElse(0) == 0)) {
|
||||
if (tag.getDouble("force_stop") == 1) {
|
||||
tag.putDouble("stop", 1);
|
||||
} else {
|
||||
tag.putDouble("loading", 16);
|
||||
player.getCooldowns().addCooldown(itemstack.getItem(), 16);
|
||||
if (entity instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.MARLIN_LOOP.get(), 100, 1);
|
||||
}
|
||||
if (tag.getDouble("load_index") == 1) {
|
||||
tag.putDouble("load_index", 0);
|
||||
} else {
|
||||
tag.putDouble("load_index", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tag.getDouble("loading") == 9) {
|
||||
tag.putInt("ammo", tag.getInt("ammo") + 1);
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = capability.rifleAmmo - 1;
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
}
|
||||
if ((tag.getInt("ammo") >= 8 || entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.rifleAmmo).orElse(0) == 0)
|
||||
&& tag.getDouble("loading") == 0 || tag.getDouble("stop") == 1) {
|
||||
tag.putDouble("force_stop", 0);
|
||||
tag.putDouble("stop", 0);
|
||||
tag.putDouble("finish", 19);
|
||||
player.getCooldowns().addCooldown(itemstack.getItem(), 19);
|
||||
tag.putBoolean("reloading", false);
|
||||
if (entity instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.MARLIN_END.get(), 100, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
var tag = itemstack.getOrCreateTag();
|
||||
if (tag.getDouble("marlin_animation_time") > 0) {
|
||||
tag.putDouble("marlin_animation_time", tag.getDouble("marlin_animation_time") - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SoundEvent> getReloadSound() {
|
||||
return Set.of(TargetModSounds.MARLIN_LOOP.get(), TargetModSounds.MARLIN_START.get(), TargetModSounds.MARLIN_END.get());
|
||||
return Set.of(TargetModSounds.MARLIN_LOOP.get(), TargetModSounds.MARLIN_PREPARE.get(), TargetModSounds.MARLIN_END.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -98,7 +98,7 @@ public class FireMessage {
|
|||
} else {
|
||||
player.getPersistentData().putBoolean("firing", true);
|
||||
}
|
||||
if (tag.getDouble("force_stop_reloading") == 1 && tag.getBoolean("reloading") && tag.getDouble("prepare") == 0 && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("prepare") == 0 && tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
tag.putDouble("force_stop", 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ public class ReloadMessage {
|
|||
|
||||
boolean can_reload = tag.getDouble("normal_reload_time") != 0 || tag.getDouble("empty_reload_time") != 0;
|
||||
|
||||
boolean can_single_reload = tag.getDouble("iterative_time") != 0;
|
||||
|
||||
//检查备弹
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN) && capability.shotgunAmmo == 0) {
|
||||
return;
|
||||
|
@ -72,19 +74,26 @@ public class ReloadMessage {
|
|||
} else if (stack.getItem() == TargetModItems.RPG.get() && tag.getInt("max_ammo") == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stack.is(TargetModTags.Items.OPEN_BOLT) && can_reload) {
|
||||
if (stack.getItem() == TargetModItems.M_60.get() || stack.getItem() == TargetModItems.ABEKIRI.get()) {
|
||||
if (tag.getInt("ammo") < tag.getDouble("mag")) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
} else {
|
||||
if (tag.getInt("ammo") < tag.getDouble("mag") + 1) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
if (can_reload) {
|
||||
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
|
||||
if (stack.getItem() == TargetModItems.M_60.get() || stack.getItem() == TargetModItems.ABEKIRI.get()) {
|
||||
if (tag.getInt("ammo") < tag.getDouble("mag")) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
} else {
|
||||
if (tag.getInt("ammo") < tag.getDouble("mag") + 1) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
}
|
||||
} else if (tag.getInt("ammo") < tag.getDouble("mag")) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (can_single_reload) {
|
||||
if (tag.getInt("ammo") < tag.getDouble("mag")) {
|
||||
tag.putBoolean("start_single_reload", true);
|
||||
}
|
||||
} else if (tag.getInt("ammo") < tag.getDouble("mag")) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1125,7 +1125,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"marlin_start": {
|
||||
"marlin_prepare": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "target:marlin/marlin_start",
|
||||
|
@ -1174,7 +1174,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"m_870_preparealt": {
|
||||
"m_870_prepare_load": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "target:m_870/m_870_preparealt",
|
||||
|
@ -1182,7 +1182,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"m_870_reloadloop": {
|
||||
"m_870_loop": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "target:m_870/m_870_reload_loop",
|
||||
|
|
|
@ -16,5 +16,9 @@
|
|||
"semi": 1,
|
||||
"burst": 0,
|
||||
"auto": 0,
|
||||
"burst_size": 1
|
||||
"burst_size": 1,
|
||||
"prepare_time": 7,
|
||||
"prepare_load_time": 36,
|
||||
"iterative_time": 16,
|
||||
"finish_time": 12
|
||||
}
|
|
@ -16,5 +16,8 @@
|
|||
"semi": 1,
|
||||
"burst": 0,
|
||||
"auto": 0,
|
||||
"burst_size": 1
|
||||
"burst_size": 1,
|
||||
"prepare_time": 8,
|
||||
"iterative_time": 16,
|
||||
"finish_time": 19
|
||||
}
|
Loading…
Add table
Reference in a new issue