移除火炮的主人(
This commit is contained in:
parent
f876137e17
commit
8c7169a01a
3 changed files with 12 additions and 136 deletions
|
@ -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<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Optional<UUID>> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
|
||||
|
@ -74,8 +69,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
|
|||
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
public static final EntityDataAccessor<Optional<UUID>> OWNER_UUID = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.OPTIONAL_UUID);
|
||||
|
||||
private final float shellGravity = 0.1f;
|
||||
|
||||
public Mle1934Entity(EntityType<Mle1934Entity> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Integer> FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Boolean> INTELLIGENT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<Optional<UUID>> 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue