From 1c04fcb0acaecdb59f0036bd36a8c7ed14b8dcec Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Wed, 25 Dec 2024 19:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/atsuishio/superbwarfare/client/ClickHandler.java | 2 +- .../superbwarfare/entity/AnnihilatorEntity.java | 8 +++++++- .../com/atsuishio/superbwarfare/entity/Mk42Entity.java | 8 +++++++- .../atsuishio/superbwarfare/entity/Mle1934Entity.java | 9 ++++++++- .../superbwarfare/event/ClientEventHandler.java | 5 +++++ .../atsuishio/superbwarfare/event/GunEventHandler.java | 2 ++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index 2522c647a..ee459834f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -318,7 +318,7 @@ public class ClickHandler { player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); } - if (!stack.is(ModTags.Items.CANNOT_RELOAD) && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0) { + if (!stack.is(ModTags.Items.CANNOT_RELOAD) && GunsTool.getGunIntTag(stack, "Ammo", 0) <= 0 && stack.getOrCreateTag().getInt("ReloadTime") == 0) { if (ReloadConfig.LEFT_CLICK_RELOAD.get()) { ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0)); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java index cc2de1855..e24bb528d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java @@ -62,6 +62,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit public static final EntityDataAccessor LASER_RIGHT_LENGTH = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ENERGY = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor OFFSET_ANGLE = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor ROT_Y = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -92,6 +93,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit this.entityData.define(LASER_RIGHT_LENGTH, 0f); this.entityData.define(ENERGY, 0f); this.entityData.define(OFFSET_ANGLE, 0f); + this.entityData.define(ROT_Y, 0f); } @Override @@ -259,6 +261,10 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit } } + if (this.level() instanceof ServerLevel) { + this.entityData.set(ROT_Y, this.getYRot()); + } + if (this.entityData.get(HEALTH) <= 0) { this.ejectPassengers(); destroy(); @@ -477,7 +483,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit diffY = Mth.clamp(diffY * 0.15f, -0.6f, 0.6f); diffX = diffX * 0.15f; - this.setYRot(this.getYRot() + diffY); + this.setYRot(this.entityData.get(ROT_Y) + diffY); this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -2f, 2f), -45, 5f + this.entityData.get(OFFSET_ANGLE))); this.setRot(this.getYRot(), this.getXRot()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java index f827c35f2..77d137050 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java @@ -53,6 +53,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor ROT_Y = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = CannonConfig.MK42_HP.get(); @@ -73,6 +74,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { protected void defineSynchedData() { this.entityData.define(COOL_DOWN, 0); this.entityData.define(HEALTH, MAX_HEALTH); + this.entityData.define(ROT_Y, 0f); } @Override @@ -246,6 +248,10 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { destroy(); } + if (this.level() instanceof ServerLevel) { + this.entityData.set(ROT_Y, this.getYRot()); + } + travel(); this.refreshDimensions(); } @@ -386,7 +392,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { diffY = Mth.clamp(diffY * 0.15f, -1.75f, 1.75f); diffX = diffX * 0.15f; - this.setYRot(this.getYRot() + diffY); + this.setYRot(this.entityData.get(ROT_Y) + diffY); this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -3f, 3f), -85, 16.3f)); this.setRot(this.getYRot(), this.getXRot()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java index 177ccb6a5..f2eb48df9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java @@ -55,6 +55,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor ROT_Y = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = CannonConfig.MLE1934_HP.get(); @@ -76,6 +77,8 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { this.entityData.define(COOL_DOWN, 0); this.entityData.define(TYPE, 0); this.entityData.define(HEALTH, MAX_HEALTH); + this.entityData.define(HEALTH, MAX_HEALTH); + this.entityData.define(ROT_Y, 0f); } @Override @@ -260,6 +263,10 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { destroy(); } + if (this.level() instanceof ServerLevel) { + this.entityData.set(ROT_Y, this.getYRot()); + } + travel(); this.refreshDimensions(); } @@ -478,7 +485,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { diffY = Mth.clamp(diffY * 0.15f, -1.25f, 1.25f); diffX = diffX * 0.15f; - this.setYRot(this.getYRot() + diffY); + this.setYRot(this.entityData.get(ROT_Y) + diffY); this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -2f, 2f), -30, 4)); this.setRot(this.getYRot(), this.getXRot()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index bc426b567..74927fc87 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -405,6 +405,11 @@ public class ClientEventHandler { actionMove = 1; } + // 判断是否为栓动武器(BoltActionTime > 0),并在开火后给一个需要上膛的状态 + if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) { + GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true); + } + revolverPreTime = 0; revolverWheelPreTime = 0; diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index 92aeb1816..39efb4837 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -387,6 +387,7 @@ public class GunEventHandler { } else { playGunEmptyReload(player); } + tag.putBoolean("start_reload", false); } stack.addTagElement("GunData", data); @@ -652,6 +653,7 @@ public class GunEventHandler { GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false); } tag.putBoolean("reloading", false); + tag.putBoolean("start_single_reload", false); MinecraftForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack)); }