重构枪械NBT存储
This commit is contained in:
parent
5d3f0639ab
commit
10a807adf2
75 changed files with 1365 additions and 862 deletions
|
@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
|||
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.network.message.send.*;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -164,9 +165,10 @@ public class ClickHandler {
|
|||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "CanSwitchScope")) {
|
||||
var data = GunData.from(stack);
|
||||
if (data.canSwitchScope()) {
|
||||
PacketDistributor.sendToServer(new SwitchScopeMessage(scroll));
|
||||
} else if (tag.getBoolean("CanAdjustZoomFov") || stack.is(ModItems.MINIGUN.get())) {
|
||||
} else if (data.canAdjustZoom() || stack.is(ModItems.MINIGUN.get())) {
|
||||
PacketDistributor.sendToServer(new AdjustZoomFovMessage(scroll));
|
||||
}
|
||||
event.setCanceled(true);
|
||||
|
@ -210,7 +212,7 @@ public class ClickHandler {
|
|||
// }
|
||||
|
||||
if (key == ModKeyMappings.RELOAD.getKey().getValue()) {
|
||||
ClientEventHandler.burstFireSize = 0;
|
||||
ClientEventHandler.burstFireAmount = 0;
|
||||
PacketDistributor.sendToServer(new ReloadMessage(0));
|
||||
}
|
||||
if (key == ModKeyMappings.FIRE_MODE.getKey().getValue()) {
|
||||
|
@ -222,7 +224,7 @@ public class ClickHandler {
|
|||
if (key == ModKeyMappings.DISMOUNT.getKey().getValue()) {
|
||||
handleDismountPress(player);
|
||||
}
|
||||
if (key == ModKeyMappings.EDIT_MODE.getKey().getValue() && ClientEventHandler.burstFireSize == 0) {
|
||||
if (key == ModKeyMappings.EDIT_MODE.getKey().getValue() && ClientEventHandler.burstFireAmount == 0) {
|
||||
ClientEventHandler.holdFire = false;
|
||||
PacketDistributor.sendToServer(new EditModeMessage(0));
|
||||
}
|
||||
|
@ -325,42 +327,31 @@ public class ClickHandler {
|
|||
ClientEventHandler.holdFire = true;
|
||||
}
|
||||
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (stack.getItem() instanceof GunItem gunItem && !(player.getVehicle() != null
|
||||
&& player.getVehicle() instanceof CannonEntity) && clientTimer.getProgress() == 0 && cantFireTime == 0
|
||||
&& (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction"))
|
||||
&& player.getVehicle() instanceof CannonEntity)
|
||||
&& clientTimer.getProgress() == 0
|
||||
&& cantFireTime == 0
|
||||
&& drawTime < 0.01
|
||||
&& !notInGame()
|
||||
) {
|
||||
if ((!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction"))
|
||||
&& cantFireTime == 0
|
||||
&& drawTime < 0.01
|
||||
&& !notInGame()) {
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
|
||||
}
|
||||
|
||||
if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(tag, "Ammo") <= 0 && GunsTool.getGunIntTag(tag, "ReloadTime") == 0) {
|
||||
if (!gunItem.useBackpackAmmo(stack) && data.getAmmo() <= 0 && GunsTool.getGunIntTag(tag, "ReloadTime") == 0) {
|
||||
if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {
|
||||
PacketDistributor.sendToServer(new ReloadMessage(0));
|
||||
ClientEventHandler.burstFireSize = 0;
|
||||
ClientEventHandler.burstFireAmount = 0;
|
||||
}
|
||||
} else {
|
||||
PacketDistributor.sendToServer(new FireMessage(0));
|
||||
if ((!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
if ((!(data.normalReloading() || data.emptyReloading())
|
||||
&& !data.isReloading()
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction"))
|
||||
&& drawTime < 0.01) {
|
||||
if (GunsTool.getGunIntTag(tag, "FireMode") == 1) {
|
||||
if (ClientEventHandler.burstFireSize == 0) {
|
||||
ClientEventHandler.burstFireSize = GunsTool.getGunIntTag(tag, "BurstSize");
|
||||
if (data.getFireMode() == 1) {
|
||||
if (ClientEventHandler.burstFireAmount == 0) {
|
||||
ClientEventHandler.burstFireAmount = data.burstAmount();
|
||||
}
|
||||
} else {
|
||||
if (!stack.is(ModItems.BOCEK.get())) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
|
@ -14,10 +15,12 @@ public class PoseTool {
|
|||
|
||||
public static HumanoidModel.ArmPose pose(LivingEntity entityLiving, InteractionHand hand, ItemStack stack) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("is_empty_reloading")
|
||||
|| tag.getBoolean("is_normal_reloading")
|
||||
|| GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
|| GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
var data = GunData.from(stack);
|
||||
if (data.emptyReloading()
|
||||
|| data.getReloadState() == GunData.ReloadState.NORMAL_RELOADING
|
||||
|| data.isReloading()
|
||||
|| GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
) {
|
||||
return HumanoidModel.ArmPose.CROSSBOW_CHARGE;
|
||||
} else if (entityLiving.isSprinting() && entityLiving.onGround() && entityLiving.getPersistentData().getDouble("noRun") == 0) {
|
||||
return HumanoidModel.ArmPose.CROSSBOW_CHARGE;
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.sniper.K98Item;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
|
@ -44,7 +45,8 @@ public class K98ItemModel extends GeoModel<K98Item> {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
if (NBTTool.getTag(stack).getDouble("prepare") > 11 && GunsTool.getGunIntTag(tag, "Ammo") == 1) {
|
||||
clip.setScaleX(0);
|
||||
clip.setScaleY(0);
|
||||
|
@ -108,7 +110,7 @@ public class K98ItemModel extends GeoModel<K98Item> {
|
|||
float numR = (float) (1 - 0.52 * zt);
|
||||
float numP = (float) (1 - 0.58 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || data.isReloading()) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -4,9 +4,8 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.shotgun.M870Item;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -100,8 +99,7 @@ public class M870ItemModel extends GeoModel<M870Item> {
|
|||
float numR = (float) (1 - 0.72 * zt);
|
||||
float numP = (float) (1 - 0.82 * zt);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (GunData.from(stack).isReloading()) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -4,8 +4,8 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.rifle.MarlinItem;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -101,8 +101,7 @@ public class MarlinItemModel extends GeoModel<MarlinItem> {
|
|||
float numR = (float) (1 - 0.55 * zt);
|
||||
float numP = (float) (1 - 0.88 * zt);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (GunData.from(stack).isReloading()) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -4,9 +4,8 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.machinegun.MinigunItem;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -59,8 +58,7 @@ public class MinigunItemModel extends GeoModel<MinigunItem> {
|
|||
double fp = ClientEventHandler.firePos;
|
||||
double fr = ClientEventHandler.fireRot;
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int rpm = GunsTool.getGunIntTag(tag, "RPM");
|
||||
int rpm = GunData.from(stack).rpm();
|
||||
|
||||
gun.setRotZ(gun.getRotZ() + times * -0.07f * ((float) rpm / 1200) * ClientEventHandler.miniGunRot);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.sniper.MosinNagantItem;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
|
@ -86,7 +87,8 @@ public class MosinNagantItemModel extends GeoModel<MosinNagantItem> {
|
|||
qiangshen.setScaleZ(1);
|
||||
}
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.4));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
|
@ -124,7 +126,7 @@ public class MosinNagantItemModel extends GeoModel<MosinNagantItem> {
|
|||
float numR = (float) (1 - 0.97 * zt);
|
||||
float numP = (float) (1 - 0.81 * zt);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading") || GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
if (data.isReloading() || GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.rifle.Qbz95Item;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
|
@ -203,7 +204,7 @@ public class Qbz95ItemModel extends GeoModel<Qbz95Item> {
|
|||
lHandRotZ = Mth.lerp(1.5f * times, lHandRotZ, isZooming ? 2.9228f : leftHand.getRotZ());
|
||||
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
leftHand.setPosX(lHandPosX);
|
||||
leftHand.setPosY(lHandPosY);
|
||||
leftHand.setPosZ(lHandPosZ);
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
|
|||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.handgun.Trachelium;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
|
@ -163,7 +164,7 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
|
|||
ammo.setRotZ(60 * Mth.DEG_TO_RAD * (float) ClientEventHandler.revolverWheelPreTime);
|
||||
ammohole.setRotZ(-60 * Mth.DEG_TO_RAD * (float) ClientEventHandler.revolverWheelPreTime);
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
lun.setRotZ(0);
|
||||
ammo.setRotZ(0);
|
||||
ammohole.setRotZ(0);
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
|||
import com.atsuishio.superbwarfare.init.ModKeyMappings;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
|
@ -21,7 +22,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FastColor;
|
||||
|
@ -64,6 +64,7 @@ public class AmmoBarOverlay {
|
|||
final var tag = NBTTool.getTag(stack);
|
||||
if (stack.getItem() instanceof GunItem gunItem && !(player.getVehicle() instanceof ArmedVehicleEntity vehicle && vehicle.banHand(player))) {
|
||||
PoseStack poseStack = event.getGuiGraphics().pose();
|
||||
var data = GunData.from(stack);
|
||||
|
||||
// 渲染图标
|
||||
event.getGuiGraphics().blit(gunItem.getGunIcon(),
|
||||
|
@ -89,7 +90,7 @@ public class AmmoBarOverlay {
|
|||
}
|
||||
|
||||
// 渲染开火模式
|
||||
ResourceLocation fireMode = getFireMode(tag);
|
||||
ResourceLocation fireMode = getFireMode(data);
|
||||
|
||||
if (stack.getItem() == ModItems.JAVELIN.get()) {
|
||||
fireMode = tag.getBoolean("TopMode") ? TOP : DIR;
|
||||
|
@ -100,7 +101,7 @@ public class AmmoBarOverlay {
|
|||
// 渲染加特林射速
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
GunsTool.getGunIntTag(tag, "RPM") + " RPM",
|
||||
data.rpm() + " RPM",
|
||||
w - 111f,
|
||||
h - 20,
|
||||
0xFFFFFF,
|
||||
|
@ -389,8 +390,8 @@ public class AmmoBarOverlay {
|
|||
poseStack.popPose();
|
||||
}
|
||||
|
||||
private static ResourceLocation getFireMode(CompoundTag tag) {
|
||||
return switch (GunsTool.getGunIntTag(tag, "FireMode")) {
|
||||
private static ResourceLocation getFireMode(GunData data) {
|
||||
return switch (data.getFireMode()) {
|
||||
case 1 -> BURST;
|
||||
case 2 -> AUTO;
|
||||
default -> SEMI;
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
|||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
|
@ -20,12 +19,12 @@ public class ClientBocekImageTooltip extends ClientGunImageTooltip {
|
|||
protected Component getDamageComponent() {
|
||||
boolean slug = false;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(data, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug) {
|
||||
slug = true;
|
||||
}
|
||||
|
||||
double total = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
|
||||
double total = data.damage() * TooltipTool.perkDamage(stack);
|
||||
|
||||
if (slug) {
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
|
|
|
@ -4,16 +4,25 @@ import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
|||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClientCellImageTooltip extends ClientGunImageTooltip {
|
||||
public class ClientCellImageTooltip implements ClientTooltipComponent {
|
||||
|
||||
protected final int width;
|
||||
protected final int height;
|
||||
protected final ItemStack stack;
|
||||
|
||||
public ClientCellImageTooltip(GunImageComponent tooltip) {
|
||||
super(tooltip);
|
||||
this.width = tooltip.width;
|
||||
this.height = tooltip.height;
|
||||
this.stack = tooltip.stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,14 +76,20 @@ public class ClientCellImageTooltip extends ClientGunImageTooltip {
|
|||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
int height = super.getHeight();
|
||||
int height = 20;
|
||||
if (shouldRenderEnergyTooltip()) height -= 10;
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth(@NotNull Font font) {
|
||||
int width = super.getWidth(font);
|
||||
int width;
|
||||
if (Screen.hasShiftDown()) {
|
||||
width = Math.max(this.width, 20);
|
||||
} else {
|
||||
width = 20;
|
||||
}
|
||||
|
||||
if (shouldRenderEnergyTooltip())
|
||||
width = Math.max(width, font.width(getEnergyComponent().getVisualOrderText()) + 10);
|
||||
return width;
|
||||
|
|
|
@ -5,19 +5,27 @@ import com.atsuishio.superbwarfare.item.ChargingStationBlockItem;
|
|||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClientChargingStationImageTooltip extends ClientGunImageTooltip {
|
||||
public class ClientChargingStationImageTooltip implements ClientTooltipComponent {
|
||||
|
||||
protected final int width;
|
||||
protected final int height;
|
||||
protected final ItemStack stack;
|
||||
|
||||
public ClientChargingStationImageTooltip(GunImageComponent tooltip) {
|
||||
super(tooltip);
|
||||
this.width = tooltip.width;
|
||||
this.height = tooltip.height;
|
||||
this.stack = tooltip.stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderImage(@NotNull Font font, int x, int y, GuiGraphics guiGraphics) {
|
||||
guiGraphics.pose().pushPose();
|
||||
|
@ -62,11 +70,14 @@ public class ClientChargingStationImageTooltip extends ClientGunImageTooltip {
|
|||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return super.getHeight() - 10;
|
||||
return Math.max(20, this.height) - 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth(@NotNull Font font) {
|
||||
return Math.max(super.getWidth(font), font.width(getEnergyComponent().getVisualOrderText()) + 10);
|
||||
if (Screen.hasShiftDown()) {
|
||||
return Math.max(this.width, 20);
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ import com.atsuishio.superbwarfare.client.TooltipTool;
|
|||
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
||||
import com.atsuishio.superbwarfare.init.ModKeyMappings;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.Font;
|
||||
|
@ -27,13 +27,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
protected final int width;
|
||||
protected final int height;
|
||||
protected final ItemStack stack;
|
||||
protected final CompoundTag tag;
|
||||
protected final GunData data;
|
||||
|
||||
public ClientGunImageTooltip(GunImageComponent tooltip) {
|
||||
this.width = tooltip.width;
|
||||
this.height = tooltip.height;
|
||||
this.stack = tooltip.stack;
|
||||
this.tag = NBTTool.getTag(stack).copy();
|
||||
this.data = GunData.from(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,7 +65,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
|
||||
protected boolean shouldRenderBypassAndHeadshotTooltip() {
|
||||
return GunsTool.getGunDoubleTag(tag, "BypassesArmor") > 0 || GunsTool.getGunDoubleTag(tag, "Headshot") > 0;
|
||||
return data.bypassArmor() > 0 || data.headshot() > 0;
|
||||
}
|
||||
|
||||
protected boolean shouldRenderEditTooltip() {
|
||||
|
@ -76,7 +76,9 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
|
||||
protected boolean shouldRenderPerks() {
|
||||
return PerkHelper.getPerkByType(tag, Perk.Type.AMMO) != null || PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE) != null || PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL) != null;
|
||||
return PerkHelper.getPerkByType(data, Perk.Type.AMMO) != null
|
||||
|| PerkHelper.getPerkByType(data, Perk.Type.DAMAGE) != null
|
||||
|| PerkHelper.getPerkByType(data, Perk.Type.FUNCTIONAL) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +94,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器伤害的文本组件
|
||||
*/
|
||||
protected Component getDamageComponent() {
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
|
||||
double damage = data.damage() * TooltipTool.perkDamage(stack);
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + "
|
||||
|
@ -106,7 +108,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
if (this.stack.getItem() instanceof GunItem gunItem && gunItem.isAutoWeapon(this.stack)) {
|
||||
return Component.translatable("des.superbwarfare.guns.rpm").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM")))
|
||||
.append(Component.literal(FormatTool.format0D(data.rpm()))
|
||||
.withStyle(ChatFormatting.GREEN));
|
||||
}
|
||||
return Component.literal("");
|
||||
|
@ -125,8 +127,8 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器等级文本组件
|
||||
*/
|
||||
protected Component getLevelComponent() {
|
||||
int level = GunsTool.getGunIntTag(tag, "Level");
|
||||
double rate = GunsTool.getGunDoubleTag(tag, "Exp") / (20 * Math.pow(level, 2) + 160 * level + 20);
|
||||
int level = data.getLevel();
|
||||
double rate = data.getExp() / (20 * Math.pow(level, 2) + 160 * level + 20);
|
||||
|
||||
ChatFormatting formatting;
|
||||
if (level < 10) {
|
||||
|
@ -152,7 +154,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器强化点数文本组件
|
||||
*/
|
||||
protected Component getUpgradePointComponent() {
|
||||
int upgradePoint = Mth.floor(GunsTool.getGunDoubleTag(tag, "UpgradePoint"));
|
||||
int upgradePoint = Mth.floor(data.getUpgradePoint());
|
||||
return Component.translatable("des.superbwarfare.guns.upgrade_point").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(String.valueOf(upgradePoint)).withStyle(ChatFormatting.WHITE).withStyle(ChatFormatting.BOLD));
|
||||
|
@ -172,13 +174,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
*/
|
||||
protected Component getBypassComponent() {
|
||||
double perkBypassArmorRate = 0;
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(data, Perk.Type.AMMO);
|
||||
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, data);
|
||||
perkBypassArmorRate = ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
|
||||
}
|
||||
double bypassRate = Math.max(GunsTool.getGunDoubleTag(tag, "BypassesArmor") + perkBypassArmorRate, 0);
|
||||
double bypassRate = Math.max(data.bypassArmor() + perkBypassArmorRate, 0);
|
||||
|
||||
return Component.translatable("des.superbwarfare.guns.bypass").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
@ -189,7 +191,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器爆头倍率文本组件
|
||||
*/
|
||||
protected Component getHeadshotComponent() {
|
||||
double headshot = GunsTool.getGunDoubleTag(tag, "Headshot");
|
||||
double headshot = data.headshot();
|
||||
return Component.translatable("des.superbwarfare.guns.headshot").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(FormatTool.format1D(headshot, "x")).withStyle(ChatFormatting.AQUA));
|
||||
|
@ -218,32 +220,32 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
|
||||
int xOffset = -20;
|
||||
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(data, Perk.Type.AMMO);
|
||||
if (ammoPerk != null && PerkHelper.getPerkItem(ammoPerk).isPresent()) {
|
||||
xOffset += 20;
|
||||
|
||||
var ammoItem = PerkHelper.getPerkItem(ammoPerk).get().get();
|
||||
ItemStack perkStack = ammoItem.getDefaultInstance();
|
||||
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(tag, Perk.Type.AMMO);
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(data, Perk.Type.AMMO);
|
||||
if (!ammoTag.isEmpty()) {
|
||||
int level = PerkHelper.getItemPerkLevel(ammoPerk, tag);
|
||||
int level = PerkHelper.getItemPerkLevel(ammoPerk, data);
|
||||
perkStack.setCount(level);
|
||||
}
|
||||
guiGraphics.renderItem(perkStack, x + xOffset, y + 2);
|
||||
guiGraphics.renderItemDecorations(font, perkStack, x + xOffset, y + 2);
|
||||
}
|
||||
|
||||
Perk funcPerk = PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL);
|
||||
Perk funcPerk = PerkHelper.getPerkByType(data, Perk.Type.FUNCTIONAL);
|
||||
if (funcPerk != null && PerkHelper.getPerkItem(funcPerk).isPresent()) {
|
||||
xOffset += 20;
|
||||
|
||||
var funcItem = PerkHelper.getPerkItem(funcPerk).get().get();
|
||||
ItemStack perkStack = funcItem.getDefaultInstance();
|
||||
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(tag, Perk.Type.FUNCTIONAL);
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(data, Perk.Type.FUNCTIONAL);
|
||||
if (!funcTag.isEmpty()) {
|
||||
int level = PerkHelper.getItemPerkLevel(funcPerk, tag);
|
||||
int level = PerkHelper.getItemPerkLevel(funcPerk, data);
|
||||
perkStack.setCount(level);
|
||||
}
|
||||
|
||||
|
@ -251,16 +253,16 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
guiGraphics.renderItemDecorations(font, perkStack, x + xOffset, y + 2);
|
||||
}
|
||||
|
||||
Perk damagePerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
Perk damagePerk = PerkHelper.getPerkByType(data, Perk.Type.DAMAGE);
|
||||
if (damagePerk != null && PerkHelper.getPerkItem(damagePerk).isPresent()) {
|
||||
xOffset += 20;
|
||||
|
||||
var damageItem = PerkHelper.getPerkItem(damagePerk).get().get();
|
||||
ItemStack perkStack = damageItem.getDefaultInstance();
|
||||
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(tag, Perk.Type.DAMAGE);
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(data, Perk.Type.DAMAGE);
|
||||
if (!damageTag.isEmpty()) {
|
||||
int level = PerkHelper.getItemPerkLevel(damagePerk, tag);
|
||||
int level = PerkHelper.getItemPerkLevel(damagePerk, data);
|
||||
perkStack.setCount(level);
|
||||
}
|
||||
|
||||
|
@ -281,13 +283,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
|
||||
int yOffset = -5;
|
||||
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(data, Perk.Type.AMMO);
|
||||
if (ammoPerk != null && PerkHelper.getPerkItem(ammoPerk).isPresent()) {
|
||||
yOffset += 25;
|
||||
var ammoItem = PerkHelper.getPerkItem(ammoPerk).get().get();
|
||||
guiGraphics.renderItem(ammoItem.getDefaultInstance(), x, y + 4 + yOffset);
|
||||
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(tag, Perk.Type.AMMO);
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(data, Perk.Type.AMMO);
|
||||
if (!ammoTag.isEmpty()) {
|
||||
var ids = ammoTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -303,13 +305,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
Perk funcPerk = PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL);
|
||||
Perk funcPerk = PerkHelper.getPerkByType(data, Perk.Type.FUNCTIONAL);
|
||||
if (funcPerk != null && PerkHelper.getPerkItem(funcPerk).isPresent()) {
|
||||
yOffset += 25;
|
||||
var funcItem = PerkHelper.getPerkItem(funcPerk).get().get();
|
||||
guiGraphics.renderItem(funcItem.getDefaultInstance(), x, y + 4 + yOffset);
|
||||
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(tag, Perk.Type.FUNCTIONAL);
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(data, Perk.Type.FUNCTIONAL);
|
||||
if (!funcTag.isEmpty()) {
|
||||
var ids = funcTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -325,13 +327,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
Perk damagePerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
Perk damagePerk = PerkHelper.getPerkByType(data, Perk.Type.DAMAGE);
|
||||
if (damagePerk != null && PerkHelper.getPerkItem(damagePerk).isPresent()) {
|
||||
yOffset += 25;
|
||||
var damageItem = PerkHelper.getPerkItem(damagePerk).get().get();
|
||||
guiGraphics.renderItem(damageItem.getDefaultInstance(), x, y + 4 + yOffset);
|
||||
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(tag, Perk.Type.DAMAGE);
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(data, Perk.Type.DAMAGE);
|
||||
if (!damageTag.isEmpty()) {
|
||||
var ids = damageTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -368,7 +370,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
|
||||
int width = 0;
|
||||
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(tag, Perk.Type.AMMO);
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(data, Perk.Type.AMMO);
|
||||
if (!ammoTag.isEmpty()) {
|
||||
var ids = ammoTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -378,7 +380,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(tag, Perk.Type.FUNCTIONAL);
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(data, Perk.Type.FUNCTIONAL);
|
||||
if (!funcTag.isEmpty()) {
|
||||
var ids = funcTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -388,7 +390,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(tag, Perk.Type.DAMAGE);
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(data, Perk.Type.DAMAGE);
|
||||
if (!damageTag.isEmpty()) {
|
||||
var ids = damageTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
|
@ -17,11 +16,11 @@ public class ClientLauncherImageTooltip extends ClientGunImageTooltip {
|
|||
|
||||
@Override
|
||||
protected Component getDamageComponent() {
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
double damage = data.damage() * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), data);
|
||||
if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f;
|
||||
|
||||
double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage");
|
||||
double explosionDamage = data.explosionDamage();
|
||||
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
|
@ -17,11 +16,11 @@ public class ClientSecondaryCataclysmImageTooltip extends ClientEnergyImageToolt
|
|||
|
||||
@Override
|
||||
protected Component getDamageComponent() {
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
double damage = data.damage() * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), data);
|
||||
if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f;
|
||||
|
||||
double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage");
|
||||
double explosionDamage = data.explosionDamage();
|
||||
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
|
|
@ -19,8 +19,7 @@ public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip {
|
|||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
||||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
double damage = (GunsTool.getGunDoubleTag(tag, "Damage") +
|
||||
GunsTool.getGunDoubleTag(tag, "ChargedDamage"))
|
||||
double damage = (data.damage() + GunsTool.getGunDoubleTag(data.getTag(), "ChargedDamage"))
|
||||
* TooltipTool.perkDamage(stack);
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
@ -28,7 +27,7 @@ public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip {
|
|||
FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : ""))
|
||||
.withStyle(ChatFormatting.AQUA).withStyle(ChatFormatting.BOLD));
|
||||
} else {
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
|
||||
double damage = data.damage() * TooltipTool.perkDamage(stack);
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ?
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
|||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
|
@ -20,22 +19,22 @@ public class ClientShotgunImageTooltip extends ClientGunImageTooltip {
|
|||
protected Component getDamageComponent() {
|
||||
boolean slug = false;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(data, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug) {
|
||||
slug = true;
|
||||
}
|
||||
|
||||
if (slug) {
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage") * GunsTool.getGunIntTag(tag, "ProjectileAmount") * TooltipTool.perkDamage(stack);
|
||||
double damage = data.damage() * data.projectileAmount() * TooltipTool.perkDamage(stack);
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " +
|
||||
FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN));
|
||||
} else {
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
|
||||
double damage = data.damage() * TooltipTool.perkDamage(stack);
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal(FormatTool.format1D(damage) + " * " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "ProjectileAmount"))).withStyle(ChatFormatting.GREEN));
|
||||
.append(Component.literal(FormatTool.format1D(damage) + " * " + FormatTool.format0D(data.projectileAmount())).withStyle(ChatFormatting.GREEN));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
|||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.network.message.send.*;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
|
@ -125,7 +126,7 @@ public class ClientEventHandler {
|
|||
public static boolean holdFireVehicle = false;
|
||||
|
||||
public static boolean zoomVehicle = false;
|
||||
public static int burstFireSize = 0;
|
||||
public static int burstFireAmount = 0;
|
||||
|
||||
public static int customRpm = 0;
|
||||
|
||||
|
@ -219,9 +220,10 @@ public class ClientEventHandler {
|
|||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var data = GunData.from(stack);
|
||||
if (holdFire || zoom) {
|
||||
miniGunRot = Math.min(miniGunRot + 5, 21);
|
||||
float rpm = (float) GunsTool.getGunIntTag(tag, "RPM") / 3600;
|
||||
float rpm = (float) data.rpm() / 3600;
|
||||
player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 0.7f + rpm);
|
||||
}
|
||||
}
|
||||
|
@ -301,6 +303,7 @@ public class ClientEventHandler {
|
|||
|
||||
public static void handleGunMelee(Player player, ItemStack stack, final CompoundTag tag) {
|
||||
if (stack.getItem() instanceof GunItem gunItem) {
|
||||
var data = GunData.from(stack);
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (gunItem.hasMeleeAttack(stack) && gunMelee == 0 && drawTime < 0.01
|
||||
&& ModKeyMappings.MELEE.isDown()
|
||||
|
@ -308,8 +311,8 @@ public class ClientEventHandler {
|
|||
&& !holdFireVehicle
|
||||
&& !notInGame()
|
||||
&& cap != null && !cap.edit
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !(data.normalReloading() || data.emptyReloading())
|
||||
&& !data.isReloading()
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
gunMelee = 36;
|
||||
|
@ -390,16 +393,16 @@ public class ClientEventHandler {
|
|||
gunSpread = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
int mode = data.getFireMode();
|
||||
|
||||
// 精准度
|
||||
float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
|
||||
|
||||
double basicDev = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
double basicDev = data.spread();
|
||||
double walk = isMoving() ? 0.3 * basicDev : 0;
|
||||
double sprint = player.isSprinting() ? 0.25 * basicDev : 0;
|
||||
double crouching = player.isCrouching() ? -0.15 * basicDev : 0;
|
||||
|
@ -428,7 +431,7 @@ public class ClientEventHandler {
|
|||
gunSpread = Mth.lerp(0.14 * times, gunSpread, spread);
|
||||
|
||||
// 开火部分
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
double weight = data.weight();
|
||||
double speed = 1 - (0.04 * weight);
|
||||
|
||||
if (player.getPersistentData().getDouble("noRun") == 0 && player.isSprinting() && !zoom) {
|
||||
|
@ -437,7 +440,7 @@ public class ClientEventHandler {
|
|||
cantFireTime = Mth.clamp(cantFireTime - 6 * speed * times, 0, 40);
|
||||
}
|
||||
|
||||
int rpm = GunsTool.getGunIntTag(tag, "RPM") + customRpm;
|
||||
int rpm = data.rpm() + customRpm;
|
||||
if (rpm == 0) {
|
||||
rpm = 600;
|
||||
}
|
||||
|
@ -463,7 +466,7 @@ public class ClientEventHandler {
|
|||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
||||
if ((holdFire || burstFireSize > 0)
|
||||
if ((holdFire || burstFireAmount > 0)
|
||||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
&& !holdFireVehicle
|
||||
&& (stack.is(ModTags.Items.NORMAL_GUN)
|
||||
|
@ -471,10 +474,10 @@ public class ClientEventHandler {
|
|||
&& drawTime < 0.01
|
||||
&& cap != null && !cap.edit
|
||||
&& !notInGame()
|
||||
&& (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& (!(data.normalReloading() || data.emptyReloading())
|
||||
&& !data.isReloading()
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo") > 0
|
||||
&& data.getAmmo() > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction")
|
||||
&& revolverPre(tag))
|
||||
|
@ -519,7 +522,7 @@ public class ClientEventHandler {
|
|||
clientTimer.stop();
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.DEVOTION.get() && (tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))) {
|
||||
if (stack.getItem() == ModItems.DEVOTION.get() && (data.normalReloading() || data.emptyReloading())) {
|
||||
customRpm = 0;
|
||||
}
|
||||
}
|
||||
|
@ -547,24 +550,25 @@ public class ClientEventHandler {
|
|||
|
||||
public static void shootClient(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var data = GunData.from(stack);
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") > 0) {
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
if (data.getAmmo() > 0) {
|
||||
int mode = data.getFireMode();
|
||||
if (mode != 2) {
|
||||
holdFire = false;
|
||||
}
|
||||
|
||||
if (mode == 1) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") == 1) {
|
||||
burstFireSize = 1;
|
||||
if (data.getAmmo() == 1) {
|
||||
burstFireAmount = 1;
|
||||
}
|
||||
if (burstFireSize == 1) {
|
||||
if (burstFireAmount == 1) {
|
||||
cantFireTime = 30;
|
||||
}
|
||||
}
|
||||
|
||||
if (burstFireSize > 0) {
|
||||
burstFireSize--;
|
||||
if (burstFireAmount > 0) {
|
||||
burstFireAmount--;
|
||||
}
|
||||
|
||||
if (stack.is(ModItems.DEVOTION.get())) {
|
||||
|
@ -581,7 +585,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0 && GunsTool.getGunIntTag(tag, "Ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
if (data.boltActionTime() > 0 && data.getAmmo() > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
|
||||
}
|
||||
|
||||
|
@ -623,11 +627,12 @@ public class ClientEventHandler {
|
|||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
PacketDistributor.sendToServer(new ShootMessage(gunSpread));
|
||||
fireRecoilTime = 10;
|
||||
|
||||
float gunRecoilY = (float) GunsTool.getGunDoubleTag(tag, "RecoilY") * 10;
|
||||
var gunRecoilY = data.recoilY() * 10;
|
||||
|
||||
recoilY = (float) (2 * Math.random() - 1) * gunRecoilY;
|
||||
|
||||
|
@ -840,7 +845,8 @@ public class ClientEventHandler {
|
|||
default -> 0.8;
|
||||
};
|
||||
|
||||
double customWeight = GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
var data = GunData.from(stack);
|
||||
double customWeight = data.customWeight();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
|
||||
|
@ -1058,10 +1064,12 @@ public class ClientEventHandler {
|
|||
|
||||
private static void handleWeaponZoom(LivingEntity entity) {
|
||||
if (!(entity instanceof Player player)) return;
|
||||
final var tag = NBTTool.getTag(player.getMainHandItem());
|
||||
var stack = player.getMainHandItem();
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
float times = 5 * Minecraft.getInstance().getTimer().getRealtimeDeltaTicks();
|
||||
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
double weight = data.weight();
|
||||
double speed = 1.5 - (0.07 * weight);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -1091,7 +1099,8 @@ public class ClientEventHandler {
|
|||
float roll = event.getRoll();
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
|
||||
double amplitude = 15000 * GunsTool.getGunDoubleTag(tag, "RecoilY") * GunsTool.getGunDoubleTag(tag, "RecoilX");
|
||||
var data = GunData.from(stack);
|
||||
double amplitude = 15000 * data.recoilY() * data.recoilX();
|
||||
|
||||
if (fireRecoilTime > 0) {
|
||||
firePosTimer = 0.001;
|
||||
|
@ -1126,7 +1135,7 @@ public class ClientEventHandler {
|
|||
double rpm = 1;
|
||||
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
rpm = (double) GunsTool.getGunIntTag(tag, "RPM") / 1800;
|
||||
rpm = (double) data.rpm() / 1800;
|
||||
}
|
||||
|
||||
float[] shake = {0, 0};
|
||||
|
@ -1210,15 +1219,16 @@ public class ClientEventHandler {
|
|||
gripRecoilY = 1.25;
|
||||
}
|
||||
|
||||
double customWeight = GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
var data = GunData.from(stack);
|
||||
double customWeight = data.customWeight();
|
||||
|
||||
double rpm = 1;
|
||||
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
rpm = (double) GunsTool.getGunIntTag(tag, "RPM") / 1800;
|
||||
rpm = (double) data.rpm() / 1800;
|
||||
}
|
||||
|
||||
float gunRecoilX = (float) GunsTool.getGunDoubleTag(tag, "RecoilX") * 60;
|
||||
float gunRecoilX = (float) data.recoilX() * 60;
|
||||
|
||||
recoilHorizon = Mth.lerp(0.2 * times, recoilHorizon, 0) + recoilY;
|
||||
recoilY = 0;
|
||||
|
@ -1512,13 +1522,14 @@ public class ClientEventHandler {
|
|||
lungeDraw = 30;
|
||||
lungeSprint = 0;
|
||||
lungeAttack = 0;
|
||||
burstFireSize = 0;
|
||||
burstFireAmount = 0;
|
||||
}
|
||||
|
||||
private static void handleWeaponDraw(LivingEntity entity, final CompoundTag tag) {
|
||||
float times = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks();
|
||||
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
var data = GunData.from(stack);
|
||||
double weight = data.weight();
|
||||
double speed = 3.2 - (0.13 * weight);
|
||||
drawTime = Math.max(drawTime - Math.max(0.2 * speed * times * drawTime, 0.0008), 0);
|
||||
}
|
||||
|
|
|
@ -9,11 +9,15 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.*;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -41,25 +45,27 @@ public class GunEventHandler {
|
|||
Player player = event.getEntity();
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
handleGunBolt(player, tag);
|
||||
handleGunReload(player, tag);
|
||||
handleGunSingleReload(player, tag);
|
||||
handleSentinelCharge(player, tag);
|
||||
var data = GunData.from(stack);
|
||||
handleGunBolt(player, data.reload());
|
||||
handleGunReload(player, data.reload());
|
||||
handleGunSingleReload(player, data.reload());
|
||||
handleSentinelCharge(player, data.reload());
|
||||
data.save();
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉大栓
|
||||
*/
|
||||
private static void handleGunBolt(Player player, final CompoundTag tag) {
|
||||
private static void handleGunBolt(Player player, GunData gunData) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
var tag = gunData.getTag();
|
||||
var data = tag.getCompound("GunData");
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
data.putInt("BoltActionTick", GunsTool.getGunIntTag(tag, "BoltActionTick") - 1);
|
||||
}
|
||||
|
@ -75,6 +81,7 @@ public class GunEventHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
gunData.save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +90,8 @@ public class GunEventHandler {
|
|||
public static void playGunSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -93,7 +101,7 @@ public class GunEventHandler {
|
|||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
||||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
float soundRadius = (float) GunsTool.getGunDoubleTag(tag, "SoundRadius");
|
||||
float soundRadius = (float) data.soundRadius();
|
||||
|
||||
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc("sentinel_charge_fire_3p"));
|
||||
if (sound3p != null) {
|
||||
|
@ -118,7 +126,7 @@ public class GunEventHandler {
|
|||
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
||||
}
|
||||
|
||||
float soundRadius = (float) (GunsTool.getGunDoubleTag(tag, "SoundRadius") * GunsTool.getGunDoubleTag(tag, "CustomSoundRadius"));
|
||||
float soundRadius = (float) data.soundRadius();
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
|
||||
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
|
||||
|
@ -141,7 +149,7 @@ public class GunEventHandler {
|
|||
public static void playGunBoltSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -156,7 +164,7 @@ public class GunEventHandler {
|
|||
|
||||
if (stack.is(ModTags.Items.REVOLVER)) return;
|
||||
|
||||
Mod.queueServerWork((int) (GunsTool.getGunDoubleTag(tag, "BoltActionTime") / 2 + 1.5 * shooterHeight), () -> {
|
||||
Mod.queueServerWork((int) (data.boltActionTime() / 2 + 1.5 * shooterHeight), () -> {
|
||||
if (stack.is(ModTags.Items.SHOTGUN)) {
|
||||
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)) {
|
||||
|
@ -171,18 +179,17 @@ public class GunEventHandler {
|
|||
|
||||
public static void gunShoot(Player player, final CompoundTag tag, double spared) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var data = GunData.from(stack);
|
||||
|
||||
if (!player.level().isClientSide()) {
|
||||
float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot");
|
||||
float damage = (float) (GunsTool.getGunDoubleTag(tag, "Damage") +
|
||||
float headshot = (float) data.headshot();
|
||||
float damage = (float) (data.damage() +
|
||||
GunsTool.getGunDoubleTag(tag, "ChargedDamage")) * (float) perkDamage(tag);
|
||||
float velocity = (float) ((GunsTool.getGunDoubleTag(tag, "Velocity") + GunsTool.getGunDoubleTag(tag, "CustomVelocity")) * perkSpeed(tag));
|
||||
int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount");
|
||||
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor");
|
||||
|
||||
float velocity = (float) ((data.velocity() + GunsTool.getGunDoubleTag(tag, "CustomVelocity")) * perkSpeed(tag));
|
||||
int projectileAmount = data.projectileAmount();
|
||||
float bypassArmorRate = (float) data.bypassArmor();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
if (perk != null && perk.descriptionId.equals("butterfly_bullet")) {
|
||||
|
@ -309,28 +316,30 @@ public class GunEventHandler {
|
|||
/**
|
||||
* 通用的武器换弹流程
|
||||
*/
|
||||
private static void handleGunReload(Player player, final CompoundTag tag) {
|
||||
private static void handleGunReload(Player player, GunData gunData) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
final CompoundTag data = tag.getCompound("GunData");
|
||||
var tag = gunData.getTag();
|
||||
var data = gunData.getData();
|
||||
|
||||
// 启动换弹
|
||||
if (GunsTool.getGunBooleanTag(tag, "StartReload")) {
|
||||
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
||||
if (gunItem.isOpenBolt(stack)) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
data.putInt("ReloadTime", data.getInt("EmptyReloadTime") + 1);
|
||||
tag.putBoolean("is_empty_reloading", true);
|
||||
if (gunData.getAmmo() == 0) {
|
||||
data.putInt("ReloadTime", gunData.emptyReloadTime() + 1);
|
||||
gunData.setReloadState(GunData.ReloadState.EMPTY_RELOADING);
|
||||
playGunEmptyReloadSounds(player);
|
||||
} else {
|
||||
data.putInt("ReloadTime", data.getInt("NormalReloadTime") + 1);
|
||||
tag.putBoolean("is_normal_reloading", true);
|
||||
data.putInt("ReloadTime", gunData.normalReloadTime() + 1);
|
||||
gunData.setReloadState(GunData.ReloadState.NORMAL_RELOADING);
|
||||
playGunNormalReloadSounds(player);
|
||||
}
|
||||
} else {
|
||||
data.putInt("ReloadTime", data.getInt("EmptyReloadTime") + 2);
|
||||
tag.putBoolean("is_empty_reloading", true);
|
||||
data.putInt("ReloadTime", gunData.emptyReloadTime() + 2);
|
||||
gunData.setReloadState(GunData.ReloadState.EMPTY_RELOADING);
|
||||
playGunEmptyReloadSounds(player);
|
||||
}
|
||||
data.putBoolean("StartReload", false);
|
||||
|
@ -349,119 +358,105 @@ public class GunEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.MK_14.get()) {
|
||||
if (data.getInt("ReloadTime") == 18) {
|
||||
if (stack.getItem() == ModItems.MK_14.get() && data.getInt("ReloadTime") == 18) {
|
||||
data.putBoolean("HoldOpen", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.SVD.get()) {
|
||||
if (data.getInt("ReloadTime") == 17) {
|
||||
if (stack.getItem() == ModItems.SVD.get() && data.getInt("ReloadTime") == 17) {
|
||||
data.putBoolean("HoldOpen", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.SKS.get()) {
|
||||
if (data.getInt("ReloadTime") == 14) {
|
||||
if (stack.getItem() == ModItems.SKS.get() && data.getInt("ReloadTime") == 14) {
|
||||
data.putBoolean("HoldOpen", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.M_60.get()) {
|
||||
if (data.getInt("ReloadTime") == 55) {
|
||||
if (stack.getItem() == ModItems.M_60.get() && data.getInt("ReloadTime") == 55) {
|
||||
data.putBoolean("HideBulletChain", false);
|
||||
}
|
||||
}
|
||||
|
||||
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 (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 (data.getInt("ReloadTime") == 9) {
|
||||
data.putBoolean("HoldOpen", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.QBZ_95.get()) {
|
||||
if (data.getInt("ReloadTime") == 14) {
|
||||
if (stack.getItem() == ModItems.QBZ_95.get() && data.getInt("ReloadTime") == 14) {
|
||||
data.putBoolean("HoldOpen", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.getInt("ReloadTime") == 1) {
|
||||
if (gunItem.isOpenBolt(stack)) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
playGunEmptyReload(player, tag);
|
||||
if (gunData.getAmmo() == 0) {
|
||||
playGunEmptyReload(player, gunData);
|
||||
} else {
|
||||
playGunNormalReload(player, tag);
|
||||
playGunNormalReload(player, gunData);
|
||||
}
|
||||
} else {
|
||||
playGunEmptyReload(player, tag);
|
||||
playGunEmptyReload(player, gunData);
|
||||
}
|
||||
data.putBoolean("StartReload", false);
|
||||
}
|
||||
|
||||
tag.put("GunData", data);
|
||||
gunData.save();
|
||||
}
|
||||
|
||||
public static void playGunNormalReload(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
public static void playGunNormalReload(Player player, GunData gunData) {
|
||||
var stack = gunData.getStack();
|
||||
var gunItem = gunData.getItem();
|
||||
|
||||
if (player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putInt("Ammo", data.getInt("Magazine") + data.getInt("CustomMagazine") + (gunItem.hasBulletInBarrel(stack) ? 1 : 0));
|
||||
gunData.setAmmo(gunData.magazine() + (gunItem.hasBulletInBarrel(stack) ? 1 : 0));
|
||||
} else {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SHOTGUN, gunItem.hasBulletInBarrel(stack));
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.SHOTGUN, gunItem.hasBulletInBarrel(stack));
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SNIPER, true);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.SNIPER, true);
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HANDGUN, true);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.HANDGUN, true);
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.RIFLE, gunItem.hasBulletInBarrel(stack));
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.RIFLE, gunItem.hasBulletInBarrel(stack));
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HEAVY, gunItem.hasBulletInBarrel(stack));
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.HEAVY, gunItem.hasBulletInBarrel(stack));
|
||||
}
|
||||
}
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
gunData.setReloadState(GunData.ReloadState.NOT_RELOADING);
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||
}
|
||||
|
||||
public static void playGunEmptyReload(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var data = tag.getCompound("GunData");
|
||||
public static void playGunEmptyReload(Player player, GunData gunData) {
|
||||
ItemStack stack = gunData.getStack();
|
||||
|
||||
if (player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
data.putInt("Ammo", data.getInt("Magazine") + data.getInt("CustomMagazine"));
|
||||
gunData.setAmmo(gunData.magazine());
|
||||
} else {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SHOTGUN);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.SHOTGUN);
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SNIPER);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.SNIPER);
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HANDGUN);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.HANDGUN);
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.RIFLE);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.RIFLE);
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HEAVY);
|
||||
GunsTool.reload(player, stack, gunData.reload(), AmmoType.HEAVY);
|
||||
} else if (stack.getItem() == ModItems.TASER.get()) {
|
||||
data.putInt("Ammo", 1);
|
||||
gunData.setAmmo(1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
} else if (stack.getItem() == ModItems.M_79.get()) {
|
||||
data.putInt("Ammo", 1);
|
||||
gunData.setAmmo(1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
} else if (stack.getItem() == ModItems.RPG.get()) {
|
||||
data.putInt("Ammo", 1);
|
||||
gunData.setAmmo(1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
} else if (stack.getItem() == ModItems.JAVELIN.get()) {
|
||||
data.putInt("Ammo", 1);
|
||||
gunData.setAmmo(1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
}
|
||||
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
gunData.setReloadState(GunData.ReloadState.NOT_RELOADING);
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||
}
|
||||
|
||||
|
@ -504,9 +499,10 @@ public class GunEventHandler {
|
|||
/**
|
||||
* 单发装填类的武器换弹流程
|
||||
*/
|
||||
private static void handleGunSingleReload(Player player, final CompoundTag tag) {
|
||||
private static void handleGunSingleReload(Player player, GunData gunData) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
var tag = gunData.getTag();
|
||||
|
||||
// 换弹流程计时器
|
||||
if (tag.getDouble("prepare") > 0) {
|
||||
|
@ -533,41 +529,38 @@ public class GunEventHandler {
|
|||
if (tag.getBoolean("start_single_reload")) {
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
||||
|
||||
if ((GunsTool.getGunIntTag(tag, "PrepareLoadTime") != 0
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo") == 0)
|
||||
|| stack.is(ModItems.SECONDARY_CATACLYSM.get())
|
||||
) {
|
||||
if ((gunData.prepareLoadTime() != 0 && gunData.getAmmo() == 0) || stack.is(ModItems.SECONDARY_CATACLYSM.get())) {
|
||||
// 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
||||
playGunPrepareLoadReloadSounds(player);
|
||||
int prepareLoadTime = GunsTool.getGunIntTag(tag, "PrepareLoadTime");
|
||||
int prepareLoadTime = gunData.prepareLoadTime();
|
||||
tag.putInt("prepare_load", prepareLoadTime + 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime);
|
||||
} else if (GunsTool.getGunIntTag(tag, "PrepareEmptyTime") != 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
} else if (gunData.prepareEmptyTime() != 0 && gunData.getAmmo() == 0) {
|
||||
// 此处判断空仓换弹,如莫辛纳甘
|
||||
playGunEmptyPrepareSounds(player);
|
||||
int prepareEmptyTime = GunsTool.getGunIntTag(tag, "PrepareEmptyTime");
|
||||
int prepareEmptyTime = gunData.prepareEmptyTime();
|
||||
tag.putInt("prepare", prepareEmptyTime + 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime);
|
||||
} else {
|
||||
playGunPrepareReloadSounds(player);
|
||||
int prepareTime = GunsTool.getGunIntTag(tag, "PrepareTime");
|
||||
int prepareTime = gunData.prepareTime();
|
||||
tag.putInt("prepare", prepareTime + 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), prepareTime);
|
||||
}
|
||||
|
||||
tag.putBoolean("force_stop", false);
|
||||
tag.putBoolean("stop", false);
|
||||
tag.putInt("reload_stage", 1);
|
||||
GunsTool.setGunBooleanTag(tag, "Reloading", true);
|
||||
gunData.setReloadStage(1);
|
||||
gunData.setReloadState(GunData.ReloadState.NORMAL_RELOADING);
|
||||
tag.putBoolean("start_single_reload", false);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.M_870.get() && tag.getInt("prepare_load") == 10) {
|
||||
singleLoad(player, tag);
|
||||
singleLoad(player, gunData);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("prepare_load") == 3) {
|
||||
singleLoad(player, tag);
|
||||
singleLoad(player, gunData);
|
||||
}
|
||||
|
||||
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
||||
|
@ -588,13 +581,13 @@ public class GunEventHandler {
|
|||
tag.putBoolean("force_stage3_start", true);
|
||||
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
|
||||
tag.putBoolean("force_stage3_start", true);
|
||||
} else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo") >= GunsTool.getGunIntTag(tag, "Magazine")) {
|
||||
} else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && gunData.getAmmo() >= gunData.magazine()) {
|
||||
tag.putBoolean("force_stage3_start", true);
|
||||
} else {
|
||||
tag.putInt("reload_stage", 2);
|
||||
}
|
||||
} else {
|
||||
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo") >= GunsTool.getGunIntTag(tag, "Magazine")) {
|
||||
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && gunData.getAmmo() >= gunData.magazine()) {
|
||||
tag.putBoolean("force_stage3_start", true);
|
||||
} else {
|
||||
tag.putInt("reload_stage", 2);
|
||||
|
@ -613,11 +606,11 @@ public class GunEventHandler {
|
|||
&& tag.getInt("reload_stage") == 2
|
||||
&& tag.getInt("iterative") == 0
|
||||
&& !tag.getBoolean("stop")
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo") < GunsTool.getGunIntTag(tag, "Magazine")
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine")) {
|
||||
&& gunData.getAmmo() < gunData.magazine()
|
||||
) {
|
||||
|
||||
playGunLoopReloadSounds(player);
|
||||
int iterativeTime = GunsTool.getGunIntTag(tag, "IterativeTime");
|
||||
int iterativeTime = gunData.iterativeTime();
|
||||
tag.putDouble("iterative", iterativeTime);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), iterativeTime);
|
||||
// 动画播放nbt
|
||||
|
@ -633,25 +626,24 @@ public class GunEventHandler {
|
|||
|| stack.getItem() == ModItems.MARLIN.get())
|
||||
&& tag.getInt("iterative") == 3
|
||||
) {
|
||||
singleLoad(player, tag);
|
||||
singleLoad(player, gunData);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("iterative") == 16) {
|
||||
singleLoad(player, tag);
|
||||
singleLoad(player, gunData);
|
||||
}
|
||||
|
||||
if ((stack.getItem() == ModItems.K_98.get()
|
||||
|| stack.getItem() == ModItems.MOSIN_NAGANT.get())
|
||||
&& tag.getInt("iterative") == 1
|
||||
) {
|
||||
singleLoad(player, tag);
|
||||
singleLoad(player, gunData);
|
||||
}
|
||||
|
||||
// 二阶段结束
|
||||
if (tag.getInt("iterative") == 1) {
|
||||
// 装满结束
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") >= GunsTool.getGunIntTag(tag, "Magazine")
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine")) {
|
||||
if (gunData.getAmmo() >= gunData.magazine()) {
|
||||
tag.putInt("reload_stage", 3);
|
||||
}
|
||||
|
||||
|
@ -685,7 +677,7 @@ public class GunEventHandler {
|
|||
if ((tag.getInt("iterative") == 1 && tag.getInt("reload_stage") == 3) || tag.getBoolean("force_stage3_start")) {
|
||||
tag.putInt("reload_stage", 3);
|
||||
tag.putBoolean("force_stage3_start", false);
|
||||
int finishTime = GunsTool.getGunIntTag(tag, "FinishTime");
|
||||
int finishTime = gunData.finishTime();
|
||||
tag.putInt("finish", finishTime + 2);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2);
|
||||
playGunEndReloadSounds(player);
|
||||
|
@ -698,19 +690,20 @@ public class GunEventHandler {
|
|||
// 三阶段结束
|
||||
if (tag.getInt("finish") == 1) {
|
||||
tag.putInt("reload_stage", 0);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0) {
|
||||
if (gunData.boltActionTime() > 0) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", false);
|
||||
}
|
||||
GunsTool.setGunBooleanTag(tag, "Reloading", false);
|
||||
gunData.setReloadState(GunData.ReloadState.NOT_RELOADING);
|
||||
tag.putBoolean("start_single_reload", false);
|
||||
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||
}
|
||||
|
||||
gunData.save();
|
||||
}
|
||||
|
||||
public static void singleLoad(Player player, final CompoundTag tag) {
|
||||
final var data = tag.getCompound("GunData");
|
||||
data.putInt("Ammo", data.getInt("Ammo") + 1);
|
||||
public static void singleLoad(Player player, GunData data) {
|
||||
data.setAmmo(data.getAmmo() + 1);
|
||||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -753,7 +746,7 @@ public class GunEventHandler {
|
|||
public static void playGunEmptyPrepareSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -766,7 +759,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)),
|
||||
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
|
||||
|
||||
Mod.queueServerWork((int) (GunsTool.getGunIntTag(tag, "PrepareEmptyTime") / 2 + 3 + 1.5 * shooterHeight), () -> {
|
||||
Mod.queueServerWork((int) (data.prepareEmptyTime() / 2 + 3 + 1.5 * shooterHeight), () -> {
|
||||
if (stack.is(ModTags.Items.SHOTGUN)) {
|
||||
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)) {
|
||||
|
@ -849,9 +842,10 @@ public class GunEventHandler {
|
|||
/**
|
||||
* 哨兵充能
|
||||
*/
|
||||
private static void handleSentinelCharge(Player player, final CompoundTag tag) {
|
||||
private static void handleSentinelCharge(Player player, GunData gunData) {
|
||||
if (!(player.getMainHandItem().getItem() instanceof GunItem)) return;
|
||||
final var data = tag.getCompound("GunData");
|
||||
var tag = gunData.getTag();
|
||||
final var data = gunData.getData();
|
||||
|
||||
// 启动换弹
|
||||
if (GunsTool.getGunBooleanTag(tag, "StartCharge")) {
|
||||
|
@ -896,5 +890,7 @@ public class GunEventHandler {
|
|||
if (GunsTool.getGunIntTag(tag, "ChargeTime") == 1) {
|
||||
data.putBoolean("Charging", false);
|
||||
}
|
||||
|
||||
gunData.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEnt
|
|||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.events.PreKillEvent;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.DrawClientMessage;
|
||||
|
@ -167,6 +168,7 @@ public class LivingEventHandler {
|
|||
double armorValue;
|
||||
armorValue = tag.getDouble("ArmorPlate");
|
||||
tag.putDouble("ArmorPlate", Math.max(tag.getDouble("ArmorPlate") - damage, 0));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
damage = Math.max(damage - armorValue, 0);
|
||||
}
|
||||
|
||||
|
@ -208,22 +210,22 @@ public class LivingEventHandler {
|
|||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
if (event.getEntity() instanceof TargetEntity) return;
|
||||
|
||||
var data = GunData.from(stack).reload();
|
||||
double amount = Math.min(0.125 * event.getAmount(), event.getEntity().getMaxHealth());
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
// 先处理发射器类武器或高爆弹的爆炸伤害
|
||||
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) {
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
|
||||
data.setExp(data.getExp() + amount);
|
||||
}
|
||||
}
|
||||
|
||||
// 再判断是不是枪械能造成的伤害
|
||||
if (!DamageTypeTool.isGunDamage(source)) return;
|
||||
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.setExp(data.getExp() + amount);
|
||||
data.save();
|
||||
}
|
||||
|
||||
private static void giveKillExpToWeapon(LivingDeathEvent event) {
|
||||
|
@ -234,35 +236,36 @@ public class LivingEventHandler {
|
|||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
if (event.getEntity() instanceof TargetEntity) return;
|
||||
|
||||
var data = GunData.from(stack).reload();
|
||||
double amount = 20 + 2 * event.getEntity().getMaxHealth();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
// 先处理发射器类武器或高爆弹的爆炸伤害
|
||||
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) {
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
|
||||
data.setExp(data.getExp() + amount);
|
||||
}
|
||||
}
|
||||
|
||||
// 再判断是不是枪械能造成的伤害
|
||||
if (DamageTypeTool.isGunDamage(source)) {
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
|
||||
data.setExp(data.getExp() + amount);
|
||||
}
|
||||
|
||||
// 提升武器等级
|
||||
int level = GunsTool.getGunIntTag(tag, "Level");
|
||||
double exp = GunsTool.getGunDoubleTag(tag, "Exp");
|
||||
int level = data.getLevel();
|
||||
double exp = data.getExp();
|
||||
double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
|
||||
while (exp >= upgradeExpNeeded) {
|
||||
exp -= upgradeExpNeeded;
|
||||
level = GunsTool.getGunIntTag(tag, "Level") + 1;
|
||||
level = data.getLevel() + 1;
|
||||
upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", exp);
|
||||
GunsTool.setGunIntTag(tag, "Level", level);
|
||||
GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint") + 0.5);
|
||||
data.setExp(exp);
|
||||
data.setLevel(level);
|
||||
data.setUpgradePoint(data.getUpgradePoint() + 0.5);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
|
||||
private static void handleGunLevels(LivingIncomingDamageEvent event) {
|
||||
|
@ -273,20 +276,20 @@ public class LivingEventHandler {
|
|||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
if (event.getEntity() instanceof TargetEntity) return;
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = GunsTool.getGunIntTag(tag, "Level");
|
||||
double exp = GunsTool.getGunDoubleTag(tag, "Exp");
|
||||
var data = GunData.from(stack).reload();
|
||||
int level = data.getLevel();
|
||||
double exp = data.getExp();
|
||||
double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
|
||||
while (exp >= upgradeExpNeeded) {
|
||||
exp -= upgradeExpNeeded;
|
||||
level = GunsTool.getGunIntTag(tag, "Level") + 1;
|
||||
level = data.getLevel() + 1;
|
||||
upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", exp);
|
||||
GunsTool.setGunIntTag(tag, "Level", level);
|
||||
GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint") + 0.5);
|
||||
data.setExp(exp);
|
||||
data.setLevel(level);
|
||||
data.setUpgradePoint(data.getUpgradePoint() + 0.5);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
|
||||
private static void killIndication(LivingDeathEvent event) {
|
||||
|
@ -353,23 +356,22 @@ public class LivingEventHandler {
|
|||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||
stopGunReloadSound(serverPlayer, oldGun);
|
||||
|
||||
CompoundTag data = oldTag.getCompound("GunData");
|
||||
var oldData = GunData.from(oldStack).reload();
|
||||
CompoundTag data = oldData.getData();
|
||||
|
||||
if (GunsTool.getGunDoubleTag(oldTag, "BoltActionTime") > 0) {
|
||||
if (oldData.boltActionTime() > 0) {
|
||||
data.putInt("BoltActionTick", 0);
|
||||
}
|
||||
|
||||
data.putInt("ReloadTime", 0);
|
||||
oldTag.put("GunData", data);
|
||||
|
||||
oldTag.putBoolean("is_normal_reloading", false);
|
||||
oldTag.putBoolean("is_empty_reloading", false);
|
||||
oldData.setReloadState(GunData.ReloadState.NOT_RELOADING);
|
||||
|
||||
if (GunsTool.getGunIntTag(oldTag, "IterativeTime") != 0) {
|
||||
if (oldData.iterativeTime() != 0) {
|
||||
oldTag.putBoolean("force_stop", false);
|
||||
oldTag.putBoolean("stop", false);
|
||||
oldTag.putInt("reload_stage", 0);
|
||||
data.putBoolean("Reloading", false);
|
||||
oldTag.putDouble("prepare", 0);
|
||||
oldTag.putDouble("prepare_load", 0);
|
||||
oldTag.putDouble("iterative", 0);
|
||||
|
@ -389,23 +391,24 @@ public class LivingEventHandler {
|
|||
}
|
||||
|
||||
if (newStack.getItem() instanceof GunItem) {
|
||||
var newData = GunData.from(newStack);
|
||||
|
||||
player.getPersistentData().putDouble("noRun", 40);
|
||||
newTag.putBoolean("draw", true);
|
||||
if (GunsTool.getGunIntTag(newTag, "BoltActionTime") > 0) {
|
||||
if (newData.boltActionTime() > 0) {
|
||||
GunsTool.setGunIntTag(newTag, "BoltActionTick", 0);
|
||||
}
|
||||
newTag.putBoolean("is_normal_reloading", false);
|
||||
newTag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
newData.setReloadState(GunData.ReloadState.NOT_RELOADING);
|
||||
|
||||
CompoundTag data = newTag.getCompound("GunData");
|
||||
data.putInt("ReloadTime", 0);
|
||||
newTag.put("GunData", data);
|
||||
|
||||
if (GunsTool.getGunIntTag(newTag, "IterativeTime") != 0) {
|
||||
if (newData.iterativeTime() != 0) {
|
||||
newTag.putBoolean("force_stop", false);
|
||||
newTag.putBoolean("stop", false);
|
||||
newTag.putInt("reload_stage", 0);
|
||||
GunsTool.setGunBooleanTag(newTag, "Reloading", false);
|
||||
newTag.putDouble("prepare", 0);
|
||||
newTag.putDouble("prepare_load", 0);
|
||||
newTag.putDouble("iterative", 0);
|
||||
|
@ -653,8 +656,9 @@ public class LivingEventHandler {
|
|||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
|
||||
int mag = GunsTool.getGunIntTag(tag, "Magazine") + GunsTool.getGunIntTag(tag, "CustomMagazine");
|
||||
int ammo = GunsTool.getGunIntTag(tag, "Ammo");
|
||||
var data = GunData.from(stack);
|
||||
int mag = data.magazine();
|
||||
int ammo = data.getAmmo();
|
||||
int ammoReload = (int) Math.min(mag, mag * rate);
|
||||
int ammoNeed = Math.min(mag - ammo, ammoReload);
|
||||
|
||||
|
@ -667,7 +671,7 @@ public class LivingEventHandler {
|
|||
} else {
|
||||
cap.rifleAmmo -= ammoFinal;
|
||||
}
|
||||
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
data.setAmmo(Math.min(mag, ammo + ammoFinal));
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
int ammoFinal = Math.min(cap.handgunAmmo, ammoNeed);
|
||||
if (flag) {
|
||||
|
@ -675,9 +679,9 @@ public class LivingEventHandler {
|
|||
} else {
|
||||
cap.handgunAmmo -= ammoFinal;
|
||||
}
|
||||
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
data.setAmmo(Math.min(mag, ammo + ammoFinal));
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
|||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.tools.*;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -115,9 +116,8 @@ public class PlayerEventHandler {
|
|||
int sprintCost;
|
||||
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
sprintCost = (int) (5 + 0.2 * weight);
|
||||
var data = GunData.from(stack);
|
||||
sprintCost = (int) (5 + 0.2 * data.weight());
|
||||
} else {
|
||||
sprintCost = 5;
|
||||
}
|
||||
|
@ -197,10 +197,12 @@ public class PlayerEventHandler {
|
|||
private static void handleSpecialWeaponAmmo(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && GunsTool.getGunIntTag(tag, "Ammo") == 1) {
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && data.getAmmo() == 1) {
|
||||
tag.putDouble("empty", 0);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,49 +265,50 @@ public class PlayerEventHandler {
|
|||
|
||||
for (ItemStack stack : player.getInventory().items) {
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack).reload();
|
||||
var tag = data.getTag();
|
||||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && cap.shotgunAmmo > 0) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SHOTGUN);
|
||||
GunsTool.reload(player, stack, data, AmmoType.SHOTGUN);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && cap.sniperAmmo > 0) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SNIPER);
|
||||
GunsTool.reload(player, stack, data, AmmoType.SNIPER);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_HANDGUN_AMMO) && cap.handgunAmmo > 0) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HANDGUN);
|
||||
GunsTool.reload(player, stack, data, AmmoType.HANDGUN);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && cap.rifleAmmo > 0) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.RIFLE);
|
||||
GunsTool.reload(player, stack, data, AmmoType.RIFLE);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && cap.heavyAmmo > 0) {
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HEAVY);
|
||||
GunsTool.reload(player, stack, data, AmmoType.HEAVY);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
data.setAmmo(1);
|
||||
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 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
data.setAmmo(1);
|
||||
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 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
data.setAmmo(1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
data.setAmmo(1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
} else {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Magazine")
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine"));
|
||||
data.setAmmo(data.magazine());
|
||||
}
|
||||
GunsTool.setGunBooleanTag(tag, "HoldOpen", false);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -353,9 +356,9 @@ public class PlayerEventHandler {
|
|||
if (left.is(ModTags.Items.GUN) && right.getItem() == ModItems.SHORTCUT_PACK.get()) {
|
||||
ItemStack output = left.copy();
|
||||
|
||||
final var outputTag = NBTTool.getTag(output);
|
||||
GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", GunsTool.getGunDoubleTag(outputTag, "UpgradePoint") + 1);
|
||||
NBTTool.saveTag(output, outputTag);
|
||||
var data = GunData.from(output).reload();
|
||||
data.setUpgradePoint(data.getUpgradePoint() + 1);
|
||||
data.save();
|
||||
|
||||
event.setOutput(output);
|
||||
event.setCost(10);
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
|||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
|
@ -186,4 +187,15 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getHighlightTip(@NotNull ItemStack item, @NotNull Component displayName) {
|
||||
// var tag = item.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag();
|
||||
// String entityTranslationKey = getEntityTranslationKey(tag.getString("EntityType"));
|
||||
//
|
||||
// super.getHighlightTip(item, displayName).
|
||||
//
|
||||
// tooltipComponents.add(Component.translatable(entityTranslationKey == null ? "des.superbwarfare.container.empty" : s).withStyle(ChatFormatting.GRAY));
|
||||
return Component.literal("tesjlktkjesjlktlejk");
|
||||
}
|
||||
}
|
||||
|
|
294
src/main/java/com/atsuishio/superbwarfare/item/gun/GunData.java
Normal file
294
src/main/java/com/atsuishio/superbwarfare/item/gun/GunData.java
Normal file
|
@ -0,0 +1,294 @@
|
|||
package com.atsuishio.superbwarfare.item.gun;
|
||||
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class GunData {
|
||||
private final ItemStack stack;
|
||||
private final GunItem item;
|
||||
private CompoundTag tag;
|
||||
private CompoundTag data;
|
||||
private final String id;
|
||||
|
||||
private static final WeakHashMap<ItemStack, GunData> dataCache = new WeakHashMap<>();
|
||||
|
||||
public GunData reload() {
|
||||
var customData = stack.get(DataComponents.CUSTOM_DATA);
|
||||
this.tag = customData != null ? customData.copyTag() : new CompoundTag();
|
||||
|
||||
if (!tag.contains("GunData")) {
|
||||
data = new CompoundTag();
|
||||
tag.put("GunData", data);
|
||||
} else {
|
||||
data = tag.getCompound("GunData");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private GunData(ItemStack stack) {
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) {
|
||||
throw new IllegalArgumentException("stack is not GunItem!");
|
||||
}
|
||||
this.item = gunItem;
|
||||
this.stack = stack;
|
||||
var id = stack.getDescriptionId();
|
||||
this.id = id.substring(id.lastIndexOf(".") + 1);
|
||||
reload();
|
||||
}
|
||||
|
||||
public static GunData from(ItemStack stack) {
|
||||
if (!dataCache.containsKey(stack)) {
|
||||
dataCache.put(stack, new GunData(stack));
|
||||
}
|
||||
return dataCache.get(stack);
|
||||
}
|
||||
|
||||
public GunItem getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public CompoundTag getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public CompoundTag getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
private double getGunData(String key) {
|
||||
return getGunData(key, 0);
|
||||
}
|
||||
|
||||
private double getGunData(String key, double defaultValue) {
|
||||
return GunsTool.gunsData.getOrDefault(id, new HashMap<>()).getOrDefault(key, defaultValue);
|
||||
}
|
||||
|
||||
public double damage() {
|
||||
return getGunData("Damage") + item.getCustomDamage(stack);
|
||||
}
|
||||
|
||||
public double explosionDamage() {
|
||||
return getGunData("ExplosionDamage");
|
||||
}
|
||||
|
||||
public double explosionRadius() {
|
||||
return getGunData("ExplosionRadius");
|
||||
}
|
||||
|
||||
public double velocity() {
|
||||
return getGunData("Velocity") + item.getCustomVelocity(stack);
|
||||
}
|
||||
|
||||
public double spread() {
|
||||
return getGunData("Spread");
|
||||
}
|
||||
|
||||
public int magazine() {
|
||||
return (int) (getGunData("Magazine") + item.getCustomMagazine(stack));
|
||||
}
|
||||
|
||||
public int projectileAmount() {
|
||||
return (int) getGunData("ProjectileAmount", 1);
|
||||
}
|
||||
|
||||
public double headshot() {
|
||||
return getGunData("Headshot", 1.5) + item.getCustomHeadshot(stack);
|
||||
}
|
||||
|
||||
public int normalReloadTime() {
|
||||
return (int) getGunData("NormalReloadTime");
|
||||
}
|
||||
|
||||
public int emptyReloadTime() {
|
||||
return (int) getGunData("EmptyReloadTime");
|
||||
}
|
||||
|
||||
public int iterativeTime() {
|
||||
return (int) getGunData("IterativeTime");
|
||||
}
|
||||
|
||||
public int prepareTime() {
|
||||
return (int) getGunData("PrepareTime");
|
||||
}
|
||||
|
||||
public int prepareLoadTime() {
|
||||
return (int) getGunData("PrepareLoadTime");
|
||||
}
|
||||
|
||||
public int prepareEmptyTime() {
|
||||
return (int) getGunData("PrepareEmptyTime");
|
||||
}
|
||||
|
||||
public int boltActionTime() {
|
||||
return (int) getGunData("BoltActionTime") + item.getCustomBoltActionTime(stack);
|
||||
}
|
||||
|
||||
public int finishTime() {
|
||||
return (int) getGunData("FinishTime");
|
||||
}
|
||||
|
||||
public int reloadTime() {
|
||||
var normalReload = normalReloadTime();
|
||||
var emptyReload = emptyReloadTime();
|
||||
|
||||
if (normalReload == 0) return emptyReload;
|
||||
if (emptyReload == 0) return normalReload;
|
||||
|
||||
return getAmmo() < magazine() ? normalReload : emptyReload;
|
||||
}
|
||||
|
||||
public double soundRadius() {
|
||||
return getGunData("SoundRadius", 15) + item.getCustomSoundRadius(stack);
|
||||
}
|
||||
|
||||
public double bypassArmor() {
|
||||
return getGunData("BypassesArmor") + item.getCustomBypassArmor(stack);
|
||||
}
|
||||
|
||||
public double recoilX() {
|
||||
return getGunData("RecoilX");
|
||||
}
|
||||
|
||||
public double recoilY() {
|
||||
return getGunData("RecoilY");
|
||||
}
|
||||
|
||||
public double weight() {
|
||||
return getGunData("Weight") + customWeight();
|
||||
}
|
||||
|
||||
public double customWeight() {
|
||||
return item.getCustomWeight(stack);
|
||||
}
|
||||
|
||||
public int getAmmo() {
|
||||
return data.getInt("Ammo");
|
||||
}
|
||||
|
||||
public void setAmmo(int ammo) {
|
||||
data.putInt("Ammo", ammo);
|
||||
}
|
||||
|
||||
public boolean isReloading() {
|
||||
return getReloadState() != ReloadState.NOT_RELOADING;
|
||||
}
|
||||
|
||||
public double defaultZoom() {
|
||||
return getGunData("DefaultZoom", 1);
|
||||
}
|
||||
|
||||
public double minZoom() {
|
||||
return getGunData("MinZoom", 1);
|
||||
}
|
||||
|
||||
public double maxZoom() {
|
||||
return getGunData("MaxZoom", 1);
|
||||
}
|
||||
|
||||
public double zoom() {
|
||||
if (minZoom() == maxZoom()) return defaultZoom();
|
||||
|
||||
return Mth.clamp(defaultZoom() + item.getCustomZoom(stack), minZoom(), maxZoom());
|
||||
}
|
||||
|
||||
public int rpm() {
|
||||
return (int) (getGunData("RPM") + item.getCustomRPM(stack));
|
||||
}
|
||||
|
||||
public int burstAmount() {
|
||||
return (int) getGunData("BurstAmount");
|
||||
}
|
||||
|
||||
public int getFireMode() {
|
||||
if (data.contains("FireMode")) {
|
||||
return data.getInt("FireMode");
|
||||
}
|
||||
return (int) getGunData("FireMode");
|
||||
}
|
||||
|
||||
public void setFireMode(int fireMode) {
|
||||
data.putInt("FireMode", fireMode);
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return data.getInt("Level");
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
data.putInt("Level", level);
|
||||
}
|
||||
|
||||
public double getExp() {
|
||||
return data.getDouble("Exp");
|
||||
}
|
||||
|
||||
public void setExp(double exp) {
|
||||
data.putDouble("Exp", exp);
|
||||
}
|
||||
|
||||
public double getUpgradePoint() {
|
||||
return data.getDouble("UpgradePoint");
|
||||
}
|
||||
|
||||
public void setUpgradePoint(double upgradePoint) {
|
||||
data.putDouble("UpgradePoint", upgradePoint);
|
||||
}
|
||||
|
||||
public boolean canAdjustZoom() {
|
||||
return item.canAdjustZoom(stack);
|
||||
}
|
||||
|
||||
public boolean canSwitchScope() {
|
||||
return item.canSwitchScope(stack);
|
||||
}
|
||||
|
||||
public enum ReloadState {
|
||||
NOT_RELOADING,
|
||||
NORMAL_RELOADING,
|
||||
EMPTY_RELOADING,
|
||||
}
|
||||
|
||||
public ReloadState getReloadState() {
|
||||
return switch (data.getInt("ReloadState")) {
|
||||
case 1 -> ReloadState.NORMAL_RELOADING;
|
||||
case 2 -> ReloadState.EMPTY_RELOADING;
|
||||
default -> ReloadState.NOT_RELOADING;
|
||||
};
|
||||
}
|
||||
|
||||
public boolean normalReloading() {
|
||||
return getReloadState() == ReloadState.NORMAL_RELOADING;
|
||||
}
|
||||
|
||||
public boolean emptyReloading() {
|
||||
return getReloadState() == ReloadState.EMPTY_RELOADING;
|
||||
}
|
||||
|
||||
public void setReloadState(ReloadState state) {
|
||||
data.putInt("ReloadState", state.ordinal());
|
||||
}
|
||||
|
||||
public int getReloadStage() {
|
||||
return data.getInt("ReloadStage");
|
||||
}
|
||||
|
||||
public void setReloadStage(int stage) {
|
||||
data.putInt("ReloadStage", stage);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
||||
reload();
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ import com.atsuishio.superbwarfare.perk.Perk;
|
|||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -66,7 +65,8 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
|| !(stack.getItem() instanceof GunItem gunItem)
|
||||
) return;
|
||||
|
||||
var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
if (tag.getString("id").isEmpty()) {
|
||||
var id = stack.getDescriptionId();
|
||||
|
@ -77,28 +77,28 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
var name = this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1);
|
||||
|
||||
if (level.getServer() != null && entity instanceof Player player && player.isCreative()) {
|
||||
GunsTool.initCreativeGun(tag, name);
|
||||
GunsTool.initCreativeGun(stack, name);
|
||||
} else {
|
||||
GunsTool.initGun(tag, name);
|
||||
}
|
||||
data.reload();
|
||||
tag = data.getTag();
|
||||
|
||||
GunsTool.generateAndSetUUID(tag);
|
||||
tag.putBoolean("init", true);
|
||||
}
|
||||
tag.putBoolean("draw", false);
|
||||
|
||||
handleGunPerks(tag);
|
||||
handleGunAttachment(tag);
|
||||
data.save();
|
||||
handleGunPerks(data);
|
||||
data.reload();
|
||||
|
||||
var hasBulletInBarrel = gunItem.hasBulletInBarrel(stack);
|
||||
var ammoCount = GunsTool.getGunIntTag(tag, "Ammo");
|
||||
var magazine = GunsTool.getGunIntTag(tag, "Magazine");
|
||||
var customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine");
|
||||
var ammoCount = data.getAmmo();
|
||||
var magazine = data.magazine();
|
||||
|
||||
if ((hasBulletInBarrel && ammoCount > magazine + customMagazine + 1)
|
||||
|| (!hasBulletInBarrel && ammoCount > magazine + customMagazine)
|
||||
) {
|
||||
int count = ammoCount - magazine + customMagazine - (hasBulletInBarrel ? 1 : 0);
|
||||
if ((hasBulletInBarrel && ammoCount > magazine + 1) || (!hasBulletInBarrel && ammoCount > magazine)) {
|
||||
int count = ammoCount - magazine - (hasBulletInBarrel ? 1 : 0);
|
||||
|
||||
var capability = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (capability != null) {
|
||||
|
@ -115,9 +115,9 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
}
|
||||
capability.syncPlayerVariables(entity);
|
||||
}
|
||||
GunsTool.setGunIntTag(tag, "Ammo", magazine + customMagazine + (hasBulletInBarrel ? 1 : 0));
|
||||
GunsTool.setGunIntTag(tag, "Ammo", magazine + (hasBulletInBarrel ? 1 : 0));
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,12 +131,12 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
@Override
|
||||
public @NotNull ItemAttributeModifiers getDefaultAttributeModifiers(@NotNull ItemStack stack) {
|
||||
var list = new ArrayList<>(super.getDefaultAttributeModifiers(stack).modifiers());
|
||||
var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
list.add(new ItemAttributeModifiers.Entry(
|
||||
Attributes.MOVEMENT_SPEED,
|
||||
new AttributeModifier(SPEED_ID,
|
||||
-0.01f - 0.005f * (GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight")),
|
||||
-0.01f - 0.005f * data.weight(),
|
||||
AttributeModifier.Operation.ADD_MULTIPLIED_BASE
|
||||
),
|
||||
EquipmentSlotGroup.MAINHAND
|
||||
|
@ -179,7 +179,9 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
}
|
||||
|
||||
|
||||
private void handleGunPerks(final CompoundTag tag) {
|
||||
private void handleGunPerks(GunData data) {
|
||||
var tag = data.getTag();
|
||||
|
||||
reducePerkTagCoolDown(tag, "HealClipTime", "KillClipReloadTime", "KillClipTime", "FourthTimesCharmTick", "HeadSeeker",
|
||||
"DesperadoTime", "DesperadoTimePost");
|
||||
|
||||
|
@ -189,52 +191,13 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmTick", 0);
|
||||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmCount", 0);
|
||||
|
||||
int mag = GunsTool.getGunIntTag(tag, "Magazine") + GunsTool.getGunIntTag(tag, "CustomMagazine");
|
||||
int mag = data.magazine();
|
||||
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, GunsTool.getGunIntTag(tag, "Ammo") + 2));
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGunAttachment(final CompoundTag rootTag) {
|
||||
CompoundTag tag = rootTag.getCompound("Attachments");
|
||||
|
||||
double scopeWeight = switch (tag.getInt("Scope")) {
|
||||
case 1 -> 0.5;
|
||||
case 2 -> 1;
|
||||
case 3 -> 1.5;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double barrelWeight = switch (tag.getInt("Barrel")) {
|
||||
case 1 -> 0.5;
|
||||
case 2 -> 1;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double magazineWeight = switch (tag.getInt("Magazine")) {
|
||||
case 1 -> 1;
|
||||
case 2 -> 2;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double stockWeight = switch (tag.getInt("Stock")) {
|
||||
case 1 -> -2;
|
||||
case 2 -> 1.5;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double gripWeight = switch (tag.getInt("Grip")) {
|
||||
case 1, 2 -> 0.25;
|
||||
case 3 -> 1;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double soundRadius = tag.getInt("Barrel") == 2 ? 0.6 : 1;
|
||||
|
||||
GunsTool.setGunDoubleTag(tag, "CustomWeight", scopeWeight + barrelWeight + magazineWeight + stockWeight + gripWeight);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomSoundRadius", soundRadius);
|
||||
}
|
||||
|
||||
public boolean canApplyPerk(Perk perk) {
|
||||
return true;
|
||||
}
|
||||
|
@ -405,6 +368,121 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外伤害加成
|
||||
*/
|
||||
public double getCustomDamage(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外爆头伤害加成
|
||||
*/
|
||||
public double getCustomHeadshot(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外护甲穿透加成
|
||||
*/
|
||||
public double getCustomBypassArmor(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外弹匣容量加成
|
||||
*/
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外缩放倍率加成
|
||||
*/
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外RPM加成
|
||||
*/
|
||||
public int getCustomRPM(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外总重量加成
|
||||
*/
|
||||
public double getCustomWeight(ItemStack stack) {
|
||||
CompoundTag tag = GunData.from(stack).getTag().getCompound("Attachments");
|
||||
|
||||
double scopeWeight = switch (tag.getInt("Scope")) {
|
||||
case 1 -> 0.5;
|
||||
case 2 -> 1;
|
||||
case 3 -> 1.5;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double barrelWeight = switch (tag.getInt("Barrel")) {
|
||||
case 1 -> 0.5;
|
||||
case 2 -> 1;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double magazineWeight = switch (tag.getInt("Magazine")) {
|
||||
case 1 -> 1;
|
||||
case 2 -> 2;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double stockWeight = switch (tag.getInt("Stock")) {
|
||||
case 1 -> -2;
|
||||
case 2 -> 1.5;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double gripWeight = switch (tag.getInt("Grip")) {
|
||||
case 1, 2 -> 0.25;
|
||||
case 3 -> 1;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
return scopeWeight + barrelWeight + magazineWeight + stockWeight + gripWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外弹速加成
|
||||
*/
|
||||
public double getCustomVelocity(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外音效半径加成
|
||||
*/
|
||||
public double getCustomSoundRadius(ItemStack stack) {
|
||||
return GunData.from(stack).getTag().getCompound("Attachments").getInt("Barrel") == 2 ? 0.6 : 1;
|
||||
}
|
||||
|
||||
public int getCustomBoltActionTime(ItemStack stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许缩放
|
||||
*/
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许切换瞄具
|
||||
*/
|
||||
public boolean canSwitchScope(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 右下角弹药显示名称
|
||||
*/
|
||||
|
|
|
@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.Glock17ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -49,11 +49,11 @@ public class Glock17Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class Glock17Item extends GunItem implements GeoItem {
|
|||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading")) && ClientEventHandler.drawTime < 0.01) {
|
||||
&& !(GunData.from(stack).normalReloading() || GunData.from(stack).emptyReloading()) && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -6,10 +6,10 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -50,11 +50,11 @@ public class Glock18Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class Glock18Item extends GunItem implements GeoItem {
|
|||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading")) && ClientEventHandler.drawTime < 0.01) {
|
||||
&& !(GunData.from(stack).normalReloading() || GunData.from(stack).emptyReloading()) && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.M1911ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -49,11 +49,11 @@ public class M1911Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class M1911Item extends GunItem implements GeoItem {
|
|||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading")) && ClientEventHandler.drawTime < 0.01) {
|
||||
&& !(GunData.from(stack).normalReloading() || GunData.from(stack).emptyReloading()) && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.Mp443ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -49,11 +49,11 @@ public class Mp443Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class Mp443Item extends GunItem implements GeoItem {
|
|||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading")) && ClientEventHandler.drawTime < 0.01) {
|
||||
&& !(GunData.from(stack).normalReloading() || GunData.from(stack).emptyReloading()) && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.handgun;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.capability.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.TooltipTool;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.TracheliumItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -18,7 +18,6 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -37,8 +36,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.NBTTool.saveTag;
|
||||
|
||||
public class Trachelium extends GunItem implements GeoItem {
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
@ -108,7 +105,8 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean stock = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE) > 0;
|
||||
|
@ -129,7 +127,7 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
if (stock) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.trachelium.reload_stock_grip"));
|
||||
|
@ -253,33 +251,64 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
if (scopeType == 3) {
|
||||
tags.putInt("Scope", 0);
|
||||
}
|
||||
|
||||
if (scopeType > 0 || gripType > 0) {
|
||||
GunsTool.setGunDoubleTag(tag, "CustomVelocity", 15);
|
||||
GunsTool.setGunDoubleTag(tag, "BypassesArmor", 0.4);
|
||||
GunsTool.setGunDoubleTag(tag, "Damage", 21);
|
||||
GunsTool.setGunDoubleTag(tag, "Headshot", 2.5);
|
||||
} else {
|
||||
GunsTool.setGunDoubleTag(tag, "CustomVelocity", 0);
|
||||
GunsTool.setGunDoubleTag(tag, "BypassesArmor", 0.3);
|
||||
GunsTool.setGunDoubleTag(tag, "Damage", 19);
|
||||
GunsTool.setGunDoubleTag(tag, "Headshot", 2);
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public int getCustomBoltActionTime(ItemStack stack) {
|
||||
return GunData.from(stack).getTag().getBoolean("DA") ? 12 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSwitchScope(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2;
|
||||
}
|
||||
|
||||
private boolean useSpecialAttributes(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP);
|
||||
return scopeType > 0 || gripType > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCustomDamage(ItemStack stack) {
|
||||
if (useSpecialAttributes(stack)) {
|
||||
return 2;
|
||||
}
|
||||
return super.getCustomDamage(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75;
|
||||
default -> 1;
|
||||
};
|
||||
|
||||
GunsTool.setGunBooleanTag(tag, "CanSwitchScope", scopeType == 2);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getGunIcon() {
|
||||
return Mod.loc("textures/gun_icon/trachelium_icon.png");
|
||||
public double getCustomVelocity(ItemStack stack) {
|
||||
if (useSpecialAttributes(stack)) {
|
||||
return 15;
|
||||
}
|
||||
return super.getCustomVelocity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCustomHeadshot(ItemStack stack) {
|
||||
if (useSpecialAttributes(stack)) {
|
||||
return 0.5;
|
||||
}
|
||||
return super.getCustomHeadshot(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCustomBypassArmor(ItemStack stack) {
|
||||
if (useSpecialAttributes(stack)) {
|
||||
return 0.1;
|
||||
}
|
||||
return super.getCustomBypassArmor(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModRarity;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -17,17 +18,14 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
public class Ntw20Item extends GunItem implements GeoItem {
|
||||
|
@ -58,17 +56,18 @@ public class Ntw20Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.shift"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.reload_empty"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -80,11 +79,12 @@ public class Ntw20Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !(data.normalReloading() || data.emptyReloading())
|
||||
&& ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.ntw_20.run_fast"));
|
||||
|
@ -126,30 +126,27 @@ public class Ntw20Item extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
int customMag = switch (magType) {
|
||||
@Override
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
return switch (GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE)) {
|
||||
case 1 -> 3;
|
||||
case 2 -> 6;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
};
|
||||
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.entity.projectile.JavelinMissileEntity;
|
|||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||
|
@ -76,7 +77,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.javelin.reload"));
|
||||
}
|
||||
|
||||
|
@ -239,7 +240,8 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
private void fire(Player player) {
|
||||
Level level = player.level();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
CompoundTag tag = data.getTag();
|
||||
|
||||
if (tag.getInt("SeekTime") < 20) return;
|
||||
|
||||
|
@ -252,11 +254,12 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
JavelinMissileEntity missileEntity = new JavelinMissileEntity(player, level,
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"),
|
||||
(float) data.damage(),
|
||||
(float) data.explosionDamage(),
|
||||
(float) data.explosionRadius(),
|
||||
tag.getInt("GuideType"),
|
||||
new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ")));
|
||||
new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ"))
|
||||
);
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
|
@ -285,8 +288,8 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 10);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.setAmmo(data.getAmmo() - 1);
|
||||
data.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -302,9 +305,13 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
public void fireOnPress(Player player, CompoundTag tag) {
|
||||
var stack = player.getMainHandItem();
|
||||
var data = GunData.from(stack);
|
||||
tag = data.getTag();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && !cap.zoom || GunsTool.getGunIntTag(tag, "Ammo") <= 0) return;
|
||||
if (cap != null && !cap.zoom || data.getAmmo() <= 0) return;
|
||||
|
||||
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||
|
@ -77,7 +78,7 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m79.reload"));
|
||||
}
|
||||
|
||||
|
@ -172,19 +173,20 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
@Override
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo") <= 0) return;
|
||||
var data = GunData.from(stack);
|
||||
if (data.isReloading()) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.getAmmo() <= 0) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zooming = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
double spread = data.spread();
|
||||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel,
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"));
|
||||
(float) data.damage(),
|
||||
(float) data.explosionDamage(),
|
||||
(float) data.explosionRadius()
|
||||
);
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
|
@ -194,11 +196,11 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
|
||||
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
|
||||
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity");
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
float velocity = (float) data.velocity();
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), data.getTag());
|
||||
if (perkLevel > 0) {
|
||||
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius") * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage") * (1.1f + perkLevel * 0.1f));
|
||||
gunGrenadeEntity.setExplosionRadius((float) data.explosionRadius() * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) data.explosionDamage() * (1.1f + perkLevel * 0.1f));
|
||||
velocity *= 1.2f;
|
||||
}
|
||||
|
||||
|
@ -223,6 +225,7 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 2);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
|
||||
data.setAmmo(data.getAmmo() - 1);
|
||||
data.save();
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||
|
@ -76,9 +77,9 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.rpg.reload"));
|
||||
}
|
||||
|
||||
|
@ -180,24 +181,27 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
public void fireOnPress(Player player, CompoundTag tag) {
|
||||
Level level = player.level();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var data = GunData.from(stack);
|
||||
tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
if (data.isReloading()
|
||||
|| player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
|| GunsTool.getGunIntTag(tag, "Ammo") <= 0
|
||||
|| data.getAmmo() <= 0
|
||||
) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
double spread = data.spread();
|
||||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
RpgRocketEntity rocket = new RpgRocketEntity(player, level,
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"));
|
||||
(float) data.damage(),
|
||||
(float) data.explosionDamage(),
|
||||
(float) data.explosionRadius()
|
||||
);
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
|
@ -205,7 +209,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
rocket.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
|
||||
}
|
||||
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity");
|
||||
float velocity = (float) data.velocity();
|
||||
|
||||
if (PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()) {
|
||||
rocket.setNoGravity(true);
|
||||
|
@ -213,7 +217,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
if (perkLevel > 0) {
|
||||
rocket.setExplosionRadius(0.5f);
|
||||
rocket.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage") * (1.1f + perkLevel * 0.1f));
|
||||
rocket.setDamage((float) data.damage() * (1.1f + perkLevel * 0.1f));
|
||||
velocity *= 1.2f;
|
||||
}
|
||||
}
|
||||
|
@ -238,12 +242,13 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") == 1) {
|
||||
if (data.getAmmo() == 1) {
|
||||
tag.putBoolean("empty", true);
|
||||
GunsTool.setGunBooleanTag(tag, "CloseHammer", true);
|
||||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 10);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
|
||||
data.setAmmo(data.getAmmo() - 1);
|
||||
data.save();
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||
|
@ -88,7 +89,8 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare_load") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.prepare"));
|
||||
|
@ -118,17 +120,18 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(tag.getBoolean("is_empty_reloading"))
|
||||
&& tag.getInt("reload_stage") != 1
|
||||
&& tag.getInt("reload_stage") != 2
|
||||
&& tag.getInt("reload_stage") != 3
|
||||
&& !data.emptyReloading()
|
||||
&& data.getTag().getInt("reload_stage") != 1
|
||||
&& data.getTag().getInt("reload_stage") != 2
|
||||
&& data.getTag().getInt("reload_stage") != 3
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& ClientEventHandler.gunMelee == 0
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
&& !data.isReloading()
|
||||
) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.sc.run_fast"));
|
||||
} else {
|
||||
|
@ -269,12 +272,13 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
@Override
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo") <= 0) return;
|
||||
var data = GunData.from(stack);
|
||||
if (data.isReloading()) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.getAmmo() <= 0) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zooming = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
double spread = data.spread();
|
||||
|
||||
var stackCap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
var hasEnoughEnergy = stackCap != null && stackCap.getEnergyStored() >= 3000;
|
||||
|
@ -283,9 +287,10 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel,
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"));
|
||||
(float) data.damage(),
|
||||
(float) data.explosionDamage(),
|
||||
(float) data.explosionRadius()
|
||||
);
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
|
@ -296,11 +301,11 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
|
||||
gunGrenadeEntity.charged(isChargedFire);
|
||||
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity");
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
float velocity = (float) data.velocity();
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), data.getTag());
|
||||
if (perkLevel > 0) {
|
||||
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius") * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage") * (1.1f + perkLevel * 0.1f));
|
||||
gunGrenadeEntity.setExplosionRadius((float) data.explosionRadius() * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) data.damage() * (1.1f + perkLevel * 0.1f));
|
||||
velocity *= 1.2f;
|
||||
}
|
||||
|
||||
|
@ -337,7 +342,8 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
|
||||
data.setAmmo(data.getAmmo() - 1);
|
||||
data.save();
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 6);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -50,11 +50,11 @@ public class DevotionItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.devotion.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.devotion.reload_normal"));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -67,11 +68,11 @@ public class M60Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m60.reload"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m60.reload2"));
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.init.ModParticleTypes;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModRarity;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
|
@ -34,6 +35,10 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
public class MinigunItem extends GunItem implements GeoItem {
|
||||
@Override
|
||||
public int getCustomRPM(ItemStack stack) {
|
||||
return GunData.from(stack).getData().getInt("CustomRPM");
|
||||
}
|
||||
|
||||
private static final String TAG_HEAT = "heat";
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
|
|
@ -6,10 +6,10 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -50,11 +50,11 @@ public class RpkItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_normal"));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.AK12ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -16,18 +17,15 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
public class AK12Item extends GunItem implements GeoItem {
|
||||
|
@ -58,12 +56,13 @@ public class AK12Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak12.reload_empty_grip"));
|
||||
} else {
|
||||
|
@ -71,7 +70,7 @@ public class AK12Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak12.reload_normal_drum_grip"));
|
||||
|
@ -134,33 +133,28 @@ public class AK12Item extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK);
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.15;
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
int customMag = switch (magType) {
|
||||
@Override
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 15;
|
||||
case 2 -> 45;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.15;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
};
|
||||
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.AK47ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -16,18 +17,15 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
public class AK47Item extends GunItem implements GeoItem {
|
||||
|
@ -58,12 +56,13 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_empty_drum_grip"));
|
||||
|
@ -79,7 +78,7 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_normal_drum_grip"));
|
||||
|
@ -142,32 +141,28 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK);
|
||||
|
||||
int customMag = switch (magType) {
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 15;
|
||||
case 2 -> 40;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.75;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
@Override
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.Hk416ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -16,11 +17,9 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
|
@ -52,12 +51,13 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.reload_empty_drum_grip"));
|
||||
|
@ -73,7 +73,7 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.reload_normal_drum_grip"));
|
||||
|
@ -131,31 +131,28 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK);
|
||||
|
||||
int customMag = switch (magType) {
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 15;
|
||||
case 2 -> 30;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
@Override
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.InsidiousItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -49,9 +49,9 @@ public class InsidiousItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.insidious.reload"));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.M4ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -16,18 +17,15 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
public class M4Item extends GunItem implements GeoItem {
|
||||
|
@ -51,14 +49,16 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
private PlayState idlePredicate(AnimationState<M4Item> event) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (player == null) return PlayState.STOP;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.reload_empty_drum_grip"));
|
||||
|
@ -74,7 +74,7 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.reload_normal_drum_grip"));
|
||||
|
@ -142,33 +142,33 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
public boolean canSwitchScope(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2;
|
||||
}
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK);
|
||||
|
||||
int customMag = switch (magType) {
|
||||
@Override
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 15;
|
||||
case 2 -> 30;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
GunsTool.setGunBooleanTag(tag, "CanSwitchScope", scopeType == 2);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
@Override
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,11 +5,11 @@ import com.atsuishio.superbwarfare.client.renderer.item.MarlinItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -49,7 +49,8 @@ public class MarlinItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.shift"));
|
||||
|
@ -79,14 +80,14 @@ public class MarlinItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
if (transformType != null && transformType.firstPerson()) {
|
||||
if (player.isSprinting()
|
||||
&& player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
&& !data.isReloading()) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.marlin.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.Mk14ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -16,18 +17,15 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
public class Mk14Item extends GunItem implements GeoItem {
|
||||
|
@ -53,12 +51,13 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m14.reload_empty_drum_grip"));
|
||||
|
@ -74,7 +73,7 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m14.reload_normal_drum_grip"));
|
||||
|
@ -137,30 +136,28 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
|
||||
int customMag = switch (magType) {
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 10;
|
||||
case 2 -> 30;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
@Override
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.Qbz95ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -54,12 +55,13 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.reload_empty_drum_grip"));
|
||||
|
@ -75,7 +77,7 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.reload_normal_drum_grip"));
|
||||
|
@ -142,27 +144,32 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
final var rootTag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(rootTag, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(rootTag, GunsTool.AttachmentType.MAGAZINE);
|
||||
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
if (magType == 1) {
|
||||
CompoundTag tag = rootTag.getCompound("Attachments");
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments");
|
||||
tag.putInt("Magazine", 2);
|
||||
}
|
||||
}
|
||||
|
||||
int customMag = magType == 2 ? 30 : 0;
|
||||
@Override
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return magType == 2 ? 30 : 0;
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.15;
|
||||
default -> GunsTool.getGunDoubleTag(rootTag, "CustomZoom");
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
rootTag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(rootTag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(rootTag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, rootTag);
|
||||
@Override
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.SksItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -58,11 +59,11 @@ public class SksItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sks.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sks.reload_normal"));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ import com.atsuishio.superbwarfare.init.ModPerks;
|
|||
import com.atsuishio.superbwarfare.init.ModRarity;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -57,11 +57,11 @@ public class Aa12Item extends GunItem implements GeoItem {
|
|||
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.aa12.reload_normal"));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponen
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -58,11 +58,11 @@ public class HomemadeShotgunItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ab.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ab.reload_normal"));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponen
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -53,29 +54,30 @@ public class M870Item extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
var data = GunData.from(stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.shift"));
|
||||
}
|
||||
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare_load") > 0) {
|
||||
if (data.getReloadStage() == 1 && tag.getDouble("prepare_load") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.preparealt"));
|
||||
}
|
||||
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare") > 0) {
|
||||
if (data.getReloadStage() == 1 && tag.getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.prepare"));
|
||||
}
|
||||
|
||||
if (tag.getDouble("load_index") == 0 && tag.getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 0 && data.getReloadStage() == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload"));
|
||||
}
|
||||
|
||||
if (tag.getDouble("load_index") == 1 && tag.getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 1 && data.getReloadStage() == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload2"));
|
||||
}
|
||||
|
||||
if (tag.getInt("reload_stage") == 3) {
|
||||
if (data.getReloadStage() == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.finish"));
|
||||
}
|
||||
|
||||
|
@ -85,15 +87,16 @@ public class M870Item extends GunItem implements GeoItem {
|
|||
private PlayState idlePredicate(AnimationState<M870Item> event) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (player == null) return PlayState.STOP;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
if (player.isSprinting()
|
||||
&& player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
&& !data.isReloading()) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.m870.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.VectorItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -50,11 +51,12 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
if (drum) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vec.reload_empty_drum"));
|
||||
} else {
|
||||
|
@ -62,7 +64,7 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
if (drum) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vec.reload_normal_drum"));
|
||||
} else {
|
||||
|
@ -118,30 +120,29 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
|
||||
int customMag = switch (magType) {
|
||||
if (scopeType == 3) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments");
|
||||
tag.putInt("Scope", 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
if (scopeType == 2) return 0.75;
|
||||
return GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 20;
|
||||
case 2 -> 57;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
if (scopeType == 3) {
|
||||
CompoundTag attachments = tag.getCompound("Attachments");
|
||||
attachments.putInt("Scope", 0);
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 0.75;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
};
|
||||
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.HuntingRifleItemRenderer
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -54,7 +54,7 @@ public class HuntingRifleItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.hunting_rifle.reload"));
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ import com.atsuishio.superbwarfare.client.renderer.item.K98ItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -47,31 +47,33 @@ public class K98Item extends GunItem implements GeoItem {
|
|||
private PlayState fireAnimPredicate(AnimationState<K98Item> event) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (player == null) return PlayState.STOP;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.shift"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.getReloadState() == GunData.ReloadState.EMPTY_RELOADING) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.reload_empty"));
|
||||
}
|
||||
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare") > 0) {
|
||||
if (data.getReloadStage() == 1 && tag.getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.prepare"));
|
||||
}
|
||||
|
||||
if (tag.getDouble("load_index") == 0 && tag.getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 0 && data.getReloadStage() == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload"));
|
||||
}
|
||||
|
||||
if (tag.getDouble("load_index") == 1 && tag.getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 1 && data.getReloadStage() == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload2"));
|
||||
}
|
||||
|
||||
if (tag.getInt("reload_stage") == 3) {
|
||||
if (data.getReloadStage() == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.finish"));
|
||||
}
|
||||
|
||||
|
@ -81,18 +83,21 @@ public class K98Item extends GunItem implements GeoItem {
|
|||
private PlayState idlePredicate(AnimationState<K98Item> event) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (player == null) return PlayState.STOP;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(tag.getBoolean("is_empty_reloading"))
|
||||
&& tag.getInt("reload_stage") != 1
|
||||
&& tag.getInt("reload_stage") != 2
|
||||
&& tag.getInt("reload_stage") != 3
|
||||
&& !(data.getReloadState() == GunData.ReloadState.EMPTY_RELOADING)
|
||||
&& data.getReloadStage() != 1
|
||||
&& data.getReloadStage() != 2
|
||||
&& data.getReloadStage() != 3
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
&& !data.isReloading()
|
||||
) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.k98.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -5,11 +5,11 @@ import com.atsuishio.superbwarfare.client.renderer.item.M98bItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -49,17 +49,18 @@ public class M98bItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m98b.shift"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m98b.reload_empty"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m98b.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -71,11 +72,12 @@ public class M98bItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading")) && ClientEventHandler.drawTime < 0.01) {
|
||||
&& !(data.normalReloading() || data.emptyReloading()) && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.m98b.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.MosinNagantItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -49,7 +50,8 @@ public class MosinNagantItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift"));
|
||||
|
@ -83,16 +85,18 @@ public class MosinNagantItem extends GunItem implements GeoItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& !(GunData.from(stack).emptyReloading())
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 1
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 2
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 3
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
&& !data.isReloading()
|
||||
) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mosin.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModRarity;
|
|||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -76,17 +77,18 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.shift"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (data.emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.reload_empty"));
|
||||
}
|
||||
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (data.normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -102,11 +104,12 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.getTag();
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !(data.normalReloading() || data.emptyReloading())
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging") && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.sentinel.run_fast"));
|
||||
|
@ -141,7 +144,7 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
|
|||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
cap.extractEnergy(1, false);
|
||||
GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0.2857142857142857
|
||||
* GunsTool.getGunDoubleTag(tag, "Damage"));
|
||||
* GunData.from(stack).damage());
|
||||
} else {
|
||||
GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.SvdItemRenderer;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -16,18 +17,15 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
public class SvdItem extends GunItem implements GeoItem {
|
||||
|
@ -54,11 +52,11 @@ public class SvdItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.svd.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (GunData.from(stack).normalReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.svd.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -107,30 +105,28 @@ public class SvdItem extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE);
|
||||
|
||||
int customMag = switch (magType) {
|
||||
public int getCustomMagazine(ItemStack stack) {
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
return switch (magType) {
|
||||
case 1 -> 10;
|
||||
case 2 -> 20;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
@Override
|
||||
public double getCustomZoom(ItemStack stack) {
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
return switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 3.75;
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
default -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
|
||||
};
|
||||
}
|
||||
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
@Override
|
||||
public boolean canAdjustZoom(ItemStack stack) {
|
||||
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.init.ModPerks;
|
|||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
||||
|
@ -96,7 +97,7 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (GunData.from(stack).emptyReloading()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.taser.reload"));
|
||||
}
|
||||
|
||||
|
@ -225,14 +226,15 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
|||
@Override
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
|
||||
var data = GunData.from(stack);
|
||||
if (data.isReloading()) return;
|
||||
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), tag);
|
||||
var energyStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
var hasEnoughEnergy = energyStorage != null && energyStorage.getEnergyStored() >= 400 + 100 * perkLevel;
|
||||
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
|| GunsTool.getGunIntTag(tag, "Ammo") <= 0
|
||||
|| data.getAmmo() <= 0
|
||||
|| !hasEnoughEnergy
|
||||
) return;
|
||||
|
||||
|
@ -241,7 +243,7 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
|||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
double spread = data.spread();
|
||||
|
||||
int volt = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), tag);
|
||||
int wireLength = PerkHelper.getItemPerkLevel(ModPerks.LONGER_WIRE.get(), tag);
|
||||
|
@ -252,19 +254,20 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
|||
var level = serverPlayer.level();
|
||||
|
||||
TaserBulletEntity taserBulletProjectile = new TaserBulletEntity(player, level,
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage"), volt, wireLength);
|
||||
(float) data.damage(), volt, wireLength);
|
||||
|
||||
taserBulletProjectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) GunsTool.getGunDoubleTag(tag, "Velocity"),
|
||||
taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) data.velocity(),
|
||||
(float) (zoom ? 0.1 : spread));
|
||||
level.addFreshEntity(taserBulletProjectile);
|
||||
|
||||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
|
||||
data.setAmmo(data.getAmmo() - 1);
|
||||
data.getTag().putBoolean("shoot", true);
|
||||
data.save();
|
||||
energyStorage.extractEnergy(400 + 100 * perkLevel, false);
|
||||
tag.putBoolean("shoot", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.init.ModBlocks;
|
|||
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.PerkItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
|
@ -207,16 +208,17 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
if (!(stack.getItem() instanceof GunItem)) {
|
||||
return;
|
||||
}
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
double oldPoint = GunsTool.getGunDoubleTag(tag, "UpgradePoint");
|
||||
double oldPoint = data.getUpgradePoint();
|
||||
int point = (int) oldPoint;
|
||||
int newPoint = this.upgradePoint.get();
|
||||
int delta = newPoint - point;
|
||||
|
||||
if (delta != 0) {
|
||||
GunsTool.setGunDoubleTag(tag, "UpgradePoint", oldPoint + delta);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,19 +295,20 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
|
||||
final var tag = NBTTool.getTag(gun);
|
||||
int level = PerkHelper.getItemPerkLevel(perkItem.getPerk(), tag);
|
||||
var data = GunData.from(gun);
|
||||
|
||||
if (level <= 0) {
|
||||
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(tag, "UpgradePoint"));
|
||||
this.upgradePoint.set((int) data.getUpgradePoint());
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack output = gun.copy();
|
||||
final var outputTag = NBTTool.getTag(output);
|
||||
PerkHelper.removePerkByType(outputTag, perkItem.getPerk().type);
|
||||
GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", Math.min(MAX_UPGRADE_POINT, level - 1 + GunsTool.getGunDoubleTag(outputTag, "UpgradePoint")));
|
||||
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(outputTag, "UpgradePoint"));
|
||||
data.setUpgradePoint(Math.min(MAX_UPGRADE_POINT, level - 1 + data.getUpgradePoint()));
|
||||
this.upgradePoint.set((int) data.getUpgradePoint());
|
||||
|
||||
NBTTool.saveTag(output, outputTag);
|
||||
data.save();
|
||||
this.container.setItem(INPUT_SLOT, output);
|
||||
this.container.setChanged();
|
||||
}
|
||||
|
@ -334,11 +337,11 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
* @param stack 输入的枪械
|
||||
*/
|
||||
private void onPlaceGun(ItemStack stack) {
|
||||
if (!(stack.getItem() instanceof GunItem)) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int point = (int) GunsTool.getGunDoubleTag(tag, "UpgradePoint");
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
int point = (int) data.getUpgradePoint();
|
||||
this.upgradePoint.set(Mth.clamp(point, 0, MAX_UPGRADE_POINT));
|
||||
|
||||
var ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
|
|
@ -4,9 +4,9 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -33,32 +33,33 @@ public record AdjustZoomFovMessage(double scroll) implements CustomPacketPayload
|
|||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
double minRpm = 300;
|
||||
double maxRpm = 2400;
|
||||
|
||||
GunsTool.setGunIntTag(tag, "RPM", (int) Mth.clamp(GunsTool.getGunIntTag(tag, "RPM") + 50 * message.scroll, minRpm, maxRpm));
|
||||
if (GunsTool.getGunIntTag(tag, "RPM") == 1150) {
|
||||
GunsTool.setGunIntTag(tag, "RPM", 1145);
|
||||
GunsTool.setGunIntTag(tag, "CustomRPM", (int) Mth.clamp(GunsTool.getGunIntTag(tag, "CustomRPM") - 1200 + 50 * message.scroll, minRpm, maxRpm));
|
||||
if (GunsTool.getGunIntTag(tag, "CustomRPM") == 1150 - 1200) {
|
||||
GunsTool.setGunIntTag(tag, "CustomRPM", 1145 - 1200);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "RPM") == 1195) {
|
||||
GunsTool.setGunIntTag(tag, "RPM", 1200);
|
||||
if (GunsTool.getGunIntTag(tag, "CustomRPM") == 1195 - 1200) {
|
||||
GunsTool.setGunIntTag(tag, "CustomRPM", 0);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "RPM") == 1095) {
|
||||
GunsTool.setGunIntTag(tag, "RPM", 1100);
|
||||
if (GunsTool.getGunIntTag(tag, "CustomRPM") == 1095 - 1200) {
|
||||
GunsTool.setGunIntTag(tag, "CustomRPM", 1100 - 1200);
|
||||
}
|
||||
player.displayClientMessage(Component.literal("RPM: " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM"))), true);
|
||||
int rpm = GunsTool.getGunIntTag(tag, "RPM");
|
||||
player.displayClientMessage(Component.literal("RPM: " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "CustomRPM") + 1200)), true);
|
||||
int rpm = GunsTool.getGunIntTag(tag, "CustomRPM");
|
||||
if (rpm > minRpm && rpm < maxRpm) {
|
||||
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
}
|
||||
} else {
|
||||
double minZoom = GunsTool.getGunDoubleTag(tag, "MinZoom") - 1.25;
|
||||
double maxZoom = GunsTool.getGunDoubleTag(tag, "MaxZoom") - 1.25;
|
||||
double minZoom = data.minZoom() - 1.25;
|
||||
double maxZoom = data.maxZoom() - 1.25;
|
||||
double customZoom = GunsTool.getGunDoubleTag(tag, "CustomZoom");
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", Mth.clamp(customZoom + 0.5 * message.scroll, minZoom, maxZoom));
|
||||
if (GunsTool.getGunDoubleTag(tag, "CustomZoom") > minZoom &&
|
||||
|
@ -66,7 +67,7 @@ public record AdjustZoomFovMessage(double scroll) implements CustomPacketPayload
|
|||
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
}
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
|||
import com.atsuishio.superbwarfare.event.GunEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
|
@ -51,8 +52,8 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (type == 0) {
|
||||
if (tag.getDouble("prepare") == 0 && GunsTool.getGunBooleanTag(tag, "Reloading") && GunsTool.getGunIntTag(tag, "Ammo") > 0) {
|
||||
tag.putDouble("force_stop", 1);
|
||||
var data = GunData.from(stack);
|
||||
if (tag.getDouble("prepare") == 0 && data.isReloading() && data.getAmmo() > 0) {
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
|
@ -87,18 +88,20 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleGunBolt(Player player, ItemStack stack, final CompoundTag tag) {
|
||||
private static void handleGunBolt(Player player, ItemStack stack, CompoundTag tag) {
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
var data = GunData.from(stack);
|
||||
tag = data.getTag();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo") > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
|
||||
if (data.boltActionTime() > 0
|
||||
&& data.getAmmo() > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
|
||||
&& GunsTool.getGunIntTag(tag, "BoltActionTick") == 0
|
||||
&& !(tag.getBoolean("is_normal_reloading")
|
||||
|| tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !(data.normalReloading()
|
||||
|| data.emptyReloading())
|
||||
&& !data.isReloading()
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(tag, "NeedBoltAction")) {
|
||||
GunsTool.setGunIntTag(tag, "BoltActionTick", GunsTool.getGunIntTag(tag, "BoltActionTime") + 1);
|
||||
GunsTool.setGunIntTag(tag, "BoltActionTick", data.boltActionTime() + 1);
|
||||
GunEventHandler.playGunBoltSounds(player);
|
||||
}
|
||||
}
|
||||
|
@ -124,11 +127,12 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
public static void spawnBullet(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (player.level().isClientSide()) return;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot");
|
||||
float headshot = (float) data.headshot();
|
||||
float velocity = 2 * (float) GunsTool.getGunDoubleTag(tag, "Power", 6) * (float) perkSpeed(tag);
|
||||
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor");
|
||||
float bypassArmorRate = (float) data.bypassArmor();
|
||||
double damage;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -137,12 +141,12 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
float spread;
|
||||
if (zoom) {
|
||||
spread = 0.01f;
|
||||
damage = 0.08333333 * GunsTool.getGunDoubleTag(tag, "Damage") *
|
||||
damage = 0.08333333 * data.damage() *
|
||||
GunsTool.getGunDoubleTag(tag, "Power", 6) * perkDamage(stack);
|
||||
} else {
|
||||
spread = perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.5f : 2.5f;
|
||||
damage = (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.08333333 : 0.008333333) *
|
||||
GunsTool.getGunDoubleTag(tag, "Damage") *
|
||||
data.damage() *
|
||||
GunsTool.getGunDoubleTag(tag, "Power", 6) * perkDamage(stack);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.atsuishio.superbwarfare.network.message.send;
|
|||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
|
@ -34,53 +34,54 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
public static void changeFireMode(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.getItem() instanceof GunItem gunItem) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int fireMode = tag.getCompound("GunData").getInt("FireMode");
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
int fireMode = data.getFireMode();
|
||||
|
||||
int mode = gunItem.getAvailableFireModes();
|
||||
mode &= 0b111;
|
||||
|
||||
if (fireMode == 0) {
|
||||
if ((mode & 2) != 0) {
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 1);
|
||||
data.setFireMode(1);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
return;
|
||||
}
|
||||
if ((mode & 4) != 0) {
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 2);
|
||||
data.setFireMode(2);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fireMode == 1) {
|
||||
if ((mode & 4) != 0) {
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 2);
|
||||
data.setFireMode(2);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
return;
|
||||
}
|
||||
if ((mode & 1) != 0) {
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 0);
|
||||
data.setFireMode(0);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fireMode == 2) {
|
||||
if ((mode & 1) != 0) {
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 0);
|
||||
data.setFireMode(0);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
return;
|
||||
}
|
||||
if ((mode & 2) != 0) {
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 1);
|
||||
data.setFireMode(1);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
if (stack.getItem() == ModItems.JAVELIN.get()) {
|
||||
tag.putBoolean("TopMode", !tag.getBoolean("TopMode"));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_ZOOM_OUT.get());
|
||||
}
|
||||
|
@ -111,13 +112,13 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
if (stack.getItem() == ModItems.TRACHELIUM.get() && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction")) {
|
||||
tag.putBoolean("DA", !tag.getBoolean("DA"));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
if (!tag.getBoolean("canImmediatelyShoot")) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.capability.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
@ -38,19 +38,20 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
var data = tag.getCompound("GunData");
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
if (!player.isSpectator()
|
||||
&& stack.getItem() instanceof GunItem gunItem
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& GunsTool.getGunIntTag(tag, "ReloadTime") == 0
|
||||
&& GunsTool.getGunIntTag(tag, "BoltActionTick") == 0
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !data.isReloading()
|
||||
) {
|
||||
boolean canSingleReload = gunItem.isIterativeReload(stack);
|
||||
boolean canReload = gunItem.isMagazineReload(stack) && !gunItem.isClipReload(stack);
|
||||
boolean clipLoad = GunsTool.getGunIntTag(tag, "Ammo") == 0 && gunItem.isClipReload(stack);
|
||||
boolean clipLoad = data.getAmmo() == 0 && gunItem.isClipReload(stack);
|
||||
|
||||
// 检查备弹
|
||||
boolean hasCreativeAmmoBox = player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||
|
@ -74,33 +75,28 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
}
|
||||
|
||||
if (canReload || clipLoad) {
|
||||
int magazine = GunsTool.getGunIntTag(tag, "Magazine");
|
||||
int ammo = GunsTool.getGunIntTag(tag, "Ammo");
|
||||
int customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine");
|
||||
int magazine = data.magazine();
|
||||
|
||||
if (gunItem.isOpenBolt(stack)) {
|
||||
if (gunItem.hasBulletInBarrel(stack)) {
|
||||
if (ammo < magazine + customMagazine + 1) {
|
||||
data.putBoolean("StartReload", true);
|
||||
if (data.getAmmo() < magazine + 1) {
|
||||
GunsTool.setGunBooleanTag(tag, "StartReload", true);
|
||||
}
|
||||
} else if (ammo < magazine + customMagazine) {
|
||||
data.putBoolean("StartReload", true);
|
||||
} else {
|
||||
if (data.getAmmo() < magazine) {
|
||||
GunsTool.setGunBooleanTag(tag, "StartReload", true);
|
||||
}
|
||||
} else if (ammo < magazine + customMagazine) {
|
||||
data.putBoolean("StartReload", true);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
} else if (data.getAmmo() < magazine) {
|
||||
GunsTool.setGunBooleanTag(tag, "StartReload", true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (canSingleReload
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo")
|
||||
< GunsTool.getGunIntTag(tag, "Magazine")
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine")) {
|
||||
|
||||
if (canSingleReload && data.getAmmo() < data.magazine()) {
|
||||
tag.putBoolean("start_single_reload", true);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,10 +7,14 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.*;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
|
@ -40,14 +44,15 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
|
||||
public static void pressAction(Player player, double spared) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var data = GunData.from(stack);
|
||||
var tag = data.getTag();
|
||||
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount", 1);
|
||||
int projectileAmount = data.projectileAmount();
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") > 0) {
|
||||
if (data.getAmmo() > 0) {
|
||||
// 空仓挂机
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo") == 1) {
|
||||
if (data.getAmmo() == 1) {
|
||||
GunsTool.setGunBooleanTag(tag, "HoldOpen", true);
|
||||
}
|
||||
|
||||
|
@ -56,14 +61,14 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
}
|
||||
|
||||
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0 && GunsTool.getGunIntTag(tag, "Ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
if (data.boltActionTime() > 0 && data.getAmmo() > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
|
||||
data.setAmmo(data.getAmmo() - 1);
|
||||
tag.putDouble("empty", 1);
|
||||
|
||||
if (stack.getItem() == ModItems.M_60.get() && GunsTool.getGunIntTag(tag, "Ammo") <= 5) {
|
||||
if (stack.getItem() == ModItems.M_60.get() && data.getAmmo() <= 5) {
|
||||
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
|
||||
}
|
||||
|
||||
|
@ -90,7 +95,6 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
}
|
||||
|
||||
GunEventHandler.playGunSounds(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -110,7 +114,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat")));
|
||||
|
||||
if (!player.level().isClientSide() && player instanceof ServerPlayer) {
|
||||
float soundRadius = (float) GunsTool.getGunDoubleTag(tag, "SoundRadius");
|
||||
float soundRadius = (float) data.soundRadius();
|
||||
|
||||
player.playSound(ModSounds.MINIGUN_FIRE_3P.get(), soundRadius * 0.2f, pitch);
|
||||
player.playSound(ModSounds.MINIGUN_FAR.get(), soundRadius * 0.5f, pitch);
|
||||
|
@ -126,10 +130,9 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
cap.rifleAmmo = cap.rifleAmmo - 1;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
data.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.perk;
|
|||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.item.PerkItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -64,6 +65,10 @@ public class PerkHelper {
|
|||
};
|
||||
}
|
||||
|
||||
public static int getItemPerkLevel(Perk perk, GunData data) {
|
||||
return getItemPerkLevel(perk, data.getTag());
|
||||
}
|
||||
|
||||
public static int getItemPerkLevel(Perk perk, final CompoundTag tag) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
if (!tagPerk.contains(perk.type.getName())) {
|
||||
|
@ -83,6 +88,10 @@ public class PerkHelper {
|
|||
return getPerkLevel(getPerkTag(tag, perk.type));
|
||||
}
|
||||
|
||||
public static CompoundTag getPerkTag(GunData data, Perk.Type type) {
|
||||
return getPerkTag(data.getTag(), type);
|
||||
}
|
||||
|
||||
public static CompoundTag getPerkTag(final CompoundTag tag, Perk.Type type) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
if (!tagPerk.contains(type.getName())) return new CompoundTag();
|
||||
|
@ -103,6 +112,11 @@ public class PerkHelper {
|
|||
setPerk(tag, perk, 1);
|
||||
}
|
||||
|
||||
public static Perk getPerkByType(GunData data, Perk.Type type) {
|
||||
return getPerkByType(data.getTag(), type);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static Perk getPerkByType(final CompoundTag tag, Perk.Type type) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.tools;
|
|||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.capability.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.GunsDataMessage;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -58,22 +59,23 @@ public class GunsTool {
|
|||
if (gunsData != null && gunsData.get(location) != null) {
|
||||
CompoundTag data = tag.getCompound("GunData");
|
||||
|
||||
gunsData.get(location).forEach(data::putDouble);
|
||||
// gunsData.get(location).forEach(data::putDouble);
|
||||
|
||||
data.putBoolean("Init", true);
|
||||
tag.put("GunData", data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initCreativeGun(final CompoundTag tag, String location) {
|
||||
var fillAmmo = !tag.getCompound("GunData").getBoolean("Init");
|
||||
public static void initCreativeGun(ItemStack stack, String location) {
|
||||
var data = GunData.from(stack);
|
||||
var fillAmmo = !data.getData().getBoolean("Init");
|
||||
|
||||
initGun(tag, location);
|
||||
initGun(data.getTag(), location);
|
||||
data.save();
|
||||
|
||||
if (fillAmmo) {
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putInt("Ammo", GunsTool.getGunIntTag(tag, "Magazine")
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine")
|
||||
);
|
||||
data.setAmmo(data.magazine());
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,19 +122,19 @@ public class GunsTool {
|
|||
});
|
||||
}
|
||||
|
||||
public static void reload(Player player, ItemStack stack, final CompoundTag tag, AmmoType type) {
|
||||
reload(player, stack, tag, type, false);
|
||||
public static void reload(Player player, ItemStack stack, GunData gunData, AmmoType type) {
|
||||
reload(player, stack, gunData, type, false);
|
||||
}
|
||||
|
||||
public static void reload(Player player, ItemStack stack, final CompoundTag tag, AmmoType type, boolean extraOne) {
|
||||
final var data = tag.getCompound("GunData");
|
||||
public static void reload(Player player, ItemStack stack, GunData gunData, AmmoType type, boolean extraOne) {
|
||||
var data = gunData.getData();
|
||||
|
||||
int mag = data.getInt("Magazine") + data.getInt("CustomMagazine");
|
||||
int ammo = data.getInt("Ammo");
|
||||
int mag = gunData.magazine();
|
||||
int ammo = gunData.getAmmo();
|
||||
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
|
||||
|
||||
// 空仓换弹的栓动武器应该在换弹后取消待上膛标记
|
||||
if (ammo == 0 && data.getInt("BoltActionTime") > 0 && !stack.is(ModTags.Items.REVOLVER)) {
|
||||
if (ammo == 0 && gunData.boltActionTime() > 0 && !stack.is(ModTags.Items.REVOLVER)) {
|
||||
data.putBoolean("NeedBoltAction", false);
|
||||
}
|
||||
|
||||
|
@ -148,9 +150,9 @@ public class GunsTool {
|
|||
|
||||
int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo);
|
||||
|
||||
data.putInt("Ammo", needToAdd);
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
gunData.setAmmo(needToAdd);
|
||||
gunData.setReloadState(GunData.ReloadState.NOT_RELOADING);
|
||||
gunData.save();
|
||||
}
|
||||
|
||||
/* PerkData */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"CustomZoom": 0.75,
|
||||
"DefaultZoom": 0.75,
|
||||
"Spread": 4,
|
||||
"Headshot": 2.5,
|
||||
"Damage": 48,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"CustomZoom": 0.75,
|
||||
"DefaultZoom": 0.75,
|
||||
"Spread": 5,
|
||||
"RecoilX": 0.0018,
|
||||
"RecoilY": 0.01,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"Magazine": 48,
|
||||
"Weight": 6,
|
||||
"FireMode": 1,
|
||||
"BurstSize": 4,
|
||||
"BurstAmount": 4,
|
||||
"EmptyReloadTime": 56,
|
||||
"BypassesArmor": 0.4,
|
||||
"SoundRadius": 12,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"CustomZoom": 1.75,
|
||||
"DefaultZoom": 1.75,
|
||||
"Spread": 5,
|
||||
"Magazine": 1,
|
||||
"Weight": 10,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"CustomZoom": 4.75,
|
||||
"DefaultZoom": 4.75,
|
||||
"MinZoom": 4,
|
||||
"MaxZoom": 8,
|
||||
"Spread": 6,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"CustomZoom": 2.25,
|
||||
"DefaultZoom": 2.25,
|
||||
"Spread": 4.8,
|
||||
"RecoilX": 0.002,
|
||||
"RecoilY": 0.063,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"CustomZoom": 1.75,
|
||||
"DefaultZoom": 1.75,
|
||||
"Spread": 6,
|
||||
"RecoilX": 0.007,
|
||||
"RecoilY": 0.018,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"Magazine": 13,
|
||||
"Weight": 3,
|
||||
"FireMode": 2,
|
||||
"BurstSize": 3,
|
||||
"BurstAmount": 3,
|
||||
"NormalReloadTime": 46,
|
||||
"EmptyReloadTime": 64,
|
||||
"BypassesArmor": 0.15,
|
||||
|
|
Loading…
Add table
Reference in a new issue