This commit is contained in:
Atsuihsio 2024-12-25 19:07:31 +08:00
parent 3b5427560f
commit 1c04fcb0ac
6 changed files with 30 additions and 4 deletions

View file

@ -318,7 +318,7 @@ public class ClickHandler {
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); 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()) { if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {
ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0)); ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0));
} }

View file

@ -62,6 +62,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
public static final EntityDataAccessor<Float> LASER_RIGHT_LENGTH = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> LASER_RIGHT_LENGTH = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> OFFSET_ANGLE = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> OFFSET_ANGLE = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ROT_Y = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); 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(LASER_RIGHT_LENGTH, 0f);
this.entityData.define(ENERGY, 0f); this.entityData.define(ENERGY, 0f);
this.entityData.define(OFFSET_ANGLE, 0f); this.entityData.define(OFFSET_ANGLE, 0f);
this.entityData.define(ROT_Y, 0f);
} }
@Override @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) { if (this.entityData.get(HEALTH) <= 0) {
this.ejectPassengers(); this.ejectPassengers();
destroy(); destroy();
@ -477,7 +483,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
diffY = Mth.clamp(diffY * 0.15f, -0.6f, 0.6f); diffY = Mth.clamp(diffY * 0.15f, -0.6f, 0.6f);
diffX = diffX * 0.15f; 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.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -2f, 2f), -45, 5f + this.entityData.get(OFFSET_ANGLE)));
this.setRot(this.getYRot(), this.getXRot()); this.setRot(this.getYRot(), this.getXRot());
} }

View file

@ -53,6 +53,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ROT_Y = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get(); 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() { protected void defineSynchedData() {
this.entityData.define(COOL_DOWN, 0); this.entityData.define(COOL_DOWN, 0);
this.entityData.define(HEALTH, MAX_HEALTH); this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(ROT_Y, 0f);
} }
@Override @Override
@ -246,6 +248,10 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
destroy(); destroy();
} }
if (this.level() instanceof ServerLevel) {
this.entityData.set(ROT_Y, this.getYRot());
}
travel(); travel();
this.refreshDimensions(); this.refreshDimensions();
} }
@ -386,7 +392,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
diffY = Mth.clamp(diffY * 0.15f, -1.75f, 1.75f); diffY = Mth.clamp(diffY * 0.15f, -1.75f, 1.75f);
diffX = diffX * 0.15f; 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.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -3f, 3f), -85, 16.3f));
this.setRot(this.getYRot(), this.getXRot()); this.setRot(this.getYRot(), this.getXRot());
} }

View file

@ -55,6 +55,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ROT_Y = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.MLE1934_HP.get(); 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(COOL_DOWN, 0);
this.entityData.define(TYPE, 0); this.entityData.define(TYPE, 0);
this.entityData.define(HEALTH, MAX_HEALTH); this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(ROT_Y, 0f);
} }
@Override @Override
@ -260,6 +263,10 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
destroy(); destroy();
} }
if (this.level() instanceof ServerLevel) {
this.entityData.set(ROT_Y, this.getYRot());
}
travel(); travel();
this.refreshDimensions(); this.refreshDimensions();
} }
@ -478,7 +485,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
diffY = Mth.clamp(diffY * 0.15f, -1.25f, 1.25f); diffY = Mth.clamp(diffY * 0.15f, -1.25f, 1.25f);
diffX = diffX * 0.15f; 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.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -2f, 2f), -30, 4));
this.setRot(this.getYRot(), this.getXRot()); this.setRot(this.getYRot(), this.getXRot());
} }

View file

@ -405,6 +405,11 @@ public class ClientEventHandler {
actionMove = 1; 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; revolverPreTime = 0;
revolverWheelPreTime = 0; revolverWheelPreTime = 0;

View file

@ -387,6 +387,7 @@ public class GunEventHandler {
} else { } else {
playGunEmptyReload(player); playGunEmptyReload(player);
} }
tag.putBoolean("start_reload", false);
} }
stack.addTagElement("GunData", data); stack.addTagElement("GunData", data);
@ -652,6 +653,7 @@ public class GunEventHandler {
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false); GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false);
} }
tag.putBoolean("reloading", false); tag.putBoolean("reloading", false);
tag.putBoolean("start_single_reload", false);
MinecraftForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack)); MinecraftForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));
} }