From 8c7169a01a498821eaed3e2281c7b74d4bd89882 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Wed, 9 Jul 2025 22:10:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=81=AB=E7=82=AE=E7=9A=84?= =?UTF-8?q?=E4=B8=BB=E4=BA=BA=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Mk42Entity.java | 51 ++---------------- .../entity/vehicle/Mle1934Entity.java | 53 ++----------------- .../entity/vehicle/MortarEntity.java | 44 ++------------- 3 files changed, 12 insertions(+), 136 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index 107fdc2c7..a9ac0ca78 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -31,7 +31,6 @@ import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.players.OldUsersConverter; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; @@ -41,7 +40,6 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MoverType; -import net.minecraft.world.entity.OwnableEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; @@ -61,18 +59,14 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.*; import software.bernie.geckolib.util.GeckoLibUtil; -import java.util.Optional; -import java.util.UUID; - import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector; -public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container, OwnableEntity { +public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor> OWNER_UUID = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.OPTIONAL_UUID); private final float shellGravity = 0.1f; @@ -88,8 +82,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity super.defineSynchedData(builder); builder.define(COOL_DOWN, 0) .define(PITCH, 0F) - .define(YAW, 0F) - .define(OWNER_UUID, Optional.empty()); + .define(YAW, 0F); } @Override @@ -129,9 +122,6 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity compound.putInt("CoolDown", this.entityData.get(COOL_DOWN)); compound.putFloat("Pitch", this.entityData.get(PITCH)); compound.putFloat("Yaw", this.entityData.get(YAW)); - if (this.getOwnerUUID() != null) { - compound.putUUID("Owner", this.getOwnerUUID()); - } } @Override @@ -140,47 +130,14 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity this.entityData.set(COOL_DOWN, compound.getInt("CoolDown")); this.entityData.set(PITCH, compound.getFloat("Pitch")); this.entityData.set(YAW, compound.getFloat("Yaw")); - UUID uuid; - if (compound.hasUUID("Owner")) { - uuid = compound.getUUID("Owner"); - } else { - String s = compound.getString("Owner"); - - assert this.getServer() != null; - uuid = OldUsersConverter.convertMobOwnerIfNecessary(this.getServer(), s); - } - - if (uuid != null) { - try { - this.setOwnerUUID(uuid); - } catch (Throwable ignored) { - } - } } - public void setOwnerUUID(@Nullable UUID pUuid) { - this.entityData.set(OWNER_UUID, Optional.ofNullable(pUuid)); - } - - @Nullable - public UUID getOwnerUUID() { - return this.entityData.get(OWNER_UUID).orElse(null); - } - - @Override public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) { ItemStack stack = player.getMainHandItem(); - if (player.isShiftKeyDown() && this.getOwner() == null) { - setOwnerUUID(player.getUUID()); - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1); - } - return InteractionResult.SUCCESS; - } - if (stack.getItem() instanceof ArtilleryIndicator indicator && player == getOwner() && this.getOwner() == player) { + if (stack.getItem() instanceof ArtilleryIndicator indicator) { if (indicator.addCannon(stack, getStringUUID())) { if (player instanceof ServerPlayer serverPlayer) { serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1); @@ -403,7 +360,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity InventoryTool.consumeItem(player.getInventory().items, ammo, 1); } - if (getFirstPassenger() != getOwner()) { + if (getFirstPassenger() != player) { this.stack = ItemStack.EMPTY; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index 1925605cc..d32b71d63 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -31,7 +31,6 @@ import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.players.OldUsersConverter; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; @@ -41,7 +40,6 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MoverType; -import net.minecraft.world.entity.OwnableEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; @@ -61,12 +59,9 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.*; import software.bernie.geckolib.util.GeckoLibUtil; -import java.util.Optional; -import java.util.UUID; - import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector; -public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container, OwnableEntity { +public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); @@ -74,8 +69,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt public static final EntityDataAccessor YAW = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); - public static final EntityDataAccessor> OWNER_UUID = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.OPTIONAL_UUID); - private final float shellGravity = 0.1f; public Mle1934Entity(EntityType type, Level world) { @@ -122,8 +115,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt builder.define(COOL_DOWN, 0) .define(TYPE, 0) .define(PITCH, 0f) - .define(YAW, 0f) - .define(OWNER_UUID, Optional.empty()); + .define(YAW, 0f); } @Override @@ -133,9 +125,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt compound.putInt("Type", this.entityData.get(TYPE)); compound.putFloat("Pitch", this.entityData.get(PITCH)); compound.putFloat("Yaw", this.entityData.get(YAW)); - if (this.getOwnerUUID() != null) { - compound.putUUID("Owner", this.getOwnerUUID()); - } } @Override @@ -145,47 +134,13 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt this.entityData.set(TYPE, compound.getInt("Type")); this.entityData.set(PITCH, compound.getFloat("Pitch")); this.entityData.set(YAW, compound.getFloat("Yaw")); - UUID uuid; - if (compound.hasUUID("Owner")) { - uuid = compound.getUUID("Owner"); - } else { - String s = compound.getString("Owner"); - - assert this.getServer() != null; - uuid = OldUsersConverter.convertMobOwnerIfNecessary(this.getServer(), s); - } - - if (uuid != null) { - try { - this.setOwnerUUID(uuid); - } catch (Throwable ignored) { - } - } } - public void setOwnerUUID(@Nullable UUID pUuid) { - this.entityData.set(OWNER_UUID, Optional.ofNullable(pUuid)); - } - - @Nullable - public UUID getOwnerUUID() { - return this.entityData.get(OWNER_UUID).orElse(null); - } - - @Override public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) { ItemStack stack = player.getMainHandItem(); - if (player.isShiftKeyDown() && this.getOwner() == null) { - setOwnerUUID(player.getUUID()); - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1); - } - return InteractionResult.SUCCESS; - } - - if (stack.getItem() instanceof ArtilleryIndicator indicator && player == getOwner() && this.getOwner() == player) { + if (stack.getItem() instanceof ArtilleryIndicator indicator) { if (indicator.addCannon(stack, getStringUUID())) { if (player instanceof ServerPlayer serverPlayer) { serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1); @@ -422,7 +377,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt consumed = stack.getCount(); } - if (getFirstPassenger() != getOwner()) { + if (getFirstPassenger() != player) { this.stack = ItemStack.EMPTY; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java index 1fff093e0..38667d06a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java @@ -19,7 +19,6 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.players.OldUsersConverter; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; @@ -29,7 +28,6 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MoverType; -import net.minecraft.world.entity.OwnableEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -44,18 +42,14 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.*; import software.bernie.geckolib.util.GeckoLibUtil; -import java.util.Optional; -import java.util.UUID; - import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector; -public class MortarEntity extends VehicleEntity implements GeoEntity, Container, OwnableEntity { +public class MortarEntity extends VehicleEntity implements GeoEntity, Container { public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor INTELLIGENT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN); - public static final EntityDataAccessor> OWNER_UUID = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.OPTIONAL_UUID); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -83,8 +77,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container, builder.define(FIRE_TIME, 0) .define(PITCH, -70f) .define(YAW, this.getYRot()) - .define(INTELLIGENT, false) - .define(OWNER_UUID, Optional.empty()); + .define(INTELLIGENT, false); } @Override @@ -98,9 +91,6 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container, compound.putFloat("Pitch", this.entityData.get(PITCH)); compound.putFloat("Yaw", this.entityData.get(YAW)); compound.putBoolean("Intelligent", this.entityData.get(INTELLIGENT)); - if (this.getOwnerUUID() != null) { - compound.putUUID("Owner", this.getOwnerUUID()); - } } @Override @@ -115,31 +105,6 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container, if (compound.contains("Intelligent")) { this.entityData.set(INTELLIGENT, compound.getBoolean("Intelligent")); } - UUID uuid; - if (compound.hasUUID("Owner")) { - uuid = compound.getUUID("Owner"); - } else { - String s = compound.getString("Owner"); - - assert this.getServer() != null; - uuid = OldUsersConverter.convertMobOwnerIfNecessary(this.getServer(), s); - } - - if (uuid != null) { - try { - this.setOwnerUUID(uuid); - } catch (Throwable ignored) { - } - } - } - - public void setOwnerUUID(@Nullable UUID pUuid) { - this.entityData.set(OWNER_UUID, Optional.ofNullable(pUuid)); - } - - @Nullable - public UUID getOwnerUUID() { - return this.entityData.get(OWNER_UUID).orElse(null); } public void fire(@Nullable LivingEntity shooter) { @@ -159,7 +124,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container, public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) { ItemStack mainHandItem = player.getMainHandItem(); - if (mainHandItem.getItem() instanceof ArtilleryIndicator indicator && player == getOwner() && this.entityData.get(INTELLIGENT)) { + if (mainHandItem.getItem() instanceof ArtilleryIndicator indicator && this.entityData.get(INTELLIGENT)) { if (indicator.addCannon(mainHandItem, getStringUUID())) { if (player instanceof ServerPlayer serverPlayer) { serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1); @@ -178,7 +143,6 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container, } if (mainHandItem.getItem() instanceof Monitor && player.isShiftKeyDown() && !this.entityData.get(INTELLIGENT)) { - setOwnerUUID(player.getUUID()); entityData.set(INTELLIGENT, true); if (player instanceof ServerPlayer serverPlayer) { serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1); @@ -281,7 +245,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container, if (level instanceof ServerLevel server) { MortarShellEntity entityToSpawn = MortarShell.createShell(shooter, level, this.stack); entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ()); - entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 13f, (float) 1); + entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 13f, (float) 0.4); level.addFreshEntity(entityToSpawn); server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, 0.007);