优化NBT#Ammo
This commit is contained in:
parent
c442d25d1d
commit
9cb33414c4
19 changed files with 83 additions and 83 deletions
|
@ -318,7 +318,7 @@ public class ClickHandler {
|
|||
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
|
||||
}
|
||||
|
||||
if (!stack.is(ModTags.Items.CANNOT_RELOAD) && stack.getOrCreateTag().getInt("ammo") <= 0) {
|
||||
if (!stack.is(ModTags.Items.CANNOT_RELOAD) && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0) {
|
||||
if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0));
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class K98ItemModel extends GeoModel<K98Item> {
|
|||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("prepare") > 11 && stack.getOrCreateTag().getInt("ammo") == 1) {
|
||||
if (stack.getOrCreateTag().getDouble("prepare") > 11 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
clip.setScaleX(0);
|
||||
clip.setScaleY(0);
|
||||
clip.setScaleZ(0);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.atsuishio.superbwarfare.client.model.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.event.PlayerEventHandler;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.client.AnimationHelper;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.event.PlayerEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.machinegun.M60Item;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -56,31 +56,33 @@ public class M60ItemModel extends GeoModel<M60Item> {
|
|||
r.setRotX(1.5f);
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") < 5 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
int ammo = GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
|
||||
if (ammo < 5 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
b5.setScaleX(0);
|
||||
b5.setScaleY(0);
|
||||
b5.setScaleZ(0);
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") < 4 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
if (ammo < 4 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
b4.setScaleX(0);
|
||||
b4.setScaleY(0);
|
||||
b4.setScaleZ(0);
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") < 3 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
if (ammo < 3 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
b3.setScaleX(0);
|
||||
b3.setScaleY(0);
|
||||
b3.setScaleZ(0);
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") < 2 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
if (ammo < 2 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
b2.setScaleX(0);
|
||||
b2.setScaleY(0);
|
||||
b2.setScaleZ(0);
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") < 1 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
if (ammo < 1 && stack.getOrCreateTag().getBoolean("HideBulletChain")) {
|
||||
b1.setScaleX(0);
|
||||
b1.setScaleY(0);
|
||||
b1.setScaleZ(0);
|
||||
|
|
|
@ -100,8 +100,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 ((stack.getOrCreateTag().getDouble("ammo") <= 5)) {
|
||||
ammo.setScaleX((float) (stack.getOrCreateTag().getDouble("ammo") / 5));
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) <= 5) {
|
||||
ammo.setScaleX((float) GunsTool.getGunIntTag(stack, "Ammo", 0) / 5);
|
||||
}
|
||||
|
||||
CoreGeoBone camera = getAnimationProcessor().getBone("camera");
|
||||
|
|
|
@ -228,7 +228,7 @@ public class AmmoBarOverlay {
|
|||
return stack.getOrCreateTag().getInt("max_ammo");
|
||||
}
|
||||
|
||||
return stack.getOrCreateTag().getInt("ammo");
|
||||
return GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
}
|
||||
|
||||
private static String getPlayerAmmoCount(Player player) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
|||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.HudUtil;
|
||||
import com.atsuishio.superbwarfare.tools.SeekTool;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
|
@ -76,7 +77,7 @@ public class JavelinHudOverlay {
|
|||
float j1 = l + j;
|
||||
preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/javelin/javelin_hud.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(event.getGuiGraphics(), ModUtils.loc(stack.getOrCreateTag().getBoolean("TopMode") ? "textures/screens/javelin/top.png" : "textures/screens/javelin/dir.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(event.getGuiGraphics(), ModUtils.loc(stack.getOrCreateTag().getInt("ammo") > 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(), ModUtils.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);
|
||||
if (stack.getOrCreateTag().getInt("SeekTime") > 1 && stack.getOrCreateTag().getInt("SeekTime") < 20) {
|
||||
preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/javelin/seek.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
|
|||
|
||||
compound.putBoolean("Linked", this.entityData.get(LINKED));
|
||||
compound.putString("Controller", this.entityData.get(CONTROLLER));
|
||||
compound.putInt("ammo", this.entityData.get(AMMO));
|
||||
compound.putInt("Ammo", this.entityData.get(AMMO));
|
||||
compound.putBoolean("Kamikaze", this.entityData.get(KAMIKAZE));
|
||||
}
|
||||
|
||||
|
@ -147,8 +147,8 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
|
|||
this.entityData.set(LINKED, compound.getBoolean("Linked"));
|
||||
if (compound.contains("Controller"))
|
||||
this.entityData.set(CONTROLLER, compound.getString("Controller"));
|
||||
if (compound.contains("ammo"))
|
||||
this.entityData.set(AMMO, compound.getInt("ammo"));
|
||||
if (compound.contains("Ammo"))
|
||||
this.entityData.set(AMMO, compound.getInt("Ammo"));
|
||||
if (compound.contains("Kamikaze"))
|
||||
this.entityData.set(KAMIKAZE, compound.getBoolean("Kamikaze"));
|
||||
}
|
||||
|
@ -170,7 +170,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void baseTick() {
|
||||
super.baseTick();
|
||||
|
|
|
@ -297,7 +297,7 @@ public class ClientEventHandler {
|
|||
&& (!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||
&& !stack.getOrCreateTag().getBoolean("reloading")
|
||||
&& !stack.getOrCreateTag().getBoolean("charging")
|
||||
&& stack.getOrCreateTag().getInt("ammo") > 0
|
||||
&& GunsTool.getGunIntTag(stack, "Ammo", 0) > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)
|
||||
&& revolverPre()
|
||||
|
@ -377,14 +377,14 @@ public class ClientEventHandler {
|
|||
public static void shootClient(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
if (stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
int mode = GunsTool.getGunIntTag(stack, "FireMode");
|
||||
if (mode != 2) {
|
||||
holdFire = false;
|
||||
}
|
||||
|
||||
if (mode == 1) {
|
||||
if (stack.getOrCreateTag().getInt("ammo") == 1) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
burstFireSize = 1;
|
||||
}
|
||||
if (burstFireSize == 1) {
|
||||
|
|
|
@ -616,18 +616,18 @@ public class LivingEventHandler {
|
|||
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
int mag = GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag");
|
||||
int ammo = stack.getOrCreateTag().getInt("ammo");
|
||||
int ammo = GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
int ammoReload = (int) Math.min(mag, mag * rate);
|
||||
int ammoNeed = Math.min(mag - ammo, ammoReload);
|
||||
|
||||
if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
int ammoFinal = Math.min(capability.rifleAmmo, ammoNeed);
|
||||
capability.rifleAmmo -= ammoFinal;
|
||||
stack.getOrCreateTag().putInt("ammo", Math.min(mag, ammo + ammoFinal));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
int ammoFinal = Math.min(capability.handgunAmmo, ammoNeed);
|
||||
capability.handgunAmmo -= ammoFinal;
|
||||
stack.getOrCreateTag().putInt("ammo", Math.min(mag, ammo + ammoFinal));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", Math.min(mag, ammo + ammoFinal));
|
||||
}
|
||||
capability.syncPlayerVariables(player);
|
||||
}
|
||||
|
|
|
@ -235,10 +235,7 @@ public class PlayerEventHandler {
|
|||
private static void handleSpecialWeaponAmmo(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() == ModItems.RPG.get() && stack.getOrCreateTag().getInt("ammo") == 1) {
|
||||
stack.getOrCreateTag().putDouble("empty", 0);
|
||||
}
|
||||
if (stack.getItem() == ModItems.BOCEK.get() && stack.getOrCreateTag().getInt("ammo") == 1) {
|
||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
stack.getOrCreateTag().putDouble("empty", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,10 +68,10 @@ public abstract class GunItem extends Item {
|
|||
handleGunPerks(stack);
|
||||
handleGunAttachment(stack);
|
||||
|
||||
if ((stack.is(ModTags.Items.EXTRA_ONE_AMMO) && stack.getOrCreateTag().getInt("ammo") > GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag") + 1)
|
||||
|| (!stack.is(ModTags.Items.EXTRA_ONE_AMMO) && stack.getOrCreateTag().getInt("ammo") > GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag"))
|
||||
if ((stack.is(ModTags.Items.EXTRA_ONE_AMMO) && GunsTool.getGunIntTag(stack, "Ammo", 0) > GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag") + 1)
|
||||
|| (!stack.is(ModTags.Items.EXTRA_ONE_AMMO) && GunsTool.getGunIntTag(stack, "Ammo", 0) > GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag"))
|
||||
) {
|
||||
int count = stack.getOrCreateTag().getInt("ammo") - GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag") - (stack.is(ModTags.Items.EXTRA_ONE_AMMO) ? 1 : 0);
|
||||
int count = GunsTool.getGunIntTag(stack, "Ammo", 0) - GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag") - (stack.is(ModTags.Items.EXTRA_ONE_AMMO) ? 1 : 0);
|
||||
entity.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
|
@ -86,7 +86,7 @@ public abstract class GunItem extends Item {
|
|||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
|
||||
stack.getOrCreateTag().putInt("ammo", GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag") + (stack.is(ModTags.Items.EXTRA_ONE_AMMO) ? 1 : 0));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag") + (stack.is(ModTags.Items.EXTRA_ONE_AMMO) ? 1 : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public abstract class GunItem extends Item {
|
|||
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", 0);
|
||||
|
||||
int mag = GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag");
|
||||
stack.getOrCreateTag().putInt("ammo", Math.min(mag, stack.getOrCreateTag().getInt("ammo") + 2));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", Math.min(mag, GunsTool.getGunIntTag(stack, "Ammo", 0) + 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public class RpgItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
if (itemStack.getOrCreateTag().getBoolean("draw")) {
|
||||
itemStack.getOrCreateTag().putBoolean("draw", false);
|
||||
|
||||
if (itemStack.getOrCreateTag().getInt("ammo") == 0) {
|
||||
if (GunsTool.getGunIntTag(itemStack, "Ammo", 0) == 0) {
|
||||
itemStack.getOrCreateTag().putDouble("empty", 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.machinegun;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.client.PoseTool;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.M60ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
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.client.PoseTool;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.AnimatedItem;
|
||||
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 net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
@ -138,7 +138,7 @@ public class M60Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
if (itemstack.getOrCreateTag().getBoolean("draw")) {
|
||||
itemstack.getOrCreateTag().putBoolean("draw", false);
|
||||
|
||||
if (itemstack.getOrCreateTag().getInt("ammo") <= 5) {
|
||||
if (GunsTool.getGunIntTag(itemstack, "Ammo", 0) <= 5) {
|
||||
itemstack.getOrCreateTag().putBoolean("HideBulletChain", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.client.PoseTool;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.SksItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.client.PoseTool;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.AnimatedItem;
|
||||
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 net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
@ -123,7 +123,7 @@ public class SksItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
if (itemstack.getOrCreateTag().getBoolean("draw")) {
|
||||
itemstack.getOrCreateTag().putBoolean("draw", false);
|
||||
|
||||
if (itemstack.getOrCreateTag().getInt("ammo") == 0) {
|
||||
if (GunsTool.getGunIntTag(itemstack, "Ammo", 0) == 0) {
|
||||
itemstack.getOrCreateTag().putBoolean("HoldOpen", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.sniper;
|
||||
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.client.PoseTool;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.MosinNagantItemRenderer;
|
||||
|
@ -12,6 +11,7 @@ import com.atsuishio.superbwarfare.item.AnimatedItem;
|
|||
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 net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
@ -77,11 +77,11 @@ public class MosinNagantItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && stack.getOrCreateTag().getInt("ammo") == 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare_empty"));
|
||||
}
|
||||
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||
if (stack.getOrCreateTag().getInt("reload_stage") == 1 && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare"));
|
||||
}
|
||||
|
||||
|
|
|
@ -106,27 +106,28 @@ public class FireMessage {
|
|||
}
|
||||
|
||||
private static void handlePlayerShoot(Player player) {
|
||||
var handItem = player.getMainHandItem();
|
||||
var stack = player.getMainHandItem();
|
||||
|
||||
if (!handItem.is(ModTags.Items.GUN)) {
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tag = handItem.getOrCreateTag();
|
||||
var tag = stack.getOrCreateTag();
|
||||
|
||||
if (handItem.getItem() == ModItems.TASER.get()) {
|
||||
if (stack.getItem() == ModItems.TASER.get()) {
|
||||
handleTaserFire(player);
|
||||
}
|
||||
|
||||
if (handItem.getItem() == ModItems.M_79.get()) {
|
||||
if (stack.getItem() == ModItems.M_79.get()) {
|
||||
handleM79Fire(player);
|
||||
}
|
||||
|
||||
if (handItem.getItem() == ModItems.RPG.get()) {
|
||||
if (stack.getItem() == ModItems.RPG.get()) {
|
||||
handleRpgFire(player);
|
||||
}
|
||||
|
||||
if (handItem.getItem() == ModItems.JAVELIN.get() && player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom && tag.getInt("ammo") > 0) {
|
||||
if (stack.getItem() == ModItems.JAVELIN.get() && player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null)
|
||||
.orElse(new ModVariables.PlayerVariables()).zoom && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
|
||||
if (seekingEntity != null) {
|
||||
tag.putString("TargetEntity", seekingEntity.getStringUUID());
|
||||
|
@ -135,11 +136,11 @@ public class FireMessage {
|
|||
}
|
||||
}
|
||||
|
||||
if (tag.getDouble("prepare") == 0 && tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("prepare") == 0 && tag.getBoolean("reloading") && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
tag.putDouble("force_stop", 1);
|
||||
}
|
||||
|
||||
if (handItem.getItem() == ModItems.BOCEK.get()) {
|
||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.bowPullHold = true;
|
||||
capability.syncPlayerVariables(player);
|
||||
|
@ -148,7 +149,8 @@ public class FireMessage {
|
|||
}
|
||||
|
||||
private static void handleGunBolt(Player player, ItemStack stack) {
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && stack.getOrCreateTag().getInt("ammo") > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0) && stack.getOrCreateTag().getInt("bolt_action_anim") == 0
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
|
||||
&& stack.getOrCreateTag().getInt("bolt_action_anim") == 0
|
||||
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||
&& !stack.getOrCreateTag().getBoolean("reloading")
|
||||
&& !stack.getOrCreateTag().getBoolean("charging")) {
|
||||
|
@ -318,9 +320,7 @@ public class FireMessage {
|
|||
iEnergyStorage -> flag.set(iEnergyStorage.getEnergyStored() >= 400 + 100 * perkLevel)
|
||||
);
|
||||
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getInt("ammo") > 0
|
||||
&& flag.get()) {
|
||||
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0 && flag.get()) {
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 5);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
|
@ -345,7 +345,7 @@ public class FireMessage {
|
|||
level.addFreshEntity(taserBulletProjectile);
|
||||
}
|
||||
|
||||
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
|
||||
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
||||
energy -> energy.extractEnergy(400 + 100 * perkLevel, false)
|
||||
|
@ -364,7 +364,7 @@ public class FireMessage {
|
|||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.getOrCreateTag().getBoolean("reloading")) {
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
|
||||
|
@ -402,7 +402,7 @@ public class FireMessage {
|
|||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.M_79_VERYFAR.get(), SoundSource.PLAYERS, 10, 1);
|
||||
}
|
||||
|
||||
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
|
||||
if (player.level() instanceof ServerLevel && player instanceof ServerPlayer serverPlayer) {
|
||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShootClientMessage(10));
|
||||
|
@ -418,7 +418,7 @@ public class FireMessage {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
if (!tag.getBoolean("reloading") && !player.getCooldowns().isOnCooldown(stack.getItem()) && tag.getInt("ammo") > 0) {
|
||||
if (!tag.getBoolean("reloading") && !player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom;
|
||||
double spread = GunsTool.getGunDoubleTag(stack, "Spread");
|
||||
|
||||
|
@ -447,7 +447,7 @@ public class FireMessage {
|
|||
30, 0.4, 0.4, 0.4, 0.005, true);
|
||||
}
|
||||
|
||||
if (tag.getInt("ammo") == 1) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
tag.putBoolean("empty", true);
|
||||
tag.putBoolean("close_hammer", true);
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ public class FireMessage {
|
|||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.RPG_VERYFAR.get(), SoundSource.PLAYERS, 10, 1);
|
||||
}
|
||||
|
||||
tag.putInt("ammo", tag.getInt("ammo") - 1);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
|
||||
if (player.level() instanceof ServerLevel && player instanceof ServerPlayer serverPlayer) {
|
||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShootClientMessage(10));
|
||||
|
@ -527,7 +527,7 @@ public class FireMessage {
|
|||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.JAVELIN_FAR.get(), SoundSource.PLAYERS, 10, 1);
|
||||
}
|
||||
|
||||
tag.putInt("ammo", tag.getInt("ammo") - 1);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
|
||||
if (player.level() instanceof ServerLevel && player instanceof ServerPlayer serverPlayer) {
|
||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShootClientMessage(10));
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ReloadMessage {
|
|||
boolean canSingleReload = GunsTool.getGunIntTag(stack, "IterativeTime", 0) != 0;
|
||||
boolean canReload = (GunsTool.getGunIntTag(stack, "NormalReloadTime") != 0 || GunsTool.getGunIntTag(stack, "EmptyReloadTime") != 0)
|
||||
&& GunsTool.getGunIntTag(stack, "ClipLoad", 0) != 1;
|
||||
boolean clipLoad = tag.getInt("ammo") == 0 && GunsTool.getGunIntTag(stack, "ClipLoad", 0) == 1;
|
||||
boolean clipLoad = GunsTool.getGunIntTag(stack, "Ammo", 0) == 0 && GunsTool.getGunIntTag(stack, "ClipLoad", 0) == 1;
|
||||
|
||||
// 检查备弹
|
||||
int count = 0;
|
||||
|
@ -101,22 +101,22 @@ public class ReloadMessage {
|
|||
|
||||
if (stack.is(ModTags.Items.OPEN_BOLT)) {
|
||||
if (stack.is(ModTags.Items.EXTRA_ONE_AMMO)) {
|
||||
if (tag.getInt("ammo") < magazine + tag.getInt("customMag") + 1) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) < magazine + tag.getInt("customMag") + 1) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
} else {
|
||||
if (tag.getInt("ammo") < magazine + tag.getInt("customMag")) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) < magazine + tag.getInt("customMag")) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
}
|
||||
} else if (tag.getInt("ammo") < magazine + tag.getInt("customMag")) {
|
||||
} else if (GunsTool.getGunIntTag(stack, "Ammo", 0) < magazine + tag.getInt("customMag")) {
|
||||
tag.putBoolean("start_reload", true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (canSingleReload) {
|
||||
if (tag.getInt("ammo") < GunsTool.getGunIntTag(stack, "Magazine", 0) + tag.getInt("customMag")) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) < GunsTool.getGunIntTag(stack, "Magazine", 0) + tag.getInt("customMag")) {
|
||||
tag.putBoolean("start_single_reload", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,9 +62,9 @@ public class ShootMessage {
|
|||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
int projectileAmount = GunsTool.getGunIntTag(stack, "ProjectileAmount", 1);
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
|
||||
// 空仓挂机
|
||||
if (stack.getOrCreateTag().getInt("ammo") == 1) {
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
|
||||
stack.getOrCreateTag().putBoolean("HoldOpen", true);
|
||||
}
|
||||
|
||||
|
@ -73,15 +73,15 @@ public class ShootMessage {
|
|||
}
|
||||
|
||||
// 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && stack.getOrCreateTag().getInt("ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
|
||||
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true);
|
||||
}
|
||||
|
||||
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) - 1);
|
||||
|
||||
stack.getOrCreateTag().putDouble("empty", 1);
|
||||
|
||||
if (stack.getItem() == ModItems.M_60.get() && stack.getOrCreateTag().getInt("ammo") <= 5) {
|
||||
if (stack.getItem() == ModItems.M_60.get() && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 5) {
|
||||
stack.getOrCreateTag().putBoolean("HideBulletChain", true);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,8 @@ public class GunsTool {
|
|||
data.putDouble(k, v);
|
||||
stack.addTagElement("GunData", data);
|
||||
});
|
||||
stack.getOrCreateTag().putInt("ammo", GunsTool.getGunIntTag(stack, "Magazine", 0) + stack.getOrCreateTag().getInt("customMag"));
|
||||
GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Magazine", 0)
|
||||
+ stack.getOrCreateTag().getInt("customMag"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ public class GunsTool {
|
|||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
int mag = GunsTool.getGunIntTag(stack, "Magazine", 0) + tag.getInt("customMag");
|
||||
int ammo = tag.getInt("ammo");
|
||||
int ammo = GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
|
||||
|
||||
// 空仓换弹的栓动武器应该在换弹后取消待上膛标记
|
||||
|
@ -131,7 +132,7 @@ public class GunsTool {
|
|||
|
||||
int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo);
|
||||
|
||||
tag.putInt("ammo", needToAdd);
|
||||
GunsTool.setGunIntTag(stack, "Ammo", needToAdd);
|
||||
tag.putBoolean("is_normal_reloading", false);
|
||||
tag.putBoolean("is_empty_reloading", false);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue