优化部分代码

This commit is contained in:
17146 2025-01-14 19:18:23 +08:00
parent edd15e6a1d
commit fedf2734e5
7 changed files with 38 additions and 51 deletions

View file

@ -331,7 +331,7 @@ public class ClickHandler {
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
}
if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0 && stack.getOrCreateTag().getInt("ReloadTime") == 0) {
if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0 && GunsTool.getGunIntTag(stack, "ReloadTime") == 0) {
if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {
ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0));
}

View file

@ -103,8 +103,6 @@ public abstract class CameraMixin {
return transform.transform(new Vector4f(x, y, z, 1));
}
@Inject(method = "setup", at = @At("TAIL"))
public void ia$setup(BlockGetter area, Entity entity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) {
if (thirdPerson && entity.getVehicle() instanceof Mk42Entity) {

View file

@ -33,9 +33,7 @@ public class MouseHandlerMixin {
Minecraft mc = Minecraft.getInstance();
Player player = Minecraft.getInstance().player;
if (player == null) {
return original;
}
if (player == null) return original;
if (player.hasEffect(ModMobEffects.SHOCK.get()) && !player.isSpectator()) {
return 0;
@ -44,11 +42,7 @@ public class MouseHandlerMixin {
ItemStack stack = mc.player.getMainHandItem();
if (player.getVehicle() instanceof ICannonEntity) {
if (ClientEventHandler.zoom) {
return 0.15;
} else {
return 0.3;
}
return ClientEventHandler.zoom ? 0.15 : 0.3;
}
if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround() && ah6Entity.getFirstPassenger() == player) {
@ -56,11 +50,7 @@ public class MouseHandlerMixin {
}
if (player.getVehicle() instanceof Lav150Entity) {
if (ClientEventHandler.zoom) {
return 0.23;
} else {
return 0.28;
}
return ClientEventHandler.zoom ? 0.23 : 0.28;
}
if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
@ -36,6 +37,7 @@ public class EditMessage {
if (player == null) return;
ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return;
CompoundTag tag = stack.getOrCreateTag().getCompound("Attachments");
switch (type) {

View file

@ -83,13 +83,12 @@ public class FireMessage {
capability.syncPlayerVariables(player);
});
if (player.getMainHandItem().getItem() == ModItems.BOCEK.get()) {
if (stack.getItem() == ModItems.BOCEK.get()) {
handleBowShoot(player);
}
if (player.getMainHandItem().getItem() == ModItems.JAVELIN.get()) {
var handItem = player.getMainHandItem();
var tag = handItem.getOrCreateTag();
if (stack.getItem() == ModItems.JAVELIN.get()) {
var tag = stack.getOrCreateTag();
handleJavelinFire(player);
tag.putBoolean("Seeking", false);
tag.putInt("SeekTime", 0);

View file

@ -55,7 +55,6 @@ public class ReloadMessage {
&& GunsTool.getGunIntTag(stack, "ReloadTime") == 0
&& GunsTool.getGunIntTag(stack, "BoltActionTick") == 0
&& !GunsTool.getGunBooleanTag(stack, "Reloading")
) {
CompoundTag tag = stack.getOrCreateTag();

View file

@ -36,40 +36,39 @@ public class ZoomMessage {
NetworkEvent.Context context = contextSupplier.get();
context.enqueueWork(() -> {
ServerPlayer player = context.getSender();
if (player == null) return;
if (player != null) {
if (message.type == 0) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = true;
capability.edit = false;
capability.syncPlayerVariables(player);
});
if (message.type == 0) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = true;
capability.edit = false;
capability.syncPlayerVariables(player);
});
if (player.isPassenger() && player.getVehicle() instanceof IArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
}
if (player.isPassenger() && player.getVehicle() instanceof IArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
}
}
if (message.type == 1) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false;
capability.breath = false;
capability.syncPlayerVariables(player);
});
if (player.isPassenger() && player.getVehicle() instanceof IArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1);
}
if (message.type == 1) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false;
capability.breath = false;
capability.syncPlayerVariables(player);
});
if (player.isPassenger() && player.getVehicle() instanceof IArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1);
}
if (player.getMainHandItem().getItem() == ModItems.JAVELIN.get()) {
var handItem = player.getMainHandItem();
var tag = handItem.getOrCreateTag();
tag.putBoolean("Seeking", false);
tag.putInt("SeekTime", 0);
tag.putString("TargetEntity", "none");
var clientboundstopsoundpacket = new ClientboundStopSoundPacket(new ResourceLocation(ModUtils.MODID, "javelin_lock"), SoundSource.PLAYERS);
player.connection.send(clientboundstopsoundpacket);
}
if (player.getMainHandItem().getItem() == ModItems.JAVELIN.get()) {
var handItem = player.getMainHandItem();
var tag = handItem.getOrCreateTag();
tag.putBoolean("Seeking", false);
tag.putInt("SeekTime", 0);
tag.putString("TargetEntity", "none");
var clientboundstopsoundpacket = new ClientboundStopSoundPacket(new ResourceLocation(ModUtils.MODID, "javelin_lock"), SoundSource.PLAYERS);
player.connection.send(clientboundstopsoundpacket);
}
}
});