正确实现PlayerVariables,优化同步机制
This commit is contained in:
parent
392a72aa93
commit
6910646584
50 changed files with 333 additions and 413 deletions
|
@ -56,6 +56,7 @@ public class Mod {
|
|||
ModArmorMaterials.MATERIALS.register(bus);
|
||||
ModAttributes.ATTRIBUTES.register(bus);
|
||||
ModCriteriaTriggers.REGISTRY.register(bus);
|
||||
ModAttachments.ATTACHMENT_TYPES.register(bus);
|
||||
|
||||
// bus.addListener(this::onCommonSetup);
|
||||
bus.addListener(this::onClientSetup);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.atsuishio.superbwarfare.block;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
@ -124,10 +124,10 @@ public class JumpPadBlock extends Block {
|
|||
level.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), ModSounds.JUMP.get(), SoundSource.BLOCKS, 1, 1, false);
|
||||
}
|
||||
|
||||
var capability = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (capability != null) {
|
||||
capability.playerDoubleJump = true;
|
||||
capability.syncPlayerVariables(entity);
|
||||
}
|
||||
var capability = entity.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
capability.playerDoubleJump = true;
|
||||
|
||||
entity.setData(ModAttachments.PLAYER_VARIABLE, capability);
|
||||
capability.sync(entity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
package com.atsuishio.superbwarfare.capability.player;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.PlayerVariablesSyncMessage;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.common.util.INBTSerializable;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
|
||||
// TODO 在退出世界时正确持久化弹药数量
|
||||
@EventBusSubscriber(modid = Mod.MODID)
|
||||
public class PlayerVariable {
|
||||
public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
||||
private PlayerVariable old = null;
|
||||
|
||||
public boolean zoom = false;
|
||||
public boolean holdFire = false;
|
||||
public int rifleAmmo = 0;
|
||||
|
@ -34,12 +40,29 @@ public class PlayerVariable {
|
|||
public boolean breathExhaustion = false;
|
||||
public boolean edit = false;
|
||||
|
||||
public void syncPlayerVariables(Entity entity) {
|
||||
public void sync(Entity entity) {
|
||||
if (!entity.hasData(ModAttachments.PLAYER_VARIABLE)) return;
|
||||
|
||||
var newVariable = entity.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (old != null && old.equals(newVariable)) return;
|
||||
|
||||
if (entity instanceof ServerPlayer) {
|
||||
PacketDistributor.sendToAllPlayers(new PlayerVariablesSyncMessage(entity.getId(), this.writeToNBT()));
|
||||
PacketDistributor.sendToAllPlayers(new PlayerVariablesSyncMessage(entity.getId(), newVariable.writeToNBT()));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (!(event.getEntity() instanceof ServerPlayer player)) return;
|
||||
|
||||
PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).writeToNBT()));
|
||||
}
|
||||
|
||||
public PlayerVariable watch() {
|
||||
this.old = this.copy();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompoundTag writeToNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putBoolean("Zoom", zoom);
|
||||
|
@ -63,86 +86,92 @@ public class PlayerVariable {
|
|||
return nbt;
|
||||
}
|
||||
|
||||
public PlayerVariable readFromNBT(Tag tag) {
|
||||
CompoundTag nbt = (CompoundTag) tag;
|
||||
|
||||
zoom = nbt.getBoolean("Zoom");
|
||||
holdFire = nbt.getBoolean("HoldFire");
|
||||
public PlayerVariable readFromNBT(CompoundTag tag) {
|
||||
zoom = tag.getBoolean("Zoom");
|
||||
holdFire = tag.getBoolean("HoldFire");
|
||||
|
||||
for (var type : AmmoType.values()) {
|
||||
type.set(this, type.get(nbt));
|
||||
type.set(this, type.get(tag));
|
||||
}
|
||||
|
||||
bowPullHold = nbt.getBoolean("BowPullHold");
|
||||
bowPull = nbt.getBoolean("BowPull");
|
||||
playerDoubleJump = nbt.getBoolean("DoubleJump");
|
||||
tacticalSprint = nbt.getBoolean("TacticalSprint");
|
||||
tacticalSprintTime = nbt.getInt("TacticalSprintTime");
|
||||
tacticalSprintExhaustion = nbt.getBoolean("TacticalSprintExhaustion");
|
||||
breath = nbt.getBoolean("Breath");
|
||||
breathTime = nbt.getInt("BreathTime");
|
||||
breathExhaustion = nbt.getBoolean("BreathExhaustion");
|
||||
edit = nbt.getBoolean("EditMode");
|
||||
bowPullHold = tag.getBoolean("BowPullHold");
|
||||
bowPull = tag.getBoolean("BowPull");
|
||||
playerDoubleJump = tag.getBoolean("DoubleJump");
|
||||
tacticalSprint = tag.getBoolean("TacticalSprint");
|
||||
tacticalSprintTime = tag.getInt("TacticalSprintTime");
|
||||
tacticalSprintExhaustion = tag.getBoolean("TacticalSprintExhaustion");
|
||||
breath = tag.getBoolean("Breath");
|
||||
breathTime = tag.getInt("BreathTime");
|
||||
breathExhaustion = tag.getBoolean("BreathExhaustion");
|
||||
edit = tag.getBoolean("EditMode");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedInSyncPlayerVariables(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (event.getEntity().level().isClientSide()) return;
|
||||
public PlayerVariable copy() {
|
||||
var clone = new PlayerVariable();
|
||||
|
||||
var player = event.getEntity();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (cap != null) cap.syncPlayerVariables(player);
|
||||
clone.zoom = this.zoom;
|
||||
clone.holdFire = this.holdFire;
|
||||
clone.rifleAmmo = this.rifleAmmo;
|
||||
clone.handgunAmmo = this.handgunAmmo;
|
||||
clone.shotgunAmmo = this.shotgunAmmo;
|
||||
clone.sniperAmmo = this.sniperAmmo;
|
||||
clone.heavyAmmo = this.heavyAmmo;
|
||||
clone.bowPullHold = this.bowPullHold;
|
||||
clone.bowPull = this.bowPull;
|
||||
clone.playerDoubleJump = this.playerDoubleJump;
|
||||
clone.tacticalSprint = this.tacticalSprint;
|
||||
clone.tacticalSprintTime = this.tacticalSprintTime;
|
||||
clone.tacticalSprintExhaustion = this.tacticalSprintExhaustion;
|
||||
clone.breath = this.breath;
|
||||
clone.breathTime = this.breathTime;
|
||||
clone.breathExhaustion = this.breathExhaustion;
|
||||
clone.edit = this.edit;
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerRespawnedSyncPlayerVariables(PlayerEvent.PlayerRespawnEvent event) {
|
||||
if (event.getEntity().level().isClientSide()) return;
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof PlayerVariable other)) return false;
|
||||
|
||||
var player = event.getEntity();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (cap != null) cap.syncPlayerVariables(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerChangedDimensionSyncPlayerVariables(PlayerEvent.PlayerChangedDimensionEvent event) {
|
||||
if (event.getEntity().level().isClientSide()) return;
|
||||
|
||||
var player = event.getEntity();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (cap != null) cap.syncPlayerVariables(player);
|
||||
return zoom == other.zoom
|
||||
&& holdFire == other.holdFire
|
||||
&& rifleAmmo == other.rifleAmmo
|
||||
&& handgunAmmo == other.handgunAmmo
|
||||
&& shotgunAmmo == other.shotgunAmmo
|
||||
&& sniperAmmo == other.sniperAmmo
|
||||
&& heavyAmmo == other.heavyAmmo
|
||||
&& bowPullHold == other.bowPullHold
|
||||
&& bowPull == other.bowPull
|
||||
&& playerDoubleJump == other.playerDoubleJump
|
||||
&& tacticalSprint == other.tacticalSprint
|
||||
// && tacticalSprintTime == other.tacticalSprintTime
|
||||
&& tacticalSprintExhaustion == other.tacticalSprintExhaustion
|
||||
&& breath == other.breath
|
||||
// && breathTime == other.breathTime
|
||||
&& breathExhaustion == other.breathExhaustion
|
||||
&& edit == other.edit;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void clonePlayer(PlayerEvent.Clone event) {
|
||||
event.getOriginal().revive();
|
||||
var original = event.getOriginal().getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
var clone = event.getEntity().getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (clone == null || original == null) return;
|
||||
|
||||
clone.zoom = original.zoom;
|
||||
clone.holdFire = original.holdFire;
|
||||
clone.rifleAmmo = original.rifleAmmo;
|
||||
clone.handgunAmmo = original.handgunAmmo;
|
||||
clone.shotgunAmmo = original.shotgunAmmo;
|
||||
clone.sniperAmmo = original.sniperAmmo;
|
||||
clone.heavyAmmo = original.heavyAmmo;
|
||||
clone.bowPullHold = original.bowPullHold;
|
||||
clone.bowPull = original.bowPull;
|
||||
clone.playerDoubleJump = original.playerDoubleJump;
|
||||
clone.tacticalSprint = original.tacticalSprint;
|
||||
clone.tacticalSprintTime = original.tacticalSprintTime;
|
||||
clone.tacticalSprintExhaustion = original.tacticalSprintExhaustion;
|
||||
clone.breath = original.breath;
|
||||
clone.breathTime = original.breathTime;
|
||||
clone.breathExhaustion = original.breathExhaustion;
|
||||
clone.edit = original.edit;
|
||||
|
||||
var original = event.getOriginal().getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (event.getEntity().level().isClientSide()) return;
|
||||
|
||||
var player = event.getEntity();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (cap != null) cap.syncPlayerVariables(player);
|
||||
event.getEntity().setData(ModAttachments.PLAYER_VARIABLE, original.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT(HolderLookup.@NotNull Provider provider) {
|
||||
return writeToNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
|
||||
readFromNBT(nbt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.config.client.ReloadConfig;
|
||||
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
|
@ -224,8 +223,7 @@ public class ClickHandler {
|
|||
PacketDistributor.sendToServer(new EditModeMessage(0));
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
if (ModKeyMappings.EDIT_GRIP.getKeyModifier().isActive(KeyConflictContext.IN_GAME)) {
|
||||
if (key == ModKeyMappings.EDIT_GRIP.getKey().getValue() && gunItem.hasCustomGrip(stack)) {
|
||||
|
@ -402,8 +400,7 @@ public class ClickHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.playerDoubleJump) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).playerDoubleJump) {
|
||||
player.setDeltaMovement(new Vec3(player.getLookAngle().x, 0.8, player.getLookAngle().z));
|
||||
level.playLocalSound(x, y, z, ModSounds.DOUBLE_JUMP.get(), SoundSource.BLOCKS, 1, 1, false);
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||
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.ModKeyMappings;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
|
@ -47,8 +46,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() == ModItems.MINIGUN.get()) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
return cap != null ? cap.rifleAmmo : 0;
|
||||
return player.getData(ModAttachments.PLAYER_VARIABLE).rifleAmmo;
|
||||
}
|
||||
|
||||
if (stack.getItem() == ModItems.BOCEK.get()) {
|
||||
|
@ -65,8 +63,7 @@ public class AmmoBarOverlay implements LayeredDraw.Layer {
|
|||
return "";
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) cap = new PlayerVariable();
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (!hasCreativeAmmo()) {
|
||||
var data = GunData.from(stack);
|
||||
if (stack.is(ModTags.Items.LAUNCHER) || stack.getItem() == ModItems.TASER.get()) {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
|
@ -87,8 +86,7 @@ public class AmmoCountOverlay implements LayeredDraw.Layer {
|
|||
var yOffset = (-h - AmmoType.values().length * fontHeight) / 2f;
|
||||
|
||||
// 渲染总弹药数量
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) cap = new PlayerVariable();
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
var font = Minecraft.getInstance().font;
|
||||
|
||||
for (var type : AmmoType.values()) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBoxInfo;
|
||||
|
@ -82,8 +82,7 @@ public class AmmoOverlay {
|
|||
var yOffset = (-h - AmmoType.values().length * fontHeight) / 2f;
|
||||
|
||||
// 渲染总弹药数量
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
var font = Minecraft.getInstance().font;
|
||||
|
||||
for (var type : AmmoType.values()) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -54,8 +54,7 @@ public class CrossHairOverlay {
|
|||
return;
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) return;
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
|
||||
if (!player.getMainHandItem().is(ModTags.Items.GUN) || (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)))
|
||||
return;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
@ -28,8 +28,8 @@ public class GrenadeLauncherOverlay {
|
|||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null || cap.edit) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (cap.edit) return;
|
||||
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -43,8 +43,7 @@ public class HandsomeFrameOverlay {
|
|||
|
||||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null || cap.edit) return;
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity;
|
||||
|
@ -9,6 +8,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
|||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
|
@ -59,8 +59,7 @@ public class HelicopterHudOverlay {
|
|||
|
||||
if (player == null) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null || cap.edit) return;
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
|
||||
if (player.getVehicle() instanceof HelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && player.getVehicle() instanceof WeaponVehicleEntity weaponVehicle) {
|
||||
poseStack.pushPose();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
|
@ -49,8 +49,7 @@ public class JavelinHudOverlay {
|
|||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null || cap.edit) return;
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.entity;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
|
@ -145,9 +145,7 @@ public class TargetEntity extends LivingEntity implements GeoEntity {
|
|||
player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get()));
|
||||
}
|
||||
} else {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
|
||||
if (cap != null && !cap.zoom) {
|
||||
if (!player.getData(ModAttachments.PLAYER_VARIABLE).zoom) {
|
||||
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
|
||||
this.setXRot(0);
|
||||
this.xRotO = this.getXRot();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.event;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.*;
|
||||
|
@ -305,17 +304,18 @@ public class ClientEventHandler {
|
|||
public static void handleGunMelee(Player player, ItemStack stack) {
|
||||
if (stack.getItem() instanceof GunItem gunItem) {
|
||||
var data = GunData.from(stack);
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (gunItem.hasMeleeAttack(stack) && gunMelee == 0 && drawTime < 0.01
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (gunItem.hasMeleeAttack(stack)
|
||||
&& gunMelee == 0
|
||||
&& drawTime < 0.01
|
||||
&& ModKeyMappings.MELEE.isDown()
|
||||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
&& !holdFireVehicle
|
||||
&& !notInGame()
|
||||
&& cap != null && !cap.edit
|
||||
&& !cap.edit
|
||||
&& !(data.reload.normal() || data.reload.empty())
|
||||
&& !data.reloading()
|
||||
&& !data.charging()
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !data.charging() && !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
) {
|
||||
gunMelee = 36;
|
||||
cantFireTime = 40;
|
||||
|
@ -464,7 +464,7 @@ public class ClientEventHandler {
|
|||
revolverPreTime = Mth.clamp(revolverPreTime - 1.2 * times, 0, 1);
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if ((holdFire || burstFireAmount > 0)
|
||||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
|
@ -472,7 +472,7 @@ public class ClientEventHandler {
|
|||
&& (stack.is(ModTags.Items.NORMAL_GUN)
|
||||
&& cantFireTime == 0
|
||||
&& drawTime < 0.01
|
||||
&& cap != null && !cap.edit
|
||||
&& !cap.edit
|
||||
&& !notInGame()
|
||||
&& (!(data.reload.normal() || data.reload.empty())
|
||||
&& !data.reloading()
|
||||
|
@ -485,7 +485,7 @@ public class ClientEventHandler {
|
|||
&& !player.isSprinting()
|
||||
&& tag.getDouble("overheat") == 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && miniGunRot >= 20
|
||||
&& (cap != null && cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player))
|
||||
&& (cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player))
|
||||
))) {
|
||||
if (mode == 0) {
|
||||
if (clientTimer.getProgress() == 0) {
|
||||
|
@ -594,12 +594,11 @@ public class ClientEventHandler {
|
|||
revolverPreTime = 0;
|
||||
revolverWheelPreTime = 0;
|
||||
|
||||
playGunClientSounds(player, tag);
|
||||
playGunClientSounds(player);
|
||||
handleClientShoot();
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(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")));
|
||||
|
||||
|
@ -661,7 +660,7 @@ public class ClientEventHandler {
|
|||
shakeType = 2 * (Math.random() - 0.5);
|
||||
}
|
||||
|
||||
public static void playGunClientSounds(Player player, final CompoundTag tag) {
|
||||
public static void playGunClientSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
|
@ -849,9 +848,9 @@ public class ClientEventHandler {
|
|||
|
||||
double customWeight = data.customWeight();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (cap != null && !cap.breath && cap.zoom) {
|
||||
if (!cap.breath && cap.zoom) {
|
||||
float newPitch = (float) (player.getXRot() - 0.01f * Mth.sin((float) (0.03 * player.tickCount)) * pose * Mth.nextDouble(RandomSource.create(), 0.1, 1) * times * sway * (1 - 0.03 * customWeight));
|
||||
player.setXRot(newPitch);
|
||||
player.xRotO = player.getXRot();
|
||||
|
@ -1017,8 +1016,7 @@ public class ClientEventHandler {
|
|||
onGround = 0.001;
|
||||
}
|
||||
|
||||
var cap = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && !cap.edit) {
|
||||
if (!entity.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (Minecraft.getInstance().options.keyUp.isDown() && firePosTimer == 0) {
|
||||
moveRotZ = Mth.lerp(0.2f * times, moveRotZ, 0.14) * (1 - zoomTime);
|
||||
} else {
|
||||
|
@ -1073,12 +1071,12 @@ public class ClientEventHandler {
|
|||
double weight = data.weight();
|
||||
double speed = 1.5 - (0.07 * weight);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (zoom
|
||||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
&& !notInGame()
|
||||
&& drawTime < 0.01
|
||||
&& cap != null && !cap.edit) {
|
||||
&& !cap.edit) {
|
||||
if (Minecraft.getInstance().player != null) {
|
||||
Minecraft.getInstance().player.getPersistentData().putDouble("noRun", 5);
|
||||
}
|
||||
|
@ -1281,8 +1279,7 @@ public class ClientEventHandler {
|
|||
|
||||
private static void handlePlayerBreath(LivingEntity entity) {
|
||||
float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
|
||||
var cap = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean breath = cap != null && cap.breath;
|
||||
boolean breath = entity.getData(ModAttachments.PLAYER_VARIABLE).breath;
|
||||
|
||||
breathTime = Mth.lerp(0.2f * times, breathTime, breath ? 1 : 0);
|
||||
}
|
||||
|
@ -1353,8 +1350,7 @@ public class ClientEventHandler {
|
|||
private static void handleBowPullAnimation(LivingEntity entity) {
|
||||
float times = 4 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
|
||||
|
||||
var cap = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.bowPull) {
|
||||
if (entity.getData(ModAttachments.PLAYER_VARIABLE).bowPull) {
|
||||
pullTimer = Math.min(pullTimer + 0.024 * times, 1.4);
|
||||
bowTimer = Math.min(bowTimer + 0.018 * times, 1);
|
||||
handTimer = Math.min(handTimer + 0.018 * times, 1);
|
||||
|
@ -1410,14 +1406,11 @@ public class ClientEventHandler {
|
|||
event.setFOV(event.getFOV() / (1.0 + p * 0.01) * (1 - 0.4 * breathTime));
|
||||
fov = event.getFOV();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
||||
// 智慧芯片
|
||||
if (zoom
|
||||
&& !notInGame()
|
||||
&& drawTime < 0.01
|
||||
&& cap != null
|
||||
&& !cap.edit) {
|
||||
&& !player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (!player.isShiftKeyDown()) {
|
||||
int intelligentChipLevel = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP);
|
||||
|
||||
|
@ -1549,8 +1542,7 @@ public class ClientEventHandler {
|
|||
public static void aimAtVillager(Player player) {
|
||||
if (aimVillagerCountdown > 0) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.zoom) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).zoom) {
|
||||
Entity entity = TraceTool.findLookingEntity(player, 10);
|
||||
if (entity instanceof AbstractVillager villager) {
|
||||
List<Entity> entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120);
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.event;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||
import com.atsuishio.superbwarfare.event.events.ReloadEvent;
|
||||
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.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.AttachmentType;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -188,8 +183,7 @@ public class GunEventHandler {
|
|||
float velocity = (float) ((data.velocity() + GunsTool.getGunDoubleTag(tag, "CustomVelocity")) * perkSpeed(data));
|
||||
int projectileAmount = data.projectileAmount();
|
||||
float bypassArmorRate = (float) data.bypassArmor();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||
var perkInstance = data.perk.getInstance(Perk.Type.AMMO);
|
||||
var perk = perkInstance != null ? perkInstance.perk() : null;
|
||||
|
||||
|
@ -557,8 +551,7 @@ public class GunEventHandler {
|
|||
// 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段
|
||||
if ((tag.getDouble("PrepareTime") == 1 || tag.getDouble("PrepareLoadTime") == 1)) {
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (capability == null) capability = new PlayerVariable();
|
||||
var capability = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) {
|
||||
tag.putBoolean("ForceStartStage3", true);
|
||||
|
@ -640,8 +633,7 @@ public class GunEventHandler {
|
|||
|
||||
// 备弹耗尽结束
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (capability == null) capability = new PlayerVariable();
|
||||
var capability = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) {
|
||||
gunData.reload.setStage(3);
|
||||
|
@ -695,8 +687,7 @@ public class GunEventHandler {
|
|||
data.setAmmo(data.ammo() + 1);
|
||||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
|
@ -713,7 +704,7 @@ public class GunEventHandler {
|
|||
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
|
||||
}
|
||||
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.atsuishio.superbwarfare.event;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.config.common.GameplayConfig;
|
||||
import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
||||
|
@ -216,7 +214,6 @@ public class LivingEventHandler {
|
|||
|
||||
var data = GunData.from(stack);
|
||||
double amount = Math.min(0.125 * event.getAmount(), event.getEntity().getMaxHealth());
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
|
||||
// 先处理发射器类武器或高爆弹的爆炸伤害
|
||||
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
|
||||
|
@ -385,11 +382,10 @@ public class LivingEventHandler {
|
|||
oldData.charge.reset();
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.edit = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.edit = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
oldData.save();
|
||||
}
|
||||
|
@ -433,11 +429,10 @@ public class LivingEventHandler {
|
|||
PacketDistributor.sendToPlayer(serverPlayer, new DrawClientMessage(true));
|
||||
}
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.tacticalSprint = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
newData.save();
|
||||
}
|
||||
|
@ -608,7 +603,6 @@ public class LivingEventHandler {
|
|||
|
||||
private static void handleKillingTallyDamage(ItemStack stack, LivingIncomingDamageEvent event) {
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.tag();
|
||||
int level = data.perk.getLevel(ModPerks.KILLING_TALLY);
|
||||
if (level == 0) return;
|
||||
|
||||
|
@ -657,8 +651,7 @@ public class LivingEventHandler {
|
|||
|
||||
float rate = level * 0.1f + (stack.is(ModTags.Items.SMG) || stack.is(ModTags.Items.RIFLE) ? 0.07f : 0f);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
int mag = data.magazine();
|
||||
int ammo = data.ammo();
|
||||
|
@ -685,7 +678,8 @@ public class LivingEventHandler {
|
|||
data.setAmmo(Math.min(mag, ammo + ammoFinal));
|
||||
}
|
||||
data.save();
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
|
||||
|
||||
|
@ -746,8 +740,7 @@ public class LivingEventHandler {
|
|||
public static void onLivingDrops(LivingDropsEvent event) {
|
||||
// 死亡掉落弹药盒
|
||||
if (event.getEntity() instanceof Player player && !player.level().getLevelData().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) cap = new PlayerVariable();
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
boolean drop = cap.rifleAmmo + cap.handgunAmmo + cap.shotgunAmmo + cap.sniperAmmo + cap.heavyAmmo > 0;
|
||||
|
||||
|
@ -762,7 +755,8 @@ public class LivingEventHandler {
|
|||
var info = new AmmoBoxInfo("All", true);
|
||||
stack.set(ModDataComponents.AMMO_BOX_INFO, info);
|
||||
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
event.getDrops().add(new ItemEntity(player.level(), player.getX(), player.getY() + 1, player.getZ(), stack));
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.atsuishio.superbwarfare.event;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.config.common.GameplayConfig;
|
||||
import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
|
@ -52,13 +52,12 @@ public class PlayerEventHandler {
|
|||
public static void onPlayerRespawned(PlayerEvent.PlayerRespawnEvent event) {
|
||||
Player player = event.getEntity();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.zoom = false;
|
||||
cap.tacticalSprintExhaustion = false;
|
||||
cap.tacticalSprintTime = 600;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.zoom = false;
|
||||
cap.tacticalSprintExhaustion = false;
|
||||
cap.tacticalSprintTime = 600;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
handleRespawnReload(player);
|
||||
handleRespawnAutoArmor(player);
|
||||
|
@ -79,6 +78,7 @@ public class PlayerEventHandler {
|
|||
public static void onPlayerTick(PlayerTickEvent.Post event) {
|
||||
Player player = event.getEntity();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var variable = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (stack.is(ModTags.Items.GUN)) {
|
||||
handlePlayerSprint(player);
|
||||
|
@ -90,11 +90,12 @@ public class PlayerEventHandler {
|
|||
handleSimulationDistance(player);
|
||||
handleTacticalSprint(player);
|
||||
handleBreath(player);
|
||||
|
||||
variable.sync(player);
|
||||
}
|
||||
|
||||
private static void handleBreath(Player player) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (cap.breath) {
|
||||
cap.breathTime = Mth.clamp(cap.breathTime - 1, 0, 100);
|
||||
|
@ -111,12 +112,11 @@ public class PlayerEventHandler {
|
|||
cap.breathExhaustion = false;
|
||||
}
|
||||
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
}
|
||||
|
||||
private static void handleTacticalSprint(Player player) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
int sprintCost;
|
||||
|
@ -161,15 +161,14 @@ public class PlayerEventHandler {
|
|||
player.getPersistentData().putBoolean("canTacticalSprint", true);
|
||||
}
|
||||
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断玩家是否在奔跑
|
||||
*/
|
||||
private static void handlePlayerSprint(Player player) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (cap.holdFire) {
|
||||
player.getPersistentData().putDouble("noRun", 10);
|
||||
|
@ -191,12 +190,11 @@ public class PlayerEventHandler {
|
|||
}
|
||||
|
||||
private static void handleGround(Player player) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (player.onGround()) {
|
||||
cap.playerDoubleJump = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,15 +206,13 @@ public class PlayerEventHandler {
|
|||
|
||||
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && data.ammo() == 1) {
|
||||
tag.remove("IsEmpty");
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleBocekPulling(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
var data = GunData.from(stack);
|
||||
final var tag = data.tag();
|
||||
|
@ -231,7 +227,7 @@ public class PlayerEventHandler {
|
|||
|
||||
cap.bowPull = true;
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
player.setSprinting(false);
|
||||
}
|
||||
if (GunsTool.getGunDoubleTag(tag, "Power") == 1) {
|
||||
|
@ -245,15 +241,16 @@ public class PlayerEventHandler {
|
|||
GunsTool.setGunDoubleTag(tag, "Power", 0);
|
||||
}
|
||||
cap.bowPull = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
}
|
||||
|
||||
if (GunsTool.getGunDoubleTag(tag, "Power") > 0) {
|
||||
cap.tacticalSprint = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
player.setSprinting(false);
|
||||
}
|
||||
|
||||
cap.sync(player);
|
||||
data.save();
|
||||
}
|
||||
|
||||
|
@ -277,8 +274,7 @@ public class PlayerEventHandler {
|
|||
var tag = data.tag();
|
||||
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && cap.shotgunAmmo > 0) {
|
||||
GunsTool.reload(player, stack, data, AmmoType.SHOTGUN);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.atsuishio.superbwarfare.init;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ModAttachments {
|
||||
public static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, Mod.MODID);
|
||||
|
||||
|
||||
public static final Supplier<AttachmentType<PlayerVariable>> PLAYER_VARIABLE = ATTACHMENT_TYPES.register(
|
||||
"player_variable", () -> AttachmentType.serializable(PlayerVariable::new).build()
|
||||
);
|
||||
|
||||
}
|
|
@ -7,8 +7,6 @@ import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
|||
import com.atsuishio.superbwarfare.capability.energy.ItemEnergyStorage;
|
||||
import com.atsuishio.superbwarfare.capability.laser.LaserCapability;
|
||||
import com.atsuishio.superbwarfare.capability.laser.LaserCapabilityProvider;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariablesProvider;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.EnergyVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.item.CreativeChargingStationBlockItem;
|
||||
|
@ -32,13 +30,11 @@ import java.util.ArrayList;
|
|||
public class ModCapabilities {
|
||||
|
||||
public static final EntityCapability<LaserCapability, Void> LASER_CAPABILITY = EntityCapability.createVoid(Mod.loc("laser_capability"), LaserCapability.class);
|
||||
public static final EntityCapability<PlayerVariable, Void> PLAYER_VARIABLE = EntityCapability.createVoid(Mod.loc("player_variable"), PlayerVariable.class);
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerCapabilities(RegisterCapabilitiesEvent event) {
|
||||
// 玩家变量和激光
|
||||
// 激光
|
||||
event.registerEntity(ModCapabilities.LASER_CAPABILITY, EntityType.PLAYER, new LaserCapabilityProvider());
|
||||
event.registerEntity(ModCapabilities.PLAYER_VARIABLE, EntityType.PLAYER, new PlayerVariablesProvider());
|
||||
|
||||
// 充电站
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.CHARGING_STATION.value(), ChargingStationBlockEntity::getEnergyStorage);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.laser.LaserHandler;
|
||||
import com.atsuishio.superbwarfare.client.TooltipTool;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.LaserEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.send.LaserShootMessage;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.item.common.ammo;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
|
@ -49,12 +49,11 @@ public class AmmoSupplierItem extends Item {
|
|||
if (offhandItem.is(ModItems.AMMO_BOX.get())) {
|
||||
this.type.add(offhandItem, ammoToAdd * count);
|
||||
} else {
|
||||
var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
var capability = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (capability != null) {
|
||||
this.type.add(capability, ammoToAdd * count);
|
||||
capability.syncPlayerVariables(player);
|
||||
}
|
||||
this.type.add(capability, ammoToAdd * count);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, capability);
|
||||
capability.sync(player);
|
||||
}
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.item.common.ammo.box;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
|
@ -41,8 +41,8 @@ public class AmmoBox extends Item {
|
|||
if (info == null) info = new AmmoBoxInfo("All", false);
|
||||
String selectedType = info.type();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (cap != null && !level.isClientSide()) {
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
if (!level.isClientSide()) {
|
||||
var types = selectedType.equals("All") ? AmmoType.values() : new AmmoType[]{AmmoType.getType(selectedType)};
|
||||
|
||||
for (var type : types) {
|
||||
|
@ -58,7 +58,8 @@ public class AmmoBox extends Item {
|
|||
type.set(stack, 0);
|
||||
}
|
||||
}
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
level.playSound(null, player.blockPosition(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 1, 1);
|
||||
|
||||
// 取出弹药时,若弹药盒为掉落物版本,则移除弹药盒物品
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.PoseTool;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
|
@ -83,21 +83,20 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
if ((hasBulletInBarrel && ammoCount > magazine + 1) || (!hasBulletInBarrel && ammoCount > magazine)) {
|
||||
int count = ammoCount - magazine - (hasBulletInBarrel ? 1 : 0);
|
||||
|
||||
var capability = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (capability != null) {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
AmmoType.SHOTGUN.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
AmmoType.SNIPER.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
AmmoType.HANDGUN.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
AmmoType.RIFLE.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
AmmoType.HEAVY.add(capability, count);
|
||||
}
|
||||
capability.syncPlayerVariables(entity);
|
||||
var capability = entity.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) {
|
||||
AmmoType.SHOTGUN.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) {
|
||||
AmmoType.SNIPER.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
|
||||
AmmoType.HANDGUN.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
|
||||
AmmoType.RIFLE.add(capability, count);
|
||||
} else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) {
|
||||
AmmoType.HEAVY.add(capability, count);
|
||||
}
|
||||
entity.setData(ModAttachments.PLAYER_VARIABLE, capability);
|
||||
capability.sync(entity);
|
||||
data.setAmmo(magazine + (hasBulletInBarrel ? 1 : 0));
|
||||
}
|
||||
data.save();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.handgun;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.TooltipTool;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.TracheliumItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -194,8 +194,7 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.trachelium.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.heavy;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.Ntw20Renderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModRarity;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
|
@ -101,8 +101,7 @@ public class Ntw20Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.launcher;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.JavelinItemRenderer;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.FlareDecoyEntity;
|
||||
|
@ -310,8 +309,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
public void fireOnPress(Player player, final GunData data) {
|
||||
var tag = data.tag();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && !cap.zoom || data.ammo() <= 0) return;
|
||||
if (!player.getData(ModAttachments.PLAYER_VARIABLE).zoom || data.ammo() <= 0) return;
|
||||
|
||||
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.launcher;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.M79ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
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.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -175,9 +171,7 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
ItemStack stack = data.stack();
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return;
|
||||
|
||||
var tag = data.tag();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zooming = cap != null && cap.zoom;
|
||||
boolean zooming = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||
double spread = data.spread();
|
||||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.launcher;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.RpgItemRenderer;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
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.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -190,8 +186,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
|| data.ammo() <= 0
|
||||
) return;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||
double spread = data.spread();
|
||||
|
||||
if (player.level() instanceof ServerLevel serverLevel) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.launcher;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.SecondaryCataclysmRenderer;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.SecondaryCataclysmImageComponent;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
|
||||
|
@ -274,9 +273,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
|
|||
ItemStack stack = data.stack();
|
||||
if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return;
|
||||
|
||||
var tag = data.tag();
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zooming = cap != null && cap.zoom;
|
||||
boolean zooming = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||
double spread = data.spread();
|
||||
|
||||
var stackCap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.machinegun;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.RpkItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
|
@ -118,8 +118,7 @@ public class RpkItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.AK12ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -111,8 +111,7 @@ public class AK12Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak12.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.AK47ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -119,8 +119,7 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.Hk416ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -114,8 +114,7 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.M4ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -115,8 +115,7 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.Mk14ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -114,8 +114,7 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m14.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.rifle;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.Qbz95ItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -117,8 +117,7 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.smg;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.VectorItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -87,8 +87,7 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vector.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.sniper;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.SvdItemRenderer;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -78,9 +78,7 @@ public class SvdItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
|
||||
if (cap != null && cap.edit) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.svd.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.special;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.BocekItemRenderer;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.BocekImageComponent;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
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.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -183,8 +179,7 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
}
|
||||
|
||||
if (GunsTool.getGunDoubleTag(tag, "Power") >= 6) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null && cap.zoom) {
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).zoom) {
|
||||
spawnBullet(player, tag);
|
||||
|
||||
SoundTool.playLocalSound(player, ModSounds.BOCEK_ZOOM_FIRE_1P.get(), 10, 1);
|
||||
|
@ -218,10 +213,9 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
|
|||
|
||||
@Override
|
||||
public void fireOnPress(Player player, final GunData data) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.bowPullHold = true;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.bowPullHold = true;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.special;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.TaserItemRenderer;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.EnergyImageComponent;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.TaserBulletEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
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.init.*;
|
||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
|
@ -225,7 +221,6 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
|||
public void fireOnPress(Player player, final GunData data) {
|
||||
if (data.reloading()) return;
|
||||
ItemStack stack = data.stack();
|
||||
var tag = data.tag();
|
||||
|
||||
int perkLevel = data.perk.getLevel(ModPerks.VOLT_OVERLOAD);
|
||||
var energyStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
@ -239,8 +234,7 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
|
|||
player.getCooldowns().addCooldown(stack.getItem(), 5);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||
double spread = data.spread();
|
||||
|
||||
int volt = data.perk.getLevel(ModPerks.VOLT_OVERLOAD);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.atsuishio.superbwarfare.network.message.receive;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -31,26 +31,7 @@ public record PlayerVariablesSyncMessage(int target, CompoundTag data) implement
|
|||
var entity = Minecraft.getInstance().player.level().getEntity(message.target());
|
||||
if (entity == null) return;
|
||||
|
||||
var variables = entity.getCapability(ModCapabilities.PLAYER_VARIABLE, null);
|
||||
if (variables == null) return;
|
||||
|
||||
variables.zoom = data.zoom;
|
||||
variables.holdFire = data.holdFire;
|
||||
variables.rifleAmmo = data.rifleAmmo;
|
||||
variables.handgunAmmo = data.handgunAmmo;
|
||||
variables.shotgunAmmo = data.shotgunAmmo;
|
||||
variables.sniperAmmo = data.sniperAmmo;
|
||||
variables.heavyAmmo = data.heavyAmmo;
|
||||
variables.bowPullHold = data.bowPullHold;
|
||||
variables.bowPull = data.bowPull;
|
||||
variables.playerDoubleJump = data.playerDoubleJump;
|
||||
variables.tacticalSprint = data.tacticalSprint;
|
||||
variables.tacticalSprintTime = data.tacticalSprintTime;
|
||||
variables.tacticalSprintExhaustion = data.tacticalSprintExhaustion;
|
||||
variables.breath = data.breath;
|
||||
variables.breathTime = data.breathTime;
|
||||
variables.breathExhaustion = data.breathExhaustion;
|
||||
variables.edit = data.edit;
|
||||
entity.setData(ModAttachments.PLAYER_VARIABLE, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
@ -23,20 +23,21 @@ public record BreathMessage(boolean msgType) implements CustomPacketPayload {
|
|||
public static void handler(final BreathMessage message, final IPayloadContext context) {
|
||||
ServerPlayer player = (ServerPlayer) context.player();
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
if (message.msgType
|
||||
&& !cap.breathExhaustion
|
||||
&& cap.zoom
|
||||
&& player.getPersistentData().getDouble("NoBreath") == 0
|
||||
) {
|
||||
cap.breath = true;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
|
||||
if (!message.msgType) {
|
||||
cap.breath = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -33,11 +33,11 @@ public record DoubleJumpMessage(boolean canDoubleJump) implements CustomPacketPa
|
|||
|
||||
level.playSound(null, BlockPos.containing(x, y, z), ModSounds.DOUBLE_JUMP.get(), SoundSource.BLOCKS, 1, 1);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
cap.playerDoubleJump = message.canDoubleJump;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||
|
@ -33,14 +33,15 @@ public record EditModeMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
if (!(mainHandItem.getItem() instanceof GunItem gunItem)) return;
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (gunItem.isCustomizable(mainHandItem) && cap != null) {
|
||||
if (gunItem.isCustomizable(mainHandItem)) {
|
||||
if (!cap.edit) {
|
||||
SoundTool.playLocalSound(player, ModSounds.EDIT_MODE.get(), 1f, 1f);
|
||||
}
|
||||
cap.edit = !cap.edit;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||
import com.atsuishio.superbwarfare.event.GunEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
|
||||
|
@ -49,39 +49,36 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
handleGunBolt(player, stack);
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (type == 0) {
|
||||
if (tag.getDouble("PrepareTime") == 0 && data.reloading() && data.ammo() > 0) {
|
||||
tag.putBoolean("ForceStop", true);
|
||||
}
|
||||
|
||||
if (cap != null) {
|
||||
cap.edit = false;
|
||||
}
|
||||
cap.edit = false;
|
||||
|
||||
// 按下开火
|
||||
if (!(stack.getItem() instanceof SpecialFireWeapon specialFireWeapon)) {
|
||||
if (cap != null) cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
return;
|
||||
}
|
||||
specialFireWeapon.fireOnPress(player, data);
|
||||
|
||||
if (cap != null) {
|
||||
cap.holdFire = true;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
cap.holdFire = true;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
} else if (type == 1) {
|
||||
if (cap != null) {
|
||||
cap.bowPullHold = false;
|
||||
cap.holdFire = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
cap.bowPullHold = false;
|
||||
cap.holdFire = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
|
||||
// 松开开火
|
||||
if (stack.getItem() instanceof SpecialFireWeapon specialFireWeapon) {
|
||||
specialFireWeapon.fireOnRelease(player, data);
|
||||
}
|
||||
}
|
||||
cap.sync(player);
|
||||
data.save();
|
||||
}
|
||||
|
||||
|
@ -122,8 +119,7 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
|||
float bypassArmorRate = (float) data.bypassArmor();
|
||||
double damage;
|
||||
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
boolean zoom = cap != null && cap.zoom;
|
||||
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
|
||||
|
||||
float spread;
|
||||
if (zoom) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -31,11 +31,10 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
public static void pressAction(Player player, int type) {
|
||||
if (type != 0) return;
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap != null) {
|
||||
cap.edit = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.edit = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
@ -56,7 +55,7 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
// 检查备弹
|
||||
boolean hasCreativeAmmoBox = player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||
|
||||
if (!hasCreativeAmmoBox && cap != null) {
|
||||
if (!hasCreativeAmmoBox) {
|
||||
if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && cap.shotgunAmmo == 0) {
|
||||
return;
|
||||
} else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && cap.sniperAmmo == 0) {
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.event.GunEventHandler;
|
||||
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.init.*;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
|
@ -96,8 +92,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
GunEventHandler.playGunSounds(player);
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (cap.rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
tag.putDouble("heat", (tag.getDouble("heat") + 0.1));
|
||||
|
@ -127,7 +122,8 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
|
|||
GunEventHandler.gunShoot(player, tag, spared);
|
||||
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
||||
cap.rifleAmmo = cap.rifleAmmo - 1;
|
||||
cap.syncPlayerVariables(player);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -32,14 +32,13 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
var vehicle = player.getVehicle();
|
||||
// 缩放音效播放条件: 载具是武器载具,且该位置有可用武器
|
||||
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (message.msgType == 0) {
|
||||
if (cap != null) {
|
||||
cap.zoom = true;
|
||||
cap.edit = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
cap.zoom = true;
|
||||
cap.edit = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
if (player.isPassenger()
|
||||
&& vehicle instanceof WeaponVehicleEntity weaponEntity
|
||||
|
@ -48,11 +47,10 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload {
|
|||
) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
|
||||
|
||||
} else if (message.msgType == 1) {
|
||||
if (cap != null) {
|
||||
cap.zoom = false;
|
||||
cap.breath = false;
|
||||
cap.syncPlayerVariables(player);
|
||||
}
|
||||
cap.zoom = false;
|
||||
cap.breath = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
if (player.isPassenger()
|
||||
&& vehicle instanceof WeaponVehicleEntity weaponEntity
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.tools;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.capability.player.PlayerVariable;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -90,18 +90,17 @@ public enum AmmoType {
|
|||
|
||||
// Entity
|
||||
public int get(Entity entity) {
|
||||
var cap = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return 0;
|
||||
var cap = entity.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
return get(cap);
|
||||
}
|
||||
|
||||
public void set(Entity entity, int count) {
|
||||
var cap = entity.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
if (cap == null) return;
|
||||
var cap = entity.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
set(cap, count);
|
||||
cap.syncPlayerVariables(entity);
|
||||
entity.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(entity);
|
||||
}
|
||||
|
||||
public void add(Entity entity, int count) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.tools;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.ReloadState;
|
||||
|
@ -88,15 +88,14 @@ public class GunsTool {
|
|||
data.bolt.markNeedless();
|
||||
}
|
||||
|
||||
var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
|
||||
var capability = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
var playerAmmo = 0;
|
||||
|
||||
if (capability != null) {
|
||||
playerAmmo = type.get(capability);
|
||||
var newAmmoCount = Math.max(0, playerAmmo - ammoToAdd);
|
||||
type.set(capability, newAmmoCount);
|
||||
capability.syncPlayerVariables(player);
|
||||
}
|
||||
playerAmmo = type.get(capability);
|
||||
var newAmmoCount = Math.max(0, playerAmmo - ammoToAdd);
|
||||
type.set(capability, newAmmoCount);
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, capability);
|
||||
capability.sync(player);
|
||||
|
||||
int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo);
|
||||
|
||||
|
@ -117,18 +116,6 @@ public class GunsTool {
|
|||
return tag.getInt(name);
|
||||
}
|
||||
|
||||
public static void setPerkDoubleTag(final CompoundTag rootTag, String name, double num) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
if (!tag.contains(name) && num == 0) return;
|
||||
tag.putDouble(name, num);
|
||||
rootTag.put("PerkData", tag);
|
||||
}
|
||||
|
||||
public static double getPerkDoubleTag(final CompoundTag rootTag, String name) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
return tag.getDouble(name);
|
||||
}
|
||||
|
||||
public static void setPerkBooleanTag(final CompoundTag rootTag, String name, boolean flag) {
|
||||
CompoundTag tag = rootTag.getCompound("PerkData");
|
||||
if (!tag.contains(name) && !flag) return;
|
||||
|
|
Loading…
Add table
Reference in a new issue