修复部分数据存储相关问题
This commit is contained in:
parent
616818d15b
commit
161abbf1a6
100 changed files with 1378 additions and 1276 deletions
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.client;
|
|||
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
|
@ -58,7 +59,7 @@ public class AnimationHelper {
|
|||
}
|
||||
|
||||
public static void handleReloadShakeAnimation(ItemStack stack, GeoBone main, GeoBone camera, float roll, float pitch) {
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
if (GunsTool.getGunIntTag(NBTTool.getTag(stack), "ReloadTime") > 0) {
|
||||
main.setRotX(roll * main.getRotX());
|
||||
main.setRotY(roll * main.getRotY());
|
||||
main.setRotZ(roll * main.getRotZ());
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.mojang.blaze3d.platform.InputConstants;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -89,6 +90,7 @@ public class ClickHandler {
|
|||
if (player.isSpectator()) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
int button = event.getButton();
|
||||
|
||||
|
@ -124,13 +126,13 @@ public class ClickHandler {
|
|||
}
|
||||
|
||||
if (button == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
|
||||
handleWeaponZoomPress(player, stack);
|
||||
handleWeaponZoomPress(player, tag);
|
||||
switchZoom = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) {
|
||||
handleWeaponZoomPress(player, stack);
|
||||
handleWeaponZoomPress(player, tag);
|
||||
switchZoom = !switchZoom;
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +165,7 @@ public class ClickHandler {
|
|||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) {
|
||||
if (GunsTool.getGunBooleanTag(stack, "CanSwitchScope", false)) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "CanSwitchScope", false)) {
|
||||
PacketDistributor.sendToServer(new SwitchScopeMessage(scroll));
|
||||
} else if (tag.getBoolean("CanAdjustZoomFov") || stack.is(ModItems.MINIGUN.get())) {
|
||||
PacketDistributor.sendToServer(new AdjustZoomFovMessage(scroll));
|
||||
|
@ -193,6 +195,7 @@ public class ClickHandler {
|
|||
if (player.isSpectator()) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
int key = event.getKey();
|
||||
if (event.getAction() == GLFW.GLFW_PRESS) {
|
||||
|
@ -264,13 +267,13 @@ public class ClickHandler {
|
|||
}
|
||||
|
||||
if (key == ModKeyMappings.HOLD_ZOOM.getKey().getValue()) {
|
||||
handleWeaponZoomPress(player, stack);
|
||||
handleWeaponZoomPress(player, tag);
|
||||
switchZoom = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue()) {
|
||||
handleWeaponZoomPress(player, stack);
|
||||
handleWeaponZoomPress(player, tag);
|
||||
switchZoom = !switchZoom;
|
||||
}
|
||||
}
|
||||
|
@ -317,16 +320,16 @@ public class ClickHandler {
|
|||
if (stack.getItem() instanceof GunItem gunItem && !(player.getVehicle() != null && player.getVehicle() instanceof CannonEntity)) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if ((!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging")
|
||||
&& !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false))
|
||||
&& cantFireTime == 0
|
||||
&& drawTime < 0.01
|
||||
&& !notInGame()) {
|
||||
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
|
||||
}
|
||||
|
||||
if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0 && GunsTool.getGunIntTag(stack, "ReloadTime") == 0) {
|
||||
if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0 && GunsTool.getGunIntTag(tag, "ReloadTime") == 0) {
|
||||
if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {
|
||||
PacketDistributor.sendToServer(new ReloadMessage(0));
|
||||
}
|
||||
|
@ -335,8 +338,8 @@ public class ClickHandler {
|
|||
if (!stack.is(ModItems.BOCEK.get())) {
|
||||
ClientEventHandler.holdFire = true;
|
||||
}
|
||||
if (GunsTool.getGunIntTag(stack, "FireMode") == 1 && ClientEventHandler.burstFireSize == 0) {
|
||||
ClientEventHandler.burstFireSize = GunsTool.getGunIntTag(stack, "BurstSize", 1);
|
||||
if (GunsTool.getGunIntTag(tag, "FireMode") == 1 && ClientEventHandler.burstFireSize == 0) {
|
||||
ClientEventHandler.burstFireSize = GunsTool.getGunIntTag(tag, "BurstSize", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +352,7 @@ public class ClickHandler {
|
|||
ClientEventHandler.customRpm = 0;
|
||||
}
|
||||
|
||||
public static void handleWeaponZoomPress(Player player, ItemStack stack) {
|
||||
public static void handleWeaponZoomPress(Player player, final CompoundTag tag) {
|
||||
PacketDistributor.sendToServer(new ZoomMessage(0));
|
||||
|
||||
if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player))) {
|
||||
|
@ -358,7 +361,7 @@ public class ClickHandler {
|
|||
}
|
||||
|
||||
ClientEventHandler.zoom = true;
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.INTELLIGENT_CHIP.get(), stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.INTELLIGENT_CHIP.get(), tag);
|
||||
if (level > 0) {
|
||||
if (ClientEventHandler.entity == null) {
|
||||
ClientEventHandler.entity = SeekTool.seekLivingEntity(player, player.level(), 32 + 8 * (level - 1), 20);
|
||||
|
|
|
@ -16,8 +16,8 @@ public class PoseTool {
|
|||
var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("is_empty_reloading")
|
||||
|| tag.getBoolean("is_normal_reloading")
|
||||
|| GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
|| GunsTool.getGunBooleanTag(stack, "Charging")) {
|
||||
|| GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
|| 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.init.ModPerks;
|
|||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -24,7 +25,7 @@ public class TooltipTool {
|
|||
}
|
||||
|
||||
public static double perkDamage(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(NBTTool.getTag(stack), Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
return ammoPerk.damageRate;
|
||||
}
|
||||
|
@ -32,14 +33,14 @@ public class TooltipTool {
|
|||
}
|
||||
|
||||
public static boolean heBullet(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(NBTTool.getTag(stack), Perk.Type.AMMO);
|
||||
return perk == ModPerks.HE_BULLET.get();
|
||||
}
|
||||
|
||||
public static int heBulletLevel(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(NBTTool.getTag(stack), Perk.Type.AMMO);
|
||||
if (perk == ModPerks.HE_BULLET.get()) {
|
||||
return PerkHelper.getItemPerkLevel(perk, stack);
|
||||
return PerkHelper.getItemPerkLevel(perk, NBTTool.getTag(stack));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ public class AK12ItemModel extends GeoModel<AK12Item> {
|
|||
double fp = ClientEventHandler.firePos;
|
||||
double fr = ClientEventHandler.fireRot;
|
||||
|
||||
int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int type = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
|
||||
float posY = switch (type) {
|
||||
case 0 -> 0.781f;
|
||||
|
@ -110,7 +111,7 @@ public class AK12ItemModel extends GeoModel<AK12Item> {
|
|||
scope2.setScaleZ(1f - (0.3f * (float) zp));
|
||||
scope3.setScaleZ(1f - (0.7f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 1.85));
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.85));
|
||||
|
||||
GeoBone shen;
|
||||
if (zt < 0.5) {
|
||||
|
@ -172,5 +173,6 @@ public class AK12ItemModel extends GeoModel<AK12Item> {
|
|||
AnimationHelper.handleReloadShakeAnimation(stack, main, camera, numR, numP);
|
||||
ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(), Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ());
|
||||
AnimationHelper.handleShellsAnimation(getAnimationProcessor(), 1f, 0.35f);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,9 @@ public class AK47ItemModel extends GeoModel<AK47Item> {
|
|||
scope2.setScaleZ(1f - (0.3f * (float) zp));
|
||||
scope3.setScaleZ(1f - (0.7f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 1.8));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.8));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
GeoBone shen;
|
||||
if (zt < 0.5) {
|
||||
|
|
|
@ -105,7 +105,9 @@ public class BocekItemModel extends GeoModel<BocekItem> {
|
|||
r.setScaleZ(1f - (0.31f * (float) zp));
|
||||
shen.setRotZ(60 * Mth.DEG_TO_RAD * (float) zp + (float) (0.05f * zpz) - 0.2f);
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !((shen_pos.getPosX() < -0.6 && gun.getPosZ() < -2)));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !((shen_pos.getPosX() < -0.6 && gun.getPosZ() < -2)));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
fire.setPosX((float) (0.75f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
fire.setPosY((float) (-0.03f * fp - 0.06f * fr));
|
||||
|
|
|
@ -74,7 +74,9 @@ public class DevotionItemModel extends GeoModel<DevotionItem> {
|
|||
GeoBone shen = getAnimationProcessor().getBone("shen");
|
||||
GeoBone holo = getAnimationProcessor().getBone("holo");
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 1.8));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.8));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
shen.setPosX((float) (0.95f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
shen.setPosY((float) (0.15f * fp + 0.18f * fr));
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.handgun.Glock17Item;
|
||||
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;
|
||||
|
@ -102,7 +103,9 @@ public class Glock17ItemModel extends GeoModel<Glock17Item> {
|
|||
float numR = (float) (1 - 0.12 * zt);
|
||||
float numP = (float) (1 - 0.68 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
@ -119,7 +122,7 @@ public class Glock17ItemModel extends GeoModel<Glock17Item> {
|
|||
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
GeoBone barrel = getAnimationProcessor().getBone("guan");
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
slide.setPosZ(1.5f);
|
||||
barrel.setRotX(4 * Mth.DEG_TO_RAD);
|
||||
bullet.setScaleX(0);
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.handgun.Glock18Item;
|
||||
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;
|
||||
|
@ -46,7 +47,8 @@ public class Glock18ItemModel extends GeoModel<Glock18Item> {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
int mode = GunsTool.getGunIntTag(stack, "FireMode");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
if (mode == 0) {
|
||||
switch_.setRotX(35 * Mth.DEG_TO_RAD);
|
||||
}
|
||||
|
@ -112,7 +114,7 @@ public class Glock18ItemModel extends GeoModel<Glock18Item> {
|
|||
float numR = (float) (1 - 0.12 * zt);
|
||||
float numP = (float) (1 - 0.68 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
@ -129,7 +131,7 @@ public class Glock18ItemModel extends GeoModel<Glock18Item> {
|
|||
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
GeoBone barrel = getAnimationProcessor().getBone("guan");
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
slide.setPosZ(1.5f);
|
||||
barrel.setRotX(4 * Mth.DEG_TO_RAD);
|
||||
bullet.setScaleX(0);
|
||||
|
|
|
@ -108,7 +108,9 @@ public class Hk416ItemModel extends GeoModel<Hk416Item> {
|
|||
scope2.setScaleZ(1f - (0.8f * (float) zp));
|
||||
scope3.setScaleZ(1f - (0.5f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 3.1));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 3.1));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
GeoBone shen;
|
||||
if (zt < 0.5) {
|
||||
|
@ -152,7 +154,7 @@ public class Hk416ItemModel extends GeoModel<Hk416Item> {
|
|||
l.setRotX(rotXBipod * Mth.DEG_TO_RAD);
|
||||
r.setRotX(rotXBipod * Mth.DEG_TO_RAD);
|
||||
|
||||
int mode = GunsTool.getGunIntTag(stack, "FireMode");
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
|
||||
kuaimanji.setRotX(mode == 2 ? 90 * Mth.DEG_TO_RAD : 0);
|
||||
|
||||
|
|
|
@ -67,7 +67,10 @@ public class JavelinItemModel extends GeoModel<JavelinItem> {
|
|||
gun.setRotZ(-4.75f * Mth.DEG_TO_RAD * (float) zp + (float) (0.02f * zpz));
|
||||
|
||||
javelin.setHidden(gun.getPosZ() > 15.85);
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosZ() > 15.85));
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosZ() > 15.85));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
shen.setPosX((float) (0.75f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
shen.setPosY((float) (-0.03f * fp - 0.06f * fr));
|
||||
|
|
|
@ -44,8 +44,8 @@ public class K98ItemModel extends GeoModel<K98Item> {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("prepare") > 11 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (NBTTool.getTag(stack).getDouble("prepare") > 11 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) {
|
||||
clip.setScaleX(0);
|
||||
clip.setScaleY(0);
|
||||
clip.setScaleZ(0);
|
||||
|
@ -108,7 +108,7 @@ public class K98ItemModel extends GeoModel<K98Item> {
|
|||
float numR = (float) (1 - 0.52 * zt);
|
||||
float numP = (float) (1 - 0.58 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.handgun.M1911Item;
|
||||
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;
|
||||
|
@ -104,7 +105,8 @@ public class M1911ItemModel extends GeoModel<M1911Item> {
|
|||
float numR = (float) (1 - 0.12 * zt);
|
||||
float numP = (float) (1 - 0.68 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
@ -120,7 +122,7 @@ public class M1911ItemModel extends GeoModel<M1911Item> {
|
|||
AnimationHelper.handleShellsAnimation(getAnimationProcessor(), 0.7f, 1f);
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
slide.setPosZ(1.5f);
|
||||
bullet.setScaleX(0);
|
||||
bullet.setScaleY(0);
|
||||
|
|
|
@ -129,7 +129,9 @@ public class M4ItemModel extends GeoModel<M4Item> {
|
|||
button6.setScaleX(1f - (0.5f * (float) zp));
|
||||
button7.setScaleX(1f - (0.5f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 2.385));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 2.385));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
if (type == 3 && zt > 0.5) {
|
||||
lh.setPosY((float) (-zt * 4));
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.machinegun.M60Item;
|
||||
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;
|
||||
|
@ -58,8 +59,9 @@ public class M60ItemModel extends GeoModel<M60Item> {
|
|||
r.setRotX(1.5f);
|
||||
}
|
||||
|
||||
int ammo = GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
boolean flag = GunsTool.getGunBooleanTag(stack, "HideBulletChain");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int ammo = GunsTool.getGunIntTag(tag, "Ammo", 0);
|
||||
boolean flag = GunsTool.getGunBooleanTag(tag, "HideBulletChain");
|
||||
|
||||
if (ammo < 5 && flag) {
|
||||
b5.setScaleX(0);
|
||||
|
@ -151,7 +153,7 @@ public class M60ItemModel extends GeoModel<M60Item> {
|
|||
AnimationHelper.handleShellsAnimation(getAnimationProcessor(), 1f, 0.45f);
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
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;
|
||||
|
@ -99,7 +100,8 @@ public class M870ItemModel extends GeoModel<M870Item> {
|
|||
float numR = (float) (1 - 0.72 * zt);
|
||||
float numP = (float) (1 - 0.82 * zt);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -88,7 +88,9 @@ public class M98bItemModel extends GeoModel<M98bItem> {
|
|||
gun.setPosZ(4.2f * (float) zp + (float) (0.3f * zpz));
|
||||
gun.setRotZ((float) (0.02f * zpz));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 1.8));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.8));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
GeoBone root = getAnimationProcessor().getBone("root");
|
||||
GeoBone zhunxing = getAnimationProcessor().getBone("shi");
|
||||
|
@ -105,7 +107,7 @@ public class M98bItemModel extends GeoModel<M98bItem> {
|
|||
float numR = (float) (1 - 0.88 * zt);
|
||||
float numP = (float) (1 - 0.68 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -101,7 +101,8 @@ public class MarlinItemModel extends GeoModel<MarlinItem> {
|
|||
float numR = (float) (1 - 0.55 * zt);
|
||||
float numP = (float) (1 - 0.88 * zt);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
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;
|
||||
|
@ -58,7 +59,8 @@ public class MinigunItemModel extends GeoModel<MinigunItem> {
|
|||
double fp = ClientEventHandler.firePos;
|
||||
double fr = ClientEventHandler.fireRot;
|
||||
|
||||
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int rpm = GunsTool.getGunIntTag(tag, "RPM", 0);
|
||||
|
||||
gun.setRotZ(gun.getRotZ() + times * -0.07f * ((float) rpm / 1200) * ClientEventHandler.miniGunRot);
|
||||
|
||||
|
|
|
@ -139,7 +139,9 @@ public class Mk14ItemModel extends GeoModel<Mk14Item> {
|
|||
|
||||
action.setPosZ(2.5f * (float) fp);
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 2.5));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 2.5));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
GeoBone root = getAnimationProcessor().getBone("root");
|
||||
root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph));
|
||||
|
@ -166,7 +168,7 @@ public class Mk14ItemModel extends GeoModel<Mk14Item> {
|
|||
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
action.setPosZ(2.5f);
|
||||
shell.setScaleX(0);
|
||||
shell.setScaleY(0);
|
||||
|
|
|
@ -86,7 +86,9 @@ public class MosinNagantItemModel extends GeoModel<MosinNagantItem> {
|
|||
qiangshen.setScaleZ(1);
|
||||
}
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 1.4));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.4));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
shen.setPosX((float) (0.95f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
shen.setPosY((float) (0.4f * fp + 0.44f * fr));
|
||||
|
@ -122,7 +124,7 @@ public class MosinNagantItemModel extends GeoModel<MosinNagantItem> {
|
|||
float numR = (float) (1 - 0.97 * zt);
|
||||
float numP = (float) (1 - 0.81 * zt);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading") || GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading") || GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.handgun.Mp443Item;
|
||||
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;
|
||||
|
@ -101,7 +102,8 @@ public class Mp443ItemModel extends GeoModel<Mp443Item> {
|
|||
float numR = (float) (1 - 0.12 * zt);
|
||||
float numP = (float) (1 - 0.68 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
@ -117,7 +119,8 @@ public class Mp443ItemModel extends GeoModel<Mp443Item> {
|
|||
AnimationHelper.handleShellsAnimation(getAnimationProcessor(), 0.7f, 1f);
|
||||
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
slide.setPosZ(1.5f);
|
||||
bullet.setScaleX(0);
|
||||
bullet.setScaleY(0);
|
||||
|
|
|
@ -137,7 +137,9 @@ public class Ntw20Model extends GeoModel<Ntw20Item> {
|
|||
|
||||
CrossHairOverlay.gunRot = shen.getRotZ();
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 4.3));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 4.3));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
action.setPosZ(3f * (float) ClientEventHandler.actionMove);
|
||||
lh.setPosZ(-3f * (float) ClientEventHandler.actionMove);
|
||||
|
@ -161,7 +163,7 @@ public class Ntw20Model extends GeoModel<Ntw20Item> {
|
|||
float numR = (float) (1 - 0.92 * zt);
|
||||
float numP = (float) (1 - 0.88 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0 || GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -83,7 +83,8 @@ public class Qbz95ItemModel extends GeoModel<Qbz95Item> {
|
|||
double fp = ClientEventHandler.firePos;
|
||||
double fr = ClientEventHandler.fireRot;
|
||||
|
||||
int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
var tag = NBTTool.getTag(stack);
|
||||
int type = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
|
||||
float posYAlt = switch (type) {
|
||||
case 2 -> 0.85f;
|
||||
|
@ -122,7 +123,7 @@ public class Qbz95ItemModel extends GeoModel<Qbz95Item> {
|
|||
button3.setScaleX(1f - (0.5f * (float) zp));
|
||||
button6.setScaleX(1f - (0.8f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", gun.getPosX() < 3.1);
|
||||
tag.putBoolean("HoloHidden", gun.getPosX() < 3.1);
|
||||
|
||||
GeoBone shen;
|
||||
if (zt < 0.5) {
|
||||
|
@ -168,12 +169,12 @@ public class Qbz95ItemModel extends GeoModel<Qbz95Item> {
|
|||
l.setRotX(rotXBipod * Mth.DEG_TO_RAD);
|
||||
r.setRotX(rotXBipod * Mth.DEG_TO_RAD);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
bolt.setPosZ(5f);
|
||||
}
|
||||
|
||||
GeoBone flare = getAnimationProcessor().getBone("flare");
|
||||
int BarrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int BarrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
|
||||
if (BarrelType == 1) {
|
||||
flare.setPosZ(-2);
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
||||
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;
|
||||
|
@ -44,7 +45,8 @@ public class RpgItemModel extends GeoModel<RpgItem> {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "CloseHammer")) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunBooleanTag(tag, "CloseHammer")) {
|
||||
hammer.setRotX(-90 * Mth.DEG_TO_RAD);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,10 @@ public class RpkItemModel extends GeoModel<RpkItem> {
|
|||
button.setScaleY(1f - (0.3f * (float) zp));
|
||||
button.setScaleZ(1f - (0.3f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 1.65));
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 1.65));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
shen.setPosX((float) (0.95f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
shen.setPosY((float) (0.15f * fp + 0.18f * fr));
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.launcher.SecondaryCataclysm;
|
||||
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;
|
||||
|
@ -99,7 +100,8 @@ public class SecondaryCataclysmModel extends GeoModel<SecondaryCataclysm> {
|
|||
float numR = (float) (1 - 0.12 * zt);
|
||||
float numP = (float) (1 - 0.68 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -75,7 +75,10 @@ public class SentinelItemModel extends GeoModel<SentinelItem> {
|
|||
|
||||
GeoBone holo = getAnimationProcessor().getBone("holo");
|
||||
holo.setPosY(0.09f);
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", !(gun.getPosX() > 2.4));
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", !(gun.getPosX() > 2.4));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
shen.setPosX((float) (0.95f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
shen.setPosY((float) (0.4f * fp + 0.44f * fr));
|
||||
|
@ -104,8 +107,8 @@ public class SentinelItemModel extends GeoModel<SentinelItem> {
|
|||
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
|
||||
root.setRotZ((float) (0.2f * movePosX + moveRotZ + Mth.DEG_TO_RAD * 90 * ClientEventHandler.drawTime + 2.7f * mph + Mth.DEG_TO_RAD * turnRotZ));
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) <= 5) {
|
||||
ammo.setScaleX((float) GunsTool.getGunIntTag(stack, "Ammo", 0) / 5);
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) <= 5) {
|
||||
ammo.setScaleX((float) GunsTool.getGunIntTag(tag, "Ammo", 0) / 5);
|
||||
}
|
||||
|
||||
GeoBone camera = getAnimationProcessor().getBone("camera");
|
||||
|
@ -114,7 +117,7 @@ public class SentinelItemModel extends GeoModel<SentinelItem> {
|
|||
float numR = (float) (1 - 0.9 * zt);
|
||||
float numP = (float) (1 - 0.98 * zt);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(stack, "Charging")) {
|
||||
if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
main.setRotX(numR * main.getRotX());
|
||||
main.setRotY(numR * main.getRotY());
|
||||
main.setRotZ(numR * main.getRotZ());
|
||||
|
|
|
@ -68,7 +68,9 @@ public class SksItemModel extends GeoModel<SksItem> {
|
|||
gun.setPosZ(2.5f * (float) zp + (float) (0.5f * zpz));
|
||||
gun.setRotZ((float) (0.05f * zpz));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", gun.getPosX() <= 1.2);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", gun.getPosX() <= 1.2);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
GeoBone shen = getAnimationProcessor().getBone("shen");
|
||||
|
||||
shen.setPosX((float) (0.95f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
|
@ -108,7 +110,7 @@ public class SksItemModel extends GeoModel<SksItem> {
|
|||
AnimationHelper.handleShellsAnimation(getAnimationProcessor(), 0.7f, 1.2f);
|
||||
GeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
shell.setScaleX(0);
|
||||
shell.setScaleY(0);
|
||||
shell.setScaleZ(0);
|
||||
|
|
|
@ -110,7 +110,9 @@ public class SvdItemModel extends GeoModel<SvdItem> {
|
|||
cross3.setScaleX((float) (1f + (0.1 * zp)));
|
||||
cross3.setScaleY((float) (1f + (0.1 * zp)));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", gun.getPosX() <= 1.4);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", gun.getPosX() <= 1.4);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
GeoBone shen;
|
||||
if (zt < 0.5) {
|
||||
|
@ -146,7 +148,7 @@ public class SvdItemModel extends GeoModel<SvdItem> {
|
|||
|
||||
bolt.setPosZ(4.5f * (float) fp);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "HoldOpen")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "HoldOpen")) {
|
||||
bolt.setPosZ(3.5f);
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,9 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
|
|||
|
||||
CrossHairOverlay.gunRot = shen.getRotZ();
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", (gun.getPosX() <= 3 || Mth.abs(shen.getRotX()) > (scopeType == 2 ? 3 : 1) * Mth.DEG_TO_RAD || Mth.abs(main.getRotX()) > (scopeType == 2 ? 5.7 : 1) * Mth.DEG_TO_RAD || Mth.abs(main.getRotY()) > 3 * Mth.DEG_TO_RAD));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("HoloHidden", (gun.getPosX() <= 3 || Mth.abs(shen.getRotX()) > (scopeType == 2 ? 3 : 1) * Mth.DEG_TO_RAD || Mth.abs(main.getRotX()) > (scopeType == 2 ? 5.7 : 1) * Mth.DEG_TO_RAD || Mth.abs(main.getRotY()) > 3 * Mth.DEG_TO_RAD));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
hammer.setRotX(50 * Mth.DEG_TO_RAD * (float) ClientEventHandler.revolverPreTime);
|
||||
lun.setRotZ(-60 * Mth.DEG_TO_RAD * (float) ClientEventHandler.revolverWheelPreTime);
|
||||
|
|
|
@ -55,7 +55,8 @@ public class VectorItemModel extends GeoModel<VectorItem> {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
int mode = GunsTool.getGunIntTag(stack, "FireMode");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
if (mode == 0) {
|
||||
kmj.setRotX(-120 * Mth.DEG_TO_RAD);
|
||||
}
|
||||
|
@ -98,7 +99,8 @@ public class VectorItemModel extends GeoModel<VectorItem> {
|
|||
gun.setScaleZ(1f - (0.5f * (float) zp));
|
||||
scope.setScaleZ(1f - (0.2f * (float) zp));
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("HoloHidden", gun.getPosX() <= 2);
|
||||
tag.putBoolean("HoloHidden", gun.getPosX() <= 2);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
GeoBone shen;
|
||||
if (zt < 0.5) {
|
||||
|
|
|
@ -21,6 +21,7 @@ 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;
|
||||
|
@ -60,6 +61,7 @@ public class AmmoBarOverlay {
|
|||
if (player.isSpectator()) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
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();
|
||||
|
||||
|
@ -87,10 +89,10 @@ public class AmmoBarOverlay {
|
|||
}
|
||||
|
||||
// 渲染开火模式
|
||||
ResourceLocation fireMode = getFireMode(stack);
|
||||
ResourceLocation fireMode = getFireMode(tag);
|
||||
|
||||
if (stack.getItem() == ModItems.JAVELIN.get()) {
|
||||
fireMode = NBTTool.getBoolean(stack, "TopMode", false) ? TOP : DIR;
|
||||
fireMode = tag.getBoolean("TopMode") ? TOP : DIR;
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.MINIGUN.get()) {
|
||||
|
@ -98,7 +100,7 @@ public class AmmoBarOverlay {
|
|||
// 渲染加特林射速
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
GunsTool.getGunIntTag(stack, "RPM", 0) + " RPM",
|
||||
GunsTool.getGunIntTag(tag, "RPM", 0) + " RPM",
|
||||
w - 111f,
|
||||
h - 20,
|
||||
0xFFFFFF,
|
||||
|
@ -128,7 +130,7 @@ public class AmmoBarOverlay {
|
|||
} else {
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
NBTTool.getBoolean(stack, "DA", false) ? Component.translatable("des.superbwarfare.revolver.sa").withStyle(ChatFormatting.BOLD) : Component.translatable("des.superbwarfare.revolver.da").withStyle(ChatFormatting.BOLD),
|
||||
tag.getBoolean("DA") ? Component.translatable("des.superbwarfare.revolver.sa").withStyle(ChatFormatting.BOLD) : Component.translatable("des.superbwarfare.revolver.da").withStyle(ChatFormatting.BOLD),
|
||||
w - 96,
|
||||
h - 20,
|
||||
0xFFFFFF,
|
||||
|
@ -387,8 +389,8 @@ public class AmmoBarOverlay {
|
|||
poseStack.popPose();
|
||||
}
|
||||
|
||||
private static ResourceLocation getFireMode(ItemStack stack) {
|
||||
return switch (GunsTool.getGunIntTag(stack, "FireMode")) {
|
||||
private static ResourceLocation getFireMode(CompoundTag tag) {
|
||||
return switch (GunsTool.getGunIntTag(tag, "FireMode")) {
|
||||
case 1 -> BURST;
|
||||
case 2 -> AUTO;
|
||||
default -> SEMI;
|
||||
|
@ -397,6 +399,7 @@ public class AmmoBarOverlay {
|
|||
|
||||
private static int getGunAmmoCount(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.getItem() == ModItems.MINIGUN.get()) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -404,14 +407,15 @@ public class AmmoBarOverlay {
|
|||
}
|
||||
|
||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||
return GunsTool.getGunIntTag(stack, "MaxAmmo");
|
||||
return GunsTool.getGunIntTag(tag, "MaxAmmo");
|
||||
}
|
||||
|
||||
return GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
return GunsTool.getGunIntTag(tag, "Ammo", 0);
|
||||
}
|
||||
|
||||
private static String getPlayerAmmoCount(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.getItem() == ModItems.MINIGUN.get() || stack.getItem() == ModItems.BOCEK.get()) {
|
||||
return "";
|
||||
|
@ -419,7 +423,7 @@ public class AmmoBarOverlay {
|
|||
|
||||
if (!hasCreativeAmmo()) {
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || stack.getItem() == ModItems.TASER.get()) {
|
||||
return "" + GunsTool.getGunIntTag(stack, "MaxAmmo");
|
||||
return "" + GunsTool.getGunIntTag(tag, "MaxAmmo");
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
|
|
@ -107,9 +107,11 @@ public class CannonHudOverlay {
|
|||
entityRange = player.distanceTo(living);
|
||||
}
|
||||
if (lookAtEntity) {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range")
|
||||
.append(Component.literal(FormatTool.format1D(entityRange, "m ") + lookingEntity.getDisplayName())),
|
||||
w / 2 + 14, h / 2 - 20, -1, false);
|
||||
var component = Component.translatable("tips.superbwarfare.drone.range").append(Component.literal(FormatTool.format1D(entityRange, "m ")));
|
||||
if (lookingEntity.getDisplayName() != null) {
|
||||
component.append(lookingEntity.getDisplayName());
|
||||
}
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, component, w / 2 + 14, h / 2 - 20, -1, false);
|
||||
} else {
|
||||
if (blockRange > 511) {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range")
|
||||
|
|
|
@ -69,7 +69,8 @@ public class CrossHairOverlay {
|
|||
float moveX = 0;
|
||||
float moveY = 0;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
if (DisplayConfig.FLOAT_CROSS_HAIR.get() && player.getVehicle() == null) {
|
||||
moveX = (float) (-6 * ClientEventHandler.turnRot[1] - (player.isSprinting() ? 10 : 6) * ClientEventHandler.movePosX);
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import com.atsuishio.superbwarfare.tools.SeekTool;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
@ -50,8 +51,8 @@ public class HandsomeFrameOverlay {
|
|||
|
||||
if (stack.getItem() instanceof GunItem && Minecraft.getInstance().options.getCameraType().isFirstPerson()) {
|
||||
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.INTELLIGENT_CHIP.get(), stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.INTELLIGENT_CHIP.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
RenderSystem.disableDepthTest();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class JavelinHudOverlay {
|
|||
float j1 = l + j;
|
||||
preciseBlit(event.getGuiGraphics(), Mod.loc("textures/screens/javelin/javelin_hud.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(event.getGuiGraphics(), Mod.loc(tag.getBoolean("TopMode") ? "textures/screens/javelin/top.png" : "textures/screens/javelin/dir.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(event.getGuiGraphics(), Mod.loc(GunsTool.getGunIntTag(stack, "Ammo", 0) > 0 ? "textures/screens/javelin/missile_green.png" : "textures/screens/javelin/missile_red.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(event.getGuiGraphics(), Mod.loc(GunsTool.getGunIntTag(tag, "Ammo", 0) > 0 ? "textures/screens/javelin/missile_green.png" : "textures/screens/javelin/missile_red.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
if (tag.getInt("SeekTime") > 1 && tag.getInt("SeekTime") < 20) {
|
||||
preciseBlit(event.getGuiGraphics(), Mod.loc("textures/screens/javelin/seek.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
}
|
||||
|
|
|
@ -87,16 +87,17 @@ public class BocekItemRenderer extends GeoItemRenderer<BocekItem> {
|
|||
ItemStack itemStack = player.getMainHandItem();
|
||||
if (!itemStack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
final var tag = NBTTool.getTag(itemStack);
|
||||
if (name.equals("holo")) {
|
||||
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom);
|
||||
bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom);
|
||||
}
|
||||
|
||||
if (name.equals("arrow")) {
|
||||
bone.setHidden(GunsTool.getGunIntTag(itemStack, "ArrowEmpty") > 0);
|
||||
bone.setHidden(GunsTool.getGunIntTag(tag, "ArrowEmpty") > 0);
|
||||
}
|
||||
|
||||
if (name.equals("jian")) {
|
||||
bone.setHidden(GunsTool.getGunIntTag(itemStack, "MaxAmmo") == 0);
|
||||
bone.setHidden(GunsTool.getGunIntTag(tag, "MaxAmmo") == 0);
|
||||
}
|
||||
|
||||
if (this.transformType.firstPerson() && renderingArms) {
|
||||
|
|
|
@ -20,12 +20,12 @@ public class ClientBocekImageTooltip extends ClientGunImageTooltip {
|
|||
protected Component getDamageComponent() {
|
||||
boolean slug = false;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug) {
|
||||
slug = true;
|
||||
}
|
||||
|
||||
double total = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
double total = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
|
||||
if (slug) {
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
|
|
|
@ -10,6 +10,7 @@ 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;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
@ -26,11 +27,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
protected final int width;
|
||||
protected final int height;
|
||||
protected final ItemStack stack;
|
||||
protected final CompoundTag tag;
|
||||
|
||||
public ClientGunImageTooltip(GunImageComponent tooltip) {
|
||||
this.width = tooltip.width;
|
||||
this.height = tooltip.height;
|
||||
this.stack = tooltip.stack;
|
||||
this.tag = NBTTool.getTag(stack).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,7 +65,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
|
||||
protected boolean shouldRenderBypassAndHeadshotTooltip() {
|
||||
return GunsTool.getGunDoubleTag(stack, "BypassesArmor", 0) > 0 || GunsTool.getGunDoubleTag(stack, "Headshot", 0) > 0;
|
||||
return GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0) > 0 || GunsTool.getGunDoubleTag(tag, "Headshot", 0) > 0;
|
||||
}
|
||||
|
||||
protected boolean shouldRenderEditTooltip() {
|
||||
|
@ -73,7 +76,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
|
||||
protected boolean shouldRenderPerks() {
|
||||
return PerkHelper.getPerkByType(stack, Perk.Type.AMMO) != null || PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE) != null || PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL) != null;
|
||||
return PerkHelper.getPerkByType(tag, Perk.Type.AMMO) != null || PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE) != null || PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +92,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器伤害的文本组件
|
||||
*/
|
||||
protected Component getDamageComponent() {
|
||||
double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * 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) ? " + "
|
||||
|
@ -103,7 +106,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(stack, "RPM", 0)))
|
||||
.append(Component.literal(FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM", 0)))
|
||||
.withStyle(ChatFormatting.GREEN));
|
||||
}
|
||||
return Component.literal("");
|
||||
|
@ -122,8 +125,8 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器等级文本组件
|
||||
*/
|
||||
protected Component getLevelComponent() {
|
||||
int level = GunsTool.getGunIntTag(stack, "Level", 0);
|
||||
double rate = GunsTool.getGunDoubleTag(stack, "Exp", 0) / (20 * Math.pow(level, 2) + 160 * level + 20);
|
||||
int level = GunsTool.getGunIntTag(tag, "Level", 0);
|
||||
double rate = GunsTool.getGunDoubleTag(tag, "Exp", 0) / (20 * Math.pow(level, 2) + 160 * level + 20);
|
||||
|
||||
ChatFormatting formatting;
|
||||
if (level < 10) {
|
||||
|
@ -149,7 +152,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器强化点数文本组件
|
||||
*/
|
||||
protected Component getUpgradePointComponent() {
|
||||
int upgradePoint = Mth.floor(GunsTool.getGunDoubleTag(stack, "UpgradePoint", 0));
|
||||
int upgradePoint = Mth.floor(GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0));
|
||||
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));
|
||||
|
@ -169,13 +172,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
*/
|
||||
protected Component getBypassComponent() {
|
||||
double perkBypassArmorRate = 0;
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
perkBypassArmorRate = ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
|
||||
}
|
||||
double bypassRate = Math.max(GunsTool.getGunDoubleTag(stack, "BypassesArmor", 0) + perkBypassArmorRate, 0);
|
||||
double bypassRate = Math.max(GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0) + perkBypassArmorRate, 0);
|
||||
|
||||
return Component.translatable("des.superbwarfare.guns.bypass").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
@ -186,7 +189,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
* 获取武器爆头倍率文本组件
|
||||
*/
|
||||
protected Component getHeadshotComponent() {
|
||||
double headshot = GunsTool.getGunDoubleTag(stack, "Headshot", 0);
|
||||
double headshot = GunsTool.getGunDoubleTag(tag, "Headshot", 0);
|
||||
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));
|
||||
|
@ -215,32 +218,32 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
|
||||
int xOffset = -20;
|
||||
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(tag, 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(stack, Perk.Type.AMMO);
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(tag, Perk.Type.AMMO);
|
||||
if (!ammoTag.isEmpty()) {
|
||||
int level = PerkHelper.getItemPerkLevel(ammoPerk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ammoPerk, tag);
|
||||
perkStack.setCount(level);
|
||||
}
|
||||
guiGraphics.renderItem(perkStack, x + xOffset, y + 2);
|
||||
guiGraphics.renderItemDecorations(font, perkStack, x + xOffset, y + 2);
|
||||
}
|
||||
|
||||
Perk funcPerk = PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL);
|
||||
Perk funcPerk = PerkHelper.getPerkByType(tag, 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(stack, Perk.Type.FUNCTIONAL);
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(tag, Perk.Type.FUNCTIONAL);
|
||||
if (!funcTag.isEmpty()) {
|
||||
int level = PerkHelper.getItemPerkLevel(funcPerk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(funcPerk, tag);
|
||||
perkStack.setCount(level);
|
||||
}
|
||||
|
||||
|
@ -248,16 +251,16 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
guiGraphics.renderItemDecorations(font, perkStack, x + xOffset, y + 2);
|
||||
}
|
||||
|
||||
Perk damagePerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
Perk damagePerk = PerkHelper.getPerkByType(tag, 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(stack, Perk.Type.DAMAGE);
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(tag, Perk.Type.DAMAGE);
|
||||
if (!damageTag.isEmpty()) {
|
||||
int level = PerkHelper.getItemPerkLevel(damagePerk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(damagePerk, tag);
|
||||
perkStack.setCount(level);
|
||||
}
|
||||
|
||||
|
@ -278,13 +281,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
|
||||
int yOffset = -5;
|
||||
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
Perk ammoPerk = PerkHelper.getPerkByType(tag, 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(stack, Perk.Type.AMMO);
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(tag, Perk.Type.AMMO);
|
||||
if (!ammoTag.isEmpty()) {
|
||||
var ids = ammoTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -300,13 +303,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
Perk funcPerk = PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL);
|
||||
Perk funcPerk = PerkHelper.getPerkByType(tag, 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(stack, Perk.Type.FUNCTIONAL);
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(tag, Perk.Type.FUNCTIONAL);
|
||||
if (!funcTag.isEmpty()) {
|
||||
var ids = funcTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -322,13 +325,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
Perk damagePerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
Perk damagePerk = PerkHelper.getPerkByType(tag, 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(stack, Perk.Type.DAMAGE);
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(tag, Perk.Type.DAMAGE);
|
||||
if (!damageTag.isEmpty()) {
|
||||
var ids = damageTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -365,7 +368,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
|
||||
int width = 0;
|
||||
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(stack, Perk.Type.AMMO);
|
||||
CompoundTag ammoTag = PerkHelper.getPerkTag(tag, Perk.Type.AMMO);
|
||||
if (!ammoTag.isEmpty()) {
|
||||
var ids = ammoTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -375,7 +378,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(stack, Perk.Type.FUNCTIONAL);
|
||||
CompoundTag funcTag = PerkHelper.getPerkTag(tag, Perk.Type.FUNCTIONAL);
|
||||
if (!funcTag.isEmpty()) {
|
||||
var ids = funcTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -385,7 +388,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
}
|
||||
}
|
||||
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(stack, Perk.Type.DAMAGE);
|
||||
CompoundTag damageTag = PerkHelper.getPerkTag(tag, Perk.Type.DAMAGE);
|
||||
if (!damageTag.isEmpty()) {
|
||||
var ids = damageTag.getString("id").split(":");
|
||||
if (ids.length > 1) {
|
||||
|
@ -409,13 +412,14 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
|||
height += 16;
|
||||
} else {
|
||||
height += 16;
|
||||
if (PerkHelper.getPerkByType(stack, Perk.Type.AMMO) != null) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (PerkHelper.getPerkByType(tag, Perk.Type.AMMO) != null) {
|
||||
height += 25;
|
||||
}
|
||||
if (PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL) != null) {
|
||||
if (PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL) != null) {
|
||||
height += 25;
|
||||
}
|
||||
if (PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE) != null) {
|
||||
if (PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE) != null) {
|
||||
height += 25;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,11 @@ public class ClientLauncherImageTooltip extends ClientGunImageTooltip {
|
|||
|
||||
@Override
|
||||
protected Component getDamageComponent() {
|
||||
double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), stack);
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f;
|
||||
|
||||
double explosionDamage = GunsTool.getGunDoubleTag(stack, "ExplosionDamage", 0);
|
||||
double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0);
|
||||
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
|
|
@ -17,11 +17,11 @@ public class ClientSecondaryCataclysmImageTooltip extends ClientEnergyImageToolt
|
|||
|
||||
@Override
|
||||
protected Component getDamageComponent() {
|
||||
double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), stack);
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f;
|
||||
|
||||
double explosionDamage = GunsTool.getGunDoubleTag(stack, "ExplosionDamage", 0);
|
||||
double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0);
|
||||
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
|
|
@ -19,8 +19,8 @@ public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip {
|
|||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
||||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
double damage = (GunsTool.getGunDoubleTag(stack, "Damage", 0) +
|
||||
GunsTool.getGunDoubleTag(stack, "ChargedDamage", 0))
|
||||
double damage = (GunsTool.getGunDoubleTag(tag, "Damage", 0) +
|
||||
GunsTool.getGunDoubleTag(tag, "ChargedDamage", 0))
|
||||
* TooltipTool.perkDamage(stack);
|
||||
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
|
@ -28,7 +28,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(stack, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * 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) ?
|
||||
|
|
|
@ -20,22 +20,22 @@ public class ClientShotgunImageTooltip extends ClientGunImageTooltip {
|
|||
protected Component getDamageComponent() {
|
||||
boolean slug = false;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug) {
|
||||
slug = true;
|
||||
}
|
||||
|
||||
if (slug) {
|
||||
double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * GunsTool.getGunIntTag(stack, "ProjectileAmount", 1) * TooltipTool.perkDamage(stack);
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * GunsTool.getGunIntTag(tag, "ProjectileAmount", 1) * 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(stack, "Damage", 0) * TooltipTool.perkDamage(stack);
|
||||
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * 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(stack, "ProjectileAmount", 1))).withStyle(ChatFormatting.GREEN));
|
||||
.append(Component.literal(FormatTool.format1D(damage) + " * " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "ProjectileAmount", 1))).withStyle(ChatFormatting.GREEN));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,9 @@ public class C4Entity extends Projectile implements GeoEntity {
|
|||
public ItemStack getItemStack() {
|
||||
ItemStack stack = new ItemStack(ModItems.C4_BOMB.get());
|
||||
if (this.getEntityData().get(IS_CONTROLLABLE)) {
|
||||
NBTTool.setBoolean(stack, TAG_CONTROL, true);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean(TAG_CONTROL, true);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
@ -44,8 +41,6 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity {
|
||||
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(CannonShellEntity.class, EntityDataSerializers.STRING);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
public String animationProcedure = "empty";
|
||||
|
@ -366,10 +361,6 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
|
|||
return 0.05F;
|
||||
}
|
||||
|
||||
public void setAnimation(String animation) {
|
||||
this.entityData.set(ANIMATION, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));
|
||||
|
|
|
@ -236,8 +236,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
}
|
||||
if (this.entityData.get(KAMIKAZE_MODE) != 0) {
|
||||
if (controller != null) {
|
||||
if (controller.getMainHandItem().is(ModItems.MONITOR.get())) {
|
||||
Monitor.disLink(controller.getMainHandItem(), controller);
|
||||
var stack = controller.getMainHandItem();
|
||||
if (stack.is(ModItems.MONITOR.get())) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
Monitor.disLink(tag, controller);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
this.hurt(new DamageSource(level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.EXPLOSION), controller), 10000);
|
||||
}
|
||||
|
@ -275,7 +278,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
this.entityData.set(LINKED, true);
|
||||
this.entityData.set(CONTROLLER, player.getStringUUID());
|
||||
|
||||
Monitor.link(stack, this.getStringUUID());
|
||||
Monitor.link(tag, this.getStringUUID());
|
||||
player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.linked").withStyle(ChatFormatting.GREEN), true);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
|
@ -294,7 +297,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
this.entityData.set(CONTROLLER, "none");
|
||||
this.entityData.set(LINKED, false);
|
||||
|
||||
Monitor.disLink(stack, player);
|
||||
Monitor.disLink(tag, player);
|
||||
player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.unlinked").withStyle(ChatFormatting.RED), true);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
|
@ -318,8 +321,9 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
|
||||
player.getInventory().items.stream().filter(stack_ -> stack_.getItem() == ModItems.MONITOR.get())
|
||||
.forEach(itemStack -> {
|
||||
if (NBTTool.getTag(itemStack).getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||
Monitor.disLink(itemStack, player);
|
||||
var tag = NBTTool.getTag(itemStack);
|
||||
if (tag.getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||
Monitor.disLink(tag, player);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -487,7 +491,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
}
|
||||
|
||||
if (controller != null && controller.getMainHandItem().is(ModItems.MONITOR.get())) {
|
||||
Monitor.disLink(controller.getMainHandItem(), controller);
|
||||
var stack = controller.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
Monitor.disLink(tag, controller);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
target.hurt(ModDamageTypes.causeDroneHitDamage(this.level().registryAccess(), this, controller), (float) (5 * lastTickSpeed));
|
||||
|
@ -542,7 +549,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||
if (controller != null) {
|
||||
if (controller.getMainHandItem().is(ModItems.MONITOR.get())) {
|
||||
Monitor.disLink(controller.getMainHandItem(), controller);
|
||||
var item = controller.getMainHandItem();
|
||||
var tag = NBTTool.getTag(item);
|
||||
Monitor.disLink(tag, controller);
|
||||
NBTTool.saveTag(item, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -559,8 +569,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
if (player != null) {
|
||||
player.getInventory().items.stream().filter(stack -> stack.getItem() == ModItems.MONITOR.get())
|
||||
.forEach(stack -> {
|
||||
if (NBTTool.getTag(stack).getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||
Monitor.disLink(stack, player);
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (tag.getString(Monitor.LINKED_DRONE).equals(this.getStringUUID())) {
|
||||
Monitor.disLink(tag, player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity.vehicle.base;
|
|||
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -139,7 +140,7 @@ public interface WeaponVehicleEntity extends ArmedVehicleEntity {
|
|||
default void setWeaponIndex(int index, int type) {
|
||||
if (!(this instanceof VehicleEntity vehicle)) return;
|
||||
|
||||
var selectedWeapons = vehicle.getEntityData().get(VehicleEntity.SELECTED_WEAPON);
|
||||
var selectedWeapons = new ArrayList<>(vehicle.getEntityData().get(VehicleEntity.SELECTED_WEAPON));
|
||||
selectedWeapons.set(index, type);
|
||||
vehicle.getEntityData().set(VehicleEntity.SELECTED_WEAPON, selectedWeapons);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.client.player.LocalPlayer;
|
|||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -185,13 +186,13 @@ public class ClientEventHandler {
|
|||
return player.getVehicle() instanceof VehicleEntity vehicle && vehicle.allowFreeCam() && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON && ModKeyMappings.FREE_CAMERA.isDown();
|
||||
}
|
||||
|
||||
private static boolean revolverPre() {
|
||||
private static boolean revolverPre(final CompoundTag tag) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return false;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.REVOLVER)) {
|
||||
return true;
|
||||
} else if (stack.is(ModTags.Items.REVOLVER) && (NBTTool.getTag(stack).getBoolean("DA") || NBTTool.getTag(stack).getBoolean("canImmediatelyShoot"))) {
|
||||
} else if (stack.is(ModTags.Items.REVOLVER) && (tag.getBoolean("DA") || tag.getBoolean("canImmediatelyShoot"))) {
|
||||
return true;
|
||||
} else {
|
||||
return revolverPreTime >= 1;
|
||||
|
@ -212,14 +213,15 @@ public class ClientEventHandler {
|
|||
@SubscribeEvent
|
||||
public static void handleClientTick(ClientTickEvent.Pre event) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
if (holdFire || zoom) {
|
||||
miniGunRot = Math.min(miniGunRot + 5, 21);
|
||||
float rpm = (float) GunsTool.getGunIntTag(stack, "RPM", 0) / 3600;
|
||||
float rpm = (float) GunsTool.getGunIntTag(tag, "RPM", 0) / 3600;
|
||||
player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 0.7f + rpm);
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +233,7 @@ public class ClientEventHandler {
|
|||
isProne(player);
|
||||
beamShoot(player, stack);
|
||||
handleLungeAttack(player, stack);
|
||||
handleGunMelee(player, stack);
|
||||
handleGunMelee(player, stack, tag);
|
||||
|
||||
var options = Minecraft.getInstance().options;
|
||||
short keys = 0;
|
||||
|
@ -240,8 +242,8 @@ public class ClientEventHandler {
|
|||
if (!notInGame() && (player.getVehicle() instanceof MobileVehicleEntity mobileVehicle
|
||||
&& mobileVehicle.getFirstPassenger() == player
|
||||
|| stack.is(ModItems.MONITOR.get())
|
||||
&& NBTTool.getBoolean(stack, "Using", false)
|
||||
&& NBTTool.getBoolean(stack, "Linked", false))
|
||||
&& tag.getBoolean("Using")
|
||||
&& tag.getBoolean("Linked"))
|
||||
) {
|
||||
if (options.keyLeft.isDown()) {
|
||||
keys |= 0b0000001;
|
||||
|
@ -297,7 +299,7 @@ public class ClientEventHandler {
|
|||
&& !level.getBlockState(BlockPos.containing(player.getX() + 0.7 * player.getLookAngle().x, player.getY() + 1.5, player.getZ() + 0.7 * player.getLookAngle().z)).canOcclude();
|
||||
}
|
||||
|
||||
public static void handleGunMelee(Player player, ItemStack stack) {
|
||||
public static void handleGunMelee(Player player, ItemStack stack, final CompoundTag tag) {
|
||||
if (stack.getItem() instanceof GunItem gunItem) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (gunItem.hasMeleeAttack(stack) && gunMelee == 0 && drawTime < 0.01
|
||||
|
@ -306,10 +308,10 @@ public class ClientEventHandler {
|
|||
&& !holdFireVehicle
|
||||
&& !notInGame()
|
||||
&& cap != null && !cap.edit
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging")) {
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
gunMelee = 36;
|
||||
cantFireTime = 40;
|
||||
player.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, 1f, 1);
|
||||
|
@ -389,13 +391,15 @@ public class ClientEventHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
int mode = GunsTool.getGunIntTag(stack, "FireMode");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
|
||||
// 精准度
|
||||
float times = (float) Math.min(Minecraft.getInstance().getTimer().getGameTimeDeltaTicks(), 0.8);
|
||||
|
||||
double basicDev = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
double basicDev = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
double walk = isMoving() ? 0.3 * basicDev : 0;
|
||||
double sprint = player.isSprinting() ? 0.25 * basicDev : 0;
|
||||
double crouching = player.isCrouching() ? -0.15 * basicDev : 0;
|
||||
|
@ -424,7 +428,7 @@ public class ClientEventHandler {
|
|||
gunSpread = Mth.lerp(0.14 * times, gunSpread, spread);
|
||||
|
||||
// 开火部分
|
||||
double weight = GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight");
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
double speed = 1 - (0.04 * weight);
|
||||
|
||||
if (player.getPersistentData().getDouble("noRun") == 0 && player.isSprinting() && !zoom) {
|
||||
|
@ -433,13 +437,13 @@ public class ClientEventHandler {
|
|||
cantFireTime = Mth.clamp(cantFireTime - 6 * speed * times, 0, 40);
|
||||
}
|
||||
|
||||
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0) + customRpm;
|
||||
int rpm = GunsTool.getGunIntTag(tag, "RPM", 0) + customRpm;
|
||||
if (rpm == 0) {
|
||||
rpm = 600;
|
||||
}
|
||||
|
||||
if (GunsTool.getPerkIntTag(stack, "DesperadoTimePost") > 0) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), stack);
|
||||
if (GunsTool.getPerkIntTag(tag, "DesperadoTimePost") > 0) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), tag);
|
||||
rpm *= (int) (1.285 + 0.015 * perkLevel);
|
||||
}
|
||||
|
||||
|
@ -449,11 +453,11 @@ public class ClientEventHandler {
|
|||
int cooldown = (int) (1000 / rps);
|
||||
|
||||
//左轮类
|
||||
if (clientTimer.getProgress() == 0 && stack.is(ModTags.Items.REVOLVER) && ((holdFire && !NBTTool.getTag(stack).getBoolean("DA"))
|
||||
|| (GunsTool.getGunIntTag(stack, "BoltActionTick") < 7 && GunsTool.getGunIntTag(stack, "BoltActionTick") > 2) || NBTTool.getTag(stack).getBoolean("canImmediatelyShoot"))) {
|
||||
if (clientTimer.getProgress() == 0 && stack.is(ModTags.Items.REVOLVER) && ((holdFire && !tag.getBoolean("DA"))
|
||||
|| (GunsTool.getGunIntTag(tag, "BoltActionTick") < 7 && GunsTool.getGunIntTag(tag, "BoltActionTick") > 2) || tag.getBoolean("canImmediatelyShoot"))) {
|
||||
revolverPreTime = Mth.clamp(revolverPreTime + 0.3 * times, 0, 1);
|
||||
revolverWheelPreTime = Mth.clamp(revolverWheelPreTime + 0.32 * times, 0, revolverPreTime > 0.7 ? 1 : 0.55);
|
||||
} else if (!NBTTool.getTag(stack).getBoolean("DA") && !NBTTool.getTag(stack).getBoolean("canImmediatelyShoot")) {
|
||||
} else if (!tag.getBoolean("DA") && !tag.getBoolean("canImmediatelyShoot")) {
|
||||
revolverPreTime = Mth.clamp(revolverPreTime - 1.2 * times, 0, 1);
|
||||
}
|
||||
|
||||
|
@ -467,23 +471,23 @@ public class ClientEventHandler {
|
|||
&& drawTime < 0.01
|
||||
&& cap != null && !cap.edit
|
||||
&& !notInGame()
|
||||
&& (!(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging")
|
||||
&& GunsTool.getGunIntTag(stack, "Ammo", 0) > 0
|
||||
&& (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo", 0) > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)
|
||||
&& revolverPre())
|
||||
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)
|
||||
&& revolverPre(tag))
|
||||
|| (stack.is(ModItems.MINIGUN.get())
|
||||
&& !player.isSprinting()
|
||||
&& NBTTool.getTag(stack).getDouble("overheat") == 0
|
||||
&& tag.getDouble("overheat") == 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && miniGunRot >= 20
|
||||
&& (cap != null && cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player))
|
||||
))) {
|
||||
if (mode == 0) {
|
||||
if (clientTimer.getProgress() == 0) {
|
||||
clientTimer.start();
|
||||
shootClient(player);
|
||||
shootClient(player, tag);
|
||||
}
|
||||
} else {
|
||||
if (!clientTimer.started()) {
|
||||
|
@ -493,7 +497,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
if (clientTimer.getProgress() >= cooldown) {
|
||||
shootClient(player);
|
||||
shootClient(player, tag);
|
||||
clientTimer.setProgress((clientTimer.getProgress() - cooldown));
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +519,7 @@ public class ClientEventHandler {
|
|||
clientTimer.stop();
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.DEVOTION.get() && (NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading"))) {
|
||||
if (stack.getItem() == ModItems.DEVOTION.get() && (tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))) {
|
||||
customRpm = 0;
|
||||
}
|
||||
}
|
||||
|
@ -541,17 +545,17 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void shootClient(Player player) {
|
||||
public static void shootClient(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
int mode = GunsTool.getGunIntTag(stack, "FireMode");
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) {
|
||||
int mode = GunsTool.getGunIntTag(tag, "FireMode");
|
||||
if (mode != 2) {
|
||||
holdFire = false;
|
||||
}
|
||||
|
||||
if (mode == 1) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) {
|
||||
burstFireSize = 1;
|
||||
}
|
||||
if (burstFireSize == 1) {
|
||||
|
@ -564,7 +568,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
if (stack.is(ModItems.DEVOTION.get())) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.TURBO_CHARGER.get(), stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.TURBO_CHARGER.get(), tag);
|
||||
customRpm = Math.min(customRpm + 15 + ((perkLevel > 0 ? 5 : 0) + 3 * perkLevel), 500);
|
||||
}
|
||||
|
||||
|
@ -577,22 +581,20 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
|
||||
}
|
||||
|
||||
revolverPreTime = 0;
|
||||
revolverWheelPreTime = 0;
|
||||
|
||||
playGunClientSounds(player);
|
||||
handleClientShoot();
|
||||
playGunClientSounds(player, tag);
|
||||
handleClientShoot(tag);
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat")));
|
||||
|
||||
player.playSound(ModSounds.MINIGUN_FIRE_1P.get(), 1f, pitch);
|
||||
|
@ -607,7 +609,7 @@ public class ClientEventHandler {
|
|||
Mod.queueClientWork((int) (1 + 1.5 * shooterHeight), () -> player.playSound(ModSounds.SHELL_CASING_NORMAL.get(), (float) Math.max(1.5 - 0.2 * shooterHeight, 0), 1));
|
||||
}
|
||||
|
||||
handleClientShoot();
|
||||
handleClientShoot(tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -616,7 +618,7 @@ public class ClientEventHandler {
|
|||
actionMove = Mth.lerp(0.125 * times, actionMove, 0);
|
||||
}
|
||||
|
||||
public static void handleClientShoot() {
|
||||
public static void handleClientShoot(final CompoundTag tag) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
@ -625,7 +627,7 @@ public class ClientEventHandler {
|
|||
PacketDistributor.sendToServer(new ShootMessage(gunSpread));
|
||||
fireRecoilTime = 10;
|
||||
|
||||
float gunRecoilY = (float) GunsTool.getGunDoubleTag(stack, "RecoilY", 0) * 10;
|
||||
float gunRecoilY = (float) GunsTool.getGunDoubleTag(tag, "RecoilY", 0) * 10;
|
||||
|
||||
recoilY = (float) (2 * Math.random() - 1) * gunRecoilY;
|
||||
|
||||
|
@ -652,11 +654,9 @@ public class ClientEventHandler {
|
|||
shakeType = 2 * (Math.random() - 0.5);
|
||||
}
|
||||
|
||||
public static void playGunClientSounds(Player player) {
|
||||
public static void playGunClientSounds(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) {
|
||||
return;
|
||||
}
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
@ -674,13 +674,13 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
player.playSound(ModSounds.HENG.get(), 1f, 1f);
|
||||
}
|
||||
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
|
||||
SoundEvent sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_1p_s" : "_fire_1p")));
|
||||
|
||||
|
@ -802,6 +802,8 @@ public class ClientEventHandler {
|
|||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle.hidePassenger(player))
|
||||
return;
|
||||
|
||||
|
@ -811,12 +813,12 @@ public class ClientEventHandler {
|
|||
if (player.isCrouching() && player.getBbHeight() >= 1 && !isProne(player)) {
|
||||
pose = 0.85f;
|
||||
} else if (isProne(player)) {
|
||||
pose = (GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f;
|
||||
pose = (GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f;
|
||||
} else {
|
||||
pose = 1;
|
||||
}
|
||||
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK);
|
||||
|
||||
double sway = switch (stockType) {
|
||||
case 1 -> 1;
|
||||
|
@ -824,7 +826,7 @@ public class ClientEventHandler {
|
|||
default -> 0.8;
|
||||
};
|
||||
|
||||
double customWeight = GunsTool.getGunDoubleTag(stack, "CustomWeight");
|
||||
double customWeight = GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
|
||||
|
@ -846,13 +848,14 @@ public class ClientEventHandler {
|
|||
|
||||
if (!(entity instanceof LivingEntity living)) return;
|
||||
ItemStack stack = living.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (level != null
|
||||
&& (stack.is(ModItems.MONITOR.get())
|
||||
&& NBTTool.getTag(stack).getBoolean("Using")
|
||||
&& NBTTool.getTag(stack).getBoolean("Linked"))
|
||||
&& tag.getBoolean("Using")
|
||||
&& tag.getBoolean("Linked"))
|
||||
) {
|
||||
handleDroneCamera(event, living);
|
||||
handleDroneCamera(event, living, tag);
|
||||
} else {
|
||||
var effect = Minecraft.getInstance().gameRenderer.currentEffect();
|
||||
if (effect != null && effect.getName().equals(Mod.MODID + ":shaders/post/scan_pincushion.json")) {
|
||||
|
@ -894,31 +897,29 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
if (level != null && stack.is(ModTags.Items.GUN)) {
|
||||
handleWeaponSway(living);
|
||||
handleWeaponSway(living, tag);
|
||||
handleWeaponMove(living);
|
||||
handleWeaponZoom(living);
|
||||
handlePlayerBreath(living);
|
||||
handleWeaponFire(event, living);
|
||||
handleWeaponFire(event, living, tag);
|
||||
handleWeaponShell();
|
||||
handleGunRecoil();
|
||||
handleGunRecoil(tag);
|
||||
handleBowPullAnimation(living);
|
||||
handleWeaponDraw(living);
|
||||
handleWeaponDraw(living, tag);
|
||||
handlePlayerCamera(event);
|
||||
}
|
||||
|
||||
handleShockCamera(event, living);
|
||||
}
|
||||
|
||||
public static void handleDroneCamera(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
|
||||
DroneEntity drone = EntityFindUtil.findDrone(entity.level(), NBTTool.getTag(stack).getString("LinkedDrone"));
|
||||
public static void handleDroneCamera(ViewportEvent.ComputeCameraAngles event, LivingEntity entity, final CompoundTag tag) {
|
||||
DroneEntity drone = EntityFindUtil.findDrone(entity.level(), tag.getString("LinkedDrone"));
|
||||
|
||||
if (drone != null) {
|
||||
event.setRoll(drone.getRoll((float) event.getPartialTick()) * (1 - (drone.getPitch((float) event.getPartialTick()) / 90)));
|
||||
}
|
||||
|
||||
if (drone != null && NBTTool.getTag(stack).getBoolean("Using")) {
|
||||
if (drone != null && tag.getBoolean("Using")) {
|
||||
if (Minecraft.getInstance().gameRenderer.currentEffect() == null) {
|
||||
Minecraft.getInstance().gameRenderer.loadEffect(Mod.loc("shaders/post/scan_pincushion.json"));
|
||||
}
|
||||
|
@ -930,28 +931,26 @@ public class ClientEventHandler {
|
|||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
InteractionHand leftHand = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
||||
InteractionHand rightHand = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
|
||||
var mainHand = Minecraft.getInstance().options.mainHand().get();
|
||||
InteractionHand leftHand = mainHand == HumanoidArm.RIGHT ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
||||
InteractionHand rightHand = mainHand == HumanoidArm.RIGHT ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
|
||||
|
||||
ItemStack rightHandItem = player.getItemInHand(rightHand);
|
||||
final var tag = NBTTool.getTag(rightHandItem);
|
||||
|
||||
if (event.getHand() == leftHand) {
|
||||
if (rightHandItem.is(ModTags.Items.GUN)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
if (event.getHand() == leftHand && rightHandItem.is(ModTags.Items.GUN)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
if (event.getHand() == rightHand) {
|
||||
if (rightHandItem.is(ModTags.Items.GUN) && drawTime > 0.15) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
if (event.getHand() == rightHand && rightHandItem.is(ModTags.Items.GUN) && drawTime > 0.15) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using") && NBTTool.getTag(stack).getBoolean("Linked")) {
|
||||
if (EntityFindUtil.findDrone(player.level(), NBTTool.getTag(stack).getString("LinkedDrone")) != null) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using")
|
||||
&& tag.getBoolean("Linked")
|
||||
&& EntityFindUtil.findDrone(player.level(), tag.getString("LinkedDrone")) != null) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) {
|
||||
|
@ -959,7 +958,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void handleWeaponSway(LivingEntity entity) {
|
||||
private static void handleWeaponSway(LivingEntity entity, final CompoundTag tag) {
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
if (stack.getItem() instanceof GunItem gunItem && entity instanceof Player player) {
|
||||
float times = 2 * (float) Math.min(Minecraft.getInstance().getTimer().getGameTimeDeltaTicks(), 0.8);
|
||||
|
@ -968,7 +967,7 @@ public class ClientEventHandler {
|
|||
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && isProne(player)) {
|
||||
pose = 0.85;
|
||||
} else if (isProne(player)) {
|
||||
pose = (GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f;
|
||||
pose = (GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f;
|
||||
} else {
|
||||
pose = 1;
|
||||
}
|
||||
|
@ -1045,10 +1044,10 @@ public class ClientEventHandler {
|
|||
|
||||
private static void handleWeaponZoom(LivingEntity entity) {
|
||||
if (!(entity instanceof Player player)) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(player.getMainHandItem());
|
||||
float times = 5 * Minecraft.getInstance().getTimer().getGameTimeDeltaTicks();
|
||||
|
||||
double weight = GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight");
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
double speed = 1.5 - (0.07 * weight);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -1071,13 +1070,14 @@ public class ClientEventHandler {
|
|||
zoomPosZ = AnimationCurves.PARABOLA.apply(zoomTime);
|
||||
}
|
||||
|
||||
private static void handleWeaponFire(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
|
||||
private static void handleWeaponFire(ViewportEvent.ComputeCameraAngles event, LivingEntity entity, final CompoundTag tag) {
|
||||
float times = 2f * Math.min(Minecraft.getInstance().getTimer().getGameTimeDeltaTicks(), 0.48f);
|
||||
float yaw = event.getYaw();
|
||||
float pitch = event.getPitch();
|
||||
float roll = event.getRoll();
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
double amplitude = 15000 * GunsTool.getGunDoubleTag(stack, "RecoilY", 0) * GunsTool.getGunDoubleTag(stack, "RecoilX", 0);
|
||||
|
||||
double amplitude = 15000 * GunsTool.getGunDoubleTag(tag, "RecoilY", 0) * GunsTool.getGunDoubleTag(tag, "RecoilX", 0);
|
||||
|
||||
if (fireRecoilTime > 0) {
|
||||
firePosTimer = 0.001;
|
||||
|
@ -1112,7 +1112,7 @@ public class ClientEventHandler {
|
|||
double rpm = 1;
|
||||
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
rpm = (double) GunsTool.getGunIntTag(stack, "RPM", 0) / 1800;
|
||||
rpm = (double) GunsTool.getGunIntTag(tag, "RPM", 0) / 1800;
|
||||
}
|
||||
|
||||
float[] shake = {0, 0};
|
||||
|
@ -1162,15 +1162,15 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void handleGunRecoil() {
|
||||
private static void handleGunRecoil(final CompoundTag tag) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
float times = (float) Math.min(Minecraft.getInstance().getTimer().getGameTimeDeltaTicks(), 1.6);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP);
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
int gripType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP);
|
||||
|
||||
double recoil = switch (barrelType) {
|
||||
case 1 -> 1.5;
|
||||
|
@ -1196,15 +1196,15 @@ public class ClientEventHandler {
|
|||
gripRecoilY = 1.25;
|
||||
}
|
||||
|
||||
double customWeight = GunsTool.getGunDoubleTag(stack, "CustomWeight");
|
||||
double customWeight = GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
|
||||
double rpm = 1;
|
||||
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
rpm = (double) GunsTool.getGunIntTag(stack, "RPM", 0) / 1800;
|
||||
rpm = (double) GunsTool.getGunIntTag(tag, "RPM", 0) / 1800;
|
||||
}
|
||||
|
||||
float gunRecoilX = (float) GunsTool.getGunDoubleTag(stack, "RecoilX", 0) * 60;
|
||||
float gunRecoilX = (float) GunsTool.getGunDoubleTag(tag, "RecoilX", 0) * 60;
|
||||
|
||||
recoilHorizon = Mth.lerp(0.2 * times, recoilHorizon, 0) + recoilY;
|
||||
recoilY = 0;
|
||||
|
@ -1214,7 +1214,7 @@ public class ClientEventHandler {
|
|||
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && !isProne(player)) {
|
||||
pose = 0.7f;
|
||||
} else if (isProne(player)) {
|
||||
if (GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) {
|
||||
if (GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) {
|
||||
pose = 0.1f;
|
||||
} else {
|
||||
pose = 0.5f;
|
||||
|
@ -1356,6 +1356,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (player.getVehicle() instanceof WeaponVehicleEntity iVehicle && zoomVehicle) {
|
||||
event.setFOV(event.getFOV() / iVehicle.zoomFov());
|
||||
|
@ -1374,7 +1375,7 @@ public class ClientEventHandler {
|
|||
p = zoomPos;
|
||||
}
|
||||
|
||||
customZoom = Mth.lerp(0.6 * times, customZoom, GunsTool.getGunDoubleTag(stack, "CustomZoom", 0));
|
||||
customZoom = Mth.lerp(0.6 * times, customZoom, GunsTool.getGunDoubleTag(tag, "CustomZoom", 0));
|
||||
|
||||
double zoomFov = 1.25 + customZoom;
|
||||
|
||||
|
@ -1393,7 +1394,7 @@ public class ClientEventHandler {
|
|||
&& cap != null
|
||||
&& !cap.edit) {
|
||||
if (!player.isShiftKeyDown()) {
|
||||
int intelligentChipLevel = PerkHelper.getItemPerkLevel(ModPerks.INTELLIGENT_CHIP.get(), stack);
|
||||
int intelligentChipLevel = PerkHelper.getItemPerkLevel(ModPerks.INTELLIGENT_CHIP.get(), tag);
|
||||
|
||||
if (intelligentChipLevel > 0) {
|
||||
if (ClientEventHandler.entity == null || !entity.isAlive()) {
|
||||
|
@ -1411,7 +1412,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using") && NBTTool.getTag(stack).getBoolean("Linked")) {
|
||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked")) {
|
||||
droneFovLerp = Mth.lerp(0.1 * Minecraft.getInstance().getTimer().getGameTimeDeltaTicks(), droneFovLerp, droneFov);
|
||||
event.setFOV(event.getFOV() / droneFovLerp);
|
||||
fov = event.getFOV();
|
||||
|
@ -1455,6 +1456,7 @@ public class ClientEventHandler {
|
|||
if (!mc.options.getCameraType().isFirstPerson()) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.getItem() instanceof GunItem) {
|
||||
event.setCanceled(true);
|
||||
|
@ -1464,7 +1466,7 @@ public class ClientEventHandler {
|
|||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using") && NBTTool.getTag(stack).getBoolean("Linked")) {
|
||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked")) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
@ -1498,10 +1500,10 @@ public class ClientEventHandler {
|
|||
lungeAttack = 0;
|
||||
}
|
||||
|
||||
private static void handleWeaponDraw(LivingEntity entity) {
|
||||
private static void handleWeaponDraw(LivingEntity entity, final CompoundTag tag) {
|
||||
float times = Minecraft.getInstance().getTimer().getGameTimeDeltaTicks();
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
double weight = GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight");
|
||||
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
double speed = 3.2 - (0.13 * weight);
|
||||
drawTime = Math.max(drawTime - Math.max(0.2 * speed * times * drawTime, 0.0008), 0);
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ public class ClientMouseHandler {
|
|||
@SubscribeEvent
|
||||
public static void calculatePlayerTurn(CalculatePlayerTurnEvent event) {
|
||||
var newSensitivity = changeSensitivity(event.getMouseSensitivity()) * invertY();
|
||||
event.setMouseSensitivity(newSensitivity);
|
||||
}
|
||||
|
||||
public static float invertY() {
|
||||
|
@ -161,7 +162,7 @@ public class ClientMouseHandler {
|
|||
return original;
|
||||
}
|
||||
|
||||
double zoom = 1.25 + GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
double zoom = 1.25 + GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
float customSens = (float) tag.getInt("sensitivity");
|
||||
|
||||
if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {
|
||||
|
|
|
@ -81,7 +81,8 @@ public class ClientSoundHandler {
|
|||
if (e instanceof DroneEntity drone) {
|
||||
distanceReduce = (float) Math.max((1 - distance / 64), 0);
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getBoolean(stack, "Using", false)) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using")) {
|
||||
player.playSound(engineSound, 1, (float) ((2 * Math.random() - 1) * 0.002f + 1.05));
|
||||
} else {
|
||||
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), e.onGround() ? 0 : distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.002f + 1.05), false);
|
||||
|
|
|
@ -35,8 +35,6 @@ import net.neoforged.neoforge.event.tick.PlayerTickEvent;
|
|||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.NBTTool.saveTag;
|
||||
|
||||
@EventBusSubscriber(modid = Mod.MODID)
|
||||
public class GunEventHandler {
|
||||
|
||||
|
@ -45,32 +43,37 @@ public class GunEventHandler {
|
|||
Player player = event.getEntity();
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
handleGunBolt(player);
|
||||
handleGunReload(player);
|
||||
handleGunSingleReload(player);
|
||||
handleSentinelCharge(player);
|
||||
handleGunBolt(player, tag);
|
||||
handleGunReload(player, tag);
|
||||
handleGunSingleReload(player, tag);
|
||||
handleSentinelCharge(player, tag);
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉大栓
|
||||
*/
|
||||
private static void handleGunBolt(Player player) {
|
||||
private static void handleGunBolt(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
GunsTool.setGunIntTag(stack, "BoltActionTick", GunsTool.getGunIntTag(stack, "BoltActionTick") - 1);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
tag.getCompound("GunData").putInt("BoltActionTick", GunsTool.getGunIntTag(tag, "BoltActionTick") - 1);
|
||||
}
|
||||
if (stack.getItem() == ModItems.MARLIN.get() && GunsTool.getGunIntTag(stack, "BoltActionTick") == 9) {
|
||||
NBTTool.setBoolean(stack, "empty", false);
|
||||
if (stack.getItem() == ModItems.MARLIN.get() && GunsTool.getGunIntTag(tag, "BoltActionTick") == 9) {
|
||||
tag.putBoolean("empty", false);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") == 1) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") == 1) {
|
||||
tag.getCompound("GunData").putBoolean("NeedBoltAction", false);
|
||||
if (stack.is(ModTags.Items.REVOLVER)) {
|
||||
NBTTool.setBoolean(stack, "canImmediatelyShoot", true);
|
||||
tag.putBoolean("canImmediatelyShoot", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,9 +84,8 @@ public class GunEventHandler {
|
|||
*/
|
||||
public static void playGunSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -93,7 +95,7 @@ public class GunEventHandler {
|
|||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
||||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
float soundRadius = (float) GunsTool.getGunDoubleTag(stack, "SoundRadius");
|
||||
float soundRadius = (float) GunsTool.getGunDoubleTag(tag, "SoundRadius");
|
||||
|
||||
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc("sentinel_charge_fire_3p"));
|
||||
if (sound3p != null) {
|
||||
|
@ -109,20 +111,17 @@ public class GunEventHandler {
|
|||
if (soundVeryFar != null) {
|
||||
player.playSound(soundVeryFar, soundRadius, 1f);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
||||
}
|
||||
|
||||
float soundRadius = (float) (GunsTool.getGunDoubleTag(stack, "SoundRadius") * GunsTool.getGunDoubleTag(stack, "CustomSoundRadius", 1));
|
||||
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
float soundRadius = (float) (GunsTool.getGunDoubleTag(tag, "SoundRadius") * GunsTool.getGunDoubleTag(tag, "CustomSoundRadius", 1));
|
||||
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
|
||||
|
||||
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
|
||||
if (sound3p != null) {
|
||||
|
@ -143,9 +142,8 @@ public class GunEventHandler {
|
|||
|
||||
public static void playGunBoltSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -160,7 +158,7 @@ public class GunEventHandler {
|
|||
|
||||
if (stack.is(ModTags.Items.REVOLVER)) return;
|
||||
|
||||
Mod.queueServerWork((int) (GunsTool.getGunDoubleTag(stack, "BoltActionTime", 0) / 2 + 1.5 * shooterHeight), () -> {
|
||||
Mod.queueServerWork((int) (GunsTool.getGunDoubleTag(tag, "BoltActionTime", 0) / 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)) {
|
||||
|
@ -173,21 +171,21 @@ public class GunEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void gunShoot(Player player, double spared) {
|
||||
public static void gunShoot(Player player, final CompoundTag tag, double spared) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (!player.level().isClientSide()) {
|
||||
float headshot = (float) GunsTool.getGunDoubleTag(stack, "Headshot", 0);
|
||||
float damage = (float) (GunsTool.getGunDoubleTag(stack, "Damage", 0) +
|
||||
GunsTool.getGunDoubleTag(stack, "ChargedDamage", 0)) * (float) perkDamage(stack);
|
||||
float velocity = (float) ((GunsTool.getGunDoubleTag(stack, "Velocity", 0) + GunsTool.getGunDoubleTag(stack, "CustomVelocity", 0)) * perkSpeed(stack));
|
||||
int projectileAmount = GunsTool.getGunIntTag(stack, "ProjectileAmount", 1);
|
||||
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(stack, "BypassesArmor", 0);
|
||||
float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot", 0);
|
||||
float damage = (float) (GunsTool.getGunDoubleTag(tag, "Damage", 0) +
|
||||
GunsTool.getGunDoubleTag(tag, "ChargedDamage", 0)) * (float) perkDamage(tag);
|
||||
float velocity = (float) ((GunsTool.getGunDoubleTag(tag, "Velocity", 0) + GunsTool.getGunDoubleTag(tag, "CustomVelocity", 0)) * perkSpeed(tag));
|
||||
int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount", 1);
|
||||
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
if (perk != null && perk.descriptionId.equals("butterfly_bullet")) {
|
||||
if (handleButterflyBullet(perk, stack, player)) return;
|
||||
|
@ -201,7 +199,7 @@ public class GunEventHandler {
|
|||
.zoom(zoom);
|
||||
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
|
||||
bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
|
||||
projectile.setRGB(ammoPerk.rgb);
|
||||
|
@ -233,24 +231,24 @@ public class GunEventHandler {
|
|||
projectile.bypassArmorRate(bypassArmorRate);
|
||||
|
||||
if (perk == ModPerks.SILVER_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.undeadMultiple(1.0f + 0.5f * level);
|
||||
} else if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
projectile.beast();
|
||||
} else if (perk == ModPerks.JHP_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.jhpBullet(level);
|
||||
} else if (perk == ModPerks.HE_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.heBullet(level);
|
||||
} else if (perk == ModPerks.INCENDIARY_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.fireBullet(level, stack.is(ModTags.Items.SHOTGUN));
|
||||
}
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(dmgPerk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(dmgPerk, tag);
|
||||
projectile.monsterMultiple(0.1f + 0.1f * level);
|
||||
}
|
||||
|
||||
|
@ -260,16 +258,16 @@ public class GunEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static double perkDamage(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
public static double perkDamage(final CompoundTag tag) {
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
return ammoPerk.damageRate;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static double perkSpeed(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
public static double perkSpeed(final CompoundTag tag) {
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
return ammoPerk.speedRate;
|
||||
}
|
||||
|
@ -277,10 +275,9 @@ public class GunEventHandler {
|
|||
}
|
||||
|
||||
// TODO 这还有联动的必要吗(
|
||||
@SuppressWarnings("ConstantValue")
|
||||
private static boolean handleButterflyBullet(Perk perk, ItemStack heldItem, Player player) {
|
||||
return true;
|
||||
// int perkLevel = PerkHelper.getItemPerkLevel(perk, heldItem);
|
||||
// int perkLevel = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
//
|
||||
// var entityType = CompatHolder.VRC_RAIN_SHOWER_BUTTERFLY;
|
||||
// if (entityType != null) {
|
||||
|
@ -314,29 +311,28 @@ public class GunEventHandler {
|
|||
/**
|
||||
* 通用的武器换弹流程
|
||||
*/
|
||||
private static void handleGunReload(Player player) {
|
||||
private static void handleGunReload(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
CompoundTag data = NBTTool.getTag(stack).getCompound("GunData");
|
||||
final CompoundTag data = tag.getCompound("GunData");
|
||||
// 启动换弹
|
||||
if (GunsTool.getGunBooleanTag(stack, "StartReload")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "StartReload")) {
|
||||
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
||||
if (gunItem.isOpenBolt(stack)) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
data.putInt("ReloadTime", data.getInt("EmptyReloadTime") + 1);
|
||||
NBTTool.getTag(stack).putBoolean("is_empty_reloading", true);
|
||||
tag.putBoolean("is_empty_reloading", true);
|
||||
playGunEmptyReloadSounds(player);
|
||||
} else {
|
||||
data.putInt("ReloadTime", data.getInt("NormalReloadTime") + 1);
|
||||
NBTTool.getTag(stack).putBoolean("is_normal_reloading", true);
|
||||
tag.putBoolean("is_normal_reloading", true);
|
||||
playGunNormalReloadSounds(player);
|
||||
}
|
||||
} else {
|
||||
data.putInt("ReloadTime", data.getInt("EmptyReloadTime") + 2);
|
||||
NBTTool.getTag(stack).putBoolean("is_empty_reloading", true);
|
||||
tag.putBoolean("is_empty_reloading", true);
|
||||
playGunEmptyReloadSounds(player);
|
||||
}
|
||||
data.putBoolean("StartReload", false);
|
||||
|
@ -393,82 +389,80 @@ public class GunEventHandler {
|
|||
|
||||
if (data.getInt("ReloadTime") == 1) {
|
||||
if (gunItem.isOpenBolt(stack)) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
playGunEmptyReload(player);
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
playGunEmptyReload(player, tag);
|
||||
} else {
|
||||
playGunNormalReload(player);
|
||||
playGunNormalReload(player, tag);
|
||||
}
|
||||
} else {
|
||||
playGunEmptyReload(player);
|
||||
playGunEmptyReload(player, tag);
|
||||
}
|
||||
data.putBoolean("StartReload", false);
|
||||
}
|
||||
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static void playGunNormalReload(Player player) {
|
||||
public static void playGunNormalReload(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
if (player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0)
|
||||
+ (gunItem.hasBulletInBarrel(stack) ? 1 : 0));
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putInt("Ammo", data.getInt("Magazine") + data.getInt("CustomMagazine") + (gunItem.hasBulletInBarrel(stack) ? 1 : 0));
|
||||
} else {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.SHOTGUN, gunItem.hasBulletInBarrel(stack));
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SHOTGUN, gunItem.hasBulletInBarrel(stack));
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.SNIPER, true);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SNIPER, true);
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.HANDGUN, true);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HANDGUN, true);
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.RIFLE, gunItem.hasBulletInBarrel(stack));
|
||||
GunsTool.reload(player, stack, tag, AmmoType.RIFLE, gunItem.hasBulletInBarrel(stack));
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.HEAVY, gunItem.hasBulletInBarrel(stack));
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HEAVY, gunItem.hasBulletInBarrel(stack));
|
||||
}
|
||||
}
|
||||
NBTTool.getTag(stack).putBoolean("is_normal_reloading", false);
|
||||
NBTTool.getTag(stack).putBoolean("is_empty_reloading", false);
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||
}
|
||||
|
||||
public static void playGunEmptyReload(Player player) {
|
||||
public static void playGunEmptyReload(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var data = tag.getCompound("GunData");
|
||||
|
||||
if (player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0));
|
||||
data.putInt("Ammo", data.getInt("Magazine") + data.getInt("CustomMagazine"));
|
||||
} else {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.SHOTGUN);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SHOTGUN);
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.SNIPER);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SNIPER);
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.HANDGUN);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HANDGUN);
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.RIFLE);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.RIFLE);
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
GunsTool.reload(player, stack, AmmoType.HEAVY);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HEAVY);
|
||||
} else if (stack.getItem() == ModItems.TASER.get()) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
data.putInt("Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
} else if (stack.getItem() == ModItems.M_79.get()) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
data.putInt("Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
} else if (stack.getItem() == ModItems.RPG.get()) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
data.putInt("Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
} else if (stack.getItem() == ModItems.JAVELIN.get()) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
data.putInt("Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
}
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("is_normal_reloading", false);
|
||||
NBTTool.getTag(stack).putBoolean("is_empty_reloading", false);
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||
}
|
||||
|
@ -501,7 +495,6 @@ public class GunEventHandler {
|
|||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
||||
SoundEvent sound1p;
|
||||
|
||||
sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + "_reload_normal"));
|
||||
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
|
@ -513,9 +506,9 @@ public class GunEventHandler {
|
|||
/**
|
||||
* 单发装填类的武器换弹流程
|
||||
*/
|
||||
private static void handleGunSingleReload(Player player) {
|
||||
private static void handleGunSingleReload(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
|
||||
// 换弹流程计时器
|
||||
if (tag.getDouble("prepare") > 0) {
|
||||
|
@ -542,24 +535,24 @@ public class GunEventHandler {
|
|||
if (tag.getBoolean("start_single_reload")) {
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
|
||||
|
||||
if ((GunsTool.getGunIntTag(stack, "PrepareLoadTime", 0) != 0
|
||||
&& GunsTool.getGunIntTag(stack, "Ammo", 0) == 0)
|
||||
if ((GunsTool.getGunIntTag(tag, "PrepareLoadTime", 0) != 0
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo", 0) == 0)
|
||||
|| stack.is(ModItems.SECONDARY_CATACLYSM.get())
|
||||
) {
|
||||
// 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870
|
||||
playGunPrepareLoadReloadSounds(player);
|
||||
int prepareLoadTime = GunsTool.getGunIntTag(stack, "PrepareLoadTime", 0);
|
||||
int prepareLoadTime = GunsTool.getGunIntTag(tag, "PrepareLoadTime", 0);
|
||||
tag.putInt("prepare_load", prepareLoadTime + 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime);
|
||||
} else if (GunsTool.getGunIntTag(stack, "PrepareEmptyTime", 0) != 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
} else if (GunsTool.getGunIntTag(tag, "PrepareEmptyTime", 0) != 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
// 此处判断空仓换弹,如莫辛纳甘
|
||||
playGunEmptyPrepareSounds(player);
|
||||
int prepareEmptyTime = GunsTool.getGunIntTag(stack, "PrepareEmptyTime", 0);
|
||||
int prepareEmptyTime = GunsTool.getGunIntTag(tag, "PrepareEmptyTime", 0);
|
||||
tag.putInt("prepare", prepareEmptyTime + 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime);
|
||||
} else {
|
||||
playGunPrepareReloadSounds(player);
|
||||
int prepareTime = GunsTool.getGunIntTag(stack, "PrepareTime", 0);
|
||||
int prepareTime = GunsTool.getGunIntTag(tag, "PrepareTime", 0);
|
||||
tag.putInt("prepare", prepareTime + 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), prepareTime);
|
||||
}
|
||||
|
@ -567,20 +560,16 @@ public class GunEventHandler {
|
|||
tag.putBoolean("force_stop", false);
|
||||
tag.putBoolean("stop", false);
|
||||
tag.putInt("reload_stage", 1);
|
||||
GunsTool.setGunBooleanTag(stack, "Reloading", true);
|
||||
tag.getCompound("GunData").putBoolean("Reloading", true);
|
||||
tag.putBoolean("start_single_reload", false);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.M_870.get()) {
|
||||
if (tag.getInt("prepare_load") == 10) {
|
||||
singleLoad(player);
|
||||
}
|
||||
if (stack.getItem() == ModItems.M_870.get() && tag.getInt("prepare_load") == 10) {
|
||||
singleLoad(player, tag);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get()) {
|
||||
if (tag.getInt("prepare_load") == 3) {
|
||||
singleLoad(player);
|
||||
}
|
||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("prepare_load") == 3) {
|
||||
singleLoad(player, tag);
|
||||
}
|
||||
|
||||
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
||||
|
@ -599,15 +588,15 @@ public class GunEventHandler {
|
|||
tag.putBoolean("force_stage3_start", true);
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && capability.heavyAmmo == 0) {
|
||||
tag.putBoolean("force_stage3_start", true);
|
||||
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
} 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(stack, "Ammo", 0) >= GunsTool.getGunIntTag(stack, "Magazine", 0)) {
|
||||
} else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo", 0) >= GunsTool.getGunIntTag(tag, "Magazine", 0)) {
|
||||
tag.putBoolean("force_stage3_start", true);
|
||||
} else {
|
||||
tag.putInt("reload_stage", 2);
|
||||
}
|
||||
} else {
|
||||
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(stack, "Ammo", 0) >= GunsTool.getGunIntTag(stack, "Magazine", 0)) {
|
||||
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo", 0) >= GunsTool.getGunIntTag(tag, "Magazine", 0)) {
|
||||
tag.putBoolean("force_stage3_start", true);
|
||||
} else {
|
||||
tag.putInt("reload_stage", 2);
|
||||
|
@ -626,11 +615,11 @@ public class GunEventHandler {
|
|||
&& tag.getInt("reload_stage") == 2
|
||||
&& tag.getInt("iterative") == 0
|
||||
&& !tag.getBoolean("stop")
|
||||
&& GunsTool.getGunIntTag(stack, "Ammo", 0) < GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0)) {
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo", 0) < GunsTool.getGunIntTag(tag, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)) {
|
||||
|
||||
playGunLoopReloadSounds(player);
|
||||
int iterativeTime = GunsTool.getGunIntTag(stack, "IterativeTime", 0);
|
||||
int iterativeTime = GunsTool.getGunIntTag(tag, "IterativeTime", 0);
|
||||
tag.putDouble("iterative", iterativeTime);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), iterativeTime);
|
||||
// 动画播放nbt
|
||||
|
@ -642,29 +631,28 @@ public class GunEventHandler {
|
|||
}
|
||||
|
||||
// 装填
|
||||
if (stack.getItem() == ModItems.M_870.get() || stack.getItem() == ModItems.MARLIN.get()) {
|
||||
if (tag.getInt("iterative") == 3) {
|
||||
singleLoad(player);
|
||||
}
|
||||
if (stack.getItem() == ModItems.M_870.get()
|
||||
|| stack.getItem() == ModItems.MARLIN.get()
|
||||
&& tag.getInt("iterative") == 3
|
||||
) {
|
||||
singleLoad(player, tag);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get()) {
|
||||
if (tag.getInt("iterative") == 16) {
|
||||
singleLoad(player);
|
||||
}
|
||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("iterative") == 16) {
|
||||
singleLoad(player, tag);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.K_98.get() || stack.getItem() == ModItems.MOSIN_NAGANT.get()) {
|
||||
if (tag.getInt("iterative") == 1) {
|
||||
singleLoad(player);
|
||||
}
|
||||
if (stack.getItem() == ModItems.K_98.get()
|
||||
|| stack.getItem() == ModItems.MOSIN_NAGANT.get()
|
||||
|| tag.getInt("iterative") == 1) {
|
||||
singleLoad(player, tag);
|
||||
}
|
||||
|
||||
// 二阶段结束
|
||||
if (tag.getInt("iterative") == 1) {
|
||||
// 装满结束
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) >= GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0)) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) >= GunsTool.getGunIntTag(tag, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)) {
|
||||
tag.putInt("reload_stage", 3);
|
||||
}
|
||||
|
||||
|
@ -698,7 +686,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(stack, "FinishTime", 0);
|
||||
int finishTime = GunsTool.getGunIntTag(tag, "FinishTime", 0);
|
||||
tag.putInt("finish", finishTime + 2);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2);
|
||||
playGunEndReloadSounds(player);
|
||||
|
@ -711,26 +699,25 @@ public class GunEventHandler {
|
|||
// 三阶段结束
|
||||
if (tag.getInt("finish") == 1) {
|
||||
tag.putInt("reload_stage", 0);
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", false);
|
||||
}
|
||||
GunsTool.setGunBooleanTag(stack, "Reloading", false);
|
||||
GunsTool.setGunBooleanTag(tag, "Reloading", false);
|
||||
tag.putBoolean("start_single_reload", false);
|
||||
|
||||
NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
|
||||
}
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static void singleLoad(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) + 1);
|
||||
public static void singleLoad(Player player, final CompoundTag tag) {
|
||||
final var data = tag.getCompound("GunData");
|
||||
data.putInt("Ammo", data.getInt("Ammo") + 1);
|
||||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
AmmoType.SHOTGUN.add(cap, -1);
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
|
@ -751,9 +738,7 @@ public class GunEventHandler {
|
|||
|
||||
public static void playGunPrepareReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -768,9 +753,8 @@ public class GunEventHandler {
|
|||
|
||||
public static void playGunEmptyPrepareSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -783,7 +767,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(stack, "PrepareEmptyTime", 0) / 2 + 3 + 1.5 * shooterHeight), () -> {
|
||||
Mod.queueServerWork((int) (GunsTool.getGunIntTag(tag, "PrepareEmptyTime", 0) / 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)) {
|
||||
|
@ -798,9 +782,7 @@ public class GunEventHandler {
|
|||
|
||||
public static void playGunPrepareLoadReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -845,9 +827,7 @@ public class GunEventHandler {
|
|||
|
||||
public static void playGunEndReloadSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
if (!player.level().isClientSide) {
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
|
@ -870,26 +850,28 @@ public class GunEventHandler {
|
|||
/**
|
||||
* 哨兵充能
|
||||
*/
|
||||
private static void handleSentinelCharge(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
private static void handleSentinelCharge(Player player, final CompoundTag tag) {
|
||||
if (!(player.getMainHandItem().getItem() instanceof GunItem)) return;
|
||||
final var data = tag.getCompound("GunData");
|
||||
|
||||
// 启动换弹
|
||||
if (GunsTool.getGunBooleanTag(stack, "StartCharge")) {
|
||||
GunsTool.setGunIntTag(stack, "ChargeTime", 127);
|
||||
GunsTool.setGunBooleanTag(stack, "Charging", true);
|
||||
if (GunsTool.getGunBooleanTag(tag, "StartCharge")) {
|
||||
data.putInt("ChargeTime", 127);
|
||||
data.putBoolean("Charging", true);
|
||||
|
||||
SoundEvent sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc("sentinel_charge"));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
||||
}
|
||||
|
||||
GunsTool.setGunBooleanTag(stack, "StartCharge", false);
|
||||
data.putBoolean("StartCharge", true);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ChargeTime", 0) > 0) {
|
||||
GunsTool.setGunIntTag(stack, "ChargeTime", GunsTool.getGunIntTag(stack, "ChargeTime", 0) - 1);
|
||||
if (GunsTool.getGunIntTag(tag, "ChargeTime", 0) > 0) {
|
||||
data.putInt("ChargeTime", data.getInt("ChargeTime") - 1);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ChargeTime", 0) == 17) {
|
||||
if (GunsTool.getGunIntTag(tag, "ChargeTime", 0) == 17) {
|
||||
for (var cell : player.getInventory().items) {
|
||||
if (cell.is(ModItems.CELL.get())) {
|
||||
var stackStorage = cell.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
@ -912,8 +894,8 @@ public class GunEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ChargeTime", 0) == 1) {
|
||||
GunsTool.setGunBooleanTag(stack, "Charging", false);
|
||||
if (GunsTool.getGunIntTag(tag, "ChargeTime", 0) == 1) {
|
||||
data.putBoolean("Charging", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,8 +133,8 @@ public class LivingEventHandler {
|
|||
|
||||
ItemStack stack = sourceEntity instanceof LivingEntity living ? living.getMainHandItem() : ItemStack.EMPTY;
|
||||
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
// 距离衰减
|
||||
if (DamageTypeTool.isGunDamage(source)) {
|
||||
|
@ -161,7 +161,6 @@ public class LivingEventHandler {
|
|||
|
||||
// 计算防弹插板减伤
|
||||
ItemStack armor = entity.getItemBySlot(EquipmentSlot.CHEST);
|
||||
var tag = NBTTool.getTag(armor);
|
||||
|
||||
if (armor != ItemStack.EMPTY && tag.contains("ArmorPlate")) {
|
||||
double armorValue;
|
||||
|
@ -209,18 +208,21 @@ public class LivingEventHandler {
|
|||
if (event.getEntity() instanceof TargetEntity) return;
|
||||
|
||||
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(), stack) > 0) {
|
||||
GunsTool.setGunDoubleTag(stack, "Exp", GunsTool.getGunDoubleTag(stack, "Exp", 0) + amount);
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) {
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount);
|
||||
}
|
||||
}
|
||||
|
||||
// 再判断是不是枪械能造成的伤害
|
||||
if (!DamageTypeTool.isGunDamage(source)) return;
|
||||
|
||||
GunsTool.setGunDoubleTag(stack, "Exp", GunsTool.getGunDoubleTag(stack, "Exp", 0) + amount);
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount);
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void giveKillExpToWeapon(LivingDeathEvent event) {
|
||||
|
@ -232,32 +234,34 @@ public class LivingEventHandler {
|
|||
if (event.getEntity() instanceof TargetEntity) return;
|
||||
|
||||
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(), stack) > 0) {
|
||||
GunsTool.setGunDoubleTag(stack, "Exp", GunsTool.getGunDoubleTag(stack, "Exp", 0) + amount);
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) {
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount);
|
||||
}
|
||||
}
|
||||
|
||||
// 再判断是不是枪械能造成的伤害
|
||||
if (DamageTypeTool.isGunDamage(source)) {
|
||||
GunsTool.setGunDoubleTag(stack, "Exp", GunsTool.getGunDoubleTag(stack, "Exp", 0) + amount);
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount);
|
||||
}
|
||||
|
||||
// 提升武器等级
|
||||
int level = GunsTool.getGunIntTag(stack, "Level", 0);
|
||||
double exp = GunsTool.getGunDoubleTag(stack, "Exp", 0);
|
||||
int level = GunsTool.getGunIntTag(tag, "Level", 0);
|
||||
double exp = GunsTool.getGunDoubleTag(tag, "Exp", 0);
|
||||
double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
|
||||
while (exp >= upgradeExpNeeded) {
|
||||
exp -= upgradeExpNeeded;
|
||||
level = GunsTool.getGunIntTag(stack, "Level", 0) + 1;
|
||||
level = GunsTool.getGunIntTag(tag, "Level", 0) + 1;
|
||||
upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
GunsTool.setGunDoubleTag(stack, "Exp", exp);
|
||||
GunsTool.setGunIntTag(stack, "Level", level);
|
||||
GunsTool.setGunDoubleTag(stack, "UpgradePoint", GunsTool.getGunDoubleTag(stack, "UpgradePoint", 0) + 0.5);
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", exp);
|
||||
GunsTool.setGunIntTag(tag, "Level", level);
|
||||
GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0) + 0.5);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleGunLevels(LivingIncomingDamageEvent event) {
|
||||
|
@ -268,18 +272,20 @@ public class LivingEventHandler {
|
|||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
if (event.getEntity() instanceof TargetEntity) return;
|
||||
|
||||
int level = GunsTool.getGunIntTag(stack, "Level", 0);
|
||||
double exp = GunsTool.getGunDoubleTag(stack, "Exp", 0);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = GunsTool.getGunIntTag(tag, "Level", 0);
|
||||
double exp = GunsTool.getGunDoubleTag(tag, "Exp", 0);
|
||||
double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
|
||||
while (exp >= upgradeExpNeeded) {
|
||||
exp -= upgradeExpNeeded;
|
||||
level = GunsTool.getGunIntTag(stack, "Level", 0) + 1;
|
||||
level = GunsTool.getGunIntTag(tag, "Level", 0) + 1;
|
||||
upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
|
||||
GunsTool.setGunDoubleTag(stack, "Exp", exp);
|
||||
GunsTool.setGunIntTag(stack, "Level", level);
|
||||
GunsTool.setGunDoubleTag(stack, "UpgradePoint", GunsTool.getGunDoubleTag(stack, "UpgradePoint", 0) + 0.5);
|
||||
GunsTool.setGunDoubleTag(tag, "Exp", exp);
|
||||
GunsTool.setGunIntTag(tag, "Level", level);
|
||||
GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0) + 0.5);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void killIndication(LivingDeathEvent event) {
|
||||
|
@ -331,9 +337,7 @@ public class LivingEventHandler {
|
|||
@SubscribeEvent
|
||||
public static void handleChangeSlot(LivingEquipmentChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player player && event.getSlot() == EquipmentSlot.MAINHAND) {
|
||||
if (player.level().isClientSide) {
|
||||
return;
|
||||
}
|
||||
if (player.level().isClientSide) return;
|
||||
|
||||
ItemStack oldStack = event.getFrom();
|
||||
ItemStack newStack = event.getTo();
|
||||
|
@ -343,97 +347,97 @@ public class LivingEventHandler {
|
|||
|
||||
var oldTag = NBTTool.getTag(oldStack);
|
||||
var newTag = NBTTool.getTag(newStack);
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
if (newStack.getItem() != oldStack.getItem()
|
||||
|| (newStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(newStack).hasUUID("UUID"))
|
||||
|| (oldStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(oldStack).hasUUID("UUID"))
|
||||
|| (newStack.is(ModTags.Items.GUN) && oldStack.is(ModTags.Items.GUN) && !Objects.equals(GunsTool.getGunUUID(newStack), GunsTool.getGunUUID(oldStack)))
|
||||
) {
|
||||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||
stopGunReloadSound(serverPlayer, oldGun);
|
||||
if (player instanceof ServerPlayer serverPlayer
|
||||
&& (newStack.getItem() != oldStack.getItem()
|
||||
|| (newStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(newTag).hasUUID("UUID"))
|
||||
|| (oldStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(oldTag).hasUUID("UUID"))
|
||||
|| (newStack.is(ModTags.Items.GUN) && oldStack.is(ModTags.Items.GUN) && !Objects.equals(GunsTool.getGunUUID(newTag), GunsTool.getGunUUID(oldTag)))
|
||||
)) {
|
||||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||
stopGunReloadSound(serverPlayer, oldGun);
|
||||
|
||||
CompoundTag data = oldTag.getCompound("GunData");
|
||||
CompoundTag data = oldTag.getCompound("GunData");
|
||||
|
||||
if (GunsTool.getGunDoubleTag(oldStack, "BoltActionTime", 0) > 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(oldStack, "IterativeTime", 0) != 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);
|
||||
oldTag.putDouble("finish", 0);
|
||||
}
|
||||
NBTTool.saveTag(oldStack, oldTag);
|
||||
|
||||
if (oldStack.is(ModItems.SENTINEL.get())) {
|
||||
data.putBoolean("Charging", false);
|
||||
data.putInt("ChargeTime", 0);
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.edit = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
if (GunsTool.getGunDoubleTag(oldTag, "BoltActionTime", 0) > 0) {
|
||||
data.putInt("BoltActionTick", 0);
|
||||
}
|
||||
|
||||
if (newStack.getItem() instanceof GunItem) {
|
||||
player.getPersistentData().putDouble("noRun", 40);
|
||||
newTag.putBoolean("draw", true);
|
||||
if (GunsTool.getGunIntTag(newStack, "BoltActionTime", 0) > 0) {
|
||||
GunsTool.setGunIntTag(newStack, "BoltActionTick", 0);
|
||||
}
|
||||
newTag.putBoolean("is_normal_reloading", false);
|
||||
newTag.putBoolean("is_empty_reloading", false);
|
||||
data.putInt("ReloadTime", 0);
|
||||
oldTag.put("GunData", data);
|
||||
|
||||
CompoundTag data = newTag.getCompound("GunData");
|
||||
data.putInt("ReloadTime", 0);
|
||||
newTag.put("GunData", data);
|
||||
oldTag.putBoolean("is_normal_reloading", false);
|
||||
oldTag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
if (GunsTool.getGunIntTag(newStack, "IterativeTime", 0) != 0) {
|
||||
newTag.putBoolean("force_stop", false);
|
||||
newTag.putBoolean("stop", false);
|
||||
newTag.putInt("reload_stage", 0);
|
||||
GunsTool.setGunBooleanTag(newStack, "Reloading", false);
|
||||
newTag.putDouble("prepare", 0);
|
||||
newTag.putDouble("prepare_load", 0);
|
||||
newTag.putDouble("iterative", 0);
|
||||
newTag.putDouble("finish", 0);
|
||||
}
|
||||
if (GunsTool.getGunIntTag(oldTag, "IterativeTime", 0) != 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);
|
||||
oldTag.putDouble("finish", 0);
|
||||
}
|
||||
|
||||
if (newStack.is(ModItems.SENTINEL.get())) {
|
||||
GunsTool.setGunBooleanTag(newStack, "Charging", false);
|
||||
GunsTool.setGunIntTag(newStack, "ChargeTime", 0);
|
||||
}
|
||||
NBTTool.saveTag(newStack, newTag);
|
||||
if (oldStack.is(ModItems.SENTINEL.get())) {
|
||||
data.putBoolean("Charging", false);
|
||||
data.putInt("ChargeTime", 0);
|
||||
}
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), newStack);
|
||||
if (level != 0) {
|
||||
GunsTool.setPerkIntTag(newStack, "KillingTally", 0);
|
||||
}
|
||||
|
||||
if (player.level() instanceof ServerLevel) {
|
||||
PacketDistributor.sendToPlayer(serverPlayer, new DrawClientMessage(true));
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.edit = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (newStack.getItem() instanceof GunItem) {
|
||||
player.getPersistentData().putDouble("noRun", 40);
|
||||
newTag.putBoolean("draw", true);
|
||||
if (GunsTool.getGunIntTag(newTag, "BoltActionTime", 0) > 0) {
|
||||
GunsTool.setGunIntTag(newTag, "BoltActionTick", 0);
|
||||
}
|
||||
newTag.putBoolean("is_normal_reloading", false);
|
||||
newTag.putBoolean("is_empty_reloading", false);
|
||||
|
||||
CompoundTag data = newTag.getCompound("GunData");
|
||||
data.putInt("ReloadTime", 0);
|
||||
newTag.put("GunData", data);
|
||||
|
||||
if (GunsTool.getGunIntTag(newTag, "IterativeTime", 0) != 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);
|
||||
newTag.putDouble("finish", 0);
|
||||
}
|
||||
|
||||
if (newStack.is(ModItems.SENTINEL.get())) {
|
||||
GunsTool.setGunBooleanTag(newTag, "Charging", false);
|
||||
GunsTool.setGunIntTag(newTag, "ChargeTime", 0);
|
||||
}
|
||||
NBTTool.saveTag(newStack, newTag);
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), newTag);
|
||||
if (level != 0) {
|
||||
GunsTool.setPerkIntTag(newTag, "KillingTally", 0);
|
||||
}
|
||||
|
||||
if (player.level() instanceof ServerLevel) {
|
||||
PacketDistributor.sendToPlayer(serverPlayer, new DrawClientMessage(true));
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
}
|
||||
NBTTool.saveTag(oldStack, oldTag);
|
||||
NBTTool.saveTag(newStack, newTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -514,7 +518,8 @@ public class LivingEventHandler {
|
|||
}
|
||||
|
||||
if (source.getDirectEntity() instanceof ProjectileEntity projectile) {
|
||||
if (PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), stack) > 0) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), tag) > 0) {
|
||||
float bypassArmorRate = projectile.getBypassArmorRate();
|
||||
if (bypassArmorRate >= 1.0f && source.is(ModDamageTypes.GUN_FIRE_HEADSHOT_ABSOLUTE)) {
|
||||
handleFourthTimesCharm(stack);
|
||||
|
@ -568,20 +573,23 @@ public class LivingEventHandler {
|
|||
}
|
||||
|
||||
private static void handleClipPerks(ItemStack stack) {
|
||||
int healClipLevel = PerkHelper.getItemPerkLevel(ModPerks.HEAL_CLIP.get(), stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int healClipLevel = PerkHelper.getItemPerkLevel(ModPerks.HEAL_CLIP.get(), tag);
|
||||
if (healClipLevel != 0) {
|
||||
GunsTool.setPerkIntTag(stack, "HealClipTime", 80 + healClipLevel * 20);
|
||||
GunsTool.setPerkIntTag(tag, "HealClipTime", 80 + healClipLevel * 20);
|
||||
}
|
||||
|
||||
int killClipLevel = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), stack);
|
||||
int killClipLevel = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), tag);
|
||||
if (killClipLevel != 0) {
|
||||
GunsTool.setPerkIntTag(stack, "KillClipReloadTime", 80);
|
||||
GunsTool.setPerkIntTag(tag, "KillClipReloadTime", 80);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleKillClipDamage(ItemStack stack, LivingIncomingDamageEvent event) {
|
||||
if (GunsTool.getPerkIntTag(stack, "KillClipTime") > 0) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (GunsTool.getPerkIntTag(tag, "KillClipTime") > 0) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), tag);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -591,21 +599,19 @@ public class LivingEventHandler {
|
|||
}
|
||||
|
||||
private static void handleGutshotStraightDamage(ItemStack stack, LivingIncomingDamageEvent event) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.GUTSHOT_STRAIGHT.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.GUTSHOT_STRAIGHT.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
event.setAmount(event.getAmount() * (1.15f + 0.05f * level));
|
||||
}
|
||||
|
||||
private static void handleKillingTallyDamage(ItemStack stack, LivingIncomingDamageEvent event) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
int killTally = GunsTool.getPerkIntTag(stack, "KillingTally");
|
||||
int killTally = GunsTool.getPerkIntTag(tag, "KillingTally");
|
||||
if (killTally == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -614,43 +620,44 @@ public class LivingEventHandler {
|
|||
}
|
||||
|
||||
private static void handleKillingTallyAddCount(ItemStack stack) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), tag);
|
||||
if (level != 0) {
|
||||
GunsTool.setPerkIntTag(stack, "KillingTally", Math.min(3, GunsTool.getPerkIntTag(stack, "KillingTally") + 1));
|
||||
GunsTool.setPerkIntTag(tag, "KillingTally", Math.min(3, GunsTool.getPerkIntTag(tag, "KillingTally") + 1));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleFourthTimesCharm(ItemStack stack) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
int fourthTimesCharmTick = GunsTool.getPerkIntTag(stack, "FourthTimesCharmTick");
|
||||
int fourthTimesCharmTick = GunsTool.getPerkIntTag(tag, "FourthTimesCharmTick");
|
||||
if (fourthTimesCharmTick <= 0) {
|
||||
GunsTool.setPerkIntTag(stack, "FourthTimesCharmTick", 40 + 10 * level);
|
||||
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", 1);
|
||||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmTick", 40 + 10 * level);
|
||||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmCount", 1);
|
||||
} else {
|
||||
int count = GunsTool.getPerkIntTag(stack, "FourthTimesCharmCount");
|
||||
int count = GunsTool.getPerkIntTag(tag, "FourthTimesCharmCount");
|
||||
if (count < 4) {
|
||||
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", Math.min(4, count + 1));
|
||||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmCount", Math.min(4, count + 1));
|
||||
}
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleSubsistence(ItemStack stack, Player player) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.SUBSISTENCE.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.SUBSISTENCE.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
float rate = level * 0.1f + (stack.is(ModTags.Items.SMG) || stack.is(ModTags.Items.RIFLE) ? 0.07f : 0f);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
|
||||
int mag = GunsTool.getGunIntTag(stack, "Magazine", 0) + GunsTool.getGunIntTag(stack, "CustomMagazine", 0);
|
||||
int ammo = GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
int mag = GunsTool.getGunIntTag(tag, "Magazine", 0) + GunsTool.getGunIntTag(tag, "CustomMagazine", 0);
|
||||
int ammo = GunsTool.getGunIntTag(tag, "Ammo", 0);
|
||||
int ammoReload = (int) Math.min(mag, mag * rate);
|
||||
int ammoNeed = Math.min(mag - ammo, ammoReload);
|
||||
|
||||
|
@ -663,7 +670,7 @@ public class LivingEventHandler {
|
|||
} else {
|
||||
cap.rifleAmmo -= ammoFinal;
|
||||
}
|
||||
GunsTool.setGunIntTag(stack, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
int ammoFinal = Math.min(cap.handgunAmmo, ammoNeed);
|
||||
if (flag) {
|
||||
|
@ -671,17 +678,17 @@ public class LivingEventHandler {
|
|||
} else {
|
||||
cap.handgunAmmo -= ammoFinal;
|
||||
}
|
||||
GunsTool.setGunIntTag(stack, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
|
||||
|
||||
private static void handleFieldDoctor(ItemStack stack, LivingIncomingDamageEvent event, Player player) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.FIELD_DOCTOR.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.FIELD_DOCTOR.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
if (event.getEntity().isAlliedTo(player)) {
|
||||
event.getEntity().heal(event.getAmount() * Math.min(1.0f, 0.25f + 0.05f * level));
|
||||
|
@ -690,32 +697,31 @@ public class LivingEventHandler {
|
|||
}
|
||||
|
||||
private static void handleHeadSeekerTime(ItemStack stack) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.HEAD_SEEKER.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.HEAD_SEEKER.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
GunsTool.setPerkIntTag(stack, "HeadSeeker", 11 + level * 2);
|
||||
GunsTool.setPerkIntTag(tag, "HeadSeeker", 11 + level * 2);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleHeadSeekerDamage(ItemStack stack, LivingIncomingDamageEvent event) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.HEAD_SEEKER.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.HEAD_SEEKER.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
if (GunsTool.getPerkIntTag(stack, "HeadSeeker") > 0) {
|
||||
if (GunsTool.getPerkIntTag(tag, "HeadSeeker") > 0) {
|
||||
event.setAmount(event.getAmount() * (1.095f + 0.0225f * level));
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleDesperado(ItemStack stack) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
GunsTool.setPerkIntTag(stack, "DesperadoTime", 90 + level * 10);
|
||||
GunsTool.setPerkIntTag(tag, "DesperadoTime", 90 + level * 10);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -780,7 +786,9 @@ public class LivingEventHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
if (stack.is(ModTags.Items.GUN) && PerkHelper.getItemPerkLevel(ModPerks.POWERFUL_ATTRACTION.get(), stack) > 0 && (DamageTypeTool.isGunDamage(source) || DamageTypeTool.isExplosionDamage(source))) {
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModTags.Items.GUN) && PerkHelper.getItemPerkLevel(ModPerks.POWERFUL_ATTRACTION.get(), tag) > 0 && (DamageTypeTool.isGunDamage(source) || DamageTypeTool.isExplosionDamage(source))) {
|
||||
var drops = event.getDrops();
|
||||
drops.forEach(itemEntity -> {
|
||||
ItemStack item = itemEntity.getItem();
|
||||
|
@ -806,7 +814,8 @@ public class LivingEventHandler {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.POWERFUL_ATTRACTION.get(), stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.POWERFUL_ATTRACTION.get(), tag);
|
||||
if (level > 0) {
|
||||
player.giveExperiencePoints((int) (event.getDroppedExperience() * (0.8f + 0.2f * level)));
|
||||
|
||||
|
@ -824,7 +833,8 @@ public class LivingEventHandler {
|
|||
private static void handleVorpalWeaponDamage(ItemStack stack, LivingIncomingDamageEvent event) {
|
||||
var entity = event.getEntity();
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.VORPAL_WEAPON.get(), stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.VORPAL_WEAPON.get(), tag);
|
||||
if (level <= 0) return;
|
||||
if (entity.getHealth() < 100.0f) return;
|
||||
|
||||
|
|
|
@ -115,7 +115,8 @@ public class PlayerEventHandler {
|
|||
int sprintCost;
|
||||
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
double weight = GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
double weight = GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight");
|
||||
sprintCost = (int) (5 + 0.2 * weight);
|
||||
} else {
|
||||
sprintCost = 5;
|
||||
|
@ -196,8 +197,10 @@ public class PlayerEventHandler {
|
|||
private static void handleSpecialWeaponAmmo(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
NBTTool.setDouble(stack, "empty", 0);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) {
|
||||
tag.putDouble("empty", 0);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,20 +210,21 @@ public class PlayerEventHandler {
|
|||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (cap.bowPullHold) {
|
||||
if (stack.getItem() == ModItems.BOCEK.get()
|
||||
&& GunsTool.getGunIntTag(stack, "MaxAmmo") > 0
|
||||
&& GunsTool.getGunIntTag(tag, "MaxAmmo") > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& GunsTool.getGunDoubleTag(stack, "Power") < 12
|
||||
&& GunsTool.getGunDoubleTag(tag, "Power") < 12
|
||||
) {
|
||||
GunsTool.setGunDoubleTag(stack, "Power", GunsTool.getGunDoubleTag(stack, "Power") + 1);
|
||||
GunsTool.setGunDoubleTag(tag, "Power", GunsTool.getGunDoubleTag(tag, "Power") + 1);
|
||||
|
||||
cap.bowPull = true;
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setSprinting(false);
|
||||
}
|
||||
if (GunsTool.getGunDoubleTag(stack, "Power") == 1) {
|
||||
if (GunsTool.getGunDoubleTag(tag, "Power") == 1) {
|
||||
if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, ModSounds.BOCEK_PULL_1P.get(), 2f, 1f);
|
||||
player.level().playSound(null, player.blockPosition(), ModSounds.BOCEK_PULL_3P.get(), SoundSource.PLAYERS, 0.5f, 1);
|
||||
|
@ -228,17 +232,19 @@ public class PlayerEventHandler {
|
|||
}
|
||||
} else {
|
||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||
GunsTool.setGunDoubleTag(stack, "Power", 0);
|
||||
GunsTool.setGunDoubleTag(tag, "Power", 0);
|
||||
}
|
||||
cap.bowPull = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunDoubleTag(stack, "Power") > 0) {
|
||||
if (GunsTool.getGunDoubleTag(tag, "Power") > 0) {
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setSprinting(false);
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleSimulationDistance(Player player) {
|
||||
|
@ -257,47 +263,49 @@ public class PlayerEventHandler {
|
|||
|
||||
for (ItemStack stack : player.getInventory().items) {
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
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, AmmoType.SHOTGUN);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SHOTGUN);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && cap.sniperAmmo > 0) {
|
||||
GunsTool.reload(player, stack, AmmoType.SNIPER);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.SNIPER);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_HANDGUN_AMMO) && cap.handgunAmmo > 0) {
|
||||
GunsTool.reload(player, stack, AmmoType.HANDGUN);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HANDGUN);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && cap.rifleAmmo > 0) {
|
||||
GunsTool.reload(player, stack, AmmoType.RIFLE);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.RIFLE);
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && cap.heavyAmmo > 0) {
|
||||
GunsTool.reload(player, stack, AmmoType.HEAVY);
|
||||
GunsTool.reload(player, stack, tag, AmmoType.HEAVY);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(tag, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
} else {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0));
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0));
|
||||
}
|
||||
GunsTool.setGunBooleanTag(stack, "HoldOpen", false);
|
||||
GunsTool.setGunBooleanTag(tag, "HoldOpen", false);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +353,9 @@ public class PlayerEventHandler {
|
|||
if (left.is(ModTags.Items.GUN) && right.getItem() == ModItems.SHORTCUT_PACK.get()) {
|
||||
ItemStack output = left.copy();
|
||||
|
||||
GunsTool.setGunDoubleTag(output, "UpgradePoint", GunsTool.getGunDoubleTag(output, "UpgradePoint", 0) + 1);
|
||||
final var outputTag = NBTTool.getTag(output);
|
||||
GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", GunsTool.getGunDoubleTag(outputTag, "UpgradePoint", 0) + 1);
|
||||
NBTTool.saveTag(output, outputTag);
|
||||
|
||||
event.setOutput(output);
|
||||
event.setCost(10);
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.init.ModPerks;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
|
@ -19,13 +20,10 @@ public class ReloadEventHandler {
|
|||
public static void onPreReload(ReloadEvent.Pre event) {
|
||||
Player player = event.player;
|
||||
ItemStack stack = event.stack;
|
||||
if (player == null || !stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.level().isClientSide) {
|
||||
return;
|
||||
}
|
||||
if (player == null
|
||||
|| !stack.is(ModTags.Items.GUN)
|
||||
|| player.level().isClientSide
|
||||
) return;
|
||||
|
||||
handleHealClipPre(stack);
|
||||
handleKillClipPre(stack);
|
||||
|
@ -51,21 +49,22 @@ public class ReloadEventHandler {
|
|||
}
|
||||
|
||||
private static void handleHealClipPre(ItemStack stack) {
|
||||
int time = GunsTool.getPerkIntTag(stack, "HealClipTime");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int time = GunsTool.getPerkIntTag(tag, "HealClipTime");
|
||||
if (time > 0) {
|
||||
GunsTool.setPerkIntTag(stack, "HealClipTime", 0);
|
||||
GunsTool.setPerkBooleanTag(stack, "HealClip", true);
|
||||
GunsTool.setPerkIntTag(tag, "HealClipTime", 0);
|
||||
GunsTool.setPerkBooleanTag(tag, "HealClip", true);
|
||||
} else {
|
||||
GunsTool.setPerkBooleanTag(stack, "HealClip", false);
|
||||
GunsTool.setPerkBooleanTag(tag, "HealClip", false);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleHealClipPost(Player player, ItemStack stack) {
|
||||
if (!GunsTool.getPerkBooleanTag(stack, "HealClip")) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (!GunsTool.getPerkBooleanTag(tag, "HealClip")) return;
|
||||
|
||||
int healClipLevel = PerkHelper.getItemPerkLevel(ModPerks.HEAL_CLIP.get(), stack);
|
||||
int healClipLevel = PerkHelper.getItemPerkLevel(ModPerks.HEAL_CLIP.get(), tag);
|
||||
if (healClipLevel == 0) {
|
||||
healClipLevel = 1;
|
||||
}
|
||||
|
@ -78,49 +77,53 @@ public class ReloadEventHandler {
|
|||
}
|
||||
|
||||
private static void handleKillClipPre(ItemStack stack) {
|
||||
int time = GunsTool.getPerkIntTag(stack, "KillClipReloadTime");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int time = GunsTool.getPerkIntTag(tag, "KillClipReloadTime");
|
||||
if (time > 0) {
|
||||
GunsTool.setPerkIntTag(stack, "KillClipReloadTime", 0);
|
||||
GunsTool.setPerkBooleanTag(stack, "KillClip", true);
|
||||
GunsTool.setPerkIntTag(tag, "KillClipReloadTime", 0);
|
||||
GunsTool.setPerkBooleanTag(tag, "KillClip", true);
|
||||
} else {
|
||||
GunsTool.setPerkBooleanTag(stack, "KillClip", false);
|
||||
GunsTool.setPerkBooleanTag(tag, "KillClip", false);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleKillClipPost(ItemStack stack) {
|
||||
if (!GunsTool.getPerkBooleanTag(stack, "KillClip")) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (!GunsTool.getPerkBooleanTag(tag, "KillClip")) return;
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), stack);
|
||||
GunsTool.setPerkIntTag(stack, "KillClipTime", 90 + 10 * level);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), tag);
|
||||
GunsTool.setPerkIntTag(tag, "KillClipTime", 90 + 10 * level);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleKillingTallyPre(ItemStack stack) {
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), stack);
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), tag);
|
||||
if (level == 0) return;
|
||||
|
||||
GunsTool.setPerkIntTag(stack, "KillingTally", 0);
|
||||
GunsTool.setPerkIntTag(tag, "KillingTally", 0);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleDesperadoPre(ItemStack stack) {
|
||||
int time = GunsTool.getPerkIntTag(stack, "DesperadoTime");
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int time = GunsTool.getPerkIntTag(tag, "DesperadoTime");
|
||||
if (time > 0) {
|
||||
GunsTool.setPerkIntTag(stack, "DesperadoTime", 0);
|
||||
GunsTool.setPerkBooleanTag(stack, "Desperado", true);
|
||||
GunsTool.setPerkIntTag(tag, "DesperadoTime", 0);
|
||||
GunsTool.setPerkBooleanTag(tag, "Desperado", true);
|
||||
} else {
|
||||
GunsTool.setPerkBooleanTag(stack, "Desperado", false);
|
||||
GunsTool.setPerkBooleanTag(tag, "Desperado", false);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleDesperadoPost(ItemStack stack) {
|
||||
if (!GunsTool.getPerkBooleanTag(stack, "Desperado")) {
|
||||
return;
|
||||
}
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (!GunsTool.getPerkBooleanTag(tag, "Desperado")) return;
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), stack);
|
||||
GunsTool.setPerkIntTag(stack, "DesperadoTimePost", 110 + level * 10);
|
||||
int level = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), tag);
|
||||
GunsTool.setPerkIntTag(tag, "DesperadoTimePost", 110 + level * 10);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,9 @@ public class ArmorPlate extends Item {
|
|||
|
||||
public static ItemStack getInfiniteInstance() {
|
||||
ItemStack stack = new ItemStack(ModItems.ARMOR_PLATE.get());
|
||||
NBTTool.getTag(stack).putBoolean("Infinite", true);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("Infinite", true);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class C4Bomb extends Item implements ProjectileItem {
|
|||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if (NBTTool.getBoolean(stack, TAG_CONTROL, false)) {
|
||||
if (NBTTool.getTag(stack).getBoolean(TAG_CONTROL)) {
|
||||
tooltipComponents.add(Component.translatable("des.superbwarfare.c4_bomb.control").withStyle(ChatFormatting.GRAY));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("des.superbwarfare.c4_bomb.time").withStyle(ChatFormatting.GRAY));
|
||||
|
@ -73,7 +73,9 @@ public class C4Bomb extends Item implements ProjectileItem {
|
|||
|
||||
public static ItemStack makeInstance() {
|
||||
ItemStack stack = new ItemStack(ModItems.C4_BOMB.get());
|
||||
NBTTool.setBoolean(stack, TAG_CONTROL, true);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean(TAG_CONTROL, true);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.tools.NBTTool;
|
|||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.CameraType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -37,21 +38,17 @@ public class Monitor extends Item {
|
|||
super(new Properties().stacksTo(1));
|
||||
}
|
||||
|
||||
public static void link(ItemStack stack, String id) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
NBTTool.setBoolean(stack, LINKED, true);
|
||||
public static void link(CompoundTag tag, String id) {
|
||||
tag.putBoolean(LINKED, true);
|
||||
tag.putString(LINKED_DRONE, id);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static void disLink(ItemStack stack, Player player) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
NBTTool.setBoolean(stack, LINKED, false);
|
||||
public static void disLink(CompoundTag tag, Player player) {
|
||||
tag.putBoolean(LINKED, false);
|
||||
tag.putString(LINKED_DRONE, "none");
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
PacketDistributor.sendToPlayer(serverPlayer, new ResetCameraTypeMessage(0));
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private void resetDroneData(DroneEntity drone) {
|
||||
|
@ -69,12 +66,12 @@ public class Monitor extends Item {
|
|||
@ParametersAreNonnullByDefault
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (!NBTTool.getBoolean(stack, LINKED, false)) {
|
||||
if (!tag.getBoolean(LINKED)) {
|
||||
return super.use(world, player, hand);
|
||||
}
|
||||
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("Using")) {
|
||||
tag.putBoolean("Using", false);
|
||||
if (world.isClientSide) {
|
||||
|
|
|
@ -13,8 +13,10 @@ public class GunEvents {
|
|||
public static void onPickup(ItemEntityPickupEvent.Pre event) {
|
||||
var stack = event.getItemEntity().getItem();
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
NBTTool.getTag(stack).putBoolean("draw", true);
|
||||
NBTTool.getTag(stack).putBoolean("init", true);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("draw", true);
|
||||
tag.putBoolean("init", true);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.NBTTool.saveTag;
|
||||
|
||||
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
|
||||
public abstract class GunItem extends Item implements CustomRendererItem {
|
||||
|
||||
|
@ -58,33 +56,33 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
|
||||
if (!(entity instanceof LivingEntity)) return;
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
if (!(entity instanceof LivingEntity)
|
||||
|| !stack.is(ModTags.Items.GUN)
|
||||
|| !(stack.getItem() instanceof GunItem gunItem)
|
||||
) return;
|
||||
|
||||
if (!NBTTool.getBoolean(stack, "init", false)) {
|
||||
GunsTool.initGun(level, stack, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1));
|
||||
GunsTool.generateAndSetUUID(stack);
|
||||
NBTTool.setBoolean(stack, "init", true);
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (!tag.getBoolean("init")) {
|
||||
GunsTool.initGun(level, tag, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1));
|
||||
GunsTool.generateAndSetUUID(tag);
|
||||
tag.putBoolean("init", true);
|
||||
}
|
||||
tag.putBoolean("draw", false);
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("draw")) {
|
||||
NBTTool.getTag(stack).putBoolean("draw", false);
|
||||
}
|
||||
handleGunPerks(tag);
|
||||
handleGunAttachment(tag);
|
||||
|
||||
handleGunPerks(stack);
|
||||
handleGunAttachment(stack);
|
||||
var hasBulletInBarrel = gunItem.hasBulletInBarrel(stack);
|
||||
var ammoCount = GunsTool.getGunIntTag(tag, "Ammo", 0);
|
||||
var magazine = GunsTool.getGunIntTag(tag, "Magazine", 0);
|
||||
var customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine", 0);
|
||||
|
||||
if ((gunItem.hasBulletInBarrel(stack) && GunsTool.getGunIntTag(stack, "Ammo", 0) >
|
||||
GunsTool.getGunIntTag(stack, "Magazine", 0) + GunsTool.getGunIntTag(stack, "CustomMagazine", 0) + 1)
|
||||
|| (!gunItem.hasBulletInBarrel(stack) && GunsTool.getGunIntTag(stack, "Ammo", 0) >
|
||||
GunsTool.getGunIntTag(stack, "Magazine", 0) + GunsTool.getGunIntTag(stack, "CustomMagazine", 0))
|
||||
if ((hasBulletInBarrel && ammoCount > magazine + customMagazine + 1)
|
||||
|| (!hasBulletInBarrel && ammoCount > magazine + customMagazine)
|
||||
) {
|
||||
int count = GunsTool.getGunIntTag(stack, "Ammo", 0) - GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0) - (gunItem.hasBulletInBarrel(stack) ? 1 : 0);
|
||||
int count = ammoCount - magazine + customMagazine - (hasBulletInBarrel ? 1 : 0);
|
||||
|
||||
var capability = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
||||
if (capability != null) {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
AmmoType.SHOTGUN.add(capability, count);
|
||||
|
@ -97,13 +95,11 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
AmmoType.HEAVY.add(capability, count);
|
||||
}
|
||||
|
||||
capability.syncPlayerVariables(entity);
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0) + (gunItem.hasBulletInBarrel(stack) ? 1 : 0));
|
||||
GunsTool.setGunIntTag(tag, "Ammo", magazine + customMagazine + (hasBulletInBarrel ? 1 : 0));
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,13 +115,13 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
// map.builder().add(
|
||||
// Attribute.BASE,
|
||||
// new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER,
|
||||
// -0.01f - 0.005f * (GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight")),
|
||||
// -0.01f - 0.005f * (GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight")),
|
||||
// AttributeModifier.Operation.ADD_MULTIPLIED_BASE)
|
||||
// )
|
||||
//
|
||||
// map.put(Attributes.MOVEMENT_SPEED,
|
||||
// new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER,
|
||||
// -0.01f - 0.005f * (GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight")),
|
||||
// -0.01f - 0.005f * (GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight")),
|
||||
// AttributeModifier.Operation.ADD_MULTIPLIED_BASE));
|
||||
// return map;
|
||||
// }
|
||||
|
@ -138,7 +134,7 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
// map = HashMultimap.create(map);
|
||||
// map.put(Attributes.MOVEMENT_SPEED,
|
||||
// new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER,
|
||||
// -0.01f - 0.005f * (GunsTool.getGunDoubleTag(stack, "Weight") + GunsTool.getGunDoubleTag(stack, "CustomWeight")),
|
||||
// -0.01f - 0.005f * (GunsTool.getGunDoubleTag(tag, "Weight") + GunsTool.getGunDoubleTag(tag, "CustomWeight")),
|
||||
// AttributeModifier.Operation.ADD_MULTIPLIED_BASE));
|
||||
// }
|
||||
// return map;
|
||||
|
@ -178,24 +174,24 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
}
|
||||
|
||||
|
||||
private void handleGunPerks(ItemStack stack) {
|
||||
reducePerkTagCoolDown(stack, "HealClipTime", "KillClipReloadTime", "KillClipTime", "FourthTimesCharmTick", "HeadSeeker",
|
||||
private void handleGunPerks(final CompoundTag tag) {
|
||||
reducePerkTagCoolDown(tag, "HealClipTime", "KillClipReloadTime", "KillClipTime", "FourthTimesCharmTick", "HeadSeeker",
|
||||
"DesperadoTime", "DesperadoTimePost");
|
||||
|
||||
if (PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), stack) > 0) {
|
||||
int count = GunsTool.getPerkIntTag(stack, "FourthTimesCharmCount");
|
||||
if (PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), tag) > 0) {
|
||||
int count = GunsTool.getPerkIntTag(tag, "FourthTimesCharmCount");
|
||||
if (count >= 4) {
|
||||
GunsTool.setPerkIntTag(stack, "FourthTimesCharmTick", 0);
|
||||
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", 0);
|
||||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmTick", 0);
|
||||
GunsTool.setPerkIntTag(tag, "FourthTimesCharmCount", 0);
|
||||
|
||||
int mag = GunsTool.getGunIntTag(stack, "Magazine", 0) + GunsTool.getGunIntTag(stack, "CustomMagazine", 0);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", Math.min(mag, GunsTool.getGunIntTag(stack, "Ammo", 0) + 2));
|
||||
int mag = GunsTool.getGunIntTag(tag, "Magazine", 0) + GunsTool.getGunIntTag(tag, "CustomMagazine", 0);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, GunsTool.getGunIntTag(tag, "Ammo", 0) + 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGunAttachment(ItemStack stack) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments");
|
||||
private void handleGunAttachment(final CompoundTag rootTag) {
|
||||
CompoundTag tag = rootTag.getCompound("Attachments");
|
||||
|
||||
double scopeWeight = switch (tag.getInt("Scope")) {
|
||||
case 1 -> 0.5;
|
||||
|
@ -230,16 +226,15 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
|
||||
double soundRadius = tag.getInt("Barrel") == 2 ? 0.6 : 1;
|
||||
|
||||
GunsTool.setGunDoubleTag(stack, "CustomWeight", scopeWeight + barrelWeight + magazineWeight + stockWeight + gripWeight);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomSoundRadius", soundRadius);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomWeight", scopeWeight + barrelWeight + magazineWeight + stockWeight + gripWeight);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomSoundRadius", soundRadius);
|
||||
}
|
||||
|
||||
public boolean canApplyPerk(Perk perk) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void reducePerkTagCoolDown(ItemStack stack, String... tags) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
private void reducePerkTagCoolDown(final CompoundTag tag, String... tags) {
|
||||
var compound = tag.getCompound("PerkData");
|
||||
|
||||
for (String t : tags) {
|
||||
|
@ -252,7 +247,6 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
}
|
||||
}
|
||||
tag.put("PerkData", compound);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.item.gun;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
|
||||
|
@ -15,7 +16,7 @@ public interface SpecialFireWeapon {
|
|||
* @param player 玩家
|
||||
*/
|
||||
|
||||
default void fireOnPress(Player player) {
|
||||
default void fireOnPress(Player player, final CompoundTag tag) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,7 +24,7 @@ public interface SpecialFireWeapon {
|
|||
*
|
||||
* @param player 玩家
|
||||
*/
|
||||
default void fireOnRelease(Player player) {
|
||||
default void fireOnRelease(Player player, final CompoundTag tag) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,8 +69,9 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
boolean stock = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) > 0;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
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;
|
||||
|
||||
if (ClientEventHandler.firePosTimer > 0 && ClientEventHandler.firePosTimer < 1.7) {
|
||||
if (stock) {
|
||||
|
@ -108,11 +109,12 @@ 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);
|
||||
|
||||
boolean stock = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) > 0;
|
||||
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;
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
if (stock) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.trachelium.action_stock_grip"));
|
||||
|
@ -243,12 +245,12 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
var tag = NBTTool.getTag(stack);
|
||||
GunsTool.setGunIntTag(stack, "BoltActionTime", tag.getBoolean("DA") ? 12 : 0);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
GunsTool.setGunIntTag(tag, "BoltActionTime", tag.getBoolean("DA") ? 12 : 0);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE);
|
||||
int gripType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP);
|
||||
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK);
|
||||
CompoundTag tags = tag.getCompound("Attachments");
|
||||
|
||||
if (stockType == 1) {
|
||||
|
@ -260,15 +262,15 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
if (scopeType > 0 || gripType > 0) {
|
||||
GunsTool.setGunDoubleTag(stack, "CustomVelocity", 15);
|
||||
GunsTool.setGunDoubleTag(stack, "BypassesArmor", 0.4);
|
||||
GunsTool.setGunDoubleTag(stack, "Damage", 21);
|
||||
GunsTool.setGunDoubleTag(stack, "Headshot", 2.5);
|
||||
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(stack, "CustomVelocity", 0);
|
||||
GunsTool.setGunDoubleTag(stack, "BypassesArmor", 0.3);
|
||||
GunsTool.setGunDoubleTag(stack, "Damage", 19);
|
||||
GunsTool.setGunDoubleTag(stack, "Headshot", 2);
|
||||
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) {
|
||||
|
@ -277,8 +279,8 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
default -> 1;
|
||||
};
|
||||
|
||||
GunsTool.setGunBooleanTag(stack, "CanSwitchScope", scopeType == 2);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunBooleanTag(tag, "CanSwitchScope", scopeType == 2);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ 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,16 +59,17 @@ 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.reload_normal"));
|
||||
}
|
||||
|
||||
|
@ -79,12 +81,13 @@ 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);
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.ntw_20.run_fast"));
|
||||
} else {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.ntw_20.run"));
|
||||
|
@ -124,11 +127,13 @@ 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);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
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) {
|
||||
case 1 -> 3;
|
||||
|
@ -139,12 +144,13 @@ public class Ntw20Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static ItemStack getGunInstance() {
|
||||
|
|
|
@ -132,9 +132,10 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (entity instanceof Player player && selected) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
||||
|
||||
if (tag.getBoolean("Seeking")) {
|
||||
|
||||
|
@ -196,8 +197,9 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
NBTTool.getTag(stack).putInt("SeekTime", 0);
|
||||
tag.putInt("SeekTime", 0);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
protected static boolean check(ItemStack stack) {
|
||||
|
@ -251,15 +253,15 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
JavelinMissileEntity missileEntity = new JavelinMissileEntity(player, level,
|
||||
(float) GunsTool.getGunDoubleTag(stack, "Damage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(stack, "ExplosionDamage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0),
|
||||
tag.getInt("GuideType"),
|
||||
new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ")));
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, tag);
|
||||
missileEntity.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
|
||||
}
|
||||
|
||||
|
@ -284,12 +286,12 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 10);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireOnRelease(Player player) {
|
||||
var tag = NBTTool.getTag(player.getMainHandItem());
|
||||
public void fireOnRelease(Player player, final CompoundTag tag) {
|
||||
fire(player);
|
||||
tag.putBoolean("Seeking", false);
|
||||
tag.putInt("SeekTime", 0);
|
||||
|
@ -301,12 +303,9 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player) {
|
||||
var stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && !cap.zoom || GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0) return;
|
||||
if (cap != null && !cap.zoom || GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0) return;
|
||||
|
||||
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.atsuishio.superbwarfare.tools.SoundTool;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -43,6 +44,7 @@ import software.bernie.geckolib.animation.*;
|
|||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -123,10 +125,13 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
if (entity instanceof Player player) {
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,34 +171,35 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player) {
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading")) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0) return;
|
||||
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zooming = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel,
|
||||
(float) GunsTool.getGunDoubleTag(stack, "Damage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(stack, "ExplosionDamage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0));
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0));
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, tag);
|
||||
gunGrenadeEntity.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
|
||||
}
|
||||
|
||||
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(stack, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
|
||||
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
|
||||
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(stack, "Velocity", 0);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), stack);
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
if (perkLevel > 0) {
|
||||
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0) * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(stack, "Damage", 0) * (1.1f + perkLevel * 0.1f));
|
||||
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0) * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage", 0) * (1.1f + perkLevel * 0.1f));
|
||||
velocity *= 1.2f;
|
||||
}
|
||||
|
||||
|
@ -218,6 +224,6 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 2);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1);
|
||||
}
|
||||
}
|
|
@ -48,8 +48,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.NBTTool.saveTag;
|
||||
|
||||
public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
@ -74,7 +72,8 @@ public class RpgItem 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")) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.rpg.reload"));
|
||||
}
|
||||
|
||||
|
@ -129,17 +128,19 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
if (NBTTool.getTag(stack).getBoolean("draw")) {
|
||||
NBTTool.getTag(stack).putBoolean("draw", false);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("draw")) {
|
||||
tag.putBoolean("draw", false);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
NBTTool.getTag(stack).putDouble("empty", 1);
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
tag.putDouble("empty", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
}
|
||||
|
@ -180,39 +181,38 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player) {
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
Level level = player.level();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
|| player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
|| GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0
|
||||
|| GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0
|
||||
) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
RpgRocketEntity rocket = new RpgRocketEntity(player, level,
|
||||
(float) GunsTool.getGunDoubleTag(stack, "Damage", 0));
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0));
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, tag);
|
||||
rocket.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
|
||||
}
|
||||
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(stack, "Velocity", 0);
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0);
|
||||
|
||||
if (PerkHelper.getPerkByType(stack, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()) {
|
||||
if (PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()) {
|
||||
rocket.setNoGravity(true);
|
||||
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
if (perkLevel > 0) {
|
||||
rocket.setExplosionRadius(0.5f);
|
||||
rocket.setDamage((float) GunsTool.getGunDoubleTag(stack, "Damage", 0) * (1.1f + perkLevel * 0.1f));
|
||||
rocket.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage", 0) * (1.1f + perkLevel * 0.1f));
|
||||
velocity *= 1.2f;
|
||||
}
|
||||
}
|
||||
|
@ -237,13 +237,12 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) {
|
||||
tag.putBoolean("empty", true);
|
||||
GunsTool.setGunBooleanTag(stack, "CloseHammer", true);
|
||||
GunsTool.setGunBooleanTag(tag, "CloseHammer", true);
|
||||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 10);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
saveTag(stack, tag);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1);
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import com.atsuishio.superbwarfare.tools.SoundTool;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -90,16 +91,17 @@ 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);
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && NBTTool.getTag(stack).getDouble("prepare_load") > 0) {
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare_load") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.prepare"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 0 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 0 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 1 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 1 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload2"));
|
||||
}
|
||||
|
||||
|
@ -107,7 +109,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.hit"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 3) {
|
||||
if (tag.getInt("reload_stage") == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.finish"));
|
||||
}
|
||||
|
||||
|
@ -119,16 +121,17 @@ 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);
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 1
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 2
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 3
|
||||
&& !(tag.getBoolean("is_empty_reloading"))
|
||||
&& tag.getInt("reload_stage") != 1
|
||||
&& tag.getInt("reload_stage") != 2
|
||||
&& tag.getInt("reload_stage") != 3
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& ClientEventHandler.gunMelee == 0
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.sc.run_fast"));
|
||||
} else {
|
||||
|
@ -177,8 +180,11 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
|
@ -263,14 +269,14 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player) {
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading")) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0) return;
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zooming = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
|
||||
var stackCap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
var hasEnoughEnergy = stackCap != null && stackCap.getEnergyStored() >= 3000;
|
||||
|
@ -279,24 +285,24 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel,
|
||||
(float) GunsTool.getGunDoubleTag(stack, "Damage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(stack, "ExplosionDamage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0));
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0),
|
||||
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0));
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, tag);
|
||||
gunGrenadeEntity.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
|
||||
}
|
||||
|
||||
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(stack, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
|
||||
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
|
||||
gunGrenadeEntity.charged(isChargedFire);
|
||||
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(stack, "Velocity", 0);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), stack);
|
||||
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
|
||||
if (perkLevel > 0) {
|
||||
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0) * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(stack, "Damage", 0) * (1.1f + perkLevel * 0.1f));
|
||||
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0) * 0.5f);
|
||||
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage", 0) * (1.1f + perkLevel * 0.1f));
|
||||
velocity *= 1.2f;
|
||||
}
|
||||
|
||||
|
@ -333,7 +339,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1);
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 6);
|
||||
}
|
||||
}
|
|
@ -114,12 +114,14 @@ public class M60Item extends GunItem implements GeoItem {
|
|||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
|
||||
if (NBTTool.getTag(stack).getBoolean("draw")) {
|
||||
NBTTool.getTag(stack).putBoolean("draw", false);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (tag.getBoolean("draw")) {
|
||||
tag.putBoolean("draw", false);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) <= 5) {
|
||||
GunsTool.setGunBooleanTag(stack, "HideBulletChain", true);
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) <= 5) {
|
||||
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
super.inventoryTick(stack, level, entity, slot, selected);
|
||||
}
|
||||
|
|
|
@ -43,17 +43,17 @@ public class MinigunItem extends GunItem implements GeoItem {
|
|||
|
||||
@Override
|
||||
public boolean isBarVisible(@NotNull ItemStack pStack) {
|
||||
return NBTTool.getDouble(pStack, TAG_HEAT, 0) != 0;
|
||||
return NBTTool.getTag(pStack).getDouble(TAG_HEAT) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarWidth(@NotNull ItemStack pStack) {
|
||||
return Math.round((float) NBTTool.getDouble(pStack, TAG_HEAT, 0) * 13.0F / 51F);
|
||||
return Math.round((float) NBTTool.getTag(pStack).getDouble(TAG_HEAT) * 13.0F / 51F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarColor(@NotNull ItemStack pStack) {
|
||||
double f = 1 - NBTTool.getDouble(pStack, TAG_HEAT, 0) / 55.0F;
|
||||
double f = 1 - NBTTool.getTag(pStack).getDouble(TAG_HEAT) / 55.0F;
|
||||
return Mth.hsvToRgb((float) f / 3.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ 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,9 +59,10 @@ 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);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
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 (grip) {
|
||||
|
@ -139,13 +141,15 @@ 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);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
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) {
|
||||
case 1 -> 15;
|
||||
|
@ -156,12 +160,14 @@ public class AK12Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.15;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,9 +59,10 @@ 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);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
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 (drum) {
|
||||
|
@ -152,10 +153,11 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
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) {
|
||||
case 1 -> 15;
|
||||
|
@ -166,12 +168,13 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.75;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -53,9 +53,10 @@ 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);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
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 (drum) {
|
||||
|
@ -114,8 +115,6 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.edit"));
|
||||
|
@ -136,10 +135,11 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
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) {
|
||||
case 1 -> 15;
|
||||
|
@ -150,12 +150,13 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,9 +54,10 @@ public class M4Item 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);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
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 (drum) {
|
||||
|
@ -152,10 +153,11 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
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) {
|
||||
case 1 -> 15;
|
||||
|
@ -166,13 +168,14 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
GunsTool.setGunBooleanTag(stack, "CanSwitchScope", scopeType == 2);
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
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
|
||||
|
|
|
@ -50,24 +50,25 @@ 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && NBTTool.getTag(stack).getDouble("prepare") > 0) {
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.prepare"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 0 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 0 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 1 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 1 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload2"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 3) {
|
||||
if (tag.getInt("reload_stage") == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.finish"));
|
||||
}
|
||||
|
||||
|
@ -79,15 +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);
|
||||
|
||||
if (transformType != null && transformType.firstPerson()) {
|
||||
|
||||
|
||||
if (player.isSprinting()
|
||||
&& player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.marlin.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -28,6 +28,7 @@ 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,11 +54,12 @@ 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);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
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 (tag.getBoolean("is_empty_reloading")) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m14.reload_empty_drum_grip"));
|
||||
|
@ -73,7 +75,7 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m14.reload_normal_drum_grip"));
|
||||
|
@ -136,13 +138,13 @@ 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);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
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) {
|
||||
case 1 -> 10;
|
||||
|
@ -153,12 +155,13 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.25;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@ 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 Qbz95Item extends GunItem implements GeoItem {
|
||||
|
@ -54,11 +55,12 @@ 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);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
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 (tag.getBoolean("is_empty_reloading")) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.reload_empty_drum_grip"));
|
||||
|
@ -74,7 +76,7 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (drum) {
|
||||
if (grip) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.reload_normal_drum_grip"));
|
||||
|
@ -115,8 +117,6 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
boolean grip = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.edit"));
|
||||
|
@ -139,16 +139,17 @@ public class Qbz95Item 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);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
|
||||
final var rootTag = NBTTool.getTag(stack);
|
||||
int scopeType = GunsTool.getAttachmentType(rootTag, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(rootTag, GunsTool.AttachmentType.MAGAZINE);
|
||||
;
|
||||
|
||||
if (magType == 1) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments");
|
||||
CompoundTag tag = rootTag.getCompound("Attachments");
|
||||
tag.putInt("Magazine", 2);
|
||||
}
|
||||
|
||||
|
@ -157,12 +158,13 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 2.15;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(rootTag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
rootTag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(rootTag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(rootTag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, rootTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -99,11 +99,13 @@ public class SksItem extends GunItem implements GeoItem {
|
|||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
|
||||
if (NBTTool.getTag(stack).getBoolean("draw")) {
|
||||
NBTTool.getTag(stack).putBoolean("draw", false);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("draw", false);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunBooleanTag(stack, "HoldOpen", true);
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunBooleanTag(tag, "HoldOpen", true);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
super.inventoryTick(stack, level, entity, slot, selected);
|
||||
}
|
||||
|
|
|
@ -54,28 +54,29 @@ 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;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && NBTTool.getTag(stack).getDouble("prepare_load") > 0) {
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare_load") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.preparealt"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && NBTTool.getTag(stack).getDouble("prepare") > 0) {
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.prepare"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 0 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 0 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 1 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 1 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload2"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 3) {
|
||||
if (tag.getInt("reload_stage") == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.finish"));
|
||||
}
|
||||
|
||||
|
@ -87,12 +88,13 @@ 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;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (player.isSprinting()
|
||||
&& player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.m870.run_fast"));
|
||||
} else {
|
||||
|
|
|
@ -51,10 +51,11 @@ 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;
|
||||
boolean drum = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2;
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
if (drum) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vec.reload_empty_drum"));
|
||||
} else {
|
||||
|
@ -62,7 +63,7 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
}
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
if (drum) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vec.reload_normal_drum"));
|
||||
} else {
|
||||
|
@ -118,8 +119,9 @@ 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);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
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) {
|
||||
case 1 -> 20;
|
||||
|
@ -128,18 +130,19 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
};
|
||||
|
||||
if (scopeType == 3) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments");
|
||||
tag.putInt("Scope", 0);
|
||||
CompoundTag attachments = tag.getCompound("Attachments");
|
||||
attachments.putInt("Scope", 0);
|
||||
}
|
||||
|
||||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 0.75;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomMagazine", customMag);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static ItemStack getGunInstance() {
|
||||
|
|
|
@ -50,28 +50,29 @@ public class K98Item 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && NBTTool.getTag(stack).getDouble("prepare") > 0) {
|
||||
if (tag.getInt("reload_stage") == 1 && tag.getDouble("prepare") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.prepare"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 0 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 0 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getDouble("load_index") == 1 && NBTTool.getTag(stack).getInt("reload_stage") == 2) {
|
||||
if (tag.getDouble("load_index") == 1 && tag.getInt("reload_stage") == 2) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload2"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 3) {
|
||||
if (tag.getInt("reload_stage") == 3) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.finish"));
|
||||
}
|
||||
|
||||
|
@ -83,16 +84,17 @@ public class K98Item 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);
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 1
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 2
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 3
|
||||
&& !(tag.getBoolean("is_empty_reloading"))
|
||||
&& tag.getInt("reload_stage") != 1
|
||||
&& tag.getInt("reload_stage") != 2
|
||||
&& tag.getInt("reload_stage") != 3
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.k98.run_fast"));
|
||||
} else {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.k98.run"));
|
||||
|
|
|
@ -50,16 +50,17 @@ 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m98b.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m98b.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
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);
|
||||
|
||||
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) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading")) && 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 {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.m98b.run"));
|
||||
|
|
|
@ -50,16 +50,17 @@ 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare"));
|
||||
}
|
||||
|
||||
|
@ -83,6 +84,7 @@ 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);
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
|
@ -91,8 +93,8 @@ public class MosinNagantItem extends GunItem implements GeoItem {
|
|||
&& NBTTool.getTag(stack).getInt("reload_stage") != 2
|
||||
&& NBTTool.getTag(stack).getInt("reload_stage") != 3
|
||||
&& ClientEventHandler.drawTime < 0.01
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mosin.run_fast"));
|
||||
} else {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mosin.run"));
|
||||
|
|
|
@ -87,20 +87,21 @@ public class SentinelItem 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);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTick") > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.shift"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_empty_reloading")) {
|
||||
if (tag.getBoolean("is_empty_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.reload_empty"));
|
||||
}
|
||||
|
||||
if (NBTTool.getTag(stack).getBoolean("is_normal_reloading")) {
|
||||
if (tag.getBoolean("is_normal_reloading")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.reload_normal"));
|
||||
}
|
||||
|
||||
if (GunsTool.getGunBooleanTag(stack, "Charging")) {
|
||||
if (GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.charge"));
|
||||
}
|
||||
|
||||
|
@ -112,12 +113,13 @@ public class SentinelItem 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);
|
||||
|
||||
if (player.isSprinting() && player.onGround()
|
||||
&& player.getPersistentData().getDouble("noRun") == 0
|
||||
&& !(NBTTool.getTag(stack).getBoolean("is_normal_reloading") || NBTTool.getTag(stack).getBoolean("is_empty_reloading"))
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging") && ClientEventHandler.drawTime < 0.01) {
|
||||
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
|
||||
&& !(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
|
||||
&& !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"));
|
||||
} else {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.sentinel.run"));
|
||||
|
@ -144,15 +146,17 @@ public class SentinelItem extends GunItem implements GeoItem {
|
|||
@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);
|
||||
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
cap.extractEnergy(1, false);
|
||||
GunsTool.setGunDoubleTag(stack, "ChargedDamage", 0.2857142857142857
|
||||
* GunsTool.getGunDoubleTag(stack, "Damage", 0));
|
||||
GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0.2857142857142857
|
||||
* GunsTool.getGunDoubleTag(tag, "Damage", 0));
|
||||
} else {
|
||||
GunsTool.setGunDoubleTag(stack, "ChargedDamage", 0);
|
||||
GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,6 +28,7 @@ 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 {
|
||||
|
@ -113,11 +114,13 @@ 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);
|
||||
|
||||
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
|
||||
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
|
||||
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) {
|
||||
case 1 -> 10;
|
||||
|
@ -128,12 +131,13 @@ public class SvdItem extends GunItem implements GeoItem {
|
|||
double customZoom = switch (scopeType) {
|
||||
case 0, 1 -> 0;
|
||||
case 2 -> 3.75;
|
||||
default -> GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
};
|
||||
|
||||
NBTTool.getTag(stack).putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(stack, "CustomMagazine", customMag);
|
||||
tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
|
||||
GunsTool.setGunIntTag(tag, "CustomMagazine", customMag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,9 +17,11 @@ import com.atsuishio.superbwarfare.perk.Perk;
|
|||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
@ -116,12 +118,15 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
@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);
|
||||
if (entity instanceof Player player) {
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "ArrowEmpty") > 0) {
|
||||
GunsTool.setGunIntTag(stack, "ArrowEmpty", GunsTool.getGunIntTag(stack, "ArrowEmpty") - 1);
|
||||
if (GunsTool.getGunIntTag(tag, "ArrowEmpty") > 0) {
|
||||
GunsTool.setGunIntTag(tag, "ArrowEmpty", GunsTool.getGunIntTag(tag, "ArrowEmpty") - 1);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,12 +171,11 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
|
||||
|
||||
@Override
|
||||
public void fireOnRelease(Player player) {
|
||||
public void fireOnRelease(Player player, final CompoundTag tag) {
|
||||
if (player.level().isClientSide()) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS);
|
||||
|
@ -180,16 +184,16 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
if (GunsTool.getGunDoubleTag(stack, "Power") >= 6) {
|
||||
if (GunsTool.getGunDoubleTag(tag, "Power") >= 6) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.zoom) {
|
||||
spawnBullet(player);
|
||||
spawnBullet(player, tag);
|
||||
|
||||
SoundTool.playLocalSound(player, ModSounds.BOCEK_ZOOM_FIRE_1P.get(), 10, 1);
|
||||
player.playSound(ModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1);
|
||||
} else {
|
||||
for (int i = 0; i < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : 10); i++) {
|
||||
spawnBullet(player);
|
||||
spawnBullet(player, tag);
|
||||
}
|
||||
|
||||
SoundTool.playLocalSound(player, ModSounds.BOCEK_SHATTER_CAP_FIRE_1P.get(), 10, 1);
|
||||
|
@ -205,8 +209,9 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 7);
|
||||
GunsTool.setGunIntTag(stack, "ArrowEmpty", 7);
|
||||
GunsTool.setGunDoubleTag(stack, "Power", 0);
|
||||
GunsTool.setGunIntTag(tag, "ArrowEmpty", 7);
|
||||
GunsTool.setGunDoubleTag(tag, "Power", 0);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player) && !player.isCreative()) {
|
||||
player.getInventory().clearOrCountMatchingItems(p -> Items.ARROW == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
|
||||
|
@ -215,7 +220,7 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player) {
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.bowPullHold = true;
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.atsuishio.superbwarfare.tools.NBTTool;
|
|||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
|
@ -153,12 +154,14 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
@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);
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(tag, "MaxAmmo", getAmmoCount(player));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.REGENERATION.get(), stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.REGENERATION.get(), tag);
|
||||
|
||||
var stackStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
if (stackStorage != null) {
|
||||
|
@ -232,16 +235,16 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fireOnPress(Player player) {
|
||||
public void fireOnPress(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (GunsTool.getGunBooleanTag(stack, "Reloading")) return;
|
||||
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
|
||||
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), stack);
|
||||
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(stack, "Ammo", 0) <= 0
|
||||
|| GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0
|
||||
|| !hasEnoughEnergy
|
||||
) return;
|
||||
|
||||
|
@ -250,10 +253,10 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
double spread = GunsTool.getGunDoubleTag(tag, "Spread");
|
||||
|
||||
int volt = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), stack);
|
||||
int wireLength = PerkHelper.getItemPerkLevel(ModPerks.LONGER_WIRE.get(), stack);
|
||||
int volt = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), tag);
|
||||
int wireLength = PerkHelper.getItemPerkLevel(ModPerks.LONGER_WIRE.get(), tag);
|
||||
|
||||
SoundTool.playLocalSound(serverPlayer, ModSounds.TASER_FIRE_1P.get(), 1, 1);
|
||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.TASER_FIRE_3P.get(), SoundSource.PLAYERS, 1, 1);
|
||||
|
@ -261,18 +264,18 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
var level = serverPlayer.level();
|
||||
|
||||
TaserBulletEntity taserBulletProjectile = new TaserBulletEntity(player, level,
|
||||
(float) GunsTool.getGunDoubleTag(stack, "Damage", 0), volt, wireLength);
|
||||
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0), 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(stack, "Velocity", 0),
|
||||
taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0),
|
||||
(float) (zoom ? 0.1 : spread));
|
||||
level.addFreshEntity(taserBulletProjectile);
|
||||
|
||||
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1);
|
||||
energyStorage.extractEnergy(400 + 100 * perkLevel, false);
|
||||
NBTTool.getTag(stack).putBoolean("shoot", true);
|
||||
tag.putBoolean("shoot", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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.util.Mth;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
|
@ -164,7 +165,8 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
ItemStack itemstack = this.container.getItem(i);
|
||||
|
||||
if (itemstack.getItem() instanceof PerkItem<?> perkItem) {
|
||||
if (!copy.isEmpty() && PerkHelper.getItemPerkLevel(perkItem.getPerk(), copy) > 0) {
|
||||
final var tag = NBTTool.getTag(copy);
|
||||
if (!copy.isEmpty() && PerkHelper.getItemPerkLevel(perkItem.getPerk(), tag) > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -206,13 +208,15 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
return;
|
||||
}
|
||||
|
||||
double oldPoint = GunsTool.getGunDoubleTag(stack, "UpgradePoint", 0);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
double oldPoint = GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0);
|
||||
int point = (int) oldPoint;
|
||||
int newPoint = this.upgradePoint.get();
|
||||
int delta = newPoint - point;
|
||||
|
||||
if (delta != 0) {
|
||||
GunsTool.setGunDoubleTag(stack, "UpgradePoint", oldPoint + delta);
|
||||
GunsTool.setGunDoubleTag(tag, "UpgradePoint", oldPoint + delta);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,28 +237,30 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
}
|
||||
|
||||
ItemStack result = gun.copy();
|
||||
final var tag = NBTTool.getTag(result);
|
||||
|
||||
if (!ammo.isEmpty() && ammo.getItem() instanceof PerkItem perkItem) {
|
||||
if (!ammo.isEmpty() && ammo.getItem() instanceof PerkItem<?> perkItem) {
|
||||
if (gunItem.canApplyPerk(perkItem.getPerk())) {
|
||||
PerkHelper.setPerk(result, perkItem.getPerk(), this.ammoPerkLevel.get());
|
||||
PerkHelper.setPerk(tag, perkItem.getPerk(), this.ammoPerkLevel.get());
|
||||
this.container.setItem(AMMO_PERK_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
if (!func.isEmpty() && func.getItem() instanceof PerkItem perkItem) {
|
||||
if (!func.isEmpty() && func.getItem() instanceof PerkItem<?> perkItem) {
|
||||
if (gunItem.canApplyPerk(perkItem.getPerk())) {
|
||||
PerkHelper.setPerk(result, perkItem.getPerk(), this.funcPerkLevel.get());
|
||||
PerkHelper.setPerk(tag, perkItem.getPerk(), this.funcPerkLevel.get());
|
||||
this.container.setItem(FUNC_PERK_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
if (!damage.isEmpty() && damage.getItem() instanceof PerkItem perkItem) {
|
||||
if (!damage.isEmpty() && damage.getItem() instanceof PerkItem<?> perkItem) {
|
||||
if (gunItem.canApplyPerk(perkItem.getPerk())) {
|
||||
PerkHelper.setPerk(result, perkItem.getPerk(), this.damagePerkLevel.get());
|
||||
PerkHelper.setPerk(tag, perkItem.getPerk(), this.damagePerkLevel.get());
|
||||
this.container.setItem(DAMAGE_PERK_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTool.saveTag(result, tag);
|
||||
handleUpgradePoint(result);
|
||||
|
||||
this.ammoPerkLevel.set(0);
|
||||
|
@ -278,25 +284,28 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
return;
|
||||
}
|
||||
|
||||
if (perk.getItem() instanceof PerkItem perkItem) {
|
||||
if (perk.getItem() instanceof PerkItem<?> perkItem) {
|
||||
switch (perkItem.getPerk().type) {
|
||||
case AMMO -> this.ammoPerkLevel.set(0);
|
||||
case FUNCTIONAL -> this.funcPerkLevel.set(0);
|
||||
case DAMAGE -> this.damagePerkLevel.set(0);
|
||||
}
|
||||
|
||||
int level = PerkHelper.getItemPerkLevel(perkItem.getPerk(), gun);
|
||||
final var tag = NBTTool.getTag(gun);
|
||||
int level = PerkHelper.getItemPerkLevel(perkItem.getPerk(), tag);
|
||||
|
||||
if (level <= 0) {
|
||||
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(gun, "UpgradePoint", 0));
|
||||
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack output = gun.copy();
|
||||
PerkHelper.removePerkByType(output, perkItem.getPerk().type);
|
||||
GunsTool.setGunDoubleTag(output, "UpgradePoint", Math.min(MAX_UPGRADE_POINT, level - 1 + GunsTool.getGunDoubleTag(output, "UpgradePoint", 0)));
|
||||
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(output, "UpgradePoint", 0));
|
||||
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", 0)));
|
||||
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(outputTag, "UpgradePoint", 0));
|
||||
|
||||
NBTTool.saveTag(output, outputTag);
|
||||
this.container.setItem(INPUT_SLOT, output);
|
||||
this.container.setChanged();
|
||||
}
|
||||
|
@ -328,27 +337,27 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
if (!(stack.getItem() instanceof GunItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int point = (int) GunsTool.getGunDoubleTag(stack, "UpgradePoint", 0);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int point = (int) GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0);
|
||||
this.upgradePoint.set(Mth.clamp(point, 0, MAX_UPGRADE_POINT));
|
||||
|
||||
var ammoPerk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (ammoPerk != null) {
|
||||
this.ammoPerkLevel.set(PerkHelper.getItemPerkLevel(ammoPerk, stack));
|
||||
this.ammoPerkLevel.set(PerkHelper.getItemPerkLevel(ammoPerk, tag));
|
||||
var ammoPerkItem = PerkHelper.getPerkItem(ammoPerk);
|
||||
ammoPerkItem.ifPresent(registryObject -> this.container.setItem(AMMO_PERK_SLOT, registryObject.get().getDefaultInstance()));
|
||||
}
|
||||
|
||||
var funcPerk = PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL);
|
||||
var funcPerk = PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL);
|
||||
if (funcPerk != null) {
|
||||
this.funcPerkLevel.set(PerkHelper.getItemPerkLevel(funcPerk, stack));
|
||||
this.funcPerkLevel.set(PerkHelper.getItemPerkLevel(funcPerk, tag));
|
||||
var funcPerkItem = PerkHelper.getPerkItem(funcPerk);
|
||||
funcPerkItem.ifPresent(registryObject -> this.container.setItem(FUNC_PERK_SLOT, registryObject.get().getDefaultInstance()));
|
||||
}
|
||||
|
||||
var damagePerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var damagePerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (damagePerk != null) {
|
||||
this.damagePerkLevel.set(PerkHelper.getItemPerkLevel(damagePerk, stack));
|
||||
this.damagePerkLevel.set(PerkHelper.getItemPerkLevel(damagePerk, tag));
|
||||
var damagePerkItem = PerkHelper.getPerkItem(damagePerk);
|
||||
damagePerkItem.ifPresent(registryObject -> this.container.setItem(DAMAGE_PERK_SLOT, registryObject.get().getDefaultInstance()));
|
||||
}
|
||||
|
@ -360,28 +369,28 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
|||
/**
|
||||
* 拿走输入槽中的枪械时,如果Perk槽中存在放入枪械时生成的Perk物品,则将其移除,如果是没有的Perk则无视
|
||||
*
|
||||
* @param pStack 输入的枪械
|
||||
* @param stack 输入的枪械
|
||||
*/
|
||||
private void onTakeGun(ItemStack pStack) {
|
||||
if (!(pStack.getItem() instanceof GunItem)) {
|
||||
private void onTakeGun(ItemStack stack) {
|
||||
if (!(stack.getItem() instanceof GunItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var ammoPerk = PerkHelper.getPerkByType(pStack, Perk.Type.AMMO);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (ammoPerk != null) {
|
||||
if (this.container.getItem(AMMO_PERK_SLOT).getItem() instanceof PerkItem<?> perkItem && perkItem.getPerk() == ammoPerk) {
|
||||
this.container.setItem(AMMO_PERK_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
var funcPerk = PerkHelper.getPerkByType(pStack, Perk.Type.FUNCTIONAL);
|
||||
var funcPerk = PerkHelper.getPerkByType(tag, Perk.Type.FUNCTIONAL);
|
||||
if (funcPerk != null) {
|
||||
if (this.container.getItem(FUNC_PERK_SLOT).getItem() instanceof PerkItem<?> perkItem && perkItem.getPerk() == funcPerk) {
|
||||
this.container.setItem(FUNC_PERK_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
var damagePerk = PerkHelper.getPerkByType(pStack, Perk.Type.DAMAGE);
|
||||
var damagePerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (damagePerk != null) {
|
||||
if (this.container.getItem(DAMAGE_PERK_SLOT).getItem() instanceof PerkItem<?> perkItem && perkItem.getPerk() == damagePerk) {
|
||||
this.container.setItem(DAMAGE_PERK_SLOT, ItemStack.EMPTY);
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.network.message.receive;
|
|||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
|
@ -19,7 +20,7 @@ public record ShootClientMessage(double time) implements CustomPacketPayload {
|
|||
);
|
||||
|
||||
public static void handler(ShootClientMessage message, final IPayloadContext context) {
|
||||
ClientEventHandler.handleClientShoot();
|
||||
ClientEventHandler.handleClientShoot(new CompoundTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.init.ModSounds;
|
|||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
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,37 +34,39 @@ public record AdjustZoomFovMessage(double scroll) implements CustomPacketPayload
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModItems.MINIGUN.get())) {
|
||||
double minRpm = 300;
|
||||
double maxRpm = 2400;
|
||||
|
||||
GunsTool.setGunIntTag(stack, "RPM", (int) Mth.clamp(GunsTool.getGunIntTag(stack, "RPM", 0) + 50 * message.scroll, minRpm, maxRpm));
|
||||
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1150) {
|
||||
GunsTool.setGunIntTag(stack, "RPM", 1145);
|
||||
GunsTool.setGunIntTag(tag, "RPM", (int) Mth.clamp(GunsTool.getGunIntTag(tag, "RPM", 0) + 50 * message.scroll, minRpm, maxRpm));
|
||||
if (GunsTool.getGunIntTag(tag, "RPM", 0) == 1150) {
|
||||
GunsTool.setGunIntTag(tag, "RPM", 1145);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1195) {
|
||||
GunsTool.setGunIntTag(stack, "RPM", 1200);
|
||||
if (GunsTool.getGunIntTag(tag, "RPM", 0) == 1195) {
|
||||
GunsTool.setGunIntTag(tag, "RPM", 1200);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1095) {
|
||||
GunsTool.setGunIntTag(stack, "RPM", 1100);
|
||||
if (GunsTool.getGunIntTag(tag, "RPM", 0) == 1095) {
|
||||
GunsTool.setGunIntTag(tag, "RPM", 1100);
|
||||
}
|
||||
player.displayClientMessage(Component.literal("RPM: " + FormatTool.format0D(GunsTool.getGunIntTag(stack, "RPM", 0))), true);
|
||||
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0);
|
||||
player.displayClientMessage(Component.literal("RPM: " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM", 0))), true);
|
||||
int rpm = GunsTool.getGunIntTag(tag, "RPM", 0);
|
||||
if (rpm > minRpm && rpm < maxRpm) {
|
||||
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
}
|
||||
} else {
|
||||
double minZoom = GunsTool.getGunDoubleTag(stack, "MinZoom", 0) - 1.25;
|
||||
double maxZoom = GunsTool.getGunDoubleTag(stack, "MaxZoom", 0) - 1.25;
|
||||
double customZoom = GunsTool.getGunDoubleTag(stack, "CustomZoom", 0);
|
||||
GunsTool.setGunDoubleTag(stack, "CustomZoom", Mth.clamp(customZoom + 0.5 * message.scroll, minZoom, maxZoom));
|
||||
if (GunsTool.getGunDoubleTag(stack, "CustomZoom", 0) > minZoom &&
|
||||
GunsTool.getGunDoubleTag(stack, "CustomZoom", 0) < maxZoom) {
|
||||
double minZoom = GunsTool.getGunDoubleTag(tag, "MinZoom", 0) - 1.25;
|
||||
double maxZoom = GunsTool.getGunDoubleTag(tag, "MaxZoom", 0) - 1.25;
|
||||
double customZoom = GunsTool.getGunDoubleTag(tag, "CustomZoom", 0);
|
||||
GunsTool.setGunDoubleTag(tag, "CustomZoom", Mth.clamp(customZoom + 0.5 * message.scroll, minZoom, maxZoom));
|
||||
if (GunsTool.getGunDoubleTag(tag, "CustomZoom", 0) > minZoom &&
|
||||
GunsTool.getGunDoubleTag(tag, "CustomZoom", 0) < maxZoom) {
|
||||
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
}
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.tools.GunsTool;
|
|||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
|
@ -44,13 +45,13 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
if (player.isSpectator()) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
handleGunBolt(player, stack);
|
||||
handleGunBolt(player, stack, tag);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (type == 0) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (tag.getDouble("prepare") == 0 && GunsTool.getGunBooleanTag(stack, "Reloading") && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
if (tag.getDouble("prepare") == 0 && GunsTool.getGunBooleanTag(tag, "Reloading") && GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) {
|
||||
tag.putDouble("force_stop", 1);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
if (cap != null) cap.syncPlayerVariables(player);
|
||||
return;
|
||||
}
|
||||
specialFireWeapon.fireOnPress(player);
|
||||
specialFireWeapon.fireOnPress(player, tag);
|
||||
|
||||
if (cap != null) {
|
||||
cap.holdFire = true;
|
||||
|
@ -79,52 +80,55 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
// 松开开火
|
||||
if (stack.getItem() instanceof SpecialFireWeapon specialFireWeapon) {
|
||||
specialFireWeapon.fireOnRelease(player);
|
||||
specialFireWeapon.fireOnRelease(player, tag);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
private static void handleGunBolt(Player player, ItemStack stack) {
|
||||
private static void handleGunBolt(Player player, ItemStack stack, final CompoundTag tag) {
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0
|
||||
&& GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
|
||||
&& GunsTool.getGunIntTag(stack, "BoltActionTick") == 0
|
||||
&& !(NBTTool.getBoolean(stack, "is_normal_reloading", false)
|
||||
|| NBTTool.getBoolean(stack, "is_empty_reloading", false))
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging")) {
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)) {
|
||||
GunsTool.setGunIntTag(stack, "BoltActionTick", GunsTool.getGunIntTag(stack, "BoltActionTime", 0) + 1);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo", 0) > (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")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)) {
|
||||
GunsTool.setGunIntTag(tag, "BoltActionTick", GunsTool.getGunIntTag(tag, "BoltActionTime", 0) + 1);
|
||||
GunEventHandler.playGunBoltSounds(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static double perkDamage(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
return ammoPerk.damageRate;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static double perkSpeed(ItemStack stack) {
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
public static double perkSpeed(final CompoundTag tag) {
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
return ammoPerk.speedRate;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static void spawnBullet(Player player) {
|
||||
public static void spawnBullet(Player player, final CompoundTag tag) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (player.level().isClientSide()) return;
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
float headshot = (float) GunsTool.getGunDoubleTag(stack, "Headshot", 0);
|
||||
float velocity = 2 * (float) GunsTool.getGunDoubleTag(stack, "Power", 6) * (float) perkSpeed(stack);
|
||||
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(stack, "BypassesArmor", 0);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot", 0);
|
||||
float velocity = 2 * (float) GunsTool.getGunDoubleTag(tag, "Power", 6) * (float) perkSpeed(tag);
|
||||
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0);
|
||||
double damage;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -133,13 +137,13 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
float spread;
|
||||
if (zoom) {
|
||||
spread = 0.01f;
|
||||
damage = 0.08333333 * GunsTool.getGunDoubleTag(stack, "Damage", 0) *
|
||||
GunsTool.getGunDoubleTag(stack, "Power", 6) * perkDamage(stack);
|
||||
damage = 0.08333333 * GunsTool.getGunDoubleTag(tag, "Damage", 0) *
|
||||
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(stack, "Damage", 0) *
|
||||
GunsTool.getGunDoubleTag(stack, "Power", 6) * perkDamage(stack);
|
||||
GunsTool.getGunDoubleTag(tag, "Damage", 0) *
|
||||
GunsTool.getGunDoubleTag(tag, "Power", 6) * perkDamage(stack);
|
||||
}
|
||||
|
||||
ProjectileEntity projectile = new ProjectileEntity(player.level())
|
||||
|
@ -148,7 +152,7 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
.zoom(zoom);
|
||||
|
||||
if (perk instanceof AmmoPerk ammoPerk) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
|
||||
bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
|
||||
projectile.setRGB(ammoPerk.rgb);
|
||||
|
@ -180,24 +184,24 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
projectile.bypassArmorRate(bypassArmorRate);
|
||||
|
||||
if (perk == ModPerks.SILVER_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.undeadMultiple(1.0f + 0.5f * level);
|
||||
} else if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
projectile.beast();
|
||||
} else if (perk == ModPerks.JHP_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.jhpBullet(level);
|
||||
} else if (perk == ModPerks.HE_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.heBullet(level);
|
||||
} else if (perk == ModPerks.INCENDIARY_BULLET.get()) {
|
||||
int level = PerkHelper.getItemPerkLevel(perk, stack);
|
||||
int level = PerkHelper.getItemPerkLevel(perk, tag);
|
||||
projectile.fireBullet(level, !zoom);
|
||||
}
|
||||
|
||||
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
|
||||
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
|
||||
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, stack);
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(dmgPerk, tag);
|
||||
projectile.monsterMultiple(0.1f + 0.1f * perkLevel);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ 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.nbt.CompoundTag;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
|
@ -35,7 +34,7 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
public static void changeFireMode(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.getItem() instanceof GunItem gunItem) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
int fireMode = tag.getInt("FireMode");
|
||||
|
||||
int mode = gunItem.getAvailableFireModes();
|
||||
|
@ -43,39 +42,45 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
if (fireMode == 0) {
|
||||
if ((mode & 2) != 0) {
|
||||
GunsTool.setGunIntTag(stack, "FireMode", 1);
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 1);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
if ((mode & 4) != 0) {
|
||||
GunsTool.setGunIntTag(stack, "FireMode", 2);
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 2);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fireMode == 1) {
|
||||
if ((mode & 4) != 0) {
|
||||
GunsTool.setGunIntTag(stack, "FireMode", 2);
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 2);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
if ((mode & 1) != 0) {
|
||||
GunsTool.setGunIntTag(stack, "FireMode", 0);
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 0);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fireMode == 2) {
|
||||
if ((mode & 1) != 0) {
|
||||
GunsTool.setGunIntTag(stack, "FireMode", 0);
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 0);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
if ((mode & 2) != 0) {
|
||||
GunsTool.setGunIntTag(stack, "FireMode", 1);
|
||||
GunsTool.setGunIntTag(tag, "FireMode", 1);
|
||||
playChangeModeSound(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -83,14 +88,14 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
if (stack.getItem() == ModItems.SENTINEL.get()
|
||||
&& !player.isSpectator()
|
||||
&& !(player.getCooldowns().isOnCooldown(stack.getItem()))
|
||||
&& GunsTool.getGunIntTag(stack, "ReloadTime") == 0
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging")) {
|
||||
&& GunsTool.getGunIntTag(tag, "ReloadTime") == 0
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")) {
|
||||
|
||||
for (var cell : player.getInventory().items) {
|
||||
if (cell.is(ModItems.CELL.get())) {
|
||||
var cap = cell.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
if (cap != null && cap.getEnergyStored() > 0) {
|
||||
GunsTool.setGunBooleanTag(stack, "StartCharge", true);
|
||||
GunsTool.setGunBooleanTag(tag, "StartCharge", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,13 +109,15 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
|
|||
}
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.TRACHELIUM.get() && !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)) {
|
||||
if (stack.getItem() == ModItems.TRACHELIUM.get() && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)) {
|
||||
tag.putBoolean("DA", !tag.getBoolean("DA"));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
if (!tag.getBoolean("canImmediatelyShoot")) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true);
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ public record InteractMessage(int msgType) implements CustomPacketPayload {
|
|||
Level level = player.level();
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
double blockRange = player.blockInteractionRange();
|
||||
double entityRange = player.blockInteractionRange();
|
||||
|
@ -59,11 +60,10 @@ public record InteractMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
player.interactOn(lookingEntity, InteractionHand.MAIN_HAND);
|
||||
} else if (stack.is(ModItems.MONITOR.get())
|
||||
&& NBTTool.getBoolean(stack, "Using", false)
|
||||
&& NBTTool.getBoolean(stack, "Linked", false)
|
||||
&& tag.getBoolean("Using")
|
||||
&& tag.getBoolean("Linked")
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
DroneEntity drone = EntityFindUtil.findDrone(player.level(), tag.getString("LinkedDrone"));
|
||||
|
||||
if (drone != null) {
|
||||
|
|
|
@ -38,16 +38,19 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
var data = tag.getCompound("GunData");
|
||||
|
||||
if (!player.isSpectator()
|
||||
&& stack.getItem() instanceof GunItem gunItem
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Charging")
|
||||
&& GunsTool.getGunIntTag(stack, "ReloadTime") == 0
|
||||
&& GunsTool.getGunIntTag(stack, "BoltActionTick") == 0
|
||||
&& !GunsTool.getGunBooleanTag(stack, "Reloading")
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Charging")
|
||||
&& GunsTool.getGunIntTag(tag, "ReloadTime") == 0
|
||||
&& GunsTool.getGunIntTag(tag, "BoltActionTick") == 0
|
||||
&& !GunsTool.getGunBooleanTag(tag, "Reloading")
|
||||
) {
|
||||
boolean canSingleReload = gunItem.isIterativeReload(stack);
|
||||
boolean canReload = gunItem.isMagazineReload(stack) && !gunItem.isClipReload(stack);
|
||||
boolean clipLoad = GunsTool.getGunIntTag(stack, "Ammo", 0) == 0 && gunItem.isClipReload(stack);
|
||||
boolean clipLoad = GunsTool.getGunIntTag(tag, "Ammo", 0) == 0 && gunItem.isClipReload(stack);
|
||||
|
||||
// 检查备弹
|
||||
boolean hasCreativeAmmoBox = player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||
|
@ -63,38 +66,41 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
return;
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && cap.heavyAmmo == 0) {
|
||||
return;
|
||||
} else if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
} else if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
|
||||
return;
|
||||
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (canReload || clipLoad) {
|
||||
int magazine = GunsTool.getGunIntTag(stack, "Magazine", 0);
|
||||
int magazine = GunsTool.getGunIntTag(tag, "Magazine", 0);
|
||||
int ammo = GunsTool.getGunIntTag(tag, "Ammo", 0);
|
||||
int customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine", 0);
|
||||
|
||||
if (gunItem.isOpenBolt(stack)) {
|
||||
if (gunItem.hasBulletInBarrel(stack)) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) < magazine + GunsTool.getGunIntTag(stack, "CustomMagazine", 0) + 1) {
|
||||
GunsTool.setGunBooleanTag(stack, "StartReload", true);
|
||||
}
|
||||
} else {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) < magazine + GunsTool.getGunIntTag(stack, "CustomMagazine", 0)) {
|
||||
GunsTool.setGunBooleanTag(stack, "StartReload", true);
|
||||
if (ammo < magazine + customMagazine + 1) {
|
||||
data.putBoolean("StartReload", true);
|
||||
}
|
||||
} else if (ammo < magazine + customMagazine) {
|
||||
data.putBoolean("StartReload", true);
|
||||
}
|
||||
} else if (GunsTool.getGunIntTag(stack, "Ammo", 0) < magazine + GunsTool.getGunIntTag(stack, "CustomMagazine", 0)) {
|
||||
GunsTool.setGunBooleanTag(stack, "StartReload", true);
|
||||
} else if (ammo < magazine + customMagazine) {
|
||||
data.putBoolean("StartReload", true);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
return;
|
||||
}
|
||||
|
||||
if (canSingleReload
|
||||
&& GunsTool.getGunIntTag(stack, "Ammo", 0)
|
||||
< GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0)) {
|
||||
NBTTool.setBoolean(stack, "start_single_reload", true);
|
||||
&& GunsTool.getGunIntTag(tag, "Ammo", 0)
|
||||
< GunsTool.getGunIntTag(tag, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)) {
|
||||
|
||||
data.putBoolean("start_single_reload", true);
|
||||
}
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,30 +39,31 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
|
||||
public static void pressAction(Player player, double spared) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
int projectileAmount = GunsTool.getGunIntTag(stack, "ProjectileAmount", 1);
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount", 1);
|
||||
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) {
|
||||
// 空仓挂机
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
GunsTool.setGunBooleanTag(stack, "HoldOpen", true);
|
||||
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) {
|
||||
GunsTool.setGunBooleanTag(tag, "HoldOpen", true);
|
||||
}
|
||||
|
||||
if (stack.is(ModTags.Items.REVOLVER)) {
|
||||
NBTTool.getTag(stack).putBoolean("canImmediatelyShoot", false);
|
||||
tag.putBoolean("canImmediatelyShoot", false);
|
||||
}
|
||||
|
||||
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true);
|
||||
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
|
||||
}
|
||||
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1);
|
||||
tag.putDouble("empty", 1);
|
||||
|
||||
NBTTool.getTag(stack).putDouble("empty", 1);
|
||||
|
||||
if (stack.getItem() == ModItems.M_60.get() && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 5) {
|
||||
GunsTool.setGunBooleanTag(stack, "HideBulletChain", true);
|
||||
if (stack.getItem() == ModItems.M_60.get() && GunsTool.getGunIntTag(tag, "Ammo", 0) <= 5) {
|
||||
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.HOMEMADE_SHOTGUN.get()) {
|
||||
|
@ -83,16 +84,16 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
}
|
||||
}
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
|
||||
for (int index0 = 0; index0 < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : projectileAmount); index0++) {
|
||||
GunEventHandler.gunShoot(player, spared);
|
||||
GunEventHandler.gunShoot(player, tag, spared);
|
||||
}
|
||||
|
||||
GunEventHandler.playGunSounds(player);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
|
||||
|
@ -106,11 +107,11 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
}
|
||||
}
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
|
||||
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(stack, "SoundRadius");
|
||||
float soundRadius = (float) GunsTool.getGunDoubleTag(tag, "SoundRadius");
|
||||
|
||||
player.playSound(ModSounds.MINIGUN_FIRE_3P.get(), soundRadius * 0.2f, pitch);
|
||||
player.playSound(ModSounds.MINIGUN_FAR.get(), soundRadius * 0.5f, pitch);
|
||||
|
@ -121,11 +122,13 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
}
|
||||
}
|
||||
|
||||
GunEventHandler.gunShoot(player, spared);
|
||||
GunEventHandler.gunShoot(player, tag, spared);
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
cap.rifleAmmo = cap.rifleAmmo - 1;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ public record SwitchScopeMessage(double scroll) implements CustomPacketPayload {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
NBTTool.setBoolean(stack, "ScopeAlt", NBTTool.getBoolean(stack, "ScopeAlt", false));
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
tag.putBoolean("ScopeAlt", tag.getBoolean("ScopeAlt"));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,14 +29,15 @@ public record VehicleMovementMessage(short keys) implements CustomPacketPayload
|
|||
var player = (ServerPlayer) context.player();
|
||||
var entity = player.getVehicle();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
VehicleEntity vehicle = null;
|
||||
if (entity instanceof MobileVehicleEntity mobileVehicleEntity) {
|
||||
if (mobileVehicleEntity.getFirstPassenger() != player) return;
|
||||
vehicle = mobileVehicleEntity;
|
||||
} else if (stack.is(ModItems.MONITOR.get())
|
||||
&& NBTTool.getBoolean(stack, "Using", false)
|
||||
&& NBTTool.getBoolean(stack, "Linked", false)
|
||||
&& tag.getBoolean("Using")
|
||||
&& tag.getBoolean("Linked")
|
||||
) vehicle = EntityFindUtil.findDrone(player.level(), NBTTool.getTag(stack).getString("LinkedDrone"));
|
||||
|
||||
if (!(vehicle instanceof ControllableVehicle controllable)) return;
|
||||
|
|
|
@ -3,12 +3,10 @@ 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.tools.NBTTool;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -66,13 +64,7 @@ public class PerkHelper {
|
|||
};
|
||||
}
|
||||
|
||||
public static int getItemPerkLevel(Perk perk, ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
public static int getItemPerkLevel(Perk perk, final CompoundTag tag) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
if (!tagPerk.contains(perk.type.getName())) {
|
||||
return 0;
|
||||
|
@ -88,20 +80,16 @@ public class PerkHelper {
|
|||
return 0;
|
||||
}
|
||||
|
||||
return getPerkLevel(getPerkTag(stack, perk.type));
|
||||
return getPerkLevel(getPerkTag(tag, perk.type));
|
||||
}
|
||||
|
||||
public static CompoundTag getPerkTag(ItemStack stack, Perk.Type type) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
public static CompoundTag getPerkTag(final CompoundTag tag, Perk.Type type) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
if (!tagPerk.contains(type.getName())) return new CompoundTag();
|
||||
return tagPerk.getCompound(type.getName());
|
||||
}
|
||||
|
||||
public static void setPerk(ItemStack stack, Perk perk, int level) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
public static void setPerk(final CompoundTag tag, Perk perk, int level) {
|
||||
var perkTag = tag.getCompound(TAG_PERK);
|
||||
if (perkTag.isEmpty()) {
|
||||
perkTag = new CompoundTag();
|
||||
|
@ -109,17 +97,14 @@ public class PerkHelper {
|
|||
|
||||
perkTag.put(perk.type.getName(), makePerk(getPerkId(perk), level));
|
||||
tag.put(TAG_PERK, perkTag);
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static void setPerk(ItemStack stack, Perk perk) {
|
||||
setPerk(stack, perk, 1);
|
||||
public static void setPerk(final CompoundTag tag, Perk perk) {
|
||||
setPerk(tag, perk, 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Perk getPerkByType(ItemStack stack, Perk.Type type) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
public static Perk getPerkByType(final CompoundTag tag, Perk.Type type) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
if (!tagPerk.contains(type.getName())) {
|
||||
return null;
|
||||
|
@ -144,9 +129,7 @@ public class PerkHelper {
|
|||
};
|
||||
}
|
||||
|
||||
public static void removePerkByType(ItemStack stack, Perk.Type type) {
|
||||
var tag = NBTTool.getTag(stack);
|
||||
|
||||
public static void removePerkByType(final CompoundTag tag, Perk.Type type) {
|
||||
var tagPerk = tag.getCompound(TAG_PERK);
|
||||
if (!tagPerk.contains(type.getName())) {
|
||||
return;
|
||||
|
|
|
@ -3,10 +3,8 @@ 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.GunItem;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.GunsDataMessage;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
@ -24,8 +22,6 @@ import java.io.InputStreamReader;
|
|||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.atsuishio.superbwarfare.tools.NBTTool.saveTag;
|
||||
|
||||
@EventBusSubscriber(modid = Mod.MODID)
|
||||
public class GunsTool {
|
||||
|
||||
|
@ -57,38 +53,34 @@ public class GunsTool {
|
|||
}
|
||||
}
|
||||
|
||||
public static void initGun(Level level, ItemStack stack, String location) {
|
||||
public static void initGun(Level level, final CompoundTag tag, String location) {
|
||||
if (level.getServer() == null) return;
|
||||
gunsData.get(location).forEach((k, v) -> {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
CompoundTag data = tag.getCompound("GunData");
|
||||
data.putDouble(k, v);
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
});
|
||||
}
|
||||
|
||||
public static void initCreativeGun(ItemStack stack, String location) {
|
||||
if (gunsData != null && gunsData.get(location) != null) {
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
gunsData.get(location).forEach((k, v) -> {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
CompoundTag data = tag.getCompound("GunData");
|
||||
data.putDouble(k, v);
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
});
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ GunsTool.getGunIntTag(stack, "CustomMagazine", 0));
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putInt("Ammo", data.getInt("Magazine") + data.getInt("CustomMagazine"));
|
||||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateAndSetUUID(ItemStack stack) {
|
||||
public static void generateAndSetUUID(final CompoundTag tag) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putUUID("UUID", uuid);
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -103,21 +95,20 @@ public class GunsTool {
|
|||
initJsonData(event.getServer().getResourceManager());
|
||||
}
|
||||
|
||||
public static void reload(Player player, ItemStack stack, AmmoType type) {
|
||||
reload(player, stack, type, false);
|
||||
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, AmmoType type, boolean extraOne) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
public static void reload(Player player, ItemStack stack, final CompoundTag tag, AmmoType type, boolean extraOne) {
|
||||
final var data = tag.getCompound("GunData");
|
||||
|
||||
int mag = GunsTool.getGunIntTag(stack, "Magazine", 0) + GunsTool.getGunIntTag(stack, "CustomMagazine", 0);
|
||||
int ammo = GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
int mag = data.getInt("Magazine") + data.getInt("CustomMagazine");
|
||||
int ammo = data.getInt("Ammo");
|
||||
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
|
||||
|
||||
// 空仓换弹的栓动武器应该在换弹后取消待上膛标记
|
||||
if (ammo == 0 && GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && !stack.is(ModTags.Items.REVOLVER)) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false);
|
||||
if (ammo == 0 && data.getInt("BoltActionTime") > 0 && !stack.is(ModTags.Items.REVOLVER)) {
|
||||
data.putBoolean("NeedBoltAction", false);
|
||||
}
|
||||
|
||||
var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
@ -132,58 +123,55 @@ public class GunsTool {
|
|||
|
||||
int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo);
|
||||
|
||||
GunsTool.setGunIntTag(stack, "Ammo", needToAdd);
|
||||
data.putInt("Ammo", needToAdd);
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
/* PerkData */
|
||||
public static void setPerkIntTag(ItemStack stack, String name, int num) {
|
||||
var rootTag = NBTTool.getTag(stack);
|
||||
public static void setPerkIntTag(final CompoundTag rootTag, String name, int num) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
tag.putInt(name, num);
|
||||
rootTag.put("PerkData", tag);
|
||||
saveTag(stack, rootTag);
|
||||
}
|
||||
|
||||
public static int getPerkIntTag(ItemStack stack, String name) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("PerkData");
|
||||
public static int getPerkIntTag(final CompoundTag rootTag, String name) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
return tag.getInt(name);
|
||||
}
|
||||
|
||||
public static void setPerkDoubleTag(ItemStack stack, String name, double num) {
|
||||
var rootTag = NBTTool.getTag(stack);
|
||||
public static void setPerkDoubleTag(final CompoundTag rootTag, String name, double num) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
tag.putDouble(name, num);
|
||||
rootTag.put("PerkData", tag);
|
||||
saveTag(stack, rootTag);
|
||||
}
|
||||
|
||||
public static double getPerkDoubleTag(ItemStack stack, String name) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("PerkData");
|
||||
public static double getPerkDoubleTag(final CompoundTag rootTag, String name) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
return tag.getDouble(name);
|
||||
}
|
||||
|
||||
public static void setPerkBooleanTag(ItemStack stack, String name, boolean flag) {
|
||||
var rootTag = NBTTool.getTag(stack);
|
||||
public static void setPerkBooleanTag(final CompoundTag rootTag, String name, boolean flag) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
tag.putBoolean(name, flag);
|
||||
rootTag.put("PerkData", tag);
|
||||
saveTag(stack, rootTag);
|
||||
}
|
||||
|
||||
public static boolean getPerkBooleanTag(ItemStack stack, String name) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("PerkData");
|
||||
public static boolean getPerkBooleanTag(final CompoundTag rootTag, String name) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
return tag.getBoolean(name);
|
||||
}
|
||||
|
||||
/* Attachments */
|
||||
public static int getAttachmentType(ItemStack stack, AttachmentType type) {
|
||||
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments");
|
||||
public static int getAttachmentType(final CompoundTag rootTag, AttachmentType type) {
|
||||
CompoundTag tag = rootTag.getCompound("Attachments");
|
||||
return tag.getInt(type.getName());
|
||||
}
|
||||
|
||||
public static int getAttachmentType(ItemStack stack, AttachmentType type) {
|
||||
return getAttachmentType(NBTTool.getTag(stack), type);
|
||||
}
|
||||
|
||||
public enum AttachmentType {
|
||||
SCOPE("Scope"),
|
||||
MAGAZINE("Magazine"),
|
||||
|
@ -203,71 +191,60 @@ public class GunsTool {
|
|||
}
|
||||
|
||||
/* GunData */
|
||||
public static CompoundTag getGunData(ItemStack stack) {
|
||||
return NBTTool.getTag(stack).getCompound("GunData");
|
||||
public static CompoundTag getGunData(final CompoundTag tag) {
|
||||
return tag.getCompound("GunData");
|
||||
}
|
||||
|
||||
public static void setGunIntTag(ItemStack stack, String name, int num) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
public static void setGunIntTag(final CompoundTag tag, String name, int num) {
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putInt(name, num);
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static int getGunIntTag(ItemStack stack, String name) {
|
||||
return getGunIntTag(stack, name, 0);
|
||||
public static int getGunIntTag(final CompoundTag tag, String name) {
|
||||
return getGunIntTag(tag, name, 0);
|
||||
}
|
||||
|
||||
public static int getGunIntTag(ItemStack stack, String name, int defaultValue) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
public static int getGunIntTag(final CompoundTag tag, String name, int defaultValue) {
|
||||
var data = tag.getCompound("GunData");
|
||||
if (!data.contains(name)) return defaultValue;
|
||||
return data.getInt(name);
|
||||
}
|
||||
|
||||
public static void setGunDoubleTag(ItemStack stack, String name, double num) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
public static void setGunDoubleTag(final CompoundTag tag, String name, double num) {
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putDouble(name, num);
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static double getGunDoubleTag(ItemStack stack, String name) {
|
||||
return getGunDoubleTag(stack, name, 0);
|
||||
public static double getGunDoubleTag(final CompoundTag tag, String name) {
|
||||
return getGunDoubleTag(tag, name, 0);
|
||||
}
|
||||
|
||||
public static double getGunDoubleTag(ItemStack stack, String name, double defaultValue) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
public static double getGunDoubleTag(final CompoundTag tag, String name, double defaultValue) {
|
||||
var data = tag.getCompound("GunData");
|
||||
if (!data.contains(name)) return defaultValue;
|
||||
return data.getDouble(name);
|
||||
}
|
||||
|
||||
public static void setGunBooleanTag(ItemStack stack, String name, boolean flag) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
public static void setGunBooleanTag(final CompoundTag tag, String name, boolean flag) {
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putBoolean(name, flag);
|
||||
tag.put("GunData", data);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static boolean getGunBooleanTag(ItemStack stack, String name) {
|
||||
return getGunBooleanTag(stack, name, false);
|
||||
public static boolean getGunBooleanTag(final CompoundTag tag, String name) {
|
||||
return getGunBooleanTag(tag, name, false);
|
||||
}
|
||||
|
||||
public static boolean getGunBooleanTag(ItemStack stack, String name, boolean defaultValue) {
|
||||
CompoundTag tag = NBTTool.getTag(stack);
|
||||
public static boolean getGunBooleanTag(final CompoundTag tag, String name, boolean defaultValue) {
|
||||
var data = tag.getCompound("GunData");
|
||||
if (!data.contains(name)) return defaultValue;
|
||||
return data.getBoolean(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static UUID getGunUUID(ItemStack stack) {
|
||||
var customData = stack.get(DataComponents.CUSTOM_DATA);
|
||||
CompoundTag tag = customData != null ? customData.copyTag() : new CompoundTag();
|
||||
public static UUID getGunUUID(final CompoundTag tag) {
|
||||
if (!tag.contains("GunData")) return null;
|
||||
|
||||
CompoundTag data = tag.getCompound("GunData");
|
||||
|
|
|
@ -7,67 +7,16 @@ import net.minecraft.world.item.component.CustomData;
|
|||
|
||||
// From Botania
|
||||
public final class NBTTool {
|
||||
public static boolean verifyExistence(ItemStack stack, String key) {
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
return !stack.isEmpty() && data != null && data.contains(key);
|
||||
}
|
||||
|
||||
public static CompoundTag getTag(ItemStack stack) {
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
if (data != null) return data.copyTag();
|
||||
|
||||
return new CompoundTag();
|
||||
}
|
||||
|
||||
public static void setBoolean(ItemStack stack, String key, boolean b) {
|
||||
var tag = getTag(stack);
|
||||
tag.putBoolean(key, b);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static boolean getBoolean(ItemStack stack, String key, boolean defaultExpected) {
|
||||
return verifyExistence(stack, key) ? getTag(stack).getBoolean(key) : defaultExpected;
|
||||
}
|
||||
|
||||
public static void setFloat(ItemStack stack, String key, float f) {
|
||||
var tag = getTag(stack);
|
||||
tag.putFloat(key, f);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static float getFloat(ItemStack stack, String key, float f) {
|
||||
return verifyExistence(stack, key) ? getTag(stack).getFloat(key) : f;
|
||||
}
|
||||
|
||||
public static void setInt(ItemStack stack, String key, int num) {
|
||||
var tag = getTag(stack);
|
||||
tag.putInt(key, num);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static int getInt(ItemStack stack, String key, int num) {
|
||||
return verifyExistence(stack, key) ? getTag(stack).getInt(key) : num;
|
||||
}
|
||||
|
||||
public static void setLong(ItemStack stack, String key, long num) {
|
||||
var tag = getTag(stack);
|
||||
tag.putLong(key, num);
|
||||
saveTag(stack, tag);
|
||||
}
|
||||
|
||||
public static long getLong(ItemStack stack, String key, long num) {
|
||||
return verifyExistence(stack, key) ? getTag(stack).getLong(key) : num;
|
||||
}
|
||||
|
||||
public static void setDouble(ItemStack stack, String key, double num) {
|
||||
getTag(stack).putDouble(key, num);
|
||||
}
|
||||
|
||||
public static double getDouble(ItemStack stack, String key, double num) {
|
||||
return verifyExistence(stack, key) ? getTag(stack).getDouble(key) : num;
|
||||
}
|
||||
|
||||
public static void saveTag(ItemStack stack, CompoundTag tag) {
|
||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
var oldTag = data != null ? data.copyTag() : new CompoundTag();
|
||||
var newTag = oldTag.merge(tag);
|
||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(newTag));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue