添加换弹event
This commit is contained in:
parent
c593b8ffdf
commit
fd31eae168
2 changed files with 61 additions and 24 deletions
|
@ -2,6 +2,7 @@ package net.mcreator.superbwarfare.event;
|
||||||
|
|
||||||
import net.mcreator.superbwarfare.ModUtils;
|
import net.mcreator.superbwarfare.ModUtils;
|
||||||
import net.mcreator.superbwarfare.entity.ProjectileEntity;
|
import net.mcreator.superbwarfare.entity.ProjectileEntity;
|
||||||
|
import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
|
||||||
import net.mcreator.superbwarfare.init.*;
|
import net.mcreator.superbwarfare.init.*;
|
||||||
import net.mcreator.superbwarfare.network.ModVariables;
|
import net.mcreator.superbwarfare.network.ModVariables;
|
||||||
import net.mcreator.superbwarfare.network.message.ZoomMessage;
|
import net.mcreator.superbwarfare.network.message.ZoomMessage;
|
||||||
|
@ -20,6 +21,7 @@ import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
@ -49,6 +51,20 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onReload(ReloadEvent event) {
|
||||||
|
Player player = event.player;
|
||||||
|
ItemStack stack = event.stack;
|
||||||
|
if (player == null || !stack.is(ModTags.Items.GUN)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.level().isClientSide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用的武器开火流程
|
* 通用的武器开火流程
|
||||||
*/
|
*/
|
||||||
|
@ -451,6 +467,8 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
stack.getOrCreateTag().putBoolean("is_normal_reloading", false);
|
stack.getOrCreateTag().putBoolean("is_normal_reloading", false);
|
||||||
stack.getOrCreateTag().putBoolean("is_empty_reloading", false);
|
stack.getOrCreateTag().putBoolean("is_empty_reloading", false);
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.post(new ReloadEvent(player, stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playGunEmptyReload(Player player) {
|
public static void playGunEmptyReload(Player player) {
|
||||||
|
@ -477,6 +495,8 @@ public class GunEventHandler {
|
||||||
|
|
||||||
stack.getOrCreateTag().putBoolean("is_normal_reloading", false);
|
stack.getOrCreateTag().putBoolean("is_normal_reloading", false);
|
||||||
stack.getOrCreateTag().putBoolean("is_empty_reloading", false);
|
stack.getOrCreateTag().putBoolean("is_empty_reloading", false);
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.post(new ReloadEvent(player, stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playGunEmptyReloadSounds(Player player) {
|
public static void playGunEmptyReloadSounds(Player player) {
|
||||||
|
@ -521,7 +541,6 @@ public class GunEventHandler {
|
||||||
CompoundTag tag = stack.getOrCreateTag();
|
CompoundTag tag = stack.getOrCreateTag();
|
||||||
|
|
||||||
// 换弹流程计时器
|
// 换弹流程计时器
|
||||||
|
|
||||||
if (tag.getDouble("prepare") > 0) {
|
if (tag.getDouble("prepare") > 0) {
|
||||||
tag.putDouble("prepare", tag.getDouble("prepare") - 1);
|
tag.putDouble("prepare", tag.getDouble("prepare") - 1);
|
||||||
}
|
}
|
||||||
|
@ -536,7 +555,6 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一阶段
|
// 一阶段
|
||||||
|
|
||||||
if (tag.getBoolean("start_single_reload")) {
|
if (tag.getBoolean("start_single_reload")) {
|
||||||
|
|
||||||
// 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
// 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
||||||
|
@ -556,7 +574,6 @@ public class GunEventHandler {
|
||||||
tag.putInt("reload_stage", 1);
|
tag.putInt("reload_stage", 1);
|
||||||
tag.putBoolean("reloading", true);
|
tag.putBoolean("reloading", true);
|
||||||
tag.putBoolean("start_single_reload", false);
|
tag.putBoolean("start_single_reload", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.M_870.get()) {
|
if (stack.getItem() == ModItems.M_870.get()) {
|
||||||
|
@ -566,8 +583,6 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
||||||
|
|
||||||
|
|
||||||
if ((tag.getDouble("prepare") == 1 || tag.getDouble("prepare_load") == 1)) {
|
if ((tag.getDouble("prepare") == 1 || tag.getDouble("prepare_load") == 1)) {
|
||||||
|
|
||||||
// 检查备弹
|
// 检查备弹
|
||||||
|
@ -591,7 +606,6 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 二阶段
|
// 二阶段
|
||||||
|
|
||||||
if ((tag.getDouble("prepare") == 0 || tag.getDouble("prepare_load") == 0)
|
if ((tag.getDouble("prepare") == 0 || tag.getDouble("prepare_load") == 0)
|
||||||
&& tag.getInt("reload_stage") == 2
|
&& tag.getInt("reload_stage") == 2
|
||||||
&& tag.getInt("iterative") == 0
|
&& tag.getInt("iterative") == 0
|
||||||
|
@ -610,7 +624,6 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 装填
|
// 装填
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.M_870.get()) {
|
if (stack.getItem() == ModItems.M_870.get()) {
|
||||||
if (tag.getInt("iterative") == 3) {
|
if (tag.getInt("iterative") == 3) {
|
||||||
singleLoad(player);
|
singleLoad(player);
|
||||||
|
@ -652,13 +665,11 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 三阶段
|
// 三阶段
|
||||||
|
|
||||||
if ((tag.getInt("iterative") == 1 && tag.getInt("reload_stage") == 3) || tag.getBoolean("force_stage3_start")) {
|
if ((tag.getInt("iterative") == 1 && tag.getInt("reload_stage") == 3) || tag.getBoolean("force_stage3_start")) {
|
||||||
tag.putBoolean("force_stage3_start", false);
|
tag.putBoolean("force_stage3_start", false);
|
||||||
tag.putDouble("finish", (int) tag.getDouble("finish_time"));
|
tag.putDouble("finish", (int) tag.getDouble("finish_time"));
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), (int) tag.getDouble("finish_time"));
|
player.getCooldowns().addCooldown(stack.getItem(), (int) tag.getDouble("finish_time"));
|
||||||
playGunEndReloadSounds(player);
|
playGunEndReloadSounds(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 三阶段结束
|
// 三阶段结束
|
||||||
|
@ -695,6 +706,8 @@ public class GunEventHandler {
|
||||||
capability.syncPlayerVariables(player);
|
capability.syncPlayerVariables(player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.post(new ReloadEvent(player, stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playGunPrepareReloadSounds(Player player) {
|
public static void playGunPrepareReloadSounds(Player player) {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package net.mcreator.superbwarfare.event.modevent;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
|
|
||||||
|
public class ReloadEvent extends Event {
|
||||||
|
|
||||||
|
public final Player player;
|
||||||
|
public final ItemStack stack;
|
||||||
|
|
||||||
|
public ReloadEvent(Player player, ItemStack stack) {
|
||||||
|
this.player = player;
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getStack() {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue