优化NBT#MaxAmmo ArrowEmpty
This commit is contained in:
parent
5e17d423f5
commit
2439335ba6
10 changed files with 37 additions and 41 deletions
|
@ -218,7 +218,7 @@ public class AmmoBarOverlay {
|
|||
}
|
||||
|
||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||
return stack.getOrCreateTag().getInt("max_ammo");
|
||||
return GunsTool.getGunIntTag(stack, "MaxAmmo");
|
||||
}
|
||||
|
||||
return GunsTool.getGunIntTag(stack, "Ammo", 0);
|
||||
|
@ -233,7 +233,7 @@ public class AmmoBarOverlay {
|
|||
|
||||
if (!hasCreativeAmmo()) {
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || stack.getItem() == ModItems.TASER.get()) {
|
||||
return "" + stack.getOrCreateTag().getInt("max_ammo");
|
||||
return "" + GunsTool.getGunIntTag(stack, "MaxAmmo");
|
||||
}
|
||||
if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
return "" + (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo;
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.model.item.BocekItemModel;
|
|||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.special.BocekItem;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -91,11 +92,11 @@ public class BocekItemRenderer extends GeoItemRenderer<BocekItem> {
|
|||
}
|
||||
|
||||
if (name.equals("arrow")) {
|
||||
bone.setHidden(itemStack.getOrCreateTag().getInt("arrow_empty") > 0);
|
||||
bone.setHidden(GunsTool.getGunIntTag(itemStack, "ArrowEmpty") > 0);
|
||||
}
|
||||
|
||||
if (name.equals("jian")) {
|
||||
bone.setHidden(itemStack.getOrCreateTag().getInt("max_ammo") == 0);
|
||||
bone.setHidden(GunsTool.getGunIntTag(itemStack, "MaxAmmo") == 0);
|
||||
}
|
||||
|
||||
if (this.transformType.firstPerson() && renderingArms) {
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.atsuishio.superbwarfare.tools.GunInfo;
|
|||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
|
@ -242,11 +241,10 @@ public class PlayerEventHandler {
|
|||
|
||||
private static void handleBocekPulling(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).bowPullHold) {
|
||||
if (stack.getItem() == ModItems.BOCEK.get()
|
||||
&& tag.getInt("max_ammo") > 0
|
||||
&& GunsTool.getGunIntTag(stack, "MaxAmmo") > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& GunsTool.getGunDoubleTag(stack, "Power") < 12
|
||||
) {
|
||||
|
@ -315,19 +313,19 @@ public class PlayerEventHandler {
|
|||
GunsTool.reload(player, stack, GunInfo.Type.RIFLE);
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.TASER.get() && stack.getOrCreateTag().getInt("max_ammo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.M_79.get() && stack.getOrCreateTag().getInt("max_ammo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.RPG.get() && stack.getOrCreateTag().getInt("max_ammo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
if (stack.getItem() == ModItems.JAVELIN.get() && stack.getOrCreateTag().getInt("max_ammo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
GunsTool.setGunIntTag(stack, "Ammo", 1);
|
||||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
|
|
|
@ -134,11 +134,11 @@ public class JavelinItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemStack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemStack, world, entity, slot, selected);
|
||||
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) {
|
||||
var tag = itemStack.getOrCreateTag();
|
||||
tag.putInt("max_ammo", getAmmoCount(player));
|
||||
var tag = stack.getOrCreateTag();
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
|
||||
if (tag.getBoolean("Seeking")) {
|
||||
Entity targetEntity = EntityFindUtil.findEntity(player.level(), tag.getString("TargetEntity"));
|
||||
|
|
|
@ -135,10 +135,10 @@ public class M79Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemStack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemStack, world, entity, slot, selected);
|
||||
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) {
|
||||
itemStack.getOrCreateTag().putInt("max_ammo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,21 +135,20 @@ public class RpgItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemStack, Level world, Entity entity, int slot, boolean selected) {
|
||||
if (itemStack.getOrCreateTag().getBoolean("draw")) {
|
||||
itemStack.getOrCreateTag().putBoolean("draw", false);
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
if (stack.getOrCreateTag().getBoolean("draw")) {
|
||||
stack.getOrCreateTag().putBoolean("draw", false);
|
||||
|
||||
if (GunsTool.getGunIntTag(itemStack, "Ammo", 0) == 0) {
|
||||
itemStack.getOrCreateTag().putDouble("empty", 1);
|
||||
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) {
|
||||
stack.getOrCreateTag().putDouble("empty", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
var tag = itemStack.getOrCreateTag();
|
||||
tag.putInt("max_ammo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
}
|
||||
|
||||
super.inventoryTick(itemStack, world, entity, slot, selected);
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
}
|
||||
|
||||
protected static boolean check(ItemStack stack) {
|
||||
|
|
|
@ -15,7 +15,6 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
|
@ -120,15 +119,14 @@ public class BocekItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemstack, world, entity, slot, selected);
|
||||
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) {
|
||||
itemstack.getOrCreateTag().putInt("max_ammo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
}
|
||||
|
||||
CompoundTag tag = itemstack.getOrCreateTag();
|
||||
if (tag.getInt("arrow_empty") > 0) {
|
||||
tag.putInt("arrow_empty", tag.getInt("arrow_empty") - 1);
|
||||
if (GunsTool.getGunIntTag(stack, "ArrowEmpty") > 0) {
|
||||
GunsTool.setGunIntTag(stack, "ArrowEmpty", GunsTool.getGunIntTag(stack, "ArrowEmpty") - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ public class TaserItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
stack.getOrCreateTag().putInt("max_ammo", getAmmoCount(player));
|
||||
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
|
||||
}
|
||||
|
||||
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.REGENERATION.get(), stack);
|
||||
|
@ -249,7 +249,8 @@ public class TaserItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
public boolean canApplyPerk(Perk perk) {
|
||||
return switch (perk.type) {
|
||||
case AMMO -> perk == ModPerks.LONGER_WIRE.get();
|
||||
case FUNCTIONAL -> perk == ModPerks.REGENERATION.get() || perk == ModPerks.POWERFUL_ATTRACTION.get() || perk == ModPerks.INTELLIGENT_CHIP.get();
|
||||
case FUNCTIONAL ->
|
||||
perk == ModPerks.REGENERATION.get() || perk == ModPerks.POWERFUL_ATTRACTION.get() || perk == ModPerks.INTELLIGENT_CHIP.get();
|
||||
case DAMAGE -> perk == ModPerks.VOLT_OVERLOAD.get();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ public class FireMessage {
|
|||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 7);
|
||||
stack.getOrCreateTag().putInt("arrow_empty", 7);
|
||||
GunsTool.setGunIntTag(stack, "ArrowEmpty", 7);
|
||||
GunsTool.setGunDoubleTag(stack, "Power", 0);
|
||||
|
||||
int count = 0;
|
||||
|
@ -230,7 +230,6 @@ public class FireMessage {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (player.level().isClientSide()) return;
|
||||
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
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);
|
||||
|
|
|
@ -78,13 +78,13 @@ public class ReloadMessage {
|
|||
return;
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && capability.rifleAmmo == 0) {
|
||||
return;
|
||||
} else if (stack.getItem() == ModItems.TASER.get() && tag.getInt("max_ammo") == 0) {
|
||||
} else if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
return;
|
||||
} else if (stack.getItem() == ModItems.M_79.get() && tag.getInt("max_ammo") == 0) {
|
||||
} else if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
return;
|
||||
} else if (stack.getItem() == ModItems.RPG.get() && tag.getInt("max_ammo") == 0) {
|
||||
} else if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
return;
|
||||
} else if (stack.getItem() == ModItems.JAVELIN.get() && tag.getInt("max_ammo") == 0) {
|
||||
} else if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue