将isEditing改为纯客户端
This commit is contained in:
parent
d7b1afe9ba
commit
a710b6b807
30 changed files with 122 additions and 217 deletions
|
@ -8,7 +8,6 @@ import net.minecraft.core.HolderLookup;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.common.util.INBTSerializable;
|
||||
|
@ -19,7 +18,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
@EventBusSubscriber(modid = Mod.MODID)
|
||||
|
@ -28,7 +26,6 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
|
||||
public Map<Ammo, Integer> ammo = new HashMap<>();
|
||||
public boolean tacticalSprint = false;
|
||||
public boolean edit = false;
|
||||
|
||||
public void sync(Entity entity) {
|
||||
if (!entity.hasData(ModAttachments.PLAYER_VARIABLE)) return;
|
||||
|
@ -41,10 +38,6 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isEditing(Entity entity) {
|
||||
return entity.getData(ModAttachments.PLAYER_VARIABLE).edit;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (!(event.getEntity() instanceof ServerPlayer player)) return;
|
||||
|
@ -79,7 +72,6 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
}
|
||||
|
||||
map.put((byte) -1, this.tacticalSprint ? 1 : 0);
|
||||
map.put((byte) -2, this.edit ? 1 : 0);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
@ -100,22 +92,10 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
if (old.tacticalSprint != this.tacticalSprint) {
|
||||
map.put((byte) -1, this.tacticalSprint ? 1 : 0);
|
||||
}
|
||||
if (old.edit != this.edit) {
|
||||
map.put((byte) -2, this.edit ? 1 : 0);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑并同步玩家变量
|
||||
*/
|
||||
public void modify(Player player, Consumer<PlayerVariable> consumer) {
|
||||
watch();
|
||||
consumer.accept(this);
|
||||
sync(player);
|
||||
}
|
||||
|
||||
|
||||
public CompoundTag writeToNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
|
@ -125,20 +105,17 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
}
|
||||
|
||||
nbt.putBoolean("TacticalSprint", tacticalSprint);
|
||||
nbt.putBoolean("EditMode", edit);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public PlayerVariable readFromNBT(CompoundTag tag) {
|
||||
public void readFromNBT(CompoundTag tag) {
|
||||
for (var type : Ammo.values()) {
|
||||
type.set(this, type.get(tag));
|
||||
}
|
||||
|
||||
tacticalSprint = tag.getBoolean("TacticalSprint");
|
||||
edit = tag.getBoolean("EditMode");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerVariable copy() {
|
||||
|
@ -148,7 +125,6 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
type.set(clone, type.get(this));
|
||||
}
|
||||
|
||||
clone.edit = this.edit;
|
||||
clone.tacticalSprint = this.tacticalSprint;
|
||||
|
||||
return clone;
|
||||
|
@ -162,8 +138,7 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
if (type.get(this) != type.get(other)) return false;
|
||||
}
|
||||
|
||||
return tacticalSprint == other.tacticalSprint
|
||||
&& edit == other.edit;
|
||||
return tacticalSprint == other.tacticalSprint;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -44,7 +44,7 @@ import static com.atsuishio.superbwarfare.event.ClientEventHandler.*;
|
|||
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
|
||||
public class ClickHandler {
|
||||
|
||||
public static boolean isEditing = false;
|
||||
public static boolean switchZoom = false;
|
||||
|
||||
private static boolean notInGame() {
|
||||
|
@ -211,6 +211,7 @@ public class ClickHandler {
|
|||
|
||||
if (key == ModKeyMappings.RELOAD.getKey().getValue()) {
|
||||
ClientEventHandler.burstFireAmount = 0;
|
||||
ClickHandler.isEditing = false;
|
||||
PacketDistributor.sendToServer(new ReloadMessage(0));
|
||||
}
|
||||
if (key == ModKeyMappings.FIRE_MODE.getKey().getValue()) {
|
||||
|
@ -224,14 +225,15 @@ public class ClickHandler {
|
|||
}
|
||||
if (key == ModKeyMappings.EDIT_MODE.getKey().getValue() && ClientEventHandler.burstFireAmount == 0) {
|
||||
ClientEventHandler.holdFire = false;
|
||||
PacketDistributor.sendToServer(new EditModeMessage(0));
|
||||
isEditing = true;
|
||||
player.playSound(ModSounds.EDIT_MODE.get(), 1, 1);
|
||||
}
|
||||
|
||||
if (key == ModKeyMappings.BREATH.getKey().getValue() && !exhaustion && zoom) {
|
||||
breath = true;
|
||||
}
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (isEditing) {
|
||||
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)) {
|
||||
|
@ -305,6 +307,7 @@ public class ClickHandler {
|
|||
}
|
||||
|
||||
public static void handleWeaponFirePress(Player player, ItemStack stack) {
|
||||
isEditing = false;
|
||||
if (player.hasEffect(ModMobEffects.SHOCK)) return;
|
||||
|
||||
if (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get())) {
|
||||
|
@ -373,12 +376,15 @@ public class ClickHandler {
|
|||
bowPull = false;
|
||||
holdFire = false;
|
||||
holdFireVehicle = false;
|
||||
isEditing = false;
|
||||
customRpm = 0;
|
||||
}
|
||||
|
||||
public static void handleWeaponZoomPress(Player player, ItemStack stack) {
|
||||
PacketDistributor.sendToServer(new ZoomMessage(0));
|
||||
|
||||
ClickHandler.isEditing = false;
|
||||
|
||||
if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player)) && iVehicle.banHand(player)) {
|
||||
ClientEventHandler.zoomVehicle = true;
|
||||
return;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
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;
|
||||
|
@ -62,8 +62,8 @@ public class CrossHairOverlay implements LayeredDraw.Layer {
|
|||
return;
|
||||
}
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
|
||||
if (ClickHandler.isEditing)
|
||||
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.client.ClickHandler;
|
||||
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;
|
||||
|
@ -34,9 +34,8 @@ public class GrenadeLauncherOverlay implements LayeredDraw.Layer {
|
|||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (cap.edit) return;
|
||||
|
||||
if (ClickHandler.isEditing)
|
||||
return;
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
if (!shouldRenderCrossHair(player)) return;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
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;
|
||||
|
@ -45,73 +45,74 @@ public class HandsomeFrameOverlay implements LayeredDraw.Layer {
|
|||
Player player = Minecraft.getInstance().player;
|
||||
PoseStack poseStack = guiGraphics.pose();
|
||||
|
||||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() instanceof GunItem && Minecraft.getInstance().options.getCameraType().isFirstPerson()) {
|
||||
var data = GunData.from(stack);
|
||||
int level = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP);
|
||||
if (level == 0) return;
|
||||
if (ClickHandler.isEditing)
|
||||
return;
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
if (stack.getItem() instanceof GunItem && Minecraft.getInstance().options.getCameraType().isFirstPerson()) {
|
||||
var data = GunData.from(stack);
|
||||
int level = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP);
|
||||
if (level == 0) return;
|
||||
|
||||
List<Entity> allEntities = SeekTool.seekLivingEntitiesThroughWall(player, player.level(), 32 + 8 * (level - 1), 30);
|
||||
List<Entity> visibleEntities = SeekTool.seekLivingEntities(player, player.level(), 32 + 8 * (level - 1), 30);
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
Entity naerestEntity = SeekTool.seekLivingEntity(player, player.level(), 32 + 8 * (level - 1), 30);
|
||||
Entity targetEntity = ClientEventHandler.entity;
|
||||
List<Entity> allEntities = SeekTool.seekLivingEntitiesThroughWall(player, player.level(), 32 + 8 * (level - 1), 30);
|
||||
List<Entity> visibleEntities = SeekTool.seekLivingEntities(player, player.level(), 32 + 8 * (level - 1), 30);
|
||||
|
||||
Entity naerestEntity = SeekTool.seekLivingEntity(player, player.level(), 32 + 8 * (level - 1), 30);
|
||||
Entity targetEntity = ClientEventHandler.entity;
|
||||
|
||||
|
||||
float fovAdjust2 = (float) (Minecraft.getInstance().options.fov().get() / 30) - 1;
|
||||
float fovAdjust2 = (float) (Minecraft.getInstance().options.fov().get() / 30) - 1;
|
||||
|
||||
double zoom = 1;
|
||||
double zoom = 1;
|
||||
|
||||
if (ClientEventHandler.zoom) {
|
||||
zoom = Minecraft.getInstance().options.fov().get() / ClientEventHandler.fov + 0.05 * fovAdjust2;
|
||||
}
|
||||
if (ClientEventHandler.zoom) {
|
||||
zoom = Minecraft.getInstance().options.fov().get() / ClientEventHandler.fov + 0.05 * fovAdjust2;
|
||||
}
|
||||
|
||||
for (var e : allEntities) {
|
||||
Vec3 playerVec = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.xo, player.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ()));
|
||||
Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.xo, e.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.zo, e.getZ()));
|
||||
Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom));
|
||||
for (var e : allEntities) {
|
||||
Vec3 playerVec = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.xo, player.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ()));
|
||||
Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.xo, e.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.zo, e.getZ()));
|
||||
Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom));
|
||||
|
||||
var cPos = playerVec.add(lookAngle);
|
||||
Vec3 point = RenderHelper.worldToScreen(pos, cPos);
|
||||
if (point == null) return;
|
||||
var cPos = playerVec.add(lookAngle);
|
||||
Vec3 point = RenderHelper.worldToScreen(pos, cPos);
|
||||
if (point == null) return;
|
||||
|
||||
boolean lockOn = e == targetEntity;
|
||||
boolean isNearestEntity = e == naerestEntity;
|
||||
boolean lockOn = e == targetEntity;
|
||||
boolean isNearestEntity = e == naerestEntity;
|
||||
|
||||
poseStack.pushPose();
|
||||
float x = (float) point.x;
|
||||
float y = (float) point.y;
|
||||
poseStack.pushPose();
|
||||
float x = (float) point.x;
|
||||
float y = (float) point.y;
|
||||
|
||||
var canBeSeen = visibleEntities.contains(e);
|
||||
var canBeSeen = visibleEntities.contains(e);
|
||||
|
||||
ResourceLocation icon;
|
||||
if (lockOn) {
|
||||
icon = FRAME_LOCK;
|
||||
} else if (canBeSeen) {
|
||||
if (isNearestEntity) {
|
||||
icon = FRAME_TARGET;
|
||||
} else {
|
||||
icon = FRAME;
|
||||
}
|
||||
ResourceLocation icon;
|
||||
if (lockOn) {
|
||||
icon = FRAME_LOCK;
|
||||
} else if (canBeSeen) {
|
||||
if (isNearestEntity) {
|
||||
icon = FRAME_TARGET;
|
||||
} else {
|
||||
icon = FRAME_WEAK;
|
||||
icon = FRAME;
|
||||
}
|
||||
|
||||
RenderHelper.preciseBlit(guiGraphics, icon, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
|
||||
poseStack.popPose();
|
||||
} else {
|
||||
icon = FRAME_WEAK;
|
||||
}
|
||||
|
||||
RenderHelper.preciseBlit(guiGraphics, icon, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity;
|
||||
|
@ -8,7 +9,6 @@ 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;
|
||||
|
@ -63,7 +63,8 @@ public class HelicopterHudOverlay implements LayeredDraw.Layer {
|
|||
|
||||
if (player == null) return;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
if (ClickHandler.isEditing)
|
||||
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.client.ClickHandler;
|
||||
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;
|
||||
|
@ -53,8 +53,8 @@ public class JavelinHudOverlay implements LayeredDraw.Layer {
|
|||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return;
|
||||
|
||||
if (ClickHandler.isEditing)
|
||||
return;
|
||||
if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
|
@ -34,7 +34,7 @@ public class StaminaOverlay implements LayeredDraw.Layer {
|
|||
var w = guiGraphics.guiWidth();
|
||||
var h = guiGraphics.guiHeight();
|
||||
|
||||
if (player != null && player.getData(ModAttachments.PLAYER_VARIABLE).edit)
|
||||
if (player != null && ClickHandler.isEditing)
|
||||
return;
|
||||
if (player != null && player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
return;
|
||||
|
|
|
@ -415,7 +415,6 @@ 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.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (gunItem.hasMeleeAttack(stack)
|
||||
&& gunMelee == 0
|
||||
&& drawTime < 0.01
|
||||
|
@ -423,7 +422,7 @@ public class ClientEventHandler {
|
|||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
&& !holdFireVehicle
|
||||
&& !notInGame()
|
||||
&& !cap.edit
|
||||
&& !ClickHandler.isEditing
|
||||
&& !(data.reload.normal() || data.reload.empty())
|
||||
&& !data.reloading()
|
||||
&& !data.charging() && !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
|
@ -575,8 +574,6 @@ public class ClientEventHandler {
|
|||
revolverPreTime = Mth.clamp(revolverPreTime - 1.2 * times, 0, 1);
|
||||
}
|
||||
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
|
||||
if (((holdFire || burstFireAmount > 0) && shootDelay >= data.shootDelay())
|
||||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
&& !holdFireVehicle
|
||||
|
@ -585,8 +582,9 @@ public class ClientEventHandler {
|
|||
&& (stack.is(ModTags.Items.NORMAL_GUN)
|
||||
&& cantFireTime == 0
|
||||
&& drawTime < 0.01
|
||||
&& !cap.edit
|
||||
&& !ClickHandler.isEditing
|
||||
&& !notInGame()
|
||||
&& !ClickHandler.isEditing
|
||||
&& (!(data.reload.normal() || data.reload.empty())
|
||||
&& !data.reloading()
|
||||
&& !data.charging()
|
||||
|
@ -1119,7 +1117,7 @@ public class ClientEventHandler {
|
|||
onGround = 0.001;
|
||||
}
|
||||
|
||||
if (!entity.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (!ClickHandler.isEditing) {
|
||||
if (Minecraft.getInstance().options.keyUp.isDown() && firePosTimer == 0) {
|
||||
moveRotZ = Mth.lerp(0.2f * times, moveRotZ, 0.14) * (1 - zoomTime);
|
||||
} else {
|
||||
|
@ -1182,12 +1180,11 @@ public class ClientEventHandler {
|
|||
double weight = data.weight();
|
||||
double speed = 1.5 - (0.07 * weight);
|
||||
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
|
||||
if (zoom
|
||||
&& !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))
|
||||
&& !notInGame()
|
||||
&& drawTime < 0.01
|
||||
&& !cap.edit) {
|
||||
&& !ClickHandler.isEditing) {
|
||||
if (Minecraft.getInstance().player != null) {
|
||||
cantSprint = 5;
|
||||
}
|
||||
|
@ -1515,7 +1512,7 @@ public class ClientEventHandler {
|
|||
if (zoom
|
||||
&& !notInGame()
|
||||
&& drawTime < 0.01
|
||||
&& !player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
&& !ClickHandler.isEditing) {
|
||||
if (!player.isShiftKeyDown()) {
|
||||
int intelligentChipLevel = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP);
|
||||
|
||||
|
@ -1625,6 +1622,7 @@ public class ClientEventHandler {
|
|||
bowPullTimer = 0;
|
||||
bowPower = 0;
|
||||
cantSprint = 20;
|
||||
ClickHandler.isEditing = false;
|
||||
}
|
||||
|
||||
private static void handleWeaponDraw(LivingEntity entity) {
|
||||
|
|
|
@ -388,12 +388,6 @@ public class LivingEventHandler {
|
|||
oldData.charge.timer.reset();
|
||||
}
|
||||
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.edit = false;
|
||||
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
oldData.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -632,8 +632,6 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
if (data.reload.prepareTimer.get() == 0 && data.reloading() && data.hasEnoughAmmoToShoot(player)) {
|
||||
data.forceStop.set(true);
|
||||
}
|
||||
|
||||
player.getData(ModAttachments.PLAYER_VARIABLE).modify(player, cap -> cap.edit = false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.handgun;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -190,7 +190,7 @@ public class Trachelium extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.ModEnumExtensions;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -101,7 +101,7 @@ public class Ntw20Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -53,13 +53,13 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isBarVisible(ItemStack stack) {
|
||||
public boolean isBarVisible(@NotNull ItemStack stack) {
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
return cap != null && cap.getEnergyStored() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarWidth(ItemStack stack) {
|
||||
public int getBarWidth(@NotNull ItemStack stack) {
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
return Math.round((float) (cap != null ? cap.getEnergyStored() : 0) * 13.0F / 24000F);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.machinegun;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
|
@ -118,7 +118,7 @@ public class RpkItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -111,7 +111,7 @@ public class AK12Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -119,7 +119,7 @@ public class AK47Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -114,7 +114,7 @@ public class Hk416Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -115,7 +115,7 @@ public class M4Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -116,7 +116,7 @@ public class Mk14Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -119,7 +119,7 @@ public class Qbz95Item extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
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.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -86,7 +86,7 @@ public class VectorItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vector.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -42,13 +42,13 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isBarVisible(ItemStack stack) {
|
||||
public boolean isBarVisible(@NotNull ItemStack stack) {
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
return cap != null && cap.getEnergyStored() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarWidth(ItemStack stack) {
|
||||
public int getBarWidth(@NotNull ItemStack stack) {
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
|
||||
return Math.round((float) (cap != null ? cap.getEnergyStored() : 0) * 13.0F / 24000F);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item.gun.sniper;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||
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.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
|
@ -80,7 +80,7 @@ public class SvdItem extends GunItem implements GeoItem {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
|
||||
if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) {
|
||||
if (ClickHandler.isEditing) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.svd.edit"));
|
||||
}
|
||||
|
||||
|
|
|
@ -50,13 +50,13 @@ public class TaserItem extends GunItem implements GeoItem, EnergyStorageItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isBarVisible(ItemStack stack) {
|
||||
public boolean isBarVisible(@NotNull ItemStack stack) {
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
return cap != null && cap.getEnergyStored() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarWidth(ItemStack stack) {
|
||||
public int getBarWidth(@NotNull ItemStack stack) {
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
return Math.round((float) (cap != null ? cap.getEnergyStored() : 0) * 13.0F / MAX_ENERGY);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class NetworkRegistry {
|
|||
public static void register(final RegisterPayloadHandlersEvent event) {
|
||||
final PayloadRegistrar registrar = event.registrar("1");
|
||||
|
||||
registrar.playToClient(PlayerVariablesSyncMessage.TYPE, PlayerVariablesSyncMessage.STREAM_CODEC, PlayerVariablesSyncMessage::handler);
|
||||
registrar.playToClient(PlayerVariablesSyncMessage.TYPE, PlayerVariablesSyncMessage.STREAM_CODEC, (message, context1) -> PlayerVariablesSyncMessage.handler(message));
|
||||
registrar.playToClient(ShakeClientMessage.TYPE, ShakeClientMessage.STREAM_CODEC, ShakeClientMessage::handler);
|
||||
registrar.playToClient(ClientMotionSyncMessage.TYPE, ClientMotionSyncMessage.STREAM_CODEC, ClientMotionSyncMessage::handler);
|
||||
registrar.playToClient(ClientIndicatorMessage.TYPE, ClientIndicatorMessage.STREAM_CODEC, ClientIndicatorMessage::handler);
|
||||
|
@ -49,7 +49,6 @@ public class NetworkRegistry {
|
|||
registrar.playToServer(SetFiringParametersMessage.TYPE, SetFiringParametersMessage.STREAM_CODEC, SetFiringParametersMessage::handler);
|
||||
registrar.playToServer(SensitivityMessage.TYPE, SensitivityMessage.STREAM_CODEC, SensitivityMessage::handler);
|
||||
registrar.playToServer(EditMessage.TYPE, EditMessage.STREAM_CODEC, EditMessage::handler);
|
||||
registrar.playToServer(EditModeMessage.TYPE, EditModeMessage.STREAM_CODEC, EditModeMessage::handler);
|
||||
registrar.playToServer(InteractMessage.TYPE, InteractMessage.STREAM_CODEC, InteractMessage::handler);
|
||||
registrar.playToServer(AdjustMortarAngleMessage.TYPE, AdjustMortarAngleMessage.STREAM_CODEC, AdjustMortarAngleMessage::handler);
|
||||
registrar.playToServer(ChangeVehicleSeatMessage.TYPE, ChangeVehicleSeatMessage.STREAM_CODEC, ChangeVehicleSeatMessage::handler);
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -31,7 +30,7 @@ public record PlayerVariablesSyncMessage(int target, Map<Byte, Integer> data) im
|
|||
);
|
||||
|
||||
|
||||
public static void handler(final PlayerVariablesSyncMessage message, final IPayloadContext context) {
|
||||
public static void handler(final PlayerVariablesSyncMessage message) {
|
||||
if (Minecraft.getInstance().player == null) return;
|
||||
|
||||
var entity = Minecraft.getInstance().player.level().getEntity(message.target());
|
||||
|
@ -42,15 +41,13 @@ public record PlayerVariablesSyncMessage(int target, Map<Byte, Integer> data) im
|
|||
|
||||
for (var entry : map.entrySet()) {
|
||||
var type = entry.getKey();
|
||||
switch (type) {
|
||||
case -1 -> variable.tacticalSprint = entry.getValue() == 1;
|
||||
case -2 -> variable.edit = entry.getValue() == 1;
|
||||
default -> {
|
||||
var ammoTypes = Ammo.values();
|
||||
if (type < ammoTypes.length) {
|
||||
var ammo = ammoTypes[type];
|
||||
variable.ammo.put(ammo, entry.getValue());
|
||||
}
|
||||
if (type == -1) {
|
||||
variable.tacticalSprint = entry.getValue() == 1;
|
||||
} else {
|
||||
var ammoTypes = Ammo.values();
|
||||
if (type < ammoTypes.length) {
|
||||
var ammo = ammoTypes[type];
|
||||
variable.ammo.put(ammo, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
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;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record EditModeMessage(int msgType) implements CustomPacketPayload {
|
||||
public static final Type<EditModeMessage> TYPE = new Type<>(Mod.loc("edit_mode"));
|
||||
|
||||
public static final StreamCodec<ByteBuf, EditModeMessage> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.INT,
|
||||
EditModeMessage::msgType,
|
||||
EditModeMessage::new
|
||||
);
|
||||
|
||||
public static void handler(EditModeMessage message, final IPayloadContext context) {
|
||||
pressAction(context.player(), message.msgType);
|
||||
}
|
||||
|
||||
public static void pressAction(Player player, int type) {
|
||||
if (player == null) return;
|
||||
if (type != 0) return;
|
||||
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
if (!(mainHandItem.getItem() instanceof GunItem gunItem)) return;
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (gunItem.isCustomizable(mainHandItem)) {
|
||||
if (!cap.edit) {
|
||||
SoundTool.playLocalSound(player, ModSounds.EDIT_MODE.get(), 1f, 1f);
|
||||
}
|
||||
cap.edit = !cap.edit;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.network.message.send;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
@ -28,18 +27,13 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
public static void pressAction(Player player, int type) {
|
||||
if (type != 0) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem gunItem)) return;
|
||||
|
||||
var data = GunData.from(stack);
|
||||
if (data.useBackpackAmmo()) return;
|
||||
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
cap.edit = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
|
||||
if (!player.isSpectator()
|
||||
&& !data.charging()
|
||||
&& !data.reloading()
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.network.message.send;
|
|||
import com.atsuishio.superbwarfare.Mod;
|
||||
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,12 +31,8 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload {
|
|||
|
||||
var vehicle = player.getVehicle();
|
||||
// 缩放音效播放条件: 载具是武器载具,且该位置有可用武器
|
||||
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
|
||||
|
||||
if (message.msgType == 0) {
|
||||
cap.edit = false;
|
||||
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
|
||||
cap.sync(player);
|
||||
|
||||
if (player.isPassenger()
|
||||
&& vehicle instanceof WeaponVehicleEntity weaponEntity
|
||||
|
|
Loading…
Add table
Reference in a new issue