规范命名部分方法
This commit is contained in:
parent
56818096ec
commit
07dc5b0c57
9 changed files with 32 additions and 28 deletions
|
@ -46,7 +46,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() == ModItems.MINIGUN.get()) {
|
||||
return GunData.from(stack).countAmmo(player);
|
||||
return GunData.from(stack).countBackupAmmo(player);
|
||||
}
|
||||
return GunData.from(stack).ammo.get();
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
|||
|
||||
if (!hasCreativeAmmo()) {
|
||||
var data = GunData.from(stack);
|
||||
return data.countAmmo(player) + "";
|
||||
return data.countBackupAmmo(player) + "";
|
||||
}
|
||||
|
||||
return "∞";
|
||||
|
|
|
@ -53,7 +53,6 @@ import net.neoforged.neoforge.capabilities.Capabilities;
|
|||
import net.neoforged.neoforge.client.event.*;
|
||||
import net.neoforged.neoforge.client.gui.VanillaGuiLayers;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import software.bernie.geckolib.animation.AnimationProcessor;
|
||||
import software.bernie.geckolib.cache.object.GeoBone;
|
||||
|
@ -591,7 +590,7 @@ public class ClientEventHandler {
|
|||
&& !player.isSprinting()
|
||||
&& tag.getDouble("overheat") == 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && miniGunRot >= 20
|
||||
&& data.hasAmmo(player)
|
||||
&& data.hasBackupAmmo(player)
|
||||
))) {
|
||||
if (mode == 0) {
|
||||
if (clientTimer.getProgress() == 0) {
|
||||
|
@ -705,7 +704,7 @@ public class ClientEventHandler {
|
|||
handleClientShoot();
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
if (data.hasAmmo(player)) {
|
||||
if (data.hasBackupAmmo(player)) {
|
||||
var perk = data.perk.get(Perk.Type.AMMO);
|
||||
float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat")));
|
||||
|
||||
|
@ -1617,7 +1616,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void handleDrawMessage(boolean draw, final IPayloadContext context) {
|
||||
public static void handleDrawMessage() {
|
||||
drawTime = 1;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
shellIndexTime[i] = 0;
|
||||
|
|
|
@ -289,7 +289,7 @@ public class GunEventHandler {
|
|||
}
|
||||
|
||||
// TODO 优化这坨判断
|
||||
if (stack.is(ModTags.Items.LAUNCHER) && !data.hasAmmo(player)
|
||||
if (stack.is(ModTags.Items.LAUNCHER) && !data.hasBackupAmmo(player)
|
||||
|| stack.is(ModItems.SECONDARY_CATACLYSM.get()) && data.ammo.get() >= data.magazine()
|
||||
) {
|
||||
startStage3 = true;
|
||||
|
@ -412,7 +412,7 @@ public class GunEventHandler {
|
|||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
data.consumeAmmo(player, 1);
|
||||
data.consumeBackupAmmo(player, 1);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,11 +300,17 @@ public class GunData {
|
|||
return new AmmoTypeInfo(AmmoConsumeType.ITEM, ammoType);
|
||||
}
|
||||
|
||||
public boolean hasAmmo(Player player) {
|
||||
return countAmmo(player) > 0;
|
||||
/**
|
||||
* 是否还有剩余弹药(不考虑枪内弹药)
|
||||
*/
|
||||
public boolean hasBackupAmmo(Player player) {
|
||||
return countBackupAmmo(player) > 0;
|
||||
}
|
||||
|
||||
public int countAmmo(Player player) {
|
||||
/**
|
||||
* 计算剩余弹药数量(不考虑枪内弹药)
|
||||
*/
|
||||
public int countBackupAmmo(Player player) {
|
||||
if (player.isCreative() || InventoryTool.hasCreativeAmmoBox(player)) return Integer.MAX_VALUE;
|
||||
|
||||
var info = ammoTypeInfo();
|
||||
|
@ -329,7 +335,10 @@ public class GunData {
|
|||
};
|
||||
}
|
||||
|
||||
public void consumeAmmo(Player player, int count) {
|
||||
/**
|
||||
* 消耗额外弹药(不影响枪内弹药)
|
||||
*/
|
||||
public void consumeBackupAmmo(Player player, int count) {
|
||||
if (player.isCreative() || InventoryTool.hasCreativeAmmoBox(player)) return;
|
||||
|
||||
var info = ammoTypeInfo();
|
||||
|
@ -367,10 +376,10 @@ public class GunData {
|
|||
bolt.needed.set(false);
|
||||
}
|
||||
|
||||
var available = countAmmo(player);
|
||||
var available = countBackupAmmo(player);
|
||||
var ammoToAdd = Math.min(ammoNeeded, available);
|
||||
|
||||
consumeAmmo(player, ammoToAdd);
|
||||
consumeBackupAmmo(player, ammoToAdd);
|
||||
this.ammo.set(ammo + ammoToAdd);
|
||||
|
||||
reload.setState(ReloadState.NOT_RELOADING);
|
||||
|
|
|
@ -160,7 +160,7 @@ public class MinigunItem extends GunItem implements GeoItem {
|
|||
public void onShoot(GunData data, Player player, double spread, boolean zoom) {
|
||||
var tag = data.tag();
|
||||
|
||||
if (!data.hasAmmo(player)) return;
|
||||
if (!data.hasBackupAmmo(player)) return;
|
||||
|
||||
// TODO 替换为通用过热处理
|
||||
tag.putDouble("heat", (tag.getDouble("heat") + 0.1));
|
||||
|
@ -188,7 +188,7 @@ public class MinigunItem extends GunItem implements GeoItem {
|
|||
}
|
||||
|
||||
shootBullet(player, data, spread, zoom);
|
||||
data.consumeAmmo(player, 1);
|
||||
data.consumeBackupAmmo(player, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage;
|
|||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
@ -98,14 +97,12 @@ public class BocekItem extends GunItem implements GeoItem {
|
|||
var data = GunData.from(stack);
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
if (GunsTool.getGunIntTag(GunData.from(stack).tag, "ArrowEmpty") > 0) {
|
||||
GunsTool.setGunIntTag(GunData.from(stack).tag, "ArrowEmpty", GunsTool.getGunIntTag(GunData.from(stack).tag, "ArrowEmpty") - 1);
|
||||
if (GunsTool.getGunIntTag(data.tag, "ArrowEmpty") > 0) {
|
||||
GunsTool.setGunIntTag(data.tag, "ArrowEmpty", GunsTool.getGunIntTag(data.tag, "ArrowEmpty") - 1);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunIntTag(GunData.from(stack).tag, "ArrowEmpty") == 0 && data.ammo.get() == 0 && (data.countAmmo(player) > 0 || InventoryTool.hasCreativeAmmoBox(player))) {
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
data.consumeAmmo(player, 1);
|
||||
}
|
||||
if (GunsTool.getGunIntTag(data.tag, "ArrowEmpty") == 0 && data.ammo.get() == 0 && data.hasBackupAmmo(player)) {
|
||||
data.consumeBackupAmmo(player, 1);
|
||||
data.ammo.set(1);
|
||||
}
|
||||
data.save();
|
||||
|
|
|
@ -17,7 +17,7 @@ public class NetworkRegistry {
|
|||
registrar.playToClient(GunsDataMessage.TYPE, GunsDataMessage.STREAM_CODEC, GunsDataMessage::handler);
|
||||
registrar.playToClient(ContainerDataMessage.TYPE, ContainerDataMessage.STREAM_CODEC, ContainerDataMessage::handler);
|
||||
registrar.playToClient(ShootClientMessage.TYPE, ShootClientMessage.STREAM_CODEC, ShootClientMessage::handler);
|
||||
registrar.playToClient(DrawClientMessage.TYPE, DrawClientMessage.STREAM_CODEC, DrawClientMessage::handler);
|
||||
registrar.playToClient(DrawClientMessage.TYPE, DrawClientMessage.STREAM_CODEC, (drawClientMessage, context) -> DrawClientMessage.handler());
|
||||
registrar.playToClient(ResetCameraTypeMessage.TYPE, ResetCameraTypeMessage.STREAM_CODEC, ResetCameraTypeMessage::handler);
|
||||
registrar.playToClient(RadarMenuOpenMessage.TYPE, RadarMenuOpenMessage.STREAM_CODEC, RadarMenuOpenMessage::handler);
|
||||
registrar.playToClient(RadarMenuCloseMessage.TYPE, RadarMenuCloseMessage.STREAM_CODEC, RadarMenuCloseMessage::handler);
|
||||
|
|
|
@ -6,7 +6,6 @@ import io.netty.buffer.ByteBuf;
|
|||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record DrawClientMessage(boolean draw) implements CustomPacketPayload {
|
||||
|
@ -18,8 +17,8 @@ public record DrawClientMessage(boolean draw) implements CustomPacketPayload {
|
|||
DrawClientMessage::new
|
||||
);
|
||||
|
||||
public static void handler(DrawClientMessage message, final IPayloadContext context) {
|
||||
ClientEventHandler.handleDrawMessage(message.draw, context);
|
||||
public static void handler() {
|
||||
ClientEventHandler.handleDrawMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,7 +49,7 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
boolean clipLoad = data.ammo.get() == 0 && gunItem.isClipReload(stack);
|
||||
|
||||
// 检查备弹
|
||||
if (!data.hasAmmo(player)) return;
|
||||
if (!data.hasBackupAmmo(player)) return;
|
||||
|
||||
if (canReload || clipLoad) {
|
||||
int magazine = data.magazine();
|
||||
|
|
Loading…
Add table
Reference in a new issue