提取更多NBT操作
This commit is contained in:
parent
a926a014c3
commit
6346b84663
41 changed files with 567 additions and 385 deletions
|
@ -44,8 +44,7 @@ public class K98ItemModel extends GeoModel<K98Item> {
|
||||||
if (!stack.is(ModTags.Items.GUN)) return;
|
if (!stack.is(ModTags.Items.GUN)) return;
|
||||||
|
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
if (data.reload.prepareTimer.get() > 11 && data.ammo() == 1) {
|
||||||
if (tag.getDouble("PrepareTime") > 11 && data.ammo() == 1) {
|
|
||||||
clip.setScaleX(0);
|
clip.setScaleX(0);
|
||||||
clip.setScaleY(0);
|
clip.setScaleY(0);
|
||||||
clip.setScaleZ(0);
|
clip.setScaleZ(0);
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.rifle.MarlinItem;
|
import com.atsuishio.superbwarfare.item.gun.rifle.MarlinItem;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
@ -84,7 +83,7 @@ public class MarlinItemModel extends GeoModel<MarlinItem> {
|
||||||
|
|
||||||
CrossHairOverlay.gunRot = shen.getRotZ();
|
CrossHairOverlay.gunRot = shen.getRotZ();
|
||||||
|
|
||||||
if (NBTTool.getTag(stack).getBoolean("IsEmpty")) {
|
if (GunData.from(stack).isEmpty()) {
|
||||||
jichui.setRotX(-0.52f);
|
jichui.setRotX(-0.52f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
@ -46,8 +45,7 @@ public class RpgItemModel extends GeoModel<RpgItem> {
|
||||||
if (!stack.is(ModTags.Items.GUN)) return;
|
if (!stack.is(ModTags.Items.GUN)) return;
|
||||||
|
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
var tag = data.tag();
|
if (data.closeHammer()) {
|
||||||
if (GunsTool.getGunBooleanTag(tag, "CloseHammer")) {
|
|
||||||
hammer.setRotX(-90 * Mth.DEG_TO_RAD);
|
hammer.setRotX(-90 * Mth.DEG_TO_RAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
|
||||||
GeoBone root = getAnimationProcessor().getBone("root");
|
GeoBone root = getAnimationProcessor().getBone("root");
|
||||||
root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph));
|
root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph));
|
||||||
root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY));
|
root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY));
|
||||||
root.setPosZ(!NBTTool.getTag(stack).getBoolean("DA") && !NBTTool.getTag(stack).getBoolean("canImmediatelyShoot") ? 0.2f * (float) ClientEventHandler.revolverPreTime : 0);
|
root.setPosZ(!GunData.from(stack).DA() && !GunData.from(stack).canImmediatelyShoot() ? 0.2f * (float) ClientEventHandler.revolverPreTime : 0);
|
||||||
root.setRotX((float) ((swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY)));
|
root.setRotX((float) ((swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY)));
|
||||||
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
|
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
|
||||||
root.setRotZ((float) (0.2f * movePosX + moveRotZ + Mth.DEG_TO_RAD * 90 * ClientEventHandler.drawTime + 2.7f * mph + Mth.DEG_TO_RAD * turnRotZ));
|
root.setRotZ((float) (0.2f * movePosX + moveRotZ + Mth.DEG_TO_RAD * 90 * ClientEventHandler.drawTime + 2.7f * mph + Mth.DEG_TO_RAD * turnRotZ));
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||||
return GunData.from(stack).data().getInt("MaxAmmo");
|
return GunData.from(stack).maxAmmo();
|
||||||
}
|
}
|
||||||
|
|
||||||
return GunData.from(stack).ammo();
|
return GunData.from(stack).ammo();
|
||||||
|
@ -69,7 +69,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
||||||
if (!hasCreativeAmmo()) {
|
if (!hasCreativeAmmo()) {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
if (stack.is(ModTags.Items.LAUNCHER) || stack.getItem() == ModItems.TASER.get()) {
|
if (stack.is(ModTags.Items.LAUNCHER) || stack.getItem() == ModItems.TASER.get()) {
|
||||||
return "" + data.data().getInt("MaxAmmo");
|
return "" + data.maxAmmo();
|
||||||
}
|
}
|
||||||
if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||||
return "" + cap.rifleAmmo;
|
return "" + cap.rifleAmmo;
|
||||||
|
@ -175,7 +175,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
||||||
} else {
|
} else {
|
||||||
guiGraphics.drawString(
|
guiGraphics.drawString(
|
||||||
Minecraft.getInstance().font,
|
Minecraft.getInstance().font,
|
||||||
tag.getBoolean("DA") ? Component.translatable("des.superbwarfare.revolver.sa").withStyle(ChatFormatting.BOLD) : Component.translatable("des.superbwarfare.revolver.da").withStyle(ChatFormatting.BOLD),
|
data.DA() ? Component.translatable("des.superbwarfare.revolver.sa").withStyle(ChatFormatting.BOLD) : Component.translatable("des.superbwarfare.revolver.da").withStyle(ChatFormatting.BOLD),
|
||||||
w - 96,
|
w - 96,
|
||||||
h - 20,
|
h - 20,
|
||||||
0xFFFFFF,
|
0xFFFFFF,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
|
||||||
import com.atsuishio.superbwarfare.client.model.item.BocekItemModel;
|
import com.atsuishio.superbwarfare.client.model.item.BocekItemModel;
|
||||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.special.BocekItem;
|
import com.atsuishio.superbwarfare.item.gun.special.BocekItem;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
|
@ -90,7 +91,7 @@ public class BocekItemRenderer extends GeoItemRenderer<BocekItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.equals("jian")) {
|
if (name.equals("jian")) {
|
||||||
bone.setHidden(GunsTool.getGunIntTag(tag, "MaxAmmo") == 0);
|
bone.setHidden(GunData.from(itemStack).maxAmmo() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderingArms) {
|
if (renderingArms) {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
|
||||||
import com.atsuishio.superbwarfare.client.model.item.RpgItemModel;
|
import com.atsuishio.superbwarfare.client.model.item.RpgItemModel;
|
||||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -78,7 +78,7 @@ public class RpgItemRenderer extends GeoItemRenderer<RpgItem> {
|
||||||
if (!itemStack.is(ModTags.Items.GUN)) return;
|
if (!itemStack.is(ModTags.Items.GUN)) return;
|
||||||
|
|
||||||
if (name.equals("Rockets")) {
|
if (name.equals("Rockets")) {
|
||||||
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("IsEmpty"));
|
bone.setHidden(GunData.from(itemStack).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.equals("flare")) {
|
if (name.equals("flare")) {
|
||||||
|
|
|
@ -187,13 +187,13 @@ public class ClientEventHandler {
|
||||||
return player.getVehicle() instanceof VehicleEntity vehicle && vehicle.allowFreeCam() && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON && ModKeyMappings.FREE_CAMERA.isDown();
|
return player.getVehicle() instanceof VehicleEntity vehicle && vehicle.allowFreeCam() && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON && ModKeyMappings.FREE_CAMERA.isDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean revolverPre(final CompoundTag tag) {
|
private static boolean revolverPre(GunData data) {
|
||||||
Player player = Minecraft.getInstance().player;
|
Player player = Minecraft.getInstance().player;
|
||||||
if (player == null) return false;
|
if (player == null) return false;
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.REVOLVER)) {
|
if (!stack.is(ModTags.Items.REVOLVER)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (stack.is(ModTags.Items.REVOLVER) && (tag.getBoolean("DA") || tag.getBoolean("canImmediatelyShoot"))) {
|
} else if (stack.is(ModTags.Items.REVOLVER) && (data.DA() || data.canImmediatelyShoot())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return revolverPreTime >= 1;
|
return revolverPreTime >= 1;
|
||||||
|
@ -456,11 +456,11 @@ public class ClientEventHandler {
|
||||||
int cooldown = (int) (1000 / rps);
|
int cooldown = (int) (1000 / rps);
|
||||||
|
|
||||||
//左轮类
|
//左轮类
|
||||||
if (clientTimer.getProgress() == 0 && stack.is(ModTags.Items.REVOLVER) && ((holdFire && !tag.getBoolean("DA"))
|
if (clientTimer.getProgress() == 0 && stack.is(ModTags.Items.REVOLVER) && ((holdFire && !data.DA())
|
||||||
|| (data.bolt.actionTime() < 7 && data.bolt.actionTime() > 2) || tag.getBoolean("canImmediatelyShoot"))) {
|
|| (data.bolt.actionTime() < 7 && data.bolt.actionTime() > 2) || data.canImmediatelyShoot())) {
|
||||||
revolverPreTime = Mth.clamp(revolverPreTime + 0.3 * times, 0, 1);
|
revolverPreTime = Mth.clamp(revolverPreTime + 0.3 * times, 0, 1);
|
||||||
revolverWheelPreTime = Mth.clamp(revolverWheelPreTime + 0.32 * times, 0, revolverPreTime > 0.7 ? 1 : 0.55);
|
revolverWheelPreTime = Mth.clamp(revolverWheelPreTime + 0.32 * times, 0, revolverPreTime > 0.7 ? 1 : 0.55);
|
||||||
} else if (!tag.getBoolean("DA") && !tag.getBoolean("canImmediatelyShoot")) {
|
} else if (!data.DA() && !data.canImmediatelyShoot()) {
|
||||||
revolverPreTime = Mth.clamp(revolverPreTime - 1.2 * times, 0, 1);
|
revolverPreTime = Mth.clamp(revolverPreTime - 1.2 * times, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ public class ClientEventHandler {
|
||||||
&& data.ammo() > 0
|
&& data.ammo() > 0
|
||||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||||
&& !data.bolt.needed()
|
&& !data.bolt.needed()
|
||||||
&& revolverPre(tag))
|
&& revolverPre(data))
|
||||||
|| (stack.is(ModItems.MINIGUN.get())
|
|| (stack.is(ModItems.MINIGUN.get())
|
||||||
&& !player.isSprinting()
|
&& !player.isSprinting()
|
||||||
&& tag.getDouble("overheat") == 0
|
&& tag.getDouble("overheat") == 0
|
||||||
|
|
|
@ -16,7 +16,6 @@ import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.effect.MobEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
|
@ -42,10 +41,10 @@ public class GunEventHandler {
|
||||||
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (stack.is(ModTags.Items.GUN)) {
|
if (stack.getItem() instanceof GunItem) {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
|
|
||||||
handleGunBolt(player, data);
|
handleGunBolt(data);
|
||||||
handleGunReload(player, data);
|
handleGunReload(player, data);
|
||||||
handleGunSingleReload(player, data);
|
handleGunSingleReload(player, data);
|
||||||
handleSentinelCharge(player, data);
|
handleSentinelCharge(player, data);
|
||||||
|
@ -57,24 +56,22 @@ public class GunEventHandler {
|
||||||
/**
|
/**
|
||||||
* 拉大栓
|
* 拉大栓
|
||||||
*/
|
*/
|
||||||
private static void handleGunBolt(Player player, GunData data) {
|
private static void handleGunBolt(GunData data) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
var stack = data.stack();
|
||||||
|
|
||||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||||
var tag = data.tag();
|
|
||||||
|
|
||||||
if (data.bolt.actionTime() > 0) {
|
if (data.bolt.actionTime() > 0) {
|
||||||
data.bolt.reduceActionTime();
|
data.bolt.reduceActionTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.MARLIN.get() && data.bolt.actionTime() == 9) {
|
if (stack.getItem() == ModItems.MARLIN.get() && data.bolt.actionTime() == 9) {
|
||||||
tag.remove("IsEmpty");
|
data.setIsEmpty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.bolt.actionTime() == 1) {
|
if (data.bolt.actionTime() == 1) {
|
||||||
data.bolt.markNeedless();
|
data.bolt.markNeedless();
|
||||||
if (stack.is(ModTags.Items.REVOLVER)) {
|
if (stack.is(ModTags.Items.REVOLVER)) {
|
||||||
tag.putBoolean("canImmediatelyShoot", true);
|
data.setCanImmediatelyShoot(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,14 +169,13 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void gunShoot(Player player, final CompoundTag tag, double spared) {
|
public static void gunShoot(Player player, GunData data, double spared) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
var stack = data.stack();
|
||||||
var data = GunData.from(stack);
|
|
||||||
|
|
||||||
if (!player.level().isClientSide()) {
|
if (!player.level().isClientSide()) {
|
||||||
float headshot = (float) data.headshot();
|
float headshot = (float) data.headshot();
|
||||||
float damage = (float) data.damage();
|
float damage = (float) data.damage();
|
||||||
float velocity = (float) ((data.velocity() + GunsTool.getGunDoubleTag(tag, "CustomVelocity")) * perkSpeed(data));
|
float velocity = (float) (data.velocity() * perkSpeed(data));
|
||||||
int projectileAmount = data.projectileAmount();
|
int projectileAmount = data.projectileAmount();
|
||||||
float bypassArmorRate = (float) data.bypassArmor();
|
float bypassArmorRate = (float) data.bypassArmor();
|
||||||
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||||
|
@ -265,87 +261,50 @@ public class GunEventHandler {
|
||||||
/**
|
/**
|
||||||
* 通用的武器换弹流程
|
* 通用的武器换弹流程
|
||||||
*/
|
*/
|
||||||
private static void handleGunReload(Player player, GunData gunData) {
|
private static void handleGunReload(Player player, GunData gun) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
var stack = gun.stack();
|
||||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
var gunItem = gun.item();
|
||||||
|
var reload = gun.reload;
|
||||||
var tag = gunData.tag();
|
|
||||||
var data = gunData.data();
|
|
||||||
|
|
||||||
// 启动换弹
|
// 启动换弹
|
||||||
if (gunData.reload.shouldStart()) {
|
if (reload.reloadStarter.start()) {
|
||||||
|
|
||||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
||||||
|
|
||||||
if (gunItem.isOpenBolt(stack)) {
|
if (gunItem.isOpenBolt(stack)) {
|
||||||
if (gunData.ammo() == 0) {
|
if (gun.ammo() == 0) {
|
||||||
gunData.reload.setTime(gunData.emptyReloadTime() + 1);
|
reload.setTime(gun.defaultEmptyReloadTime() + 1);
|
||||||
gunData.reload.setState(ReloadState.EMPTY_RELOADING);
|
reload.setState(ReloadState.EMPTY_RELOADING);
|
||||||
playGunEmptyReloadSounds(player);
|
playGunEmptyReloadSounds(player);
|
||||||
} else {
|
} else {
|
||||||
gunData.reload.setTime(gunData.normalReloadTime() + 1);
|
reload.setTime(gun.defaultNormalReloadTime() + 1);
|
||||||
gunData.reload.setState(ReloadState.NORMAL_RELOADING);
|
reload.setState(ReloadState.NORMAL_RELOADING);
|
||||||
playGunNormalReloadSounds(player);
|
playGunNormalReloadSounds(player);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gunData.reload.setTime(gunData.emptyReloadTime() + 2);
|
reload.setTime(gun.defaultEmptyReloadTime() + 2);
|
||||||
gunData.reload.setState(ReloadState.EMPTY_RELOADING);
|
reload.setState(ReloadState.EMPTY_RELOADING);
|
||||||
playGunEmptyReloadSounds(player);
|
playGunEmptyReloadSounds(player);
|
||||||
}
|
}
|
||||||
gunData.reload.markStarted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gunData.reload.reduce();
|
reload.reduce();
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.RPG.get()) {
|
var behavior = gunItem.reloadTimeBehaviors.get(reload.time());
|
||||||
if (gunData.reload.time() == 84) {
|
if (behavior != null) {
|
||||||
tag.remove("IsEmpty");
|
behavior.accept(gun);
|
||||||
}
|
|
||||||
if (gunData.reload.time() == 9) {
|
|
||||||
data.remove("CloseHammer");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.MK_14.get() && gunData.reload.time() == 18) {
|
if (reload.time() == 1) {
|
||||||
data.remove("HoldOpen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.SVD.get() && gunData.reload.time() == 17) {
|
|
||||||
data.remove("HoldOpen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.SKS.get() && gunData.reload.time() == 14) {
|
|
||||||
data.remove("HoldOpen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.M_60.get() && gunData.reload.time() == 55) {
|
|
||||||
data.remove("HideBulletChain");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.GLOCK_17.get()
|
|
||||||
|| stack.getItem() == ModItems.GLOCK_18.get()
|
|
||||||
|| stack.getItem() == ModItems.M_1911.get()
|
|
||||||
|| stack.getItem() == ModItems.MP_443.get()
|
|
||||||
) {
|
|
||||||
if (gunData.reload.time() == 9) {
|
|
||||||
data.remove("HoldOpen");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.QBZ_95.get() && gunData.reload.time() == 14) {
|
|
||||||
data.remove("HoldOpen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gunData.reload.time() == 1) {
|
|
||||||
if (gunItem.isOpenBolt(stack)) {
|
if (gunItem.isOpenBolt(stack)) {
|
||||||
if (gunData.ammo() == 0) {
|
if (gun.ammo() == 0) {
|
||||||
playGunEmptyReload(player, gunData);
|
playGunEmptyReload(player, gun);
|
||||||
} else {
|
} else {
|
||||||
playGunNormalReload(player, gunData);
|
playGunNormalReload(player, gun);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
playGunEmptyReload(player, gunData);
|
playGunEmptyReload(player, gun);
|
||||||
}
|
}
|
||||||
gunData.reload.markStarted();
|
reload.reloadStarter.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,45 +331,35 @@ public class GunEventHandler {
|
||||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playGunEmptyReload(Player player, GunData gunData) {
|
public static void playGunEmptyReload(Player player, GunData data) {
|
||||||
ItemStack stack = gunData.stack();
|
ItemStack stack = data.stack();
|
||||||
|
|
||||||
if (player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
if (player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||||
gunData.setAmmo(gunData.magazine());
|
data.setAmmo(data.magazine());
|
||||||
} else {
|
} else {
|
||||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||||
GunsTool.reload(player, stack, gunData, AmmoType.SHOTGUN);
|
GunsTool.reload(player, stack, data, AmmoType.SHOTGUN);
|
||||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||||
GunsTool.reload(player, stack, gunData, AmmoType.SNIPER);
|
GunsTool.reload(player, stack, data, AmmoType.SNIPER);
|
||||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||||
GunsTool.reload(player, stack, gunData, AmmoType.HANDGUN);
|
GunsTool.reload(player, stack, data, AmmoType.HANDGUN);
|
||||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||||
GunsTool.reload(player, stack, gunData, AmmoType.RIFLE);
|
GunsTool.reload(player, stack, data, AmmoType.RIFLE);
|
||||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||||
GunsTool.reload(player, stack, gunData, AmmoType.HEAVY);
|
GunsTool.reload(player, stack, data, AmmoType.HEAVY);
|
||||||
} else if (stack.getItem() == ModItems.TASER.get()) {
|
} else if (data.item().getCustomAmmoItem() != null) {
|
||||||
gunData.setAmmo(1);
|
var ammoItem = data.item().getCustomAmmoItem();
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
data.setAmmo(1);
|
||||||
} else if (stack.getItem() == ModItems.M_79.get()) {
|
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ammoItem, 1, player.inventoryMenu.getCraftSlots());
|
||||||
gunData.setAmmo(1);
|
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
|
||||||
} else if (stack.getItem() == ModItems.RPG.get()) {
|
|
||||||
gunData.setAmmo(1);
|
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
|
||||||
} else if (stack.getItem() == ModItems.JAVELIN.get()) {
|
|
||||||
gunData.setAmmo(1);
|
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gunData.reload.setState(ReloadState.NOT_RELOADING);
|
data.reload.setState(ReloadState.NOT_RELOADING);
|
||||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playGunEmptyReloadSounds(Player player) {
|
public static void playGunEmptyReloadSounds(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) {
|
if (!stack.is(ModTags.Items.GUN)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!player.level().isClientSide) {
|
if (!player.level().isClientSide) {
|
||||||
String origin = stack.getItem().getDescriptionId();
|
String origin = stack.getItem().getDescriptionId();
|
||||||
|
@ -445,151 +394,130 @@ public class GunEventHandler {
|
||||||
/**
|
/**
|
||||||
* 单发装填类的武器换弹流程
|
* 单发装填类的武器换弹流程
|
||||||
*/
|
*/
|
||||||
private static void handleGunSingleReload(Player player, GunData gunData) {
|
private static void handleGunSingleReload(Player player, GunData data) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
var stack = data.stack();
|
||||||
if (!(stack.getItem() instanceof GunItem)) return;
|
var reload = data.reload;
|
||||||
var tag = gunData.tag();
|
|
||||||
|
|
||||||
// 换弹流程计时器
|
// 换弹流程计时器
|
||||||
if (tag.getDouble("PrepareTime") > 0) {
|
reload.prepareTimer.reduce();
|
||||||
tag.putDouble("PrepareTime", tag.getDouble("PrepareTime") - 1);
|
reload.prepareLoadTimer.reduce();
|
||||||
}
|
reload.iterativeLoadTimer.reduce();
|
||||||
if (tag.getDouble("PrepareLoadTime") > 0) {
|
reload.finishTimer.reduce();
|
||||||
tag.putDouble("PrepareLoadTime", tag.getDouble("PrepareLoadTime") - 1);
|
|
||||||
}
|
|
||||||
if (tag.getDouble("IterativeLoadTime") > 0) {
|
|
||||||
tag.putDouble("IterativeLoadTime", tag.getDouble("IterativeLoadTime") - 1);
|
|
||||||
}
|
|
||||||
if (tag.getDouble("FinishTime") > 0) {
|
|
||||||
tag.putDouble("FinishTime", tag.getDouble("FinishTime") - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// player.displayClientMessage(Component.literal("prepare: " + new DecimalFormat("##.#").format(tag.getDouble("PrepareTime"))
|
// player.displayClientMessage(Component.literal("prepare: " + new DecimalFormat("##.#").format(data.reload.prepareTimer.get())
|
||||||
// + " prepare_load: " + new DecimalFormat("##.#").format(tag.getDouble("PrepareLoadTime"))
|
// + " prepare_load: " + new DecimalFormat("##.#").format(data.reload.iterativeLoadTimer.get())
|
||||||
// + " iterative: " + new DecimalFormat("##.#").format(tag.getDouble("IterativeLoadTime"))
|
// + " iterative: " + new DecimalFormat("##.#").format(tag.getDouble("IterativeLoadTime"))
|
||||||
// + " finish: " + new DecimalFormat("##.#").format(tag.getDouble("FinishTime"))
|
// + " finish: " + new DecimalFormat("##.#").format(tag.getDouble("FinishTime"))
|
||||||
// + " reload_stage: " + new DecimalFormat("##.#").format(tag.getDouble("reload_stage"))
|
// + " reload_stage: " + new DecimalFormat("##.#").format(tag.getDouble("reload_stage"))
|
||||||
// ), true);
|
// ), true);
|
||||||
|
|
||||||
// 一阶段
|
// 一阶段
|
||||||
if (tag.getBoolean("StartSingleReload")) {
|
if (reload.singleReloadStarter.start()) {
|
||||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
||||||
|
|
||||||
if ((gunData.prepareLoadTime() != 0 && gunData.ammo() == 0) || stack.is(ModItems.SECONDARY_CATACLYSM.get())) {
|
if ((data.defaultPrepareLoadTime() != 0 && data.ammo() == 0) || stack.is(ModItems.SECONDARY_CATACLYSM.get())) {
|
||||||
// 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
// 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
||||||
playGunPrepareLoadReloadSounds(player);
|
playGunPrepareLoadReloadSounds(player);
|
||||||
int prepareLoadTime = gunData.prepareLoadTime();
|
int prepareLoadTime = data.defaultPrepareLoadTime();
|
||||||
tag.putInt("PrepareLoadTime", prepareLoadTime + 1);
|
reload.prepareLoadTimer.set(prepareLoadTime + 1);
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime);
|
player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime);
|
||||||
} else if (gunData.prepareEmptyTime() != 0 && gunData.ammo() == 0) {
|
} else if (data.defaultPrepareEmptyTime() != 0 && data.ammo() == 0) {
|
||||||
// 此处判断空仓换弹,如莫辛纳甘
|
// 此处判断空仓换弹,如莫辛纳甘
|
||||||
playGunEmptyPrepareSounds(player);
|
playGunEmptyPrepareSounds(player);
|
||||||
int prepareEmptyTime = gunData.prepareEmptyTime();
|
int prepareEmptyTime = data.defaultPrepareEmptyTime();
|
||||||
tag.putInt("PrepareTime", prepareEmptyTime + 1);
|
reload.prepareTimer.set(prepareEmptyTime + 1);
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime);
|
player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime);
|
||||||
} else {
|
} else {
|
||||||
playGunPrepareReloadSounds(player);
|
playGunPrepareReloadSounds(player);
|
||||||
int prepareTime = gunData.prepareTime();
|
int prepareTime = data.defaultPrepareTime();
|
||||||
tag.putInt("PrepareTime", prepareTime + 1);
|
reload.prepareTimer.set(prepareTime + 1);
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), prepareTime);
|
player.getCooldowns().addCooldown(stack.getItem(), prepareTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.remove("ForceStop");
|
data.setForceStop(false);
|
||||||
tag.remove("Stopped");
|
data.setStopped(false);
|
||||||
gunData.reload.setStage(1);
|
reload.setStage(1);
|
||||||
gunData.reload.setState(ReloadState.NORMAL_RELOADING);
|
reload.setState(ReloadState.NORMAL_RELOADING);
|
||||||
tag.remove("StartSingleReload");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.M_870.get() && tag.getInt("PrepareLoadTime") == 10) {
|
if (stack.getItem() == ModItems.M_870.get() && reload.prepareLoadTimer.get() == 10) {
|
||||||
singleLoad(player, gunData);
|
singleLoad(player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("PrepareLoadTime") == 3) {
|
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && reload.prepareLoadTimer.get() == 3) {
|
||||||
singleLoad(player, gunData);
|
singleLoad(player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
||||||
if ((tag.getDouble("PrepareTime") == 1 || tag.getDouble("PrepareLoadTime") == 1)) {
|
if ((reload.prepareTimer.get() == 1 || reload.prepareLoadTimer.get() == 1)) {
|
||||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||||
var capability = player.getData(ModAttachments.PLAYER_VARIABLE);
|
var capability = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||||
|
|
||||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) {
|
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
|| stack.is(ModTags.Items.USE_SNIPER_AMMO) && capability.sniperAmmo == 0
|
||||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && capability.sniperAmmo == 0) {
|
|| stack.is(ModTags.Items.USE_HANDGUN_AMMO) && capability.handgunAmmo == 0
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
|| stack.is(ModTags.Items.USE_RIFLE_AMMO) && capability.rifleAmmo == 0
|
||||||
} else if ((stack.is(ModTags.Items.USE_HANDGUN_AMMO) || stack.is(ModTags.Items.SMG)) && capability.handgunAmmo == 0) {
|
|| stack.is(ModTags.Items.USE_HEAVY_AMMO) && capability.heavyAmmo == 0
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
|| stack.is(ModTags.Items.LAUNCHER) && data.maxAmmo() == 0
|
||||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && capability.rifleAmmo == 0) {
|
|| stack.is(ModItems.SECONDARY_CATACLYSM.get()) && data.ammo() >= data.magazine()
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
) {
|
||||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && capability.heavyAmmo == 0) {
|
reload.stage3Starter.markStart();
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
|
||||||
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
|
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
|
||||||
} else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && gunData.ammo() >= gunData.magazine()) {
|
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
|
||||||
} else {
|
} else {
|
||||||
gunData.reload.setStage(2);
|
reload.setStage(2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && gunData.ammo() >= gunData.magazine()) {
|
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && data.ammo() >= data.magazine()) {
|
||||||
tag.putBoolean("ForceStartStage3", true);
|
reload.stage3Starter.markStart();
|
||||||
} else {
|
} else {
|
||||||
gunData.reload.setStage(2);
|
reload.setStage(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 检查备弹
|
// 检查备弹
|
||||||
}
|
}
|
||||||
|
|
||||||
// 强制停止换弹,进入三阶段
|
// 强制停止换弹,进入三阶段
|
||||||
if (tag.getBoolean("ForceStop") && gunData.reload.stage() == 2 && tag.getInt("IterativeLoadTime") > 0) {
|
if (data.forceStop() && reload.stage() == 2 && reload.iterativeLoadTimer.get() > 0) {
|
||||||
tag.putBoolean("Stopped", true);
|
data.setForceStop(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 二阶段
|
// 二阶段
|
||||||
if ((tag.getDouble("PrepareTime") == 0 || tag.getDouble("PrepareLoadTime") == 0)
|
if ((reload.prepareTimer.get() == 0 || reload.iterativeLoadTimer.get() == 0)
|
||||||
&& gunData.reload.stage() == 2
|
&& reload.stage() == 2
|
||||||
&& tag.getInt("IterativeLoadTime") == 0
|
&& reload.iterativeLoadTimer.get() == 0
|
||||||
&& !tag.getBoolean("Stopped")
|
&& !data.stopped()
|
||||||
&& gunData.ammo() < gunData.magazine()
|
&& data.ammo() < data.magazine()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
playGunLoopReloadSounds(player);
|
playGunLoopReloadSounds(player);
|
||||||
int iterativeTime = gunData.iterativeTime();
|
int iterativeTime = data.defaultIterativeTime();
|
||||||
tag.putDouble("IterativeLoadTime", iterativeTime);
|
reload.iterativeLoadTimer.set(iterativeTime);
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), iterativeTime);
|
player.getCooldowns().addCooldown(stack.getItem(), iterativeTime);
|
||||||
// 动画播放nbt
|
// 动画播放nbt
|
||||||
if (tag.getDouble("LoadIndex") == 1) {
|
data.setLoadIndex(data.loadIndex() == 1 ? 0 : 1);
|
||||||
tag.putDouble("LoadIndex", 0);
|
|
||||||
} else {
|
|
||||||
tag.putDouble("LoadIndex", 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 装填
|
// 装填
|
||||||
if ((stack.getItem() == ModItems.M_870.get()
|
if ((stack.getItem() == ModItems.M_870.get()
|
||||||
|| stack.getItem() == ModItems.MARLIN.get())
|
|| stack.getItem() == ModItems.MARLIN.get())
|
||||||
&& tag.getInt("IterativeLoadTime") == 3
|
&& reload.iterativeLoadTimer.get() == 3
|
||||||
) {
|
) {
|
||||||
singleLoad(player, gunData);
|
singleLoad(player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("IterativeLoadTime") == 16) {
|
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && reload.iterativeLoadTimer.get() == 16) {
|
||||||
singleLoad(player, gunData);
|
singleLoad(player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((stack.getItem() == ModItems.K_98.get()
|
if ((stack.getItem() == ModItems.K_98.get() || stack.getItem() == ModItems.MOSIN_NAGANT.get())
|
||||||
|| stack.getItem() == ModItems.MOSIN_NAGANT.get())
|
&& reload.iterativeLoadTimer.get() == 1
|
||||||
&& tag.getInt("IterativeLoadTime") == 1
|
|
||||||
) {
|
) {
|
||||||
singleLoad(player, gunData);
|
singleLoad(player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 二阶段结束
|
// 二阶段结束
|
||||||
if (tag.getInt("IterativeLoadTime") == 1) {
|
if (reload.iterativeLoadTimer.get() == 1) {
|
||||||
// 装满结束
|
// 装满结束
|
||||||
if (gunData.ammo() >= gunData.magazine()) {
|
if (data.ammo() >= data.magazine()) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 备弹耗尽结束
|
// 备弹耗尽结束
|
||||||
|
@ -597,48 +525,50 @@ public class GunEventHandler {
|
||||||
var capability = player.getData(ModAttachments.PLAYER_VARIABLE);
|
var capability = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||||
|
|
||||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) {
|
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && capability.sniperAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && capability.sniperAmmo == 0) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
} else if ((stack.is(ModTags.Items.USE_HANDGUN_AMMO) || stack.is(ModTags.Items.SMG)) && capability.handgunAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO) && capability.handgunAmmo == 0) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && capability.rifleAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && capability.rifleAmmo == 0) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && capability.heavyAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && capability.heavyAmmo == 0) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 强制结束
|
// 强制结束
|
||||||
if (tag.getBoolean("Stopped")) {
|
if (data.stopped()) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
tag.remove("ForceStop");
|
data.setStopped(false);
|
||||||
tag.remove("Stopped");
|
data.setForceStop(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 三阶段
|
// 三阶段
|
||||||
if ((tag.getInt("IterativeLoadTime") == 1 && gunData.reload.stage() == 3) || tag.getBoolean("ForceStartStage3")) {
|
if ((reload.iterativeLoadTimer.get() == 1 && reload.stage() == 3) || reload.stage3Starter.shouldStart()) {
|
||||||
gunData.reload.setStage(3);
|
reload.setStage(3);
|
||||||
tag.remove("ForceStartStage3");
|
reload.stage3Starter.finish();
|
||||||
int finishTime = gunData.finishTime();
|
|
||||||
tag.putInt("FinishTime", finishTime + 2);
|
int finishTime = data.defaultFinishTime();
|
||||||
|
reload.finishTimer.set(finishTime + 2);
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2);
|
player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2);
|
||||||
|
|
||||||
playGunEndReloadSounds(player);
|
playGunEndReloadSounds(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.MARLIN.get() && tag.getInt("FinishTime") == 10) {
|
if (stack.getItem() == ModItems.MARLIN.get() && reload.finishTimer.get() == 10) {
|
||||||
tag.remove("IsEmpty");
|
data.setIsEmpty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 三阶段结束
|
// 三阶段结束
|
||||||
if (tag.getInt("FinishTime") == 1) {
|
if (reload.finishTimer.get() == 1) {
|
||||||
gunData.reload.setStage(0);
|
reload.setStage(0);
|
||||||
if (gunData.bolt.defaultActionTime() > 0) {
|
if (data.bolt.defaultActionTime() > 0) {
|
||||||
gunData.bolt.markNeedless();
|
data.bolt.markNeedless();
|
||||||
}
|
}
|
||||||
gunData.reload.setState(ReloadState.NOT_RELOADING);
|
reload.setState(ReloadState.NOT_RELOADING);
|
||||||
tag.remove("StartSingleReload");
|
reload.singleReloadStarter.finish();
|
||||||
|
|
||||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||||
}
|
}
|
||||||
|
@ -662,7 +592,7 @@ public class GunEventHandler {
|
||||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||||
AmmoType.HEAVY.add(cap, -1);
|
AmmoType.HEAVY.add(cap, -1);
|
||||||
} else if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get()) {
|
} else if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get()) {
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == data.item().getCustomAmmoItem(), 1, player.inventoryMenu.getCraftSlots());
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||||
|
@ -700,7 +630,7 @@ public class GunEventHandler {
|
||||||
double shooterHeight = player.getEyePosition().distanceTo((Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(new Vec3(0, -1, 0).scale(10)),
|
double shooterHeight = player.getEyePosition().distanceTo((Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(new Vec3(0, -1, 0).scale(10)),
|
||||||
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
|
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
|
||||||
|
|
||||||
Mod.queueServerWork((int) (data.prepareEmptyTime() / 2 + 3 + 1.5 * shooterHeight), () -> {
|
Mod.queueServerWork((int) (data.defaultPrepareEmptyTime() / 2 + 3 + 1.5 * shooterHeight), () -> {
|
||||||
if (stack.is(ModTags.Items.SHOTGUN)) {
|
if (stack.is(ModTags.Items.SHOTGUN)) {
|
||||||
SoundTool.playLocalSound(serverPlayer, ModSounds.SHELL_CASING_SHOTGUN.get(), (float) Math.max(0.75 - 0.12 * shooterHeight, 0), 1);
|
SoundTool.playLocalSound(serverPlayer, ModSounds.SHELL_CASING_SHOTGUN.get(), (float) Math.max(0.75 - 0.12 * shooterHeight, 0), 1);
|
||||||
} else if (stack.is(ModTags.Items.SNIPER_RIFLE) || stack.is(ModTags.Items.HEAVY_WEAPON)) {
|
} else if (stack.is(ModTags.Items.SNIPER_RIFLE) || stack.is(ModTags.Items.HEAVY_WEAPON)) {
|
||||||
|
@ -784,25 +714,19 @@ public class GunEventHandler {
|
||||||
* 哨兵充能
|
* 哨兵充能
|
||||||
*/
|
*/
|
||||||
private static void handleSentinelCharge(Player player, GunData data) {
|
private static void handleSentinelCharge(Player player, GunData data) {
|
||||||
if (!(player.getMainHandItem().getItem() instanceof GunItem)) return;
|
|
||||||
|
|
||||||
// 启动充能
|
// 启动充能
|
||||||
if (data.charge.shouldStartCharge()) {
|
if (data.charge.starter.start()) {
|
||||||
data.charge.setTime(127);
|
data.charge.timer.set(127);
|
||||||
|
|
||||||
SoundEvent sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc("sentinel_charge"));
|
SoundEvent sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc("sentinel_charge"));
|
||||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||||
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.charge.markStarted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.charge.time() > 0) {
|
data.charge.timer.reduce();
|
||||||
data.charge.reduce();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.charge.time() == 17) {
|
if (data.charge.timer.get() == 17) {
|
||||||
for (var cell : player.getInventory().items) {
|
for (var cell : player.getInventory().items) {
|
||||||
if (cell.is(ModItems.CELL.get())) {
|
if (cell.is(ModItems.CELL.get())) {
|
||||||
var stackStorage = data.stack().getCapability(Capabilities.EnergyStorage.ITEM);
|
var stackStorage = data.stack().getCapability(Capabilities.EnergyStorage.ITEM);
|
||||||
|
|
|
@ -348,38 +348,35 @@ public class LivingEventHandler {
|
||||||
var newTag = NBTTool.getTag(newStack);
|
var newTag = NBTTool.getTag(newStack);
|
||||||
if (player instanceof ServerPlayer serverPlayer
|
if (player instanceof ServerPlayer serverPlayer
|
||||||
&& (newStack.getItem() != oldStack.getItem()
|
&& (newStack.getItem() != oldStack.getItem()
|
||||||
|| (newStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(newTag).hasUUID("UUID"))
|
|| (newStack.is(ModTags.Items.GUN) && !GunData.from(newStack).initialized())
|
||||||
|| (oldStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(oldTag).hasUUID("UUID"))
|
|| (oldStack.is(ModTags.Items.GUN) && !GunData.from(oldStack).initialized())
|
||||||
|| (newStack.is(ModTags.Items.GUN) && oldStack.is(ModTags.Items.GUN) && !Objects.equals(GunsTool.getGunUUID(newTag), GunsTool.getGunUUID(oldTag)))
|
|| (newStack.is(ModTags.Items.GUN) && oldStack.is(ModTags.Items.GUN) && !Objects.equals(GunsTool.getGunUUID(newTag), GunsTool.getGunUUID(oldTag)))
|
||||||
)) {
|
)) {
|
||||||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||||
stopGunReloadSound(serverPlayer, oldGun);
|
stopGunReloadSound(serverPlayer, oldGun);
|
||||||
|
|
||||||
var oldData = GunData.from(oldStack);
|
var oldData = GunData.from(oldStack);
|
||||||
oldTag = oldData.tag();
|
|
||||||
var data = oldData.data();
|
|
||||||
|
|
||||||
if (oldData.bolt.defaultActionTime() > 0) {
|
if (oldData.bolt.defaultActionTime() > 0) {
|
||||||
oldData.bolt.setActionTime(0);
|
oldData.bolt.setActionTime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
oldData.reload.setTime(0);
|
oldData.reload.setTime(0);
|
||||||
oldTag.put("GunData", data);
|
|
||||||
|
|
||||||
oldData.reload.setState(ReloadState.NOT_RELOADING);
|
oldData.reload.setState(ReloadState.NOT_RELOADING);
|
||||||
|
|
||||||
if (oldData.iterativeTime() != 0) {
|
if (oldData.defaultIterativeTime() != 0) {
|
||||||
oldTag.remove("ForceStop");
|
oldData.setStopped(false);
|
||||||
oldTag.remove("Stopped");
|
oldData.setForceStop(false);
|
||||||
oldData.reload.setStage(0);
|
oldData.reload.setStage(0);
|
||||||
oldTag.remove("PrepareTime");
|
oldData.reload.prepareTimer.reset();
|
||||||
oldTag.remove("PrepareLoadTime");
|
oldData.reload.prepareLoadTimer.reset();
|
||||||
oldTag.remove("IterativeLoadTime");
|
oldData.reload.iterativeLoadTimer.reset();
|
||||||
oldTag.remove("FinishTime");
|
oldData.reload.finishTimer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldStack.is(ModItems.SENTINEL.get())) {
|
if (oldStack.is(ModItems.SENTINEL.get())) {
|
||||||
oldData.charge.reset();
|
oldData.charge.timer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||||
|
@ -401,23 +398,20 @@ public class LivingEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
newData.reload.setState(ReloadState.NOT_RELOADING);
|
newData.reload.setState(ReloadState.NOT_RELOADING);
|
||||||
|
newData.reload.reloadTimer.reset();
|
||||||
|
|
||||||
var data = newData.data();
|
if (newData.defaultIterativeTime() != 0) {
|
||||||
newData.reload.setTime(0);
|
newData.setForceStop(false);
|
||||||
newTag.put("GunData", data);
|
newData.setStopped(false);
|
||||||
|
|
||||||
if (newData.iterativeTime() != 0) {
|
|
||||||
newTag.remove("ForceStop");
|
|
||||||
newTag.remove("Stopped");
|
|
||||||
newData.reload.setStage(0);
|
newData.reload.setStage(0);
|
||||||
newTag.remove("PrepareTime");
|
newData.reload.prepareTimer.reset();
|
||||||
newTag.remove("PrepareLoadTime");
|
newData.reload.prepareLoadTimer.reset();
|
||||||
newTag.remove("IterativeLoadTime");
|
newData.reload.iterativeLoadTimer.reset();
|
||||||
newTag.remove("FinishTime");
|
newData.reload.finishTimer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newStack.is(ModItems.SENTINEL.get())) {
|
if (newStack.is(ModItems.SENTINEL.get())) {
|
||||||
newData.charge.reset();
|
newData.charge.timer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int level = newData.perk.getLevel(ModPerks.KILLING_TALLY);
|
int level = newData.perk.getLevel(ModPerks.KILLING_TALLY);
|
||||||
|
|
|
@ -205,10 +205,9 @@ public class PlayerEventHandler {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
var tag = data.tag();
|
|
||||||
|
|
||||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && data.ammo() == 1) {
|
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && data.ammo() == 1) {
|
||||||
tag.remove("IsEmpty");
|
data.setIsEmpty(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +221,7 @@ public class PlayerEventHandler {
|
||||||
|
|
||||||
if (cap.bowPullHold) {
|
if (cap.bowPullHold) {
|
||||||
if (stack.getItem() == ModItems.BOCEK.get()
|
if (stack.getItem() == ModItems.BOCEK.get()
|
||||||
&& GunsTool.getGunIntTag(tag, "MaxAmmo") > 0
|
&& data.maxAmmo() > 0
|
||||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||||
&& GunsTool.getGunDoubleTag(tag, "Power") < 12
|
&& GunsTool.getGunDoubleTag(tag, "Power") < 12
|
||||||
) {
|
) {
|
||||||
|
@ -291,19 +290,19 @@ public class PlayerEventHandler {
|
||||||
GunsTool.reload(player, stack, data, AmmoType.HEAVY);
|
GunsTool.reload(player, stack, data, AmmoType.HEAVY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && data.ammo() == 0) {
|
if (stack.getItem() == ModItems.TASER.get() && data.maxAmmo() > 0 && data.ammo() == 0) {
|
||||||
data.setAmmo(1);
|
data.setAmmo(1);
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||||
}
|
}
|
||||||
if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && data.ammo() == 0) {
|
if (stack.getItem() == ModItems.M_79.get() && data.maxAmmo() > 0 && data.ammo() == 0) {
|
||||||
data.setAmmo(1);
|
data.setAmmo(1);
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||||
}
|
}
|
||||||
if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && data.ammo() == 0) {
|
if (stack.getItem() == ModItems.RPG.get() && data.maxAmmo() > 0 && data.ammo() == 0) {
|
||||||
data.setAmmo(1);
|
data.setAmmo(1);
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||||
}
|
}
|
||||||
if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && data.ammo() == 0) {
|
if (stack.getItem() == ModItems.JAVELIN.get() && data.maxAmmo() > 0 && data.ammo() == 0) {
|
||||||
data.setAmmo(1);
|
data.setAmmo(1);
|
||||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,15 @@ import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsE
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
import java.util.function.Consumer;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
|
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
|
||||||
public abstract class GunItem extends Item implements CustomRendererItem {
|
public abstract class GunItem extends Item implements CustomRendererItem {
|
||||||
|
|
||||||
public GunItem(Properties properties) {
|
public GunItem(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
|
addReloadTimeBehavior(this.reloadTimeBehaviors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -497,6 +497,18 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Map<Integer, Consumer<GunData>> reloadTimeBehaviors = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加达到指定换弹时间时的额外行为
|
||||||
|
*/
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item getCustomAmmoItem() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
private static void registerGunExtensions(RegisterClientExtensionsEvent event) {
|
private static void registerGunExtensions(RegisterClientExtensionsEvent event) {
|
||||||
for (var item : ModItems.GUNS.getEntries()) {
|
for (var item : ModItems.GUNS.getEntries()) {
|
||||||
|
|
|
@ -1,43 +1,15 @@
|
||||||
package com.atsuishio.superbwarfare.item.gun.data;
|
package com.atsuishio.superbwarfare.item.gun.data;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
|
|
||||||
public final class Charge {
|
public final class Charge {
|
||||||
private final CompoundTag data;
|
public final Timer timer;
|
||||||
|
public final Starter starter;
|
||||||
|
|
||||||
Charge(GunData data) {
|
Charge(GunData data) {
|
||||||
this.data = data.data();
|
this.timer = new Timer(data.data(), "Charge");
|
||||||
}
|
this.starter = new Starter(data.data(), "Charge");
|
||||||
|
|
||||||
public void markStart() {
|
|
||||||
data.putBoolean("StartCharge", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldStartCharge() {
|
|
||||||
return data.getBoolean("StartCharge");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markStarted() {
|
|
||||||
data.remove("StartCharge");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int time() {
|
public int time() {
|
||||||
return data.getInt("ChargeTime");
|
return timer.get();
|
||||||
}
|
|
||||||
|
|
||||||
public void reduce() {
|
|
||||||
setTime(time() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTime(int chargeTime) {
|
|
||||||
if (chargeTime <= 0) {
|
|
||||||
data.remove("ChargeTime");
|
|
||||||
} else {
|
|
||||||
data.putInt("ChargeTime", chargeTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
setTime(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,31 +155,31 @@ public class GunData {
|
||||||
return getGunData("Headshot", 1.5) + item.getCustomHeadshot(stack);
|
return getGunData("Headshot", 1.5) + item.getCustomHeadshot(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int normalReloadTime() {
|
public int defaultNormalReloadTime() {
|
||||||
return (int) getGunData("NormalReloadTime");
|
return (int) getGunData("NormalReloadTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int emptyReloadTime() {
|
public int defaultEmptyReloadTime() {
|
||||||
return (int) getGunData("EmptyReloadTime");
|
return (int) getGunData("EmptyReloadTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int iterativeTime() {
|
public int defaultIterativeTime() {
|
||||||
return (int) getGunData("IterativeTime");
|
return (int) getGunData("IterativeTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int prepareTime() {
|
public int defaultPrepareTime() {
|
||||||
return (int) getGunData("PrepareTime");
|
return (int) getGunData("PrepareTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int prepareLoadTime() {
|
public int defaultPrepareLoadTime() {
|
||||||
return (int) getGunData("PrepareLoadTime");
|
return (int) getGunData("PrepareLoadTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int prepareEmptyTime() {
|
public int defaultPrepareEmptyTime() {
|
||||||
return (int) getGunData("PrepareEmptyTime");
|
return (int) getGunData("PrepareEmptyTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int finishTime() {
|
public int defaultFinishTime() {
|
||||||
return (int) getGunData("FinishTime");
|
return (int) getGunData("FinishTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +300,102 @@ public class GunData {
|
||||||
return charge.time() > 0;
|
return charge.time() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canImmediatelyShoot() {
|
||||||
|
return data.getBoolean("CanImmediatelyShoot");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanImmediatelyShoot(boolean value) {
|
||||||
|
if (!value) {
|
||||||
|
data.remove("CanImmediatelyShoot");
|
||||||
|
} else {
|
||||||
|
data.putBoolean("CanImmediatelyShoot", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean DA() {
|
||||||
|
return data.getBoolean("DA");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDA(boolean value) {
|
||||||
|
if (!value) {
|
||||||
|
data.remove("DA");
|
||||||
|
} else {
|
||||||
|
data.putBoolean("DA", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return data.getBoolean("IsEmpty");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsEmpty(boolean value) {
|
||||||
|
if (!value) {
|
||||||
|
data.remove("IsEmpty");
|
||||||
|
} else {
|
||||||
|
data.putBoolean("IsEmpty", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean closeHammer() {
|
||||||
|
return data.getBoolean("CloseHammer");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCloseHammer(boolean value) {
|
||||||
|
if (!value) {
|
||||||
|
data.remove("CloseHammer");
|
||||||
|
} else {
|
||||||
|
data.putBoolean("CloseHammer", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean stopped() {
|
||||||
|
return data.getBoolean("Stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStopped(boolean value) {
|
||||||
|
if (!value) {
|
||||||
|
data.remove("Stopped");
|
||||||
|
} else {
|
||||||
|
data.putBoolean("Stopped", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean forceStop() {
|
||||||
|
return data.getBoolean("ForceStop");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForceStop(boolean value) {
|
||||||
|
if (!value) {
|
||||||
|
data.remove("ForceStop");
|
||||||
|
} else {
|
||||||
|
data.putBoolean("ForceStop", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int loadIndex() {
|
||||||
|
return data.getInt("LoadIndex");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoadIndex(int value) {
|
||||||
|
if (value == 0) {
|
||||||
|
data.remove("LoadIndex");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data.putInt("LoadIndex", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int maxAmmo() {
|
||||||
|
return data.getInt("MaxAmmo");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxAmmo(int value) {
|
||||||
|
if (value == 0) {
|
||||||
|
data.remove("MaxAmmo");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data.putInt("MaxAmmo", value);
|
||||||
|
}
|
||||||
|
|
||||||
public final Bolt bolt;
|
public final Bolt bolt;
|
||||||
public final Attachment attachment;
|
public final Attachment attachment;
|
||||||
public final Perks perk;
|
public final Perks perk;
|
||||||
|
|
|
@ -5,8 +5,28 @@ import net.minecraft.nbt.CompoundTag;
|
||||||
public final class Reload {
|
public final class Reload {
|
||||||
private final CompoundTag data;
|
private final CompoundTag data;
|
||||||
|
|
||||||
|
public final Timer reloadTimer;
|
||||||
|
public final Timer prepareTimer;
|
||||||
|
public final Timer prepareLoadTimer;
|
||||||
|
public final Timer iterativeLoadTimer;
|
||||||
|
public final Timer finishTimer;
|
||||||
|
|
||||||
|
public final Starter reloadStarter;
|
||||||
|
public final Starter singleReloadStarter;
|
||||||
|
public final Starter stage3Starter;
|
||||||
|
|
||||||
Reload(GunData data) {
|
Reload(GunData data) {
|
||||||
this.data = data.data();
|
this.data = data.data();
|
||||||
|
|
||||||
|
reloadTimer = new Timer(this.data, "Reload");
|
||||||
|
prepareTimer = new Timer(this.data, "Prepare");
|
||||||
|
prepareLoadTimer = new Timer(this.data, "PrepareLoad");
|
||||||
|
iterativeLoadTimer = new Timer(this.data, "IterativeLoad");
|
||||||
|
finishTimer = new Timer(this.data, "Finish");
|
||||||
|
|
||||||
|
reloadStarter = new Starter(this.data, "Reload");
|
||||||
|
singleReloadStarter = new Starter(this.data, "SingleReload");
|
||||||
|
stage3Starter = new Starter(this.data, "Stage3Forcefully");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReloadState state() {
|
public ReloadState state() {
|
||||||
|
@ -45,31 +65,16 @@ public final class Reload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markStart() {
|
|
||||||
data.putBoolean("StartReload", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markStarted() {
|
|
||||||
data.remove("StartReload");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldStart() {
|
|
||||||
return data.getBoolean("StartReload");
|
|
||||||
}
|
|
||||||
|
|
||||||
public int time() {
|
public int time() {
|
||||||
return data.getInt("ReloadTime");
|
return reloadTimer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(int time) {
|
public void setTime(int time) {
|
||||||
if (time <= 0) {
|
reloadTimer.set(time);
|
||||||
data.remove("ReloadTime");
|
|
||||||
} else {
|
|
||||||
data.putInt("ReloadTime", time);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reduce() {
|
public void reduce() {
|
||||||
setTime(time() - 1);
|
reloadTimer.reduce();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.atsuishio.superbwarfare.item.gun.data;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
|
public class Starter {
|
||||||
|
private final CompoundTag tag;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
Starter(CompoundTag tag, String name) {
|
||||||
|
this.tag = tag;
|
||||||
|
this.name = "Start" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测当前状态是否应该开始
|
||||||
|
*/
|
||||||
|
public boolean shouldStart() {
|
||||||
|
return tag.getBoolean(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将当前状态设置为开始
|
||||||
|
*/
|
||||||
|
public void markStart() {
|
||||||
|
tag.putBoolean(name, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将当前状态设置为结束
|
||||||
|
*/
|
||||||
|
public void finish() {
|
||||||
|
tag.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测阶段是否应该开始,返回当前状态,并设置为结束
|
||||||
|
*/
|
||||||
|
public boolean start() {
|
||||||
|
if (shouldStart()) {
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.atsuishio.superbwarfare.item.gun.data;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
|
public class Timer {
|
||||||
|
private final CompoundTag tag;
|
||||||
|
public final String name;
|
||||||
|
|
||||||
|
Timer(CompoundTag tag, String name) {
|
||||||
|
this.tag = tag;
|
||||||
|
this.name = name + "Time";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get() {
|
||||||
|
return tag.getInt(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(int time) {
|
||||||
|
if (time <= 0) {
|
||||||
|
tag.remove(name);
|
||||||
|
} else {
|
||||||
|
tag.putInt(name, time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int time) {
|
||||||
|
set(get() + time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reduce() {
|
||||||
|
add(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
set(0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,9 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Glock17Item extends GunItem implements GeoItem {
|
public class Glock17Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -138,4 +140,11 @@ public class Glock17Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag;
|
return FireMode.SEMI.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(9, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,9 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Glock18Item extends GunItem implements GeoItem {
|
public class Glock18Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -146,4 +148,11 @@ public class Glock18Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag + FireMode.AUTO.flag;
|
return FireMode.SEMI.flag + FireMode.AUTO.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(9, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,9 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class M1911Item extends GunItem implements GeoItem {
|
public class M1911Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -141,4 +143,11 @@ public class M1911Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag;
|
return FireMode.SEMI.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(9, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,9 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Mp443Item extends GunItem implements GeoItem {
|
public class Mp443Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -138,4 +140,11 @@ public class Mp443Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag;
|
return FireMode.SEMI.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(9, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -249,7 +249,7 @@ public class Trachelium extends GunItem implements GeoItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCustomBoltActionTime(ItemStack stack) {
|
public int getCustomBoltActionTime(ItemStack stack) {
|
||||||
return GunData.from(stack).tag().getBoolean("DA") ? 12 : 0;
|
return GunData.from(stack).DA() ? 12 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,6 +32,7 @@ import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.animal.Pig;
|
import net.minecraft.world.entity.animal.Pig;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.ClipContext;
|
import net.minecraft.world.level.ClipContext;
|
||||||
|
@ -136,7 +137,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
final var tag = data.tag();
|
final var tag = data.tag();
|
||||||
|
|
||||||
if (entity instanceof Player player && selected) {
|
if (entity instanceof Player player && selected) {
|
||||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
data.setMaxAmmo(getAmmoCount(player));
|
||||||
|
|
||||||
if (tag.getBoolean("Seeking")) {
|
if (tag.getBoolean("Seeking")) {
|
||||||
|
|
||||||
|
@ -329,4 +330,9 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
tag.putBoolean("Seeking", true);
|
tag.putBoolean("Seeking", true);
|
||||||
tag.putInt("SeekTime", 0);
|
tag.putInt("SeekTime", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getCustomAmmoItem() {
|
||||||
|
return ModItems.JAVELIN_MISSILE.get();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,6 @@ import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -27,6 +26,7 @@ import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Rarity;
|
import net.minecraft.world.item.Rarity;
|
||||||
|
@ -125,8 +125,7 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
data.setMaxAmmo(getAmmoCount(player));
|
||||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
|
||||||
data.save();
|
data.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,4 +219,9 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), 2);
|
player.getCooldowns().addCooldown(stack.getItem(), 2);
|
||||||
data.setAmmo(data.ammo() - 1);
|
data.setAmmo(data.ammo() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getCustomAmmoItem() {
|
||||||
|
return ModItems.GRENADE_40MM.get();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,6 @@ import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -27,6 +26,7 @@ import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Rarity;
|
import net.minecraft.world.item.Rarity;
|
||||||
|
@ -40,8 +40,10 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
|
|
||||||
|
@ -134,12 +136,12 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
tag.putBoolean("draw", false);
|
tag.putBoolean("draw", false);
|
||||||
|
|
||||||
if (data.ammo() == 0) {
|
if (data.ammo() == 0) {
|
||||||
tag.putBoolean("IsEmpty", true);
|
data.setIsEmpty(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
data.setMaxAmmo(getAmmoCount(player));
|
||||||
}
|
}
|
||||||
data.save();
|
data.save();
|
||||||
|
|
||||||
|
@ -179,7 +181,6 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
public void fireOnPress(Player player, final GunData data) {
|
public void fireOnPress(Player player, final GunData data) {
|
||||||
Level level = player.level();
|
Level level = player.level();
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
var tag = data.tag();
|
|
||||||
|
|
||||||
if (data.reloading()
|
if (data.reloading()
|
||||||
|| player.getCooldowns().isOnCooldown(stack.getItem())
|
|| player.getCooldowns().isOnCooldown(stack.getItem())
|
||||||
|
@ -236,11 +237,24 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.ammo() == 1) {
|
if (data.ammo() == 1) {
|
||||||
tag.putBoolean("IsEmpty", true);
|
data.setIsEmpty(true);
|
||||||
GunsTool.setGunBooleanTag(tag, "CloseHammer", true);
|
data.setCloseHammer(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), 10);
|
player.getCooldowns().addCooldown(stack.getItem(), 10);
|
||||||
data.setAmmo(data.ammo() - 1);
|
data.setAmmo(data.ammo() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(84, data -> data.setIsEmpty(false));
|
||||||
|
behaviors.put(9, data -> data.setCloseHammer(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getCustomAmmoItem() {
|
||||||
|
return ModItems.ROCKET.get();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,6 @@ import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -30,6 +29,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||||
|
@ -87,17 +87,16 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (data.reload.stage() == 1 && tag.getDouble("PrepareLoadTime") > 0) {
|
if (data.reload.stage() == 1 && data.reload.prepareLoadTimer.get() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.prepare"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.prepare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 0 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 0 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 1 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 1 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload2"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +179,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
data.setMaxAmmo(getAmmoCount(player));
|
||||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
|
||||||
data.save();
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,4 +344,9 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
||||||
public int getMaxEnergy() {
|
public int getMaxEnergy() {
|
||||||
return 24000;
|
return 24000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getCustomAmmoItem() {
|
||||||
|
return ModItems.GRENADE_40MM.get();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -28,7 +28,9 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class M60Item extends GunItem implements GeoItem {
|
public class M60Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -159,4 +161,11 @@ public class M60Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.AUTO.flag;
|
return FireMode.AUTO.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(55, data -> data.data().remove("HideBulletChain"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -49,21 +49,20 @@ public class MarlinItem extends GunItem implements GeoItem {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (data.bolt.actionTime() > 0) {
|
if (data.bolt.actionTime() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.shift"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.shift"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.reload.stage() == 1 && tag.getDouble("PrepareTime") > 0) {
|
if (data.reload.stage() == 1 && data.reload.prepareTimer.get() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.prepare"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.prepare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 0 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 0 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 1 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 1 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload2"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,9 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Mk14Item extends GunItem implements GeoItem {
|
public class Mk14Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -238,4 +240,11 @@ public class Mk14Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag + FireMode.AUTO.flag;
|
return FireMode.SEMI.flag + FireMode.AUTO.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(18, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -30,7 +30,9 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Qbz95Item extends GunItem implements GeoItem {
|
public class Qbz95Item extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -246,4 +248,11 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag + FireMode.AUTO.flag;
|
return FireMode.SEMI.flag + FireMode.AUTO.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(14, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,7 +27,9 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class SksItem extends GunItem implements GeoItem {
|
public class SksItem extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -143,4 +145,11 @@ public class SksItem extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag;
|
return FireMode.SEMI.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(14, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@ import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -54,25 +53,24 @@ public class M870Item extends GunItem implements GeoItem {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = NBTTool.getTag(stack);
|
|
||||||
|
|
||||||
if (data.bolt.actionTime() > 0) {
|
if (data.bolt.actionTime() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.shift"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.shift"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.reload.stage() == 1 && tag.getDouble("PrepareLoadTime") > 0) {
|
if (data.reload.stage() == 1 && data.reload.iterativeLoadTimer.get() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.preparealt"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.preparealt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.reload.stage() == 1 && tag.getDouble("PrepareTime") > 0) {
|
if (data.reload.stage() == 1 && data.reload.prepareTimer.get() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.prepare"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.prepare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 0 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 0 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 1 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 1 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload2"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ public class K98Item extends GunItem implements GeoItem {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (data.bolt.actionTime() > 0) {
|
if (data.bolt.actionTime() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.shift"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.shift"));
|
||||||
|
@ -60,15 +59,15 @@ public class K98Item extends GunItem implements GeoItem {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.reload_empty"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.reload_empty"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.reload.stage() == 1 && tag.getDouble("PrepareTime") > 0) {
|
if (data.reload.stage() == 1 && data.reload.prepareTimer.get() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.prepare"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.prepare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 0 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 0 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.getDouble("LoadIndex") == 1 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 1 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload2"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +85,6 @@ public class K98Item extends GunItem implements GeoItem {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (player.isSprinting() && player.onGround()
|
if (player.isSprinting() && player.onGround()
|
||||||
&& player.getPersistentData().getDouble("noRun") == 0
|
&& player.getPersistentData().getDouble("noRun") == 0
|
||||||
|
|
|
@ -9,7 +9,6 @@ import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -50,7 +49,6 @@ public class MosinNagantItem extends GunItem implements GeoItem {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (data.bolt.actionTime() > 0) {
|
if (data.bolt.actionTime() > 0) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift"));
|
||||||
|
@ -64,11 +62,11 @@ public class MosinNagantItem extends GunItem implements GeoItem {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NBTTool.getTag(stack).getDouble("LoadIndex") == 0 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 0 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.iterativeload"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.iterativeload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NBTTool.getTag(stack).getDouble("LoadIndex") == 1 && data.reload.stage() == 2) {
|
if (data.loadIndex() == 1 && data.reload.stage() == 2) {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.iterativeload2"));
|
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.iterativeload2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +83,6 @@ public class MosinNagantItem extends GunItem implements GeoItem {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (player.isSprinting() && player.onGround()
|
if (player.isSprinting() && player.onGround()
|
||||||
&& player.getPersistentData().getDouble("noRun") == 0
|
&& player.getPersistentData().getDouble("noRun") == 0
|
||||||
|
|
|
@ -27,7 +27,9 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class SvdItem extends GunItem implements GeoItem {
|
public class SvdItem extends GunItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -192,4 +194,11 @@ public class SvdItem extends GunItem implements GeoItem {
|
||||||
public int getAvailableFireModes() {
|
public int getAvailableFireModes() {
|
||||||
return FireMode.SEMI.flag;
|
return FireMode.SEMI.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReloadTimeBehavior(Map<Integer, Consumer<GunData>> behaviors) {
|
||||||
|
super.addReloadTimeBehavior(behaviors);
|
||||||
|
|
||||||
|
behaviors.put(17, data -> data.data().remove("HoldOpen"));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -115,7 +115,7 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
final var tag = data.tag();
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
data.setMaxAmmo(getAmmoCount(player));
|
||||||
data.save();
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
@ -24,6 +23,7 @@ import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Rarity;
|
import net.minecraft.world.item.Rarity;
|
||||||
|
@ -142,10 +142,9 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
||||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
data.setMaxAmmo(getAmmoCount(player));
|
||||||
data.save();
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,4 +264,9 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
||||||
public int getMaxEnergy() {
|
public int getMaxEnergy() {
|
||||||
return MAX_ENERGY;
|
return MAX_ENERGY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getCustomAmmoItem() {
|
||||||
|
return ModItems.TASER_ELECTRODE.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,14 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!stack.is(ModTags.Items.GUN)) return;
|
if (!stack.is(ModTags.Items.GUN)) return;
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
|
||||||
|
|
||||||
handleGunBolt(player, stack);
|
handleGunBolt(player, stack);
|
||||||
|
|
||||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||||
|
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
if (tag.getDouble("PrepareTime") == 0 && data.reloading() && data.ammo() > 0) {
|
if (data.reload.prepareTimer.get() == 0 && data.reloading() && data.ammo() > 0) {
|
||||||
tag.putBoolean("ForceStop", true);
|
data.setForceStop(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
cap.edit = false;
|
cap.edit = false;
|
||||||
|
|
|
@ -95,7 +95,7 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
||||||
if (cell.is(ModItems.CELL.get())) {
|
if (cell.is(ModItems.CELL.get())) {
|
||||||
var cap = cell.getCapability(Capabilities.EnergyStorage.ITEM);
|
var cap = cell.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||||
if (cap != null && cap.getEnergyStored() > 0) {
|
if (cap != null && cap.getEnergyStored() > 0) {
|
||||||
data.charge.markStart();
|
data.charge.starter.markStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,8 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.TRACHELIUM.get() && !data.bolt.needed()) {
|
if (stack.getItem() == ModItems.TRACHELIUM.get() && !data.bolt.needed()) {
|
||||||
tag.putBoolean("DA", !tag.getBoolean("DA"));
|
data.setDA(!data.DA());
|
||||||
if (!tag.getBoolean("canImmediatelyShoot")) {
|
if (!data.canImmediatelyShoot()) {
|
||||||
data.bolt.markNeeded();
|
data.bolt.markNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.network.codec.ByteBufCodecs;
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
@ -40,7 +39,6 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
||||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||||
|
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
var tag = data.tag();
|
|
||||||
|
|
||||||
if (!player.isSpectator()
|
if (!player.isSpectator()
|
||||||
&& !data.charging()
|
&& !data.charging()
|
||||||
|
@ -60,15 +58,15 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
||||||
return;
|
return;
|
||||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && cap.sniperAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && cap.sniperAmmo == 0) {
|
||||||
return;
|
return;
|
||||||
} else if ((stack.is(ModTags.Items.USE_HANDGUN_AMMO) || stack.is(ModTags.Items.SMG)) && cap.handgunAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO) && cap.handgunAmmo == 0) {
|
||||||
return;
|
return;
|
||||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && cap.rifleAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && cap.rifleAmmo == 0) {
|
||||||
return;
|
return;
|
||||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && cap.heavyAmmo == 0) {
|
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && cap.heavyAmmo == 0) {
|
||||||
return;
|
return;
|
||||||
} else if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
|
} else if (stack.getItem() == ModItems.TASER.get() && data.maxAmmo() == 0) {
|
||||||
return;
|
return;
|
||||||
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
|
} else if (stack.is(ModTags.Items.LAUNCHER) && data.maxAmmo() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,13 +77,13 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
||||||
var maxAmmo = magazine + extra;
|
var maxAmmo = magazine + extra;
|
||||||
|
|
||||||
if (data.ammo() < maxAmmo) {
|
if (data.ammo() < maxAmmo) {
|
||||||
data.reload.markStart();
|
data.reload.reloadStarter.markStart();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canSingleReload && data.ammo() < data.magazine()) {
|
if (canSingleReload && data.ammo() < data.magazine()) {
|
||||||
tag.putBoolean("StartSingleReload", true);
|
data.reload.singleReloadStarter.markStart();
|
||||||
}
|
}
|
||||||
data.save();
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.is(ModTags.Items.REVOLVER)) {
|
if (stack.is(ModTags.Items.REVOLVER)) {
|
||||||
tag.putBoolean("canImmediatelyShoot", false);
|
data.setCanImmediatelyShoot(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
||||||
|
@ -61,7 +61,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setAmmo(data.ammo() - 1);
|
data.setAmmo(data.ammo() - 1);
|
||||||
tag.putBoolean("IsEmpty", true);
|
data.setIsEmpty(true);
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.M_60.get() && data.ammo() <= 5) {
|
if (stack.getItem() == ModItems.M_60.get() && data.ammo() <= 5) {
|
||||||
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
|
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
|
||||||
|
@ -86,7 +86,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
||||||
var perk = data.perk.get(Perk.Type.AMMO);
|
var perk = data.perk.get(Perk.Type.AMMO);
|
||||||
|
|
||||||
for (int index0 = 0; index0 < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : projectileAmount); index0++) {
|
for (int index0 = 0; index0 < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : projectileAmount); index0++) {
|
||||||
GunEventHandler.gunShoot(player, tag, spared);
|
GunEventHandler.gunShoot(player, data, spared);
|
||||||
}
|
}
|
||||||
|
|
||||||
GunEventHandler.playGunSounds(player);
|
GunEventHandler.playGunSounds(player);
|
||||||
|
@ -119,7 +119,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GunEventHandler.gunShoot(player, tag, spared);
|
GunEventHandler.gunShoot(player, data, spared);
|
||||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||||
cap.rifleAmmo = cap.rifleAmmo - 1;
|
cap.rifleAmmo = cap.rifleAmmo - 1;
|
||||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||||
|
|
Loading…
Add table
Reference in a new issue