修复各种换弹bug
This commit is contained in:
parent
971a61d264
commit
30e656d423
12 changed files with 139 additions and 237 deletions
|
@ -103,6 +103,7 @@ public class TargetMod {
|
||||||
addNetworkMessage(SensitivityMessage.class, SensitivityMessage::encode, SensitivityMessage::decode, SensitivityMessage::handler);
|
addNetworkMessage(SensitivityMessage.class, SensitivityMessage::encode, SensitivityMessage::decode, SensitivityMessage::handler);
|
||||||
addNetworkMessage(AdjustZoomFovMessage.class, AdjustZoomFovMessage::encode, AdjustZoomFovMessage::decode, AdjustZoomFovMessage::handler);
|
addNetworkMessage(AdjustZoomFovMessage.class, AdjustZoomFovMessage::encode, AdjustZoomFovMessage::decode, AdjustZoomFovMessage::handler);
|
||||||
addNetworkMessage(AdjustMortarAngleMessage.class, AdjustMortarAngleMessage::encode, AdjustMortarAngleMessage::decode, AdjustMortarAngleMessage::handler);
|
addNetworkMessage(AdjustMortarAngleMessage.class, AdjustMortarAngleMessage::encode, AdjustMortarAngleMessage::decode, AdjustMortarAngleMessage::handler);
|
||||||
|
addNetworkMessage(GunReloadResultMessage.class, GunReloadResultMessage::encode, GunReloadResultMessage::decode, GunReloadResultMessage::handler);
|
||||||
|
|
||||||
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
||||||
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), TargetModPotion.SHOCK.get())));
|
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), TargetModPotion.SHOCK.get())));
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((player.getPersistentData().getBoolean("firing") || stack.getOrCreateTag().getInt("burst_fire") > 0)
|
if ((player.getPersistentData().getBoolean("firing") || stack.getOrCreateTag().getInt("burst_fire") > 0)
|
||||||
&& !stack.getOrCreateTag().getBoolean("reloading")
|
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||||
&& !stack.getOrCreateTag().getBoolean("charging")
|
&& !stack.getOrCreateTag().getBoolean("charging")
|
||||||
&& stack.getOrCreateTag().getInt("ammo") > 0
|
&& stack.getOrCreateTag().getInt("ammo") > 0
|
||||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||||
|
@ -348,48 +348,45 @@ public class GunEventHandler {
|
||||||
private static void handleGunReload(Player player) {
|
private static void handleGunReload(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
CompoundTag tag = stack.getOrCreateTag();
|
CompoundTag tag = stack.getOrCreateTag();
|
||||||
|
//启动换弹
|
||||||
if (player.getPersistentData().getBoolean("start_reload")) {
|
if (tag.getBoolean("start_reload")) {
|
||||||
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
|
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
|
||||||
if(tag.getInt("ammo") == 0) {
|
if(tag.getInt("ammo") == 0) {
|
||||||
player.getPersistentData().putInt("gun_reloading_time",(int)tag.getDouble("empty_reload_time"));
|
tag.putInt("gun_reloading_time",(int)tag.getDouble("empty_reload_time"));
|
||||||
stack.getOrCreateTag().putBoolean("is_empty_reloading",true);
|
stack.getOrCreateTag().putBoolean("is_empty_reloading",true);
|
||||||
playGunEmptyReloadSounds(player);
|
playGunEmptyReloadSounds(player);
|
||||||
player.getPersistentData().putBoolean("start_reload",false);
|
|
||||||
} else {
|
} else {
|
||||||
player.getPersistentData().putInt("gun_reloading_time",(int)tag.getDouble("normal_reload_time"));
|
tag.putInt("gun_reloading_time",(int)tag.getDouble("normal_reload_time"));
|
||||||
stack.getOrCreateTag().putBoolean("is_reloading",true);
|
stack.getOrCreateTag().putBoolean("is_normal_reloading",true);
|
||||||
playGunNormalReloadSounds(player);
|
playGunNormalReloadSounds(player);
|
||||||
player.getPersistentData().putBoolean("start_reload",false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.getPersistentData().putInt("gun_reloading_time",(int)tag.getDouble("normal_reload_time"));
|
tag.putInt("gun_reloading_time",(int)tag.getDouble("normal_reload_time"));
|
||||||
stack.getOrCreateTag().putBoolean("is_reloading",true);
|
stack.getOrCreateTag().putBoolean("is_normal_reloading",true);
|
||||||
playGunNormalReloadSounds(player);
|
playGunNormalReloadSounds(player);
|
||||||
player.getPersistentData().putBoolean("start_reload",false);
|
|
||||||
}
|
}
|
||||||
|
tag.putBoolean("start_reload",false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getPersistentData().getInt("gun_reloading_time") > 0) {
|
if (tag.getInt("gun_reloading_time") > 0) {
|
||||||
player.getPersistentData().putInt("gun_reloading_time",player.getPersistentData().getInt("gun_reloading_time") - 1);
|
tag.putInt("gun_reloading_time",tag.getInt("gun_reloading_time") - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getPersistentData().getInt("gun_reloading_time") == 0 && (stack.getOrCreateTag().getBoolean("is_empty_reloading") || stack.getOrCreateTag().getBoolean("is_reloading"))) {
|
if (tag.getInt("gun_reloading_time") == 1) {
|
||||||
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
|
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
|
||||||
if(tag.getInt("ammo") == 0) {
|
if(tag.getInt("ammo") == 0) {
|
||||||
|
playGunEmptyReload(player);
|
||||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
|
||||||
GunsTool.reload(player, GunInfo.Type.SHOTGUN);
|
|
||||||
} else if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
|
||||||
GunsTool.reload(player, GunInfo.Type.SNIPER);
|
|
||||||
} else if (stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG)) {
|
|
||||||
GunsTool.reload(player, GunInfo.Type.HANDGUN);
|
|
||||||
} else if (stack.is(TargetModTags.Items.RIFLE)) {
|
|
||||||
GunsTool.reload(player, GunInfo.Type.RIFLE);
|
|
||||||
}
|
|
||||||
stack.getOrCreateTag().putBoolean("is_empty_reloading",false);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
playGunNormalReload(player);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
playGunEmptyReload(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void playGunNormalReload(Player player) {
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||||
GunsTool.reload(player, GunInfo.Type.SHOTGUN ,true);
|
GunsTool.reload(player, GunInfo.Type.SHOTGUN ,true);
|
||||||
|
@ -400,10 +397,10 @@ public class GunEventHandler {
|
||||||
} else if (stack.is(TargetModTags.Items.RIFLE)) {
|
} else if (stack.is(TargetModTags.Items.RIFLE)) {
|
||||||
GunsTool.reload(player, GunInfo.Type.RIFLE ,true);
|
GunsTool.reload(player, GunInfo.Type.RIFLE ,true);
|
||||||
}
|
}
|
||||||
stack.getOrCreateTag().putBoolean("is_reloading",false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
public static void playGunEmptyReload(Player player) {
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||||
GunsTool.reload(player, GunInfo.Type.SHOTGUN);
|
GunsTool.reload(player, GunInfo.Type.SHOTGUN);
|
||||||
|
@ -414,10 +411,6 @@ public class GunEventHandler {
|
||||||
} else if (stack.is(TargetModTags.Items.RIFLE)) {
|
} else if (stack.is(TargetModTags.Items.RIFLE)) {
|
||||||
GunsTool.reload(player, GunInfo.Type.RIFLE);
|
GunsTool.reload(player, GunInfo.Type.RIFLE);
|
||||||
}
|
}
|
||||||
stack.getOrCreateTag().putBoolean("is_reloading",false);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playGunEmptyReloadSounds(Player player) {
|
public static void playGunEmptyReloadSounds(Player player) {
|
||||||
|
@ -432,7 +425,7 @@ public class GunEventHandler {
|
||||||
|
|
||||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_reload_empty"));
|
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_reload_empty"));
|
||||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||||
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
SoundTool.playLocalSound(serverPlayer, sound1p, 10f, 1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,7 +442,7 @@ public class GunEventHandler {
|
||||||
|
|
||||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_reload_normal"));
|
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_reload_normal"));
|
||||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||||
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
SoundTool.playLocalSound(serverPlayer, sound1p, 10f, 1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,45 +144,41 @@ public class LivingEventHandler {
|
||||||
ItemStack oldStack = event.getFrom();
|
ItemStack oldStack = event.getFrom();
|
||||||
ItemStack newStack = event.getTo();
|
ItemStack newStack = event.getTo();
|
||||||
|
|
||||||
if (!newStack.is(TargetModTags.Items.GUN) ){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player instanceof ServerPlayer serverPlayer) {
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
var newTag = newStack.getTag();
|
|
||||||
var oldTag = oldStack.getTag();
|
|
||||||
|
|
||||||
if (newStack.getItem() != oldStack.getItem()
|
if (newStack.getItem() != oldStack.getItem()
|
||||||
|| newTag == null || oldTag == null
|
|| newStack.getTag() == null || oldStack.getTag() == null
|
||||||
|| !newTag.hasUUID("gun_uuid") || !oldTag.hasUUID("gun_uuid")
|
|| !newStack.getTag().hasUUID("gun_uuid") || !oldStack.getTag().hasUUID("gun_uuid")
|
||||||
|| !newTag.getUUID("gun_uuid").equals(oldTag.getUUID("gun_uuid"))
|
|| !newStack.getTag().getUUID("gun_uuid").equals(oldStack.getTag().getUUID("gun_uuid"))
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
if (!newStack.is(TargetModTags.Items.GUN)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (newStack.getItem() instanceof GunItem) {
|
if (newStack.getItem() instanceof GunItem) {
|
||||||
newStack.getOrCreateTag().putBoolean("draw", true);
|
newStack.getOrCreateTag().putBoolean("draw", true);
|
||||||
|
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
|
||||||
|
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
|
||||||
|
}
|
||||||
|
newStack.getOrCreateTag().putBoolean("is_normal_reloading",false);
|
||||||
|
newStack.getOrCreateTag().putBoolean("is_empty_reloading",false);
|
||||||
|
newStack.getOrCreateTag().putInt("gun_reloading_time",0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||||
stopGunReloadSound(serverPlayer, oldGun);
|
stopGunReloadSound(serverPlayer, oldGun);
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (oldStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
|
||||||
capability.zoom = false;
|
oldStack.getOrCreateTag().putInt("bolt_action_anim", 0);
|
||||||
capability.zooming = false;
|
}
|
||||||
capability.syncPlayerVariables(player);
|
oldStack.getOrCreateTag().putBoolean("is_normal_reloading",false);
|
||||||
});
|
|
||||||
player.getPersistentData().putDouble("zoom_pos", 0);
|
|
||||||
player.getPersistentData().putDouble("zoom_animation_time", 0);
|
|
||||||
oldStack.getOrCreateTag().putBoolean("is_reloading",false);
|
|
||||||
oldStack.getOrCreateTag().putBoolean("is_empty_reloading",false);
|
oldStack.getOrCreateTag().putBoolean("is_empty_reloading",false);
|
||||||
player.getPersistentData().putInt("gun_reloading_time",0);
|
oldStack.getOrCreateTag().putInt("gun_reloading_time",0);
|
||||||
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
|
|
||||||
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void stopGunReloadSound(ServerPlayer player, GunItem gun) {
|
private static void stopGunReloadSound(ServerPlayer player, GunItem gun) {
|
||||||
|
@ -192,6 +188,7 @@ public class LivingEventHandler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void handlePlayerKillEntity(LivingDeathEvent event) {
|
private static void handlePlayerKillEntity(LivingDeathEvent event) {
|
||||||
LivingEntity entity = event.getEntity();
|
LivingEntity entity = event.getEntity();
|
||||||
DamageSource source = event.getSource();
|
DamageSource source = event.getSource();
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class PlayerEventHandler {
|
||||||
private static void handlePrepareZoom(Player player) {
|
private static void handlePrepareZoom(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (stack.is(TargetModTags.Items.GUN) && !stack.getOrCreateTag().getBoolean("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")) {
|
||||||
if (player.getMainHandItem().getItem() != TargetModItems.MINIGUN.get()) {
|
if (player.getMainHandItem().getItem() != TargetModItems.MINIGUN.get()) {
|
||||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
|
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
|
||||||
player.setSprinting(false);
|
player.setSprinting(false);
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_empty"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_empty"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getOrCreateTag().getBoolean("is_reloading")) {
|
if (stack.getOrCreateTag().getBoolean("is_normal_reloading")) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_normal"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_normal"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,61 +173,6 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @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.putBoolean("empty_reload", false);
|
|
||||||
// tag.putBoolean("reloading", false);
|
|
||||||
// tag.putDouble("reload_time", 0);
|
|
||||||
// }
|
|
||||||
// if (tag.getBoolean("reloading") && tag.getInt("ammo") == 0) {
|
|
||||||
// if (tag.getDouble("reload_time") == 66) {
|
|
||||||
// entity.getPersistentData().putDouble("id", id);
|
|
||||||
// if (!entity.level().isClientSide()) {
|
|
||||||
// SoundTool.playLocalSound(player, TargetModSounds.AK_47_RELOAD_EMPTY.get(), 100, 1);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (player.getMainHandItem().getItem() == itemStack.getItem()
|
|
||||||
// && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
// if (tag.getDouble("reload_time") > 0) {
|
|
||||||
// tag.putDouble("reload_time", (tag.getDouble("reload_time") - 1));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// tag.putBoolean("reloading", false);
|
|
||||||
// tag.putBoolean("empty_reload", false);
|
|
||||||
// tag.putDouble("reload_time", 0);
|
|
||||||
// }
|
|
||||||
// if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
// GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
|
||||||
// }
|
|
||||||
// } else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
|
||||||
// if (tag.getDouble("reload_time") == 51) {
|
|
||||||
// entity.getPersistentData().putDouble("id", id);
|
|
||||||
// if (!entity.level().isClientSide()) {
|
|
||||||
// SoundTool.playLocalSound(player, TargetModSounds.AK_47_RELOAD_NORMAL.get(), 100, 1);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (player.getMainHandItem().getItem() == itemStack.getItem()
|
|
||||||
// && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
// if (tag.getDouble("reload_time") > 0) {
|
|
||||||
// tag.putDouble("reload_time", (tag.getDouble("reload_time") - 1));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// tag.putBoolean("reloading", false);
|
|
||||||
// tag.putBoolean("empty_reload", false);
|
|
||||||
// tag.putDouble("reload_time", 0);
|
|
||||||
// }
|
|
||||||
// if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
// GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static ItemStack getGunInstance() {
|
public static ItemStack getGunInstance() {
|
||||||
ItemStack stack = new ItemStack(TargetModItems.AK_47.get());
|
ItemStack stack = new ItemStack(TargetModItems.AK_47.get());
|
||||||
GunsTool.initCreativeGun(stack, TargetModItems.AK_47.getId().getPath());
|
GunsTool.initCreativeGun(stack, TargetModItems.AK_47.getId().getPath());
|
||||||
|
|
|
@ -93,11 +93,11 @@ public class Aa12Item extends GunItem implements GeoItem, AnimatedItem {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.fire"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.fire"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getOrCreateTag().getBoolean("reloading") && stack.getOrCreateTag().getBoolean("empty_reload")) {
|
if (stack.getOrCreateTag().getBoolean("is_empty_reloading")) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.reload_empty"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.reload_empty"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getOrCreateTag().getBoolean("reloading") && !stack.getOrCreateTag().getBoolean("empty_reload")) {
|
if (stack.getOrCreateTag().getBoolean("is_normal_reloading")) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.reload_normal"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.reload_normal"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,62 +173,6 @@ public class Aa12Item extends GunItem implements GeoItem, AnimatedItem {
|
||||||
TooltipTool.addShotgunTips(list, stack, 8);
|
TooltipTool.addShotgunTips(list, stack, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inventoryTick(ItemStack itemStack, Level world, Entity entity, int slot, boolean selected) {
|
|
||||||
super.inventoryTick(itemStack, world, entity, slot, selected);
|
|
||||||
|
|
||||||
var tag = itemStack.getOrCreateTag();
|
|
||||||
double id = tag.getDouble("id");
|
|
||||||
if (entity instanceof Player player) {
|
|
||||||
if (player.getMainHandItem().getOrCreateTag().getDouble("id") != tag.getDouble("id")) {
|
|
||||||
tag.putBoolean("empty_reload", false);
|
|
||||||
tag.putBoolean("reloading", false);
|
|
||||||
tag.putDouble("reload_time", 0);
|
|
||||||
}
|
|
||||||
if (tag.getBoolean("reloading") && tag.getInt("ammo") == 0) {
|
|
||||||
if (tag.getDouble("reload_time") == 82) {
|
|
||||||
entity.getPersistentData().putDouble("id", id);
|
|
||||||
if (entity instanceof ServerPlayer serverPlayer) {
|
|
||||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.AA_12_RELOAD_EMPTY.get(), 100, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (player.getMainHandItem().getItem() == itemStack.getItem()
|
|
||||||
&& player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
if (tag.getDouble("reload_time") > 0) {
|
|
||||||
tag.putDouble("reload_time", tag.getDouble("reload_time") - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tag.putBoolean("reloading", false);
|
|
||||||
tag.putBoolean("empty_reload", false);
|
|
||||||
tag.putDouble("reload_time", 0);
|
|
||||||
}
|
|
||||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
GunsTool.reload(entity, GunInfo.Type.SHOTGUN);
|
|
||||||
}
|
|
||||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
|
||||||
if (tag.getDouble("reload_time") == 61) {
|
|
||||||
entity.getPersistentData().putDouble("id", id);
|
|
||||||
if (entity instanceof ServerPlayer serverPlayer) {
|
|
||||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.AA_12_RELOAD_NORMAL.get(), 100, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (player.getMainHandItem().getItem() == itemStack.getItem()
|
|
||||||
&& player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
if (tag.getDouble("reload_time") > 0) {
|
|
||||||
tag.putDouble("reload_time", (tag.getDouble("reload_time") - 1));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tag.putBoolean("reloading", false);
|
|
||||||
tag.putBoolean("empty_reload", false);
|
|
||||||
tag.putDouble("reload_time", 0);
|
|
||||||
}
|
|
||||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
|
||||||
GunsTool.reload(entity, GunInfo.Type.SHOTGUN, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SoundEvent> getReloadSound() {
|
public Set<SoundEvent> getReloadSound() {
|
||||||
return Set.of(TargetModSounds.AA_12_RELOAD_EMPTY.get(), TargetModSounds.AA_12_RELOAD_NORMAL.get());
|
return Set.of(TargetModSounds.AA_12_RELOAD_EMPTY.get(), TargetModSounds.AA_12_RELOAD_NORMAL.get());
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package net.mcreator.target.network.message;
|
||||||
|
|
||||||
|
import net.mcreator.target.init.TargetModTags;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class GunReloadResultMessage {
|
||||||
|
private final int need_to_add;
|
||||||
|
|
||||||
|
public GunReloadResultMessage(int need_to_add) {
|
||||||
|
this.need_to_add = need_to_add;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void encode(GunReloadResultMessage message, FriendlyByteBuf byteBuf) {
|
||||||
|
byteBuf.writeInt(message.need_to_add);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GunReloadResultMessage decode(FriendlyByteBuf byteBuf) {
|
||||||
|
return new GunReloadResultMessage(byteBuf.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handler(GunReloadResultMessage message, Supplier<NetworkEvent.Context> context) {
|
||||||
|
context.get().enqueueWork(() -> {
|
||||||
|
ServerPlayer player = context.get().getSender();
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var tag = stack.getOrCreateTag();
|
||||||
|
|
||||||
|
tag.putInt("ammo", message.need_to_add);
|
||||||
|
tag.putBoolean("is_normal_reloading", false);
|
||||||
|
tag.putBoolean("is_empty_reloading", false);
|
||||||
|
});
|
||||||
|
context.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -44,7 +44,7 @@ public class ReloadMessage {
|
||||||
if (!world.hasChunkAt(entity.blockPosition()))
|
if (!world.hasChunkAt(entity.blockPosition()))
|
||||||
return;
|
return;
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
PlayerReloadProcedure.execute(entity);
|
// PlayerReloadProcedure.execute(entity);
|
||||||
|
|
||||||
ItemStack stack = entity.getMainHandItem();
|
ItemStack stack = entity.getMainHandItem();
|
||||||
var capability = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables());
|
var capability = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables());
|
||||||
|
@ -53,10 +53,16 @@ public class ReloadMessage {
|
||||||
&& stack.is(TargetModTags.Items.GUN)
|
&& stack.is(TargetModTags.Items.GUN)
|
||||||
&& !capability.zooming
|
&& !capability.zooming
|
||||||
&& !(entity.getCooldowns().isOnCooldown(stack.getItem()))
|
&& !(entity.getCooldowns().isOnCooldown(stack.getItem()))
|
||||||
&& entity.getPersistentData().getInt("gun_reloading_time") == 0
|
&& (stack.getOrCreateTag().getInt("gun_reloading_time") == 0)
|
||||||
) {
|
) {
|
||||||
CompoundTag tag = stack.getOrCreateTag();
|
CompoundTag tag = stack.getOrCreateTag();
|
||||||
|
|
||||||
|
boolean can_reload = false;
|
||||||
|
|
||||||
|
if (tag.getDouble("normal_reload_time") != 0 || tag.getDouble("empty_reload_time") != 0) {
|
||||||
|
can_reload = true;
|
||||||
|
}
|
||||||
|
//检查备弹
|
||||||
if (stack.is(TargetModTags.Items.SHOTGUN) && capability.shotgunAmmo == 0) {
|
if (stack.is(TargetModTags.Items.SHOTGUN) && capability.shotgunAmmo == 0) {
|
||||||
return;
|
return;
|
||||||
} else if (stack.is(TargetModTags.Items.SNIPER_RIFLE) && capability.sniperAmmo == 0) {
|
} else if (stack.is(TargetModTags.Items.SNIPER_RIFLE) && capability.sniperAmmo == 0) {
|
||||||
|
@ -67,12 +73,13 @@ public class ReloadMessage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.is(TargetModTags.Items.OPEN_BOLT) && (tag.getDouble("normal_reload_time") != 0 || tag.getDouble("empty_reload_time") != 0)) {
|
if (stack.is(TargetModTags.Items.OPEN_BOLT) && can_reload) {
|
||||||
|
//有OPEN_BOLT的枪非空仓换弹子弹会多一发
|
||||||
if (tag.getInt("ammo") < tag.getDouble("mag") + 1) {
|
if (tag.getInt("ammo") < tag.getDouble("mag") + 1) {
|
||||||
entity.getPersistentData().putBoolean("start_reload",true);
|
tag.putBoolean("start_reload",true);
|
||||||
}
|
}
|
||||||
} else if (tag.getInt("ammo") < tag.getDouble("mag")){
|
} else if (tag.getInt("ammo") < tag.getDouble("mag")){
|
||||||
entity.getPersistentData().putBoolean("start_reload",true);
|
tag.putBoolean("start_reload",true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,23 +169,6 @@ public class PlayerReloadProcedure {
|
||||||
tag.putDouble("reload_time", 72);
|
tag.putDouble("reload_time", 72);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (player.getMainHandItem().getItem() == TargetModItems.AK_47.get()
|
|
||||||
// && !(player.getCooldowns().isOnCooldown(player.getMainHandItem().getItem()))
|
|
||||||
// && !tag.getBoolean("reloading")
|
|
||||||
// && tag.getInt("ammo") < 31
|
|
||||||
// && (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo > 0) {
|
|
||||||
// if (tag.getInt("ammo") > 0) {
|
|
||||||
// tag.putBoolean("reloading", true);
|
|
||||||
// tag.putBoolean("empty_reload", false);
|
|
||||||
// tag.putDouble("id", (Mth.nextDouble(RandomSource.create(), 1, 1919810)));
|
|
||||||
// tag.putDouble("reload_time", 51);
|
|
||||||
// } else if (tag.getInt("ammo") == 0) {
|
|
||||||
// tag.putBoolean("reloading", true);
|
|
||||||
// tag.putDouble("empty_reload", 1);
|
|
||||||
// tag.putDouble("id", (Mth.nextDouble(RandomSource.create(), 1, 1919810)));
|
|
||||||
// tag.putDouble("reload_time", 66);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if ((player.getMainHandItem().getItem() == TargetModItems.M_4.get()
|
if ((player.getMainHandItem().getItem() == TargetModItems.M_4.get()
|
||||||
|| player.getMainHandItem().getItem() == TargetModItems.HK_416.get())
|
|| player.getMainHandItem().getItem() == TargetModItems.HK_416.get())
|
||||||
&& !(player.getCooldowns().isOnCooldown(player.getMainHandItem().getItem()))
|
&& !(player.getCooldowns().isOnCooldown(player.getMainHandItem().getItem()))
|
||||||
|
@ -204,23 +187,6 @@ public class PlayerReloadProcedure {
|
||||||
tag.putDouble("reload_time", 61);
|
tag.putDouble("reload_time", 61);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (player.getMainHandItem().getItem() == TargetModItems.AA_12.get()
|
|
||||||
&& !(player.getCooldowns().isOnCooldown(player.getMainHandItem().getItem()))
|
|
||||||
&& !tag.getBoolean("reloading")
|
|
||||||
&& tag.getInt("ammo") < 26
|
|
||||||
&& (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunAmmo > 0) {
|
|
||||||
if (tag.getInt("ammo") > 0) {
|
|
||||||
tag.putBoolean("reloading", true);
|
|
||||||
tag.putBoolean("empty_reload", false);
|
|
||||||
tag.putDouble("id", (Mth.nextDouble(RandomSource.create(), 1, 1919810)));
|
|
||||||
tag.putDouble("reload_time", 61);
|
|
||||||
} else if (tag.getInt("ammo") == 0) {
|
|
||||||
tag.putBoolean("reloading", true);
|
|
||||||
tag.putDouble("empty_reload", 1);
|
|
||||||
tag.putDouble("id", (Mth.nextDouble(RandomSource.create(), 1, 1919810)));
|
|
||||||
tag.putDouble("reload_time", 82);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (player.getMainHandItem().getItem() == TargetModItems.DEVOTION.get()
|
if (player.getMainHandItem().getItem() == TargetModItems.DEVOTION.get()
|
||||||
&& !(player.getCooldowns().isOnCooldown(player.getMainHandItem().getItem()))
|
&& !(player.getCooldowns().isOnCooldown(player.getMainHandItem().getItem()))
|
||||||
&& !tag.getBoolean("reloading")
|
&& !tag.getBoolean("reloading")
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class PressFireProcedure {
|
||||||
capability.syncPlayerVariables(player);
|
capability.syncPlayerVariables(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tag.getInt("ammo") == 0) {
|
// if (tag.getInt("ammo") == 0) {
|
||||||
PlayerReloadProcedure.execute(player);
|
// PlayerReloadProcedure.execute(player);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 栓动武器左键手动拉栓
|
// 栓动武器左键手动拉栓
|
||||||
if (mainHandItem.is(TargetModTags.Items.GUN) && tag.getInt("bolt_action_time") > 0 && tag.getInt("ammo") > 0 && tag.getInt("bolt_action_anim") == 0) {
|
if (mainHandItem.is(TargetModTags.Items.GUN) && tag.getInt("bolt_action_time") > 0 && tag.getInt("ammo") > 0 && tag.getInt("bolt_action_anim") == 0) {
|
||||||
|
|
|
@ -3,6 +3,8 @@ package net.mcreator.target.tools;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import net.mcreator.target.TargetMod;
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
|
import net.mcreator.target.network.message.AdjustMortarAngleMessage;
|
||||||
|
import net.mcreator.target.network.message.GunReloadResultMessage;
|
||||||
import net.mcreator.target.network.message.GunsDataMessage;
|
import net.mcreator.target.network.message.GunsDataMessage;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
@ -130,9 +132,8 @@ public class GunsTool {
|
||||||
|
|
||||||
capability.syncPlayerVariables(entity);
|
capability.syncPlayerVariables(entity);
|
||||||
});
|
});
|
||||||
tag.putInt("ammo", ammo + Math.min(ammoToAdd, playerAmmo));
|
|
||||||
|
|
||||||
tag.putBoolean("reloading", false);
|
int need_to_add = ammo + Math.min(ammoToAdd, playerAmmo);
|
||||||
tag.putBoolean("empty_reload", false);
|
TargetMod.PACKET_HANDLER.sendToServer(new GunReloadResultMessage(need_to_add));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,7 @@
|
||||||
"semi": 1,
|
"semi": 1,
|
||||||
"burst": 0,
|
"burst": 0,
|
||||||
"auto": 1,
|
"auto": 1,
|
||||||
"burst_size": 1
|
"burst_size": 1,
|
||||||
|
"normal_reload_time": 61,
|
||||||
|
"empty_reload_time": 82
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue