干掉maxAmmo
This commit is contained in:
parent
cc3c593889
commit
280a25ad3f
14 changed files with 15 additions and 228 deletions
|
@ -3,13 +3,10 @@ package com.atsuishio.superbwarfare.client.overlay;
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModKeyMappings;
|
import com.atsuishio.superbwarfare.init.ModKeyMappings;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
|
||||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
@ -48,12 +45,13 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
||||||
private static int getGunAmmoCount(Player player) {
|
private static int getGunAmmoCount(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
|
// TODO 替换为直接使用背包弹药判断
|
||||||
if (stack.getItem() == ModItems.MINIGUN.get()) {
|
if (stack.getItem() == ModItems.MINIGUN.get()) {
|
||||||
return player.getData(ModAttachments.PLAYER_VARIABLE).rifleAmmo;
|
return GunData.from(stack).countAmmo(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||||
return GunData.from(stack).maxAmmo.get();
|
return GunData.from(stack).countAmmo(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GunData.from(stack).ammo.get();
|
return GunData.from(stack).ammo.get();
|
||||||
|
@ -66,25 +64,9 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
|
||||||
if (!hasCreativeAmmo()) {
|
if (!hasCreativeAmmo()) {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
if (stack.is(ModTags.Items.LAUNCHER) || stack.getItem() == ModItems.TASER.get()) {
|
return data.countAmmo(player) + "";
|
||||||
return "" + data.maxAmmo.get();
|
|
||||||
}
|
|
||||||
var ammoTypeInfo = data.ammoTypeInfo();
|
|
||||||
return switch (ammoTypeInfo.type()) {
|
|
||||||
case PLAYER_AMMO -> {
|
|
||||||
var type = AmmoType.getType(ammoTypeInfo.value());
|
|
||||||
assert type != null;
|
|
||||||
|
|
||||||
yield type.get(cap) + "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO 正确计算弹药数量
|
|
||||||
case ITEM, TAG -> "" + data.maxAmmo.get();
|
|
||||||
default -> "";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "∞";
|
return "∞";
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class BocekItemRenderer extends GeoItemRenderer<BocekItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.equals("jian")) {
|
if (name.equals("jian")) {
|
||||||
bone.setHidden(GunData.from(itemStack).maxAmmo.get() == 0);
|
bone.setHidden(!GunData.from(itemStack).hasAmmo(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderingArms) {
|
if (renderingArms) {
|
||||||
|
|
|
@ -452,7 +452,7 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 优化这坨判断
|
// TODO 优化这坨判断
|
||||||
if (stack.is(ModTags.Items.LAUNCHER) && data.maxAmmo.get() == 0
|
if (stack.is(ModTags.Items.LAUNCHER) && !data.hasAmmo(player)
|
||||||
|| stack.is(ModItems.SECONDARY_CATACLYSM.get()) && data.ammo.get() >= data.magazine()
|
|| stack.is(ModItems.SECONDARY_CATACLYSM.get()) && data.ammo.get() >= data.magazine()
|
||||||
) {
|
) {
|
||||||
startStage3 = true;
|
startStage3 = true;
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.SimulationDistanceMessage;
|
import com.atsuishio.superbwarfare.network.message.receive.SimulationDistanceMessage;
|
||||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
|
||||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -16,7 +15,6 @@ import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.tags.ItemTags;
|
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
|
@ -109,40 +107,7 @@ public class PlayerEventHandler {
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
|
|
||||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
data.reload(player);
|
||||||
var ammoTypeInfo = data.ammoTypeInfo();
|
|
||||||
switch (ammoTypeInfo.type()) {
|
|
||||||
case PLAYER_AMMO -> {
|
|
||||||
var type = AmmoType.getType(ammoTypeInfo.value());
|
|
||||||
assert type != null;
|
|
||||||
|
|
||||||
if (type.get(cap) == 0) {
|
|
||||||
data.reload(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ITEM -> {
|
|
||||||
// TODO 弃用maxAmmo
|
|
||||||
if (data.ammo.get() == 0 && data.maxAmmo.get() == 0) {
|
|
||||||
data.ammo.set(1);
|
|
||||||
player.getInventory().clearOrCountMatchingItems(
|
|
||||||
p -> p.getItem().toString().equals(ammoTypeInfo.value()),
|
|
||||||
1,
|
|
||||||
player.inventoryMenu.getCraftSlots()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case TAG -> {
|
|
||||||
// TODO 弃用maxAmmo
|
|
||||||
if (data.ammo.get() == 0 && data.maxAmmo.get() == 0) {
|
|
||||||
data.ammo.set(1);
|
|
||||||
player.getInventory().clearOrCountMatchingItems(
|
|
||||||
p -> p.is(ItemTags.create(ResourceLocation.parse(ammoTypeInfo.value()))),
|
|
||||||
1,
|
|
||||||
player.inventoryMenu.getCraftSlots()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
data.ammo.set(data.magazine());
|
data.ammo.set(data.magazine());
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,6 @@ public class GunData {
|
||||||
stopped = new BooleanValue(data, "Stopped");
|
stopped = new BooleanValue(data, "Stopped");
|
||||||
forceStop = new BooleanValue(data, "ForceStop");
|
forceStop = new BooleanValue(data, "ForceStop");
|
||||||
loadIndex = new IntValue(data, "LoadIndex");
|
loadIndex = new IntValue(data, "LoadIndex");
|
||||||
maxAmmo = new IntValue(data, "MaxAmmo");
|
|
||||||
holdOpen = new BooleanValue(data, "HoldOpen");
|
holdOpen = new BooleanValue(data, "HoldOpen");
|
||||||
hideBulletChain = new BooleanValue(data, "HideBulletChain");
|
hideBulletChain = new BooleanValue(data, "HideBulletChain");
|
||||||
draw = new BooleanValue(data, "Draw");
|
draw = new BooleanValue(data, "Draw");
|
||||||
|
@ -300,6 +299,10 @@ public class GunData {
|
||||||
return new AmmoTypeInfo(AmmoConsumeType.ITEM, ammoType);
|
return new AmmoTypeInfo(AmmoConsumeType.ITEM, ammoType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasAmmo(Player player) {
|
||||||
|
return countAmmo(player) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public int countAmmo(Player player) {
|
public int countAmmo(Player player) {
|
||||||
var info = ammoTypeInfo();
|
var info = ammoTypeInfo();
|
||||||
return switch (info.type()) {
|
return switch (info.type()) {
|
||||||
|
@ -404,7 +407,6 @@ public class GunData {
|
||||||
public final BooleanValue stopped;
|
public final BooleanValue stopped;
|
||||||
public final BooleanValue forceStop;
|
public final BooleanValue forceStop;
|
||||||
public final IntValue loadIndex;
|
public final IntValue loadIndex;
|
||||||
public final IntValue maxAmmo;
|
|
||||||
|
|
||||||
public final BooleanValue holdOpen;
|
public final BooleanValue holdOpen;
|
||||||
public final BooleanValue hideBulletChain;
|
public final BooleanValue hideBulletChain;
|
||||||
|
|
|
@ -106,27 +106,6 @@ public class JavelinItem extends GunItem implements GeoItem, ReleaseSpecialWeapo
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAmmoCount(Player player) {
|
|
||||||
int count = 0;
|
|
||||||
for (var inv : player.getInventory().items) {
|
|
||||||
if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
|
|
||||||
ItemStack itemstack = player.getInventory().getItem(i);
|
|
||||||
if (check(itemstack)) {
|
|
||||||
sum += itemstack.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
return (int) Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SoundEvent> getReloadSound() {
|
public Set<SoundEvent> getReloadSound() {
|
||||||
return Set.of(ModSounds.JAVELIN_RELOAD_EMPTY.get(), ModSounds.JAVELIN_LOCK.get(), ModSounds.JAVELIN_LOCKON.get());
|
return Set.of(ModSounds.JAVELIN_RELOAD_EMPTY.get(), ModSounds.JAVELIN_LOCK.get(), ModSounds.JAVELIN_LOCKON.get());
|
||||||
|
@ -140,8 +119,6 @@ public class JavelinItem extends GunItem implements GeoItem, ReleaseSpecialWeapo
|
||||||
final var tag = data.tag();
|
final var tag = data.tag();
|
||||||
|
|
||||||
if (entity instanceof Player player && selected) {
|
if (entity instanceof Player player && selected) {
|
||||||
data.maxAmmo.set(getAmmoCount(player));
|
|
||||||
|
|
||||||
if (tag.getBoolean("Seeking")) {
|
if (tag.getBoolean("Seeking")) {
|
||||||
|
|
||||||
List<Entity> decoy = SeekTool.seekLivingEntities(player, player.level(), 512, 8);
|
List<Entity> decoy = SeekTool.seekLivingEntities(player, player.level(), 512, 8);
|
||||||
|
|
|
@ -20,14 +20,12 @@ import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Rarity;
|
import net.minecraft.world.item.Rarity;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import software.bernie.geckolib.animatable.GeoItem;
|
import software.bernie.geckolib.animatable.GeoItem;
|
||||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||||
|
@ -35,7 +33,6 @@ import software.bernie.geckolib.animation.*;
|
||||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
@ -95,38 +92,6 @@ public class M79Item extends GunItem implements GeoItem, PressFireSpecialWeapon
|
||||||
data.add(idleController);
|
data.add(idleController);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAmmoCount(Player player) {
|
|
||||||
int count = 0;
|
|
||||||
for (var inv : player.getInventory().items) {
|
|
||||||
if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
|
|
||||||
ItemStack itemstack = player.getInventory().getItem(i);
|
|
||||||
if (check(itemstack)) {
|
|
||||||
sum += itemstack.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
return (int) Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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) {
|
|
||||||
var data = GunData.from(stack);
|
|
||||||
data.maxAmmo.set(getAmmoCount(player));
|
|
||||||
data.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static boolean check(ItemStack stack) {
|
protected static boolean check(ItemStack stack) {
|
||||||
return stack.getItem() == ModItems.GRENADE_40MM.get();
|
return stack.getItem() == ModItems.GRENADE_40MM.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,27 +98,6 @@ public class RpgItem extends GunItem implements GeoItem, PressFireSpecialWeapon
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAmmoCount(Player player) {
|
|
||||||
int count = 0;
|
|
||||||
for (var inv : player.getInventory().items) {
|
|
||||||
if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
|
|
||||||
ItemStack itemstack = player.getInventory().getItem(i);
|
|
||||||
if (check(itemstack)) {
|
|
||||||
sum += itemstack.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
return (int) Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SoundEvent> getReloadSound() {
|
public Set<SoundEvent> getReloadSound() {
|
||||||
return Set.of(ModSounds.RPG_RELOAD_EMPTY.get());
|
return Set.of(ModSounds.RPG_RELOAD_EMPTY.get());
|
||||||
|
@ -136,9 +115,6 @@ public class RpgItem extends GunItem implements GeoItem, PressFireSpecialWeapon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
|
||||||
data.maxAmmo.set(getAmmoCount(player));
|
|
||||||
}
|
|
||||||
data.save();
|
data.save();
|
||||||
|
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
|
|
|
@ -14,7 +14,6 @@ import com.atsuishio.superbwarfare.item.gun.PressFireSpecialWeapon;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
import com.atsuishio.superbwarfare.perk.PerkHelper;
|
||||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
@ -149,32 +148,11 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, PressFireSpe
|
||||||
data.add(idleController);
|
data.add(idleController);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAmmoCount(Player player) {
|
|
||||||
if (InventoryTool.hasCreativeAmmoBox(player)) {
|
|
||||||
return (int) Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
|
|
||||||
ItemStack itemstack = player.getInventory().getItem(i);
|
|
||||||
if (check(itemstack)) {
|
|
||||||
sum += itemstack.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
|
||||||
var data = GunData.from(stack);
|
|
||||||
data.maxAmmo.set(getAmmoCount(player));
|
|
||||||
data.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
for (var cell : player.getInventory().items) {
|
for (var cell : player.getInventory().items) {
|
||||||
if (cell.is(ModItems.CELL.get())) {
|
if (cell.is(ModItems.CELL.get())) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.client.renderer.item.BocekItemRenderer;
|
import com.atsuishio.superbwarfare.client.renderer.item.BocekItemRenderer;
|
||||||
import com.atsuishio.superbwarfare.client.tooltip.component.BocekImageComponent;
|
import com.atsuishio.superbwarfare.client.tooltip.component.BocekImageComponent;
|
||||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
|
@ -86,26 +85,6 @@ public class BocekItem extends GunItem implements GeoItem, ReleaseSpecialWeapon
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAmmoCount(Player player) {
|
|
||||||
int count = 0;
|
|
||||||
for (var inv : player.getInventory().items) {
|
|
||||||
if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
|
|
||||||
ItemStack itemstack = player.getInventory().getItem(i);
|
|
||||||
if (check(itemstack)) {
|
|
||||||
sum += itemstack.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
return (int) Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
|
@ -113,10 +92,6 @@ public class BocekItem extends GunItem implements GeoItem, ReleaseSpecialWeapon
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
final var tag = data.tag();
|
final var tag = data.tag();
|
||||||
if (entity instanceof Player player) {
|
|
||||||
data.maxAmmo.set(getAmmoCount(player));
|
|
||||||
data.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GunsTool.getGunIntTag(tag, "ArrowEmpty") > 0) {
|
if (GunsTool.getGunIntTag(tag, "ArrowEmpty") > 0) {
|
||||||
GunsTool.setGunIntTag(tag, "ArrowEmpty", GunsTool.getGunIntTag(tag, "ArrowEmpty") - 1);
|
GunsTool.setGunIntTag(tag, "ArrowEmpty", GunsTool.getGunIntTag(tag, "ArrowEmpty") - 1);
|
||||||
|
|
|
@ -113,26 +113,6 @@ public class TaserItem extends GunItem implements GeoItem, EnergyStorageItem, Pr
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAmmoCount(Player player) {
|
|
||||||
int count = 0;
|
|
||||||
for (var inv : player.getInventory().items) {
|
|
||||||
if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
|
|
||||||
ItemStack itemstack = player.getInventory().getItem(i);
|
|
||||||
if (check(itemstack)) {
|
|
||||||
sum += itemstack.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
return (int) Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
|
@ -140,11 +120,6 @@ public class TaserItem extends GunItem implements GeoItem, EnergyStorageItem, Pr
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
var data = GunData.from(stack);
|
var data = GunData.from(stack);
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
|
||||||
data.maxAmmo.set(getAmmoCount(player));
|
|
||||||
data.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
int perkLevel = data.perk.getLevel(ModPerks.REGENERATION);
|
int perkLevel = data.perk.getLevel(ModPerks.REGENERATION);
|
||||||
|
|
||||||
var stackStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
var stackStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||||
|
|
|
@ -9,7 +9,6 @@ import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.ReleaseSpecialWeapon;
|
import com.atsuishio.superbwarfare.item.gun.ReleaseSpecialWeapon;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.special.BocekItem;
|
|
||||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
@ -67,11 +66,7 @@ public record FireMessage(int msgType, double power, boolean zoom) implements Cu
|
||||||
} else if (type == 1) {
|
} else if (type == 1) {
|
||||||
// 松开开火
|
// 松开开火
|
||||||
if (stack.getItem() instanceof ReleaseSpecialWeapon releaseSpecialWeapon) {
|
if (stack.getItem() instanceof ReleaseSpecialWeapon releaseSpecialWeapon) {
|
||||||
if (releaseSpecialWeapon instanceof BocekItem) {
|
releaseSpecialWeapon.fireOnRelease(player, data, power, zoom);
|
||||||
releaseSpecialWeapon.fireOnRelease(player, data, power, zoom);
|
|
||||||
} else {
|
|
||||||
releaseSpecialWeapon.fireOnRelease(player, data, 0, zoom);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cap.sync(player);
|
cap.sync(player);
|
||||||
|
|
|
@ -61,10 +61,7 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
||||||
assert ammoType != null;
|
assert ammoType != null;
|
||||||
|
|
||||||
if (ammoType.get(cap) == 0) return;
|
if (ammoType.get(cap) == 0) return;
|
||||||
} else if ((ammoTypeInfo.type() == GunData.AmmoConsumeType.ITEM || ammoTypeInfo.type() == GunData.AmmoConsumeType.TAG)
|
} else if ((ammoTypeInfo.type() == GunData.AmmoConsumeType.ITEM || ammoTypeInfo.type() == GunData.AmmoConsumeType.TAG) && !data.hasAmmo(player)) {
|
||||||
// TODO 弃用maxAmmo
|
|
||||||
&& data.maxAmmo.get() == 0
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public record ShootMessage(double spread, boolean zoom) implements CustomPacketP
|
||||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||||
|
|
||||||
if (cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player)) {
|
if (data.hasAmmo(player) || InventoryTool.hasCreativeAmmoBox(player)) {
|
||||||
tag.putDouble("heat", (tag.getDouble("heat") + 0.1));
|
tag.putDouble("heat", (tag.getDouble("heat") + 0.1));
|
||||||
if (tag.getDouble("heat") >= 50.5) {
|
if (tag.getDouble("heat") >= 50.5) {
|
||||||
tag.putDouble("overheat", 40);
|
tag.putDouble("overheat", 40);
|
||||||
|
@ -124,7 +124,7 @@ public record ShootMessage(double spread, boolean zoom) implements CustomPacketP
|
||||||
|
|
||||||
GunEventHandler.gunShoot(player, data, spared, false);
|
GunEventHandler.gunShoot(player, data, spared, false);
|
||||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||||
cap.rifleAmmo = cap.rifleAmmo - 1;
|
data.consumeAmmo(player, 1);
|
||||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||||
cap.sync(player);
|
cap.sync(player);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue